Skip to content

Commit b4b228c

Browse files
committed
Make this a non-breaking change
This will detect the current rubocop version and auto-enable --editor-mode for newer version of rubocop without affecting users of older versions of rubocop.
1 parent b8a90cf commit b4b228c

File tree

3 files changed

+38
-44
lines changed

3 files changed

+38
-44
lines changed

autoload/ale/fixers/rubocop.vim

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
call ale#Set('ruby_rubocop_options', '')
22
call ale#Set('ruby_rubocop_auto_correct_all', 0)
33
call ale#Set('ruby_rubocop_executable', 'rubocop')
4-
call ale#Set('ruby_rubocop_editor_mode', '1')
54

65
" Rubocop fixer outputs diagnostics first and then the fixed
76
" output. These are delimited by a "=======" string that we
@@ -20,11 +19,11 @@ function! ale#fixers#rubocop#PostProcess(buffer, output) abort
2019
return a:output[l:line :]
2120
endfunction
2221

23-
function! ale#fixers#rubocop#GetCommand(buffer) abort
22+
function! ale#fixers#rubocop#GetCommand(buffer, version) abort
2423
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
2524
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
2625
let l:auto_correct_all = ale#Var(a:buffer, 'ruby_rubocop_auto_correct_all')
27-
let l:editor_mode= ale#Var(a:buffer, 'ruby_rubocop_editor_mode')
26+
let l:editor_mode = ale#semver#GTE(a:version, [1, 61, 0])
2827

2928
return ale#ruby#EscapeExecutable(l:executable, 'rubocop')
3029
\ . (!empty(l:options) ? ' ' . l:options : '')
@@ -33,9 +32,21 @@ function! ale#fixers#rubocop#GetCommand(buffer) abort
3332
\ . ' --force-exclusion --stdin %s'
3433
endfunction
3534

36-
function! ale#fixers#rubocop#Fix(buffer) abort
35+
function! ale#fixers#rubocop#GetCommandForVersion(buffer, version) abort
3736
return {
38-
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
39-
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
37+
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer, a:version),
38+
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
4039
\}
4140
endfunction
41+
42+
function! ale#fixers#rubocop#Fix(buffer) abort
43+
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
44+
let l:command = l:executable . ale#Pad('--version')
45+
46+
return ale#semver#RunWithVersionCheck(
47+
\ a:buffer,
48+
\ l:executable,
49+
\ l:command,
50+
\ function('ale#fixers#rubocop#GetCommandForVersion'),
51+
\)
52+
endfunction

doc/ale-ruby.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,6 @@ g:ale_ruby_rubocop_auto_correct_all
187187
This variable can be changed to make rubocop to correct all offenses (unsafe).
188188

189189

190-
*ale-options.ruby_rubocop_editor_mode*
191-
*g:ale_ruby_rubocop_editor_mode*
192-
*b:ale_ruby_rubocop_editor_mode*
193-
ruby_rubocop_editor_mode
194-
g:ale_ruby_rubocop_editor_mode
195-
Type: |Number|
196-
Default: `1`
197-
198-
This variable can be changed to 0 to run rubocop without the `--editor-mode`
199-
flag (if using RuboCop < v1.61.0).
200-
201-
202190
===============================================================================
203191
ruby *ale-ruby-ruby*
204192

test/fixers/test_rubocop_fixer_callback.vader

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
11
Before:
2-
Save g:ale_ruby_rubocop_executable
3-
Save g:ale_ruby_rubocop_options
4-
5-
" Use an invalid global executable, so we don't match it.
6-
let g:ale_ruby_rubocop_executable = 'xxxinvalid'
7-
let g:ale_ruby_rubocop_options = ''
8-
9-
call ale#test#SetDirectory('/testplugin/test/fixers')
2+
call ale#assert#SetUpFixerTest('ruby', 'rubocop')
103

114
After:
12-
Restore
13-
14-
call ale#test#RestoreDirectory()
5+
call ale#assert#TearDownFixerTest()
156

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

19-
AssertEqual
10+
GivenCommandOutput ['1.61.0']
11+
12+
AssertFixer
2013
\ {
2114
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
2215
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
2316
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
24-
\ },
25-
\ ale#fixers#rubocop#Fix(bufnr(''))
17+
\ }
2618

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

31-
AssertEqual
23+
GivenCommandOutput ['1.61.0']
24+
25+
AssertFixer
3226
\ {
3327
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
3428
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
3529
\ . ' --except Lint/Debugger'
3630
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
37-
\ },
38-
\ ale#fixers#rubocop#Fix(bufnr(''))
31+
\ }
3932

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

44-
AssertEqual
37+
GivenCommandOutput ['1.61.0']
38+
39+
AssertFixer
4540
\ {
4641
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
4742
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
4843
\ . ' --auto-correct-all --editor-mode --force-exclusion --stdin %s'
49-
\ },
50-
\ ale#fixers#rubocop#Fix(bufnr(''))
44+
\ }
5145

5246
Execute(The rubocop post-processor should remove diagnostics content):
5347
AssertEqual
@@ -88,14 +82,15 @@ Execute(The rubocop post-processor should remove diagnostics content):
8882
\ ' ''run'']',
8983
\ ])
9084

91-
Execute(The rubocop callback should not use editor-mode option when configured not to):
92-
let g:ale_ruby_rubocop_editor_mode = 0
85+
Execute(The rubocop callback should not use editor-mode option with older versions):
9386
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
9487

95-
AssertEqual
88+
GivenCommandOutput ['1.59.0']
89+
90+
AssertFixer
9691
\ {
9792
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
9893
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
99-
\ . ' --auto-correct-all --force-exclusion --stdin %s'
100-
\ },
101-
\ ale#fixers#rubocop#Fix(bufnr(''))
94+
\ . ' --auto-correct --force-exclusion --stdin %s'
95+
\ }
96+

0 commit comments

Comments
 (0)