Restore old behavior of ALEFix command for Rubocop (#3237)

* Restore old behavior of ALEFix command for Rubocop

Since RuboCop 0.60 ALEFix command stopped to fix all found offenses. This change restores the 
previous behavior by allowing rubocop to fix all detected offenses.

* Fix tests
* Allow to configure auto-correct option for Rubocop
This commit is contained in:
Nihad Abbasov 2020-08-12 16:04:54 +03:00 committed by GitHub
parent d3f410b6f7
commit d5912b53dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -1,15 +1,18 @@
call ale#Set('ruby_rubocop_options', '')
call ale#Set('ruby_rubocop_auto_correct_all', 0)
call ale#Set('ruby_rubocop_executable', 'rubocop')
function! ale#fixers#rubocop#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
let l:auto_correct_all = ale#Var(a:buffer, 'ruby_rubocop_auto_correct_all')
return ale#ruby#EscapeExecutable(l:executable, 'rubocop')
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --auto-correct --force-exclusion %t'
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
\ . ' --force-exclusion %t'
endfunction
function! ale#fixers#rubocop#Fix(buffer) abort

View file

@ -114,6 +114,14 @@ g:ale_ruby_rubocop_options *g:ale_ruby_rubocop_options*
This variable can be changed to modify flags given to rubocop.
g:ale_ruby_rubocop_auto_correct_all *g:ale_ruby_rubocop_options*
*b:ale_ruby_rubocop_options*
Type: Number
Default: `0`
This variable can be changed to make rubocop to correct all offenses (unsafe).
===============================================================================
ruby *ale-ruby-ruby*

View file

@ -52,3 +52,16 @@ Execute(The rubocop callback should include custom rubocop options):
\ . ' --auto-correct --force-exclusion %t',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))
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('ruby_paths/with_config/dummy.rb')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
\ . ' --auto-correct-all --force-exclusion %t',
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))