Fix #1178 - Don't use the output from eslint_d for fixing files when the output is an error message

This commit is contained in:
w0rp 2017-11-29 10:08:54 +00:00
parent a43ada93e4
commit 6503b85d3d
2 changed files with 32 additions and 0 deletions

View File

@ -22,6 +22,17 @@ function! ale#fixers#eslint#ProcessFixDryRunOutput(buffer, output) abort
return [] return []
endfunction endfunction
function! ale#fixers#eslint#ProcessEslintDOutput(buffer, output) abort
" If the output is an error message, don't use it.
for l:line in a:output[:10]
if l:line =~# '^Error:'
return []
endif
endfor
return a:output
endfunction
function! ale#fixers#eslint#ApplyFixForVersion(buffer, version_output) abort function! ale#fixers#eslint#ApplyFixForVersion(buffer, version_output) abort
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer) let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
let l:version = ale#semver#GetVersion(l:executable, a:version_output) let l:version = ale#semver#GetVersion(l:executable, a:version_output)
@ -37,6 +48,7 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version_output) abort
return { return {
\ 'command': ale#node#Executable(a:buffer, l:executable) \ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ' --stdin-filename %s --stdin --fix-to-stdout', \ . ' --stdin-filename %s --stdin --fix-to-stdout',
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
\} \}
endif endif

View File

@ -101,6 +101,7 @@ Execute(--fix-to-stdout should be used for eslint_d):
\ 'command': \ 'command':
\ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d')) \ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
\ . ' --stdin-filename %s --stdin --fix-to-stdout', \ . ' --stdin-filename %s --stdin --fix-to-stdout',
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
\ }, \ },
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v3.19.0 (eslint_d v4.2.0)']) \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v3.19.0 (eslint_d v4.2.0)'])
@ -110,6 +111,7 @@ Execute(--fix-to-stdout should be used for eslint_d):
\ 'command': \ 'command':
\ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d')) \ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
\ . ' --stdin-filename %s --stdin --fix-to-stdout', \ . ' --stdin-filename %s --stdin --fix-to-stdout',
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
\ }, \ },
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0']) \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0'])
@ -150,3 +152,21 @@ Execute(The --fix-dry-run post-processor should handle JSON output correctly):
AssertEqual AssertEqual
\ ['foo', 'bar'], \ ['foo', 'bar'],
\ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{"output": "foo\nbar"}]']) \ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{"output": "foo\nbar"}]'])
Execute(The eslint_d post-processor should permit regular JavaScript content):
AssertEqual
\ [
\ 'const x = ''Error: foo''',
\ 'const y = 3',
\ ],
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
\ 'const x = ''Error: foo''',
\ 'const y = 3',
\ ])
Execute(The eslint_d post-processor should handle error messages correctly):
AssertEqual
\ [],
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
\ 'Error: No ESLint configuration found.',
\ ])