File: xo.vim

package info (click to toggle)
vim-ale 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,764 kB
  • sloc: sh: 499; python: 311; perl: 31; makefile: 4; xml: 4; javascript: 1
file content (36 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
" Author: Albert Marquez - https://github.com/a-marquez
" Description: Fixing files with XO.

function! ale#fixers#xo#Fix(buffer) abort
    let l:executable = ale#handlers#xo#GetExecutable(a:buffer)
    let l:options = ale#handlers#xo#GetOptions(a:buffer)

    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])
        return {
        \   'command': l:executable
        \       . ' --stdin --stdin-filename %s'
        \       . ' --fix'
        \       . l:options,
        \}
    endif

    return {
    \   'command': l:executable
    \       . ' --fix %t'
    \       . l:options,
    \   'read_temporary_file': 1,
    \}
endfunction