mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-17 15:34:14 +08:00
Fix #988 - Support --fix-dry-run for ESLint where available, and --fix-to-stdout for eslint_d
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user