Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See: https://github.com/testdouble/standard StandardRB is to RuboCop what StandardJS is to ESLint. This commit naively copies the RuboCop linter and fixer to point at the standardrb executable. Any other adjustments are very minor (the only I can think of is that standardrb takes a `--fix` option instead of `--auto-correct`). This raises a confusing point to me as both developer and a user: since ale enables all linters by default, won't this run both RuboCop and StandardRB (the results of which will almost always be in conflict with one another)? How does ale already solve for this for the similar case of StandardJS and ESLint?
- Loading branch information
1 parent
c899ff3
commit 2cfa09e
Showing
12 changed files
with
198 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
" Author: Justin Searls https://github.com/searls, ynonp - https://github.com/ynonp, Eddie Lebow https://github.com/elebow | ||
" based on the ale rubocop linter | ||
" Description: StandardRB - Ruby Style Guide, with linter & automatic code fixer | ||
|
||
call ale#Set('ruby_standardrb_executable', 'standardrb') | ||
call ale#Set('ruby_standardrb_options', '') | ||
|
||
function! ale_linters#ruby#standardrb#GetCommand(buffer) abort | ||
let l:executable = ale#Var(a:buffer, 'ruby_standardrb_executable') | ||
|
||
return ale#handlers#ruby#EscapeExecutable(l:executable, 'standardrb') | ||
\ . ' --format json --force-exclusion ' | ||
\ . ale#Var(a:buffer, 'ruby_standardrb_options') | ||
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p')) | ||
endfunction | ||
|
||
" standardrb is based on RuboCop so the callback is the same | ||
call ale#linter#Define('ruby', { | ||
\ 'name': 'standardrb', | ||
\ 'executable_callback': ale#VarFunc('ruby_standardrb_executable'), | ||
\ 'command_callback': 'ale_linters#ruby#standardrb#GetCommand', | ||
\ 'callback': 'ale#ruby#HandleRubocopOutput', | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
" Author: Justin Searls - https://github.com/searls | ||
" Description: Fix Ruby files with StandardRB. | ||
|
||
call ale#Set('ruby_standardrb_options', '') | ||
call ale#Set('ruby_standardrb_executable', 'standardrb') | ||
|
||
function! ale#fixers#standardrb#GetCommand(buffer) abort | ||
let l:executable = ale#Var(a:buffer, 'ruby_standardrb_executable') | ||
let l:config = ale#path#FindNearestFile(a:buffer, '.standard.yml') | ||
let l:options = ale#Var(a:buffer, 'ruby_standardrb_options') | ||
|
||
return ale#handlers#ruby#EscapeExecutable(l:executable, 'standardrb') | ||
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '') | ||
\ . (!empty(l:options) ? ' ' . l:options : '') | ||
\ . ' --fix --force-exclusion %t' | ||
endfunction | ||
|
||
function! ale#fixers#standardrb#Fix(buffer) abort | ||
return { | ||
\ 'command': ale#fixers#standardrb#GetCommand(a:buffer), | ||
\ 'read_temporary_file': 1, | ||
\} | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
29 changes: 29 additions & 0 deletions
29
test/command_callback/test_standardrb_command_callback.vader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Before: | ||
call ale#assert#SetUpLinterTest('ruby', 'standardrb') | ||
call ale#test#SetFilename('dummy.rb') | ||
|
||
let g:ale_ruby_standardrb_executable = 'standardrb' | ||
let g:ale_ruby_standardrb_options = '' | ||
|
||
After: | ||
call ale#assert#TearDownLinterTest() | ||
|
||
Execute(Executable should default to standardrb): | ||
AssertLinter 'standardrb', ale#Escape('standardrb') | ||
\ . ' --format json --force-exclusion --stdin ' | ||
\ . ale#Escape(ale#path#Simplify(g:dir . '/dummy.rb')) | ||
|
||
Execute(Should be able to set a custom executable): | ||
let g:ale_ruby_standardrb_executable = 'bin/standardrb' | ||
|
||
AssertLinter 'bin/standardrb' , ale#Escape('bin/standardrb') | ||
\ . ' --format json --force-exclusion --stdin ' | ||
\ . ale#Escape(ale#path#Simplify(g:dir . '/dummy.rb')) | ||
|
||
Execute(Setting bundle appends 'exec standardrb'): | ||
let g:ale_ruby_standardrb_executable = 'path to/bundle' | ||
|
||
AssertLinter 'path to/bundle', ale#Escape('path to/bundle') | ||
\ . ' exec standardrb' | ||
\ . ' --format json --force-exclusion --stdin ' | ||
\ . ale#Escape(ale#path#Simplify(g:dir . '/dummy.rb')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Before: | ||
Save g:ale_ruby_standardrb_executable | ||
Save g:ale_ruby_standardrb_options | ||
|
||
" Use an invalid global executable, so we don't match it. | ||
let g:ale_ruby_standardrb_executable = 'xxxinvalid' | ||
let g:ale_ruby_standardrb_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 standardrb 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_standardrb_executable) | ||
\ . ' --fix --force-exclusion %t', | ||
\ }, | ||
\ ale#fixers#standardrb#Fix(bufnr('')) | ||
|
||
Execute(The standardrb callback should include configuration files): | ||
call ale#test#SetFilename('ruby_paths/with_config/dummy.rb') | ||
|
||
AssertEqual | ||
\ { | ||
\ 'read_temporary_file': 1, | ||
\ 'command': ale#Escape(g:ale_ruby_standardrb_executable) | ||
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.standard.yml')) | ||
\ . ' --fix --force-exclusion %t', | ||
\ }, | ||
\ ale#fixers#standardrb#Fix(bufnr('')) | ||
|
||
Execute(The standardrb callback should include custom rubocop options): | ||
let g:ale_ruby_standardrb_options = '--except Lint/Debugger' | ||
call ale#test#SetFilename('ruby_paths/with_config/dummy.rb') | ||
|
||
AssertEqual | ||
\ { | ||
\ 'read_temporary_file': 1, | ||
\ 'command': ale#Escape(g:ale_ruby_standardrb_executable) | ||
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.standard.yml')) | ||
\ . ' --except Lint/Debugger' | ||
\ . ' --fix --force-exclusion %t', | ||
\ }, | ||
\ ale#fixers#standardrb#Fix(bufnr('')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters