diff options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/xo.vim | 29 | ||||
-rw-r--r-- | autoload/ale/handlers/xo.vim | 6 |
2 files changed, 33 insertions, 2 deletions
diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 6c2901db..2c8ab114 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -14,10 +14,35 @@ function! ale#fixers#xo#Fix(buffer) abort let l:executable = ale#handlers#xo#GetExecutable(a:buffer, l:type) let l:options = ale#handlers#xo#GetOptions(a:buffer, l:type) + return ale#semver#RunWithVersionCheck( + \ a:buffer, + \ l:executable, + \ '%e --version', + \ {b, v -> ale#fixers#xo#ApplyFixForVersion(b, v, l:executable, l:options)} + \) +endfunction + +function! ale#fixers#xo#ApplyFixForVersion(buffer, version, executable, options) abort + let l:executable = ale#node#Executable(a:buffer, a:executable) + let l:options = ale#Pad(a:options) + + " 0.30.0 is the first version with a working --stdin --fix + if ale#semver#GTE(a:version, [0, 30, 0]) + let l:project_root = ale#handlers#xo#GetProjectRoot(a:buffer) + + return { + \ 'command': ale#path#CdString(l:project_root) + \ . l:executable + \ . ' --stdin --stdin-filename %s' + \ . ' --fix' + \ . l:options, + \} + endif + return { - \ 'command': ale#node#Executable(a:buffer, l:executable) + \ 'command': l:executable \ . ' --fix %t' - \ . ale#Pad(l:options), + \ . l:options, \ 'read_temporary_file': 1, \} endfunction diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 3f7c72cb..0bea74e4 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -27,3 +27,9 @@ endfunction function! ale#handlers#xo#HandleJSON(buffer, lines) abort return ale#handlers#eslint#HandleJSON(a:buffer, a:lines) endfunction + +function! ale#handlers#xo#GetProjectRoot(buffer) abort + let l:package_path = ale#path#FindNearestFile(a:buffer, 'package.json') + + return empty(l:package_path) ? '' : fnamemodify(l:package_path, ':p:h') +endfunction |