Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions autoload/ale/fixers/rubocop.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,34 @@ function! ale#fixers#rubocop#PostProcess(buffer, output) abort
return a:output[l:line :]
endfunction

function! ale#fixers#rubocop#GetCommand(buffer) abort
function! ale#fixers#rubocop#GetCommand(buffer, version) abort
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
let l:auto_correct_all = ale#Var(a:buffer, 'ruby_rubocop_auto_correct_all')
let l:editor_mode = ale#semver#GTE(a:version, [1, 61, 0])

return ale#ruby#EscapeExecutable(l:executable, 'rubocop')
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
\ . (l:editor_mode ? ' --editor-mode' : '')
\ . ' --force-exclusion --stdin %s'
endfunction

function! ale#fixers#rubocop#Fix(buffer) abort
function! ale#fixers#rubocop#GetCommandForVersion(buffer, version) abort
return {
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer, a:version),
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
\}
endfunction

function! ale#fixers#rubocop#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
let l:command = l:executable . ale#Pad('--version')

return ale#semver#RunWithVersionCheck(
\ a:buffer,
\ l:executable,
\ l:command,
\ function('ale#fixers#rubocop#GetCommandForVersion'),
\)
endfunction
53 changes: 30 additions & 23 deletions test/fixers/test_rubocop_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
Before:
Save g:ale_ruby_rubocop_executable
Save g:ale_ruby_rubocop_options

" Use an invalid global executable, so we don't match it.
let g:ale_ruby_rubocop_executable = 'xxxinvalid'
let g:ale_ruby_rubocop_options = ''

call ale#test#SetDirectory('/testplugin/test/fixers')
call ale#assert#SetUpFixerTest('ruby', 'rubocop')

After:
Restore

call ale#test#RestoreDirectory()
call ale#assert#TearDownFixerTest()

Execute(The rubocop callback should return the correct default values):
call ale#test#SetFilename('../test-files/ruby/dummy.rb')

AssertEqual
GivenCommandOutput ['1.61.0']

AssertFixer
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct --force-exclusion --stdin %s',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
\ }

Execute(The rubocop callback should include custom rubocop options):
let g:ale_ruby_rubocop_options = '--except Lint/Debugger'
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

AssertEqual
GivenCommandOutput ['1.61.0']

AssertFixer
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --except Lint/Debugger'
\ . ' --auto-correct --force-exclusion --stdin %s',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
\ }

Execute(The rubocop callback should use auto-correct-all option when set):
let g:ale_ruby_rubocop_auto_correct_all = 1
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

AssertEqual
GivenCommandOutput ['1.61.0']

AssertFixer
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct-all --force-exclusion --stdin %s'
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))
\ . ' --auto-correct-all --editor-mode --force-exclusion --stdin %s'
\ }

Execute(The rubocop post-processor should remove diagnostics content):
AssertEqual
Expand Down Expand Up @@ -87,3 +81,16 @@ Execute(The rubocop post-processor should remove diagnostics content):
\ ' ''forrest'',',
\ ' ''run'']',
\ ])

Execute(The rubocop callback should not use editor-mode option with older versions):
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

GivenCommandOutput ['1.59.0']

AssertFixer
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct --force-exclusion --stdin %s'
\ }