summaryrefslogtreecommitdiff
path: root/autoload/ale/fixers/xo.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/ale/fixers/xo.vim')
-rw-r--r--autoload/ale/fixers/xo.vim29
1 files changed, 27 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