mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 05:24:46 +08:00
Fix 1695 - Change rubocop fixer to use stdin (#3230)
* Fix 1695 - Change rubocop fixer to use stdin * Update test_rubocop_fixer_callback.vader Co-authored-by: Horacio Sanson <horacio@allm.inc> Co-authored-by: w0rp <w0rp@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,23 @@ call ale#Set('ruby_rubocop_options', '')
|
|||||||
call ale#Set('ruby_rubocop_auto_correct_all', 0)
|
call ale#Set('ruby_rubocop_auto_correct_all', 0)
|
||||||
call ale#Set('ruby_rubocop_executable', 'rubocop')
|
call ale#Set('ruby_rubocop_executable', 'rubocop')
|
||||||
|
|
||||||
|
" Rubocop fixer outputs diagnostics first and then the fixed
|
||||||
|
" output. These are delimited by a "=======" string that we
|
||||||
|
" look for to remove everything before it.
|
||||||
|
function! ale#fixers#rubocop#PostProcess(buffer, output) abort
|
||||||
|
let l:line = 0
|
||||||
|
|
||||||
|
for l:output in a:output
|
||||||
|
let l:line = l:line + 1
|
||||||
|
|
||||||
|
if l:output =~# "^=\\+$"
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return a:output[l:line :]
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#rubocop#GetCommand(buffer) abort
|
function! ale#fixers#rubocop#GetCommand(buffer) abort
|
||||||
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||||
let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
||||||
@@ -12,12 +29,13 @@ function! ale#fixers#rubocop#GetCommand(buffer) abort
|
|||||||
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
|
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
|
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
|
||||||
\ . ' --force-exclusion %t'
|
\ . ' --force-exclusion --stdin '
|
||||||
|
\ . ale#Escape(expand('#' . a:buffer . ':p'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#rubocop#Fix(buffer) abort
|
function! ale#fixers#rubocop#Fix(buffer) abort
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
|
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
|
||||||
\ 'read_temporary_file': 1,
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ Execute(The rubocop callback should return the correct default values):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --auto-correct --force-exclusion %t',
|
\ . ' --auto-correct --force-exclusion --stdin '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||||
|
|
||||||
@@ -32,10 +33,11 @@ Execute(The rubocop callback should include configuration files):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
||||||
\ . ' --auto-correct --force-exclusion %t',
|
\ . ' --auto-correct --force-exclusion --stdin '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||||
|
|
||||||
@@ -45,11 +47,12 @@ Execute(The rubocop callback should include custom rubocop options):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
||||||
\ . ' --except Lint/Debugger'
|
\ . ' --except Lint/Debugger'
|
||||||
\ . ' --auto-correct --force-exclusion %t',
|
\ . ' --auto-correct --force-exclusion --stdin '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||||
|
|
||||||
@@ -59,9 +62,49 @@ Execute(The rubocop callback should use auto-correct-all option when set):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
\ . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/ruby_paths/with_config/.rubocop.yml'))
|
||||||
\ . ' --auto-correct-all --force-exclusion %t',
|
\ . ' --auto-correct-all --force-exclusion --stdin '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The rubocop post-processor should remove diagnostics content):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ 'class MyModel < ApplicationRecord',
|
||||||
|
\ ' # rubocop:disable Rails/InverseOf',
|
||||||
|
\ ' has_one :something',
|
||||||
|
\ ' # rubocop:enable Rails/InverseOf',
|
||||||
|
\ 'end',
|
||||||
|
\ '',
|
||||||
|
\ 'array = [1, 2, 3,',
|
||||||
|
\ ' 4, 5, 6]',
|
||||||
|
\ 'array = [''run'',',
|
||||||
|
\ ' ''forrest'',',
|
||||||
|
\ ' ''run'']',
|
||||||
|
\ ],
|
||||||
|
\ ale#fixers#rubocop#PostProcess(bufnr(''), [
|
||||||
|
\ 'Inspecting 1 file',
|
||||||
|
\ 'C',
|
||||||
|
\ '',
|
||||||
|
\ 'Offenses:',
|
||||||
|
\ 'app/models/my_model.rb:8:3: C: [Corrected] Layout/ArrayAlignment: ',
|
||||||
|
\ '4, 5, 6]',
|
||||||
|
\ '^',
|
||||||
|
\ '',
|
||||||
|
\ '1 file inspected, 3 offenses detected, 3 offenses corrected',
|
||||||
|
\ '====================',
|
||||||
|
\ 'class MyModel < ApplicationRecord',
|
||||||
|
\ ' # rubocop:disable Rails/InverseOf',
|
||||||
|
\ ' has_one :something',
|
||||||
|
\ ' # rubocop:enable Rails/InverseOf',
|
||||||
|
\ 'end',
|
||||||
|
\ '',
|
||||||
|
\ 'array = [1, 2, 3,',
|
||||||
|
\ ' 4, 5, 6]',
|
||||||
|
\ 'array = [''run'',',
|
||||||
|
\ ' ''forrest'',',
|
||||||
|
\ ' ''run'']',
|
||||||
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user