mirror of https://github.com/dense-analysis/ale
Add Sorbet ruby linter and fixer (#2614)
This commit is contained in:
parent
6c47d7fc35
commit
abb38955d3
|
@ -0,0 +1,23 @@
|
|||
call ale#Set('ruby_sorbet_executable', 'srb')
|
||||
call ale#Set('ruby_sorbet_options', '')
|
||||
|
||||
function! ale_linters#ruby#sorbet#GetCommand(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'ruby_sorbet_executable')
|
||||
let l:options = ale#Var(a:buffer, 'ruby_sorbet_options')
|
||||
|
||||
return ale#handlers#ruby#EscapeExecutable(l:executable, 'srb')
|
||||
\ . ' tc'
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' --lsp --disable-watchman'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('ruby', {
|
||||
\ 'name': 'sorbet',
|
||||
\ 'aliases': ['srb'],
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'language': 'ruby',
|
||||
\ 'executable': {b -> ale#Var(b, 'ruby_sorbet_executable')},
|
||||
\ 'command': function('ale_linters#ruby#sorbet#GetCommand'),
|
||||
\ 'project_root': function('ale#ruby#FindProjectRoot')
|
||||
\})
|
||||
|
|
@ -115,6 +115,11 @@ let s:default_registry = {
|
|||
\ 'suggested_filetypes': ['scala'],
|
||||
\ 'description': 'Fix Scala files using scalafmt',
|
||||
\ },
|
||||
\ 'sorbet': {
|
||||
\ 'function': 'ale#fixers#sorbet#Fix',
|
||||
\ 'suggested_filetypes': ['ruby'],
|
||||
\ 'description': 'Fix ruby files with srb tc --autocorrect.',
|
||||
\ },
|
||||
\ 'standard': {
|
||||
\ 'function': 'ale#fixers#standard#Fix',
|
||||
\ 'suggested_filetypes': ['javascript'],
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
call ale#Set('ruby_sorbet_executable', 'srb')
|
||||
call ale#Set('ruby_sorbet_options', '')
|
||||
|
||||
function! ale#fixers#sorbet#GetCommand(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'ruby_sorbet_executable')
|
||||
let l:options = ale#Var(a:buffer, 'ruby_sorbet_options')
|
||||
|
||||
return ale#handlers#ruby#EscapeExecutable(l:executable, 'srb')
|
||||
\ . ' tc'
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' --autocorrect --file %t'
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#sorbet#Fix(buffer) abort
|
||||
return {
|
||||
\ 'command': ale#fixers#sorbet#GetCommand(a:buffer),
|
||||
\ 'read_temporary_file': 1,
|
||||
\}
|
||||
endfunction
|
|
@ -129,6 +129,26 @@ g:ale_ruby_solargraph_executable *g:ale_ruby_solargraph_executable*
|
|||
from binstubs or a bundle.
|
||||
|
||||
|
||||
===============================================================================
|
||||
sorbet *ale-ruby-sorbet*
|
||||
|
||||
g:ale_ruby_sorbet_executable *g:ale_ruby_sorbet_executable*
|
||||
*b:ale_ruby_sorbet_executable*
|
||||
Type: String
|
||||
Default: `'srb'`
|
||||
|
||||
Override the invoked sorbet binary. Set this to `'bundle'` to invoke
|
||||
`'bundle` `exec` srb'.
|
||||
|
||||
|
||||
g:ale_ruby_sorbet_options *g:ale_ruby_sorbet_options*
|
||||
*b:ale_ruby_sorbet_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be change to modify flags given to sorbet.
|
||||
|
||||
|
||||
===============================================================================
|
||||
standardrb *ale-ruby-standardrb*
|
||||
|
||||
|
|
|
@ -392,6 +392,7 @@ Notes:
|
|||
* `ruby`
|
||||
* `rufo`
|
||||
* `solargraph`
|
||||
* `sorbet`
|
||||
* `standardrb`
|
||||
* Rust
|
||||
* `cargo`!!
|
||||
|
|
|
@ -2220,6 +2220,7 @@ documented in additional help files.
|
|||
ruby..................................|ale-ruby-ruby|
|
||||
rufo..................................|ale-ruby-rufo|
|
||||
solargraph............................|ale-ruby-solargraph|
|
||||
sorbet................................|ale-ruby-sorbet|
|
||||
standardrb............................|ale-ruby-standardrb|
|
||||
rust....................................|ale-rust-options|
|
||||
cargo.................................|ale-rust-cargo|
|
||||
|
|
|
@ -401,6 +401,7 @@ formatting.
|
|||
* [ruby](https://www.ruby-lang.org)
|
||||
* [rufo](https://github.com/ruby-formatter/rufo)
|
||||
* [solargraph](https://solargraph.org)
|
||||
* [sorbet](https://github.com/sorbet/sorbet)
|
||||
* [standardrb](https://github.com/testdouble/standard)
|
||||
* Rust
|
||||
* [cargo](https://github.com/rust-lang/cargo) :floppy_disk: (see `:help ale-integration-rust` for configuration instructions)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('ruby', 'sorbet')
|
||||
call ale#test#SetFilename('dummy.rb')
|
||||
|
||||
let g:ale_ruby_sorbet_executable = 'srb'
|
||||
let g:ale_ruby_sorbet_options = ''
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(Executable should default to srb):
|
||||
AssertLinter 'srb', ale#Escape('srb')
|
||||
\ . ' tc --lsp --disable-watchman'
|
||||
|
||||
Execute(Should be able to set a custom executable):
|
||||
let g:ale_ruby_sorbet_executable = 'bin/srb'
|
||||
|
||||
AssertLinter 'bin/srb' , ale#Escape('bin/srb')
|
||||
\ . ' tc --lsp --disable-watchman'
|
||||
|
||||
Execute(Setting bundle appends 'exec srb tc'):
|
||||
let g:ale_ruby_sorbet_executable = 'path to/bundle'
|
||||
|
||||
AssertLinter 'path to/bundle', ale#Escape('path to/bundle')
|
||||
\ . ' exec srb'
|
||||
\ . ' tc --lsp --disable-watchman'
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
Before:
|
||||
Save g:ale_ruby_sorbet_executable
|
||||
Save g:ale_ruby_sorbet_options
|
||||
|
||||
" Use an invalid global executable, so we don't match it.
|
||||
let g:ale_ruby_sorbet_executable = 'xxxinvalid'
|
||||
let g:ale_ruby_sorbet_options = ''
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||
silent cd ..
|
||||
silent cd command_callback
|
||||
let g:dir = getcwd()
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(The sorbet callback should return the correct default values):
|
||||
call ale#test#SetFilename('ruby_paths/dummy.rb')
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape(g:ale_ruby_sorbet_executable)
|
||||
\ . ' tc --autocorrect --file %t',
|
||||
\ },
|
||||
\ ale#fixers#sorbet#Fix(bufnr(''))
|
||||
|
||||
Execute(The sorbet callback should include custom sorbet options):
|
||||
let g:ale_ruby_sorbet_options = '--enable-experimental-lsp-hover'
|
||||
call ale#test#SetFilename('ruby_paths/with_config/dummy.rb')
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape(g:ale_ruby_sorbet_executable)
|
||||
\ . ' tc --enable-experimental-lsp-hover'
|
||||
\ . ' --autocorrect --file %t',
|
||||
\ },
|
||||
\ ale#fixers#sorbet#Fix(bufnr(''))
|
Loading…
Reference in New Issue