mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 13:14:29 +08:00
Fix #988 - Support --fix-dry-run for ESLint by processing the JSON output
This commit is contained in:
@@ -14,6 +14,14 @@ function! ale#fixers#eslint#Fix(buffer) abort
|
||||
\}
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#eslint#ProcessFixDryRunOutput(buffer, output) abort
|
||||
for l:item in ale#util#FuzzyJSONDecode(a:output, [])
|
||||
return split(get(l:item, 'output', ''), "\n")
|
||||
endfor
|
||||
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#eslint#ApplyFixForVersion(buffer, version_output) abort
|
||||
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
|
||||
let l:version = ale#semver#GetVersion(l:executable, a:version_output)
|
||||
@@ -32,6 +40,15 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version_output) abort
|
||||
\}
|
||||
endif
|
||||
|
||||
" 4.9.0 is the first version with --fix-dry-run
|
||||
if ale#semver#GTE(l:version, [4, 9, 0])
|
||||
return {
|
||||
\ 'command': ale#node#Executable(a:buffer, l:executable)
|
||||
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
||||
\}
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': ale#node#Executable(a:buffer, l:executable)
|
||||
\ . ' -c ' . ale#Escape(l:config)
|
||||
|
||||
@@ -250,7 +250,14 @@ function! ale#util#FuzzyJSONDecode(data, default) abort
|
||||
let l:str = type(a:data) == type('') ? a:data : join(a:data, '')
|
||||
|
||||
try
|
||||
return json_decode(l:str)
|
||||
let l:result = json_decode(l:str)
|
||||
|
||||
" Vim 8 only uses the value v:none for decoding blank strings.
|
||||
if !has('nvim') && l:result is v:none
|
||||
return a:default
|
||||
endif
|
||||
|
||||
return l:result
|
||||
catch /E474/
|
||||
return a:default
|
||||
endtry
|
||||
|
||||
Reference in New Issue
Block a user