diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-22 23:23:14 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-22 23:23:14 +0000 |
commit | 5160f814d929e0936c3d920087e0c4d16040ae9c (patch) | |
tree | 185d2cf775d027a29f23534a54415626608fbbbe /autoload | |
parent | 6318a08e08716d460f8441457813875495050023 (diff) | |
download | ale-5160f814d929e0936c3d920087e0c4d16040ae9c.zip |
Fix #988 - Support --fix-dry-run for ESLint by processing the JSON output
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/eslint.vim | 17 | ||||
-rw-r--r-- | autoload/ale/util.vim | 9 |
2 files changed, 25 insertions, 1 deletions
diff --git a/autoload/ale/fixers/eslint.vim b/autoload/ale/fixers/eslint.vim index d30f1ba6..76615fb5 100644 --- a/autoload/ale/fixers/eslint.vim +++ b/autoload/ale/fixers/eslint.vim @@ -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) diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index cf8d5bec..1f590adc 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -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 |