Add support for syntax_tree fixer (#4268)

This is the library that now powers prettier/plugin-ruby but is also
stands on its own: https://github.com/ruby-syntax-tree/syntax_tree
This commit is contained in:
Mo Lawson 2022-08-09 07:11:20 -05:00 committed by GitHub
parent 5063804d44
commit 233b681029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 0 deletions

View File

@ -221,6 +221,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['swift'],
\ 'description': 'Apply SwiftFormat to a file.',
\ },
\ 'syntax_tree': {
\ 'function': 'ale#fixers#syntax_tree#Fix',
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'Fix ruby files with stree write',
\ },
\ 'apple-swift-format': {
\ 'function': 'ale#fixers#appleswiftformat#Fix',
\ 'suggested_filetypes': ['swift'],

View File

@ -0,0 +1,19 @@
call ale#Set('ruby_syntax_tree_options', '')
call ale#Set('ruby_syntax_tree_executable', 'stree')
function! ale#fixers#syntax_tree#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_syntax_tree_executable')
let l:options = ale#Var(a:buffer, 'ruby_syntax_tree_options')
return ale#ruby#EscapeExecutable(l:executable, 'stree')
\ . ' write'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' %t'
endfunction
function! ale#fixers#syntax_tree#Fix(buffer) abort
return {
\ 'command': ale#fixers#syntax_tree#GetCommand(a:buffer),
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -219,5 +219,25 @@ g:ale_ruby_standardrb_options *g:ale_ruby_standardrb_options*
This variable can be changed to modify flags given to standardrb.
===============================================================================
syntax_tree *ale-ruby-syntax_tree*
g:ale_ruby_syntax_tree_executable *g:ale_ruby_syntax_tree_executable*
*b:ale_ruby_syntax_tree_executable*
Type: String
Default: `'stree'`
Override the invoked SyntaxTree binary. Set this to `'bundle'` to invoke
`'bundle` `exec` stree'.
g:ale_ruby_syntax_tree_options *g:ale_ruby_syntax_tree_options*
*b:ale_ruby_syntax_tree_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to SyntaxTree.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -529,6 +529,7 @@ Notes:
* `solargraph`
* `sorbet`
* `standardrb`
* `syntax_tree`
* Rust
* `cargo`!!
* `cspell`

View File

@ -3167,6 +3167,7 @@ documented in additional help files.
solargraph............................|ale-ruby-solargraph|
sorbet................................|ale-ruby-sorbet|
standardrb............................|ale-ruby-standardrb|
syntax_tree...........................|ale-ruby-syntax_tree|
rust....................................|ale-rust-options|
analyzer..............................|ale-rust-analyzer|
cargo.................................|ale-rust-cargo|

View File

@ -538,6 +538,7 @@ formatting.
* [solargraph](https://solargraph.org)
* [sorbet](https://github.com/sorbet/sorbet)
* [standardrb](https://github.com/testdouble/standard)
* [syntax_tree](https://github.com/ruby-syntax-tree/syntax_tree)
* Rust
* [cargo](https://github.com/rust-lang/cargo) :floppy_disk: (see `:help ale-integration-rust` for configuration instructions)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)

View File

@ -0,0 +1,37 @@
Before:
Save g:ale_ruby_syntax_tree_executable
Save g:ale_ruby_syntax_tree_options
" Use an invalid global executable, so we don't match it.
let g:ale_ruby_syntax_tree_executable = 'xxxinvalid'
let g:ale_ruby_syntax_tree_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The syntax_tree callback should return the correct default values):
call ale#test#SetFilename('../test-files/ruby/dummy.rb')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_ruby_syntax_tree_executable)
\ . ' write %t',
\ },
\ ale#fixers#syntax_tree#Fix(bufnr(''))
Execute(The syntax_tree callback should include custom options):
let g:ale_ruby_syntax_tree_options = '--print-width=100 --plugins=plugin/trailing_comma'
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_ruby_syntax_tree_executable)
\ . ' write --print-width=100 --plugins=plugin/trailing_comma %t',
\ },
\ ale#fixers#syntax_tree#Fix(bufnr(''))