Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions autoload/ale/fixers/rubocop.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
call ale#Set('ruby_rubocop_options', '')
call ale#Set('ruby_rubocop_auto_correct_all', 0)
call ale#Set('ruby_rubocop_executable', 'rubocop')
call ale#Set('ruby_rubocop_editor_mode', '1')

" Rubocop fixer outputs diagnostics first and then the fixed
" output. These are delimited by a "=======" string that we
Expand All @@ -23,10 +24,12 @@ function! ale#fixers#rubocop#GetCommand(buffer) 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#Var(a:buffer, 'ruby_rubocop_editor_mode')

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

Expand Down
12 changes: 12 additions & 0 deletions doc/ale-ruby.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ g:ale_ruby_rubocop_auto_correct_all
This variable can be changed to make rubocop to correct all offenses (unsafe).


*ale-options.ruby_rubocop_editor_mode*
*g:ale_ruby_rubocop_editor_mode*
*b:ale_ruby_rubocop_editor_mode*
ruby_rubocop_editor_mode
g:ale_ruby_rubocop_editor_mode
Type: |Number|
Default: `1`

This variable can be changed to 0 to run rubocop without the `--editor-mode`
flag (if using RuboCop < v1.61.0).


===============================================================================
ruby *ale-ruby-ruby*

Expand Down
18 changes: 15 additions & 3 deletions test/fixers/test_rubocop_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Execute(The rubocop callback should return the correct default values):
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct --force-exclusion --stdin %s',
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))

Expand All @@ -33,7 +33,7 @@ Execute(The rubocop callback should include custom rubocop options):
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --except Lint/Debugger'
\ . ' --auto-correct --force-exclusion --stdin %s',
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))

Expand All @@ -45,7 +45,7 @@ Execute(The rubocop callback should use auto-correct-all option when set):
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct-all --force-exclusion --stdin %s'
\ . ' --auto-correct-all --editor-mode --force-exclusion --stdin %s'
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))

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

Execute(The rubocop callback should not use editor-mode option when configured not to):
let g:ale_ruby_rubocop_editor_mode = 0
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

AssertEqual
\ {
\ '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(''))