Fix #988 - Support --fix-dry-run for ESLint where available, and --fix-to-stdout for eslint_d

This commit is contained in:
w0rp
2017-11-22 16:51:04 +00:00
parent 91fe749d03
commit b5ec1a5fd0
2 changed files with 114 additions and 3 deletions

View File

@@ -3,12 +3,43 @@
function! ale#fixers#eslint#Fix(buffer) abort
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
let l:command = ale#semver#HasVersion(l:executable)
\ ? ''
\ : ale#node#Executable(a:buffer, l:executable) . ' --version'
return {
\ 'command': l:command,
\ 'chain_with': 'ale#fixers#eslint#ApplyFixForVersion',
\}
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)
let l:config = ale#handlers#eslint#FindConfig(a:buffer)
if empty(l:config)
return 0
endif
" Use --fix-to-stdout with eslint_d
if l:executable =~# 'eslint_d$' && ale#semver#GTE(l:version, [3, 19, 0])
return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
\}
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',
\}
endif
return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ' -c ' . ale#Escape(l:config)