All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Fixing files with eslint.
4 function! ale#fixers#eslint#Fix(buffer) abort
5 let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
6 let l:command = ale#node#Executable(a:buffer, l:executable)
9 return ale#semver#RunWithVersionCheck(
13 \ function('ale#fixers#eslint#ApplyFixForVersion'),
17 function! ale#fixers#eslint#ProcessFixDryRunOutput(buffer, output) abort
18 for l:item in ale#util#FuzzyJSONDecode(a:output, [])
19 return split(get(l:item, 'output', ''), "\n")
25 function! ale#fixers#eslint#ProcessEslintDOutput(buffer, output) abort
26 " If the output is an error message, don't use it.
27 for l:line in a:output[:10]
28 if l:line =~# '\v^Error:|^Could not connect'
36 function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
37 let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
38 let l:options = ale#Var(a:buffer, 'javascript_eslint_options')
40 " Use the configuration file from the options, if configured.
41 if l:options =~# '\v(^| )-c|(^| )--config'
45 let l:config = ale#handlers#eslint#FindConfig(a:buffer)
46 let l:has_config = !empty(l:config)
53 " Use --fix-to-stdout with eslint_d
54 if l:executable =~# 'eslint_d$' && ale#semver#GTE(a:version, [3, 19, 0])
56 \ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
57 \ 'command': ale#node#Executable(a:buffer, l:executable)
58 \ . ale#Pad(l:options)
59 \ . ' --stdin-filename %s --stdin --fix-to-stdout',
60 \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
64 " 4.9.0 is the first version with --fix-dry-run
65 if ale#semver#GTE(a:version, [4, 9, 0])
67 \ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
68 \ 'command': ale#node#Executable(a:buffer, l:executable)
69 \ . ale#Pad(l:options)
70 \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
71 \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
76 \ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
77 \ 'command': ale#node#Executable(a:buffer, l:executable)
78 \ . ale#Pad(l:options)
79 \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
81 \ 'read_temporary_file': 1,