#852 Capture error codes for ESLint

This commit is contained in:
w0rp 2017-11-13 23:21:45 +00:00
parent 764a33b1c9
commit 8a3a2da87e
2 changed files with 30 additions and 19 deletions

View File

@ -48,7 +48,7 @@ function! ale#handlers#eslint#GetCommand(buffer) abort
endfunction
let s:col_end_patterns = [
\ '\vParsing error: Unexpected token (.+) ',
\ '\vParsing error: Unexpected token (.+) ?',
\ '\v''(.+)'' is not defined.',
\ '\v%(Unexpected|Redundant use of) [''`](.+)[''`]',
\ '\vUnexpected (console) statement',
@ -111,7 +111,6 @@ function! ale#handlers#eslint#Handle(buffer, lines) abort
let l:output = []
for l:match in ale#util#GetMatches(a:lines, [l:pattern, l:parsing_pattern])
let l:type = 'Error'
let l:text = l:match[3]
if ale#Var(a:buffer, 'javascript_eslint_suppress_eslintignore')
@ -120,19 +119,24 @@ function! ale#handlers#eslint#Handle(buffer, lines) abort
endif
endif
" Take the error type from the output if available.
if !empty(l:match[4])
let l:type = split(l:match[4], '/')[0]
let l:text .= ' [' . l:match[4] . ']'
endif
let l:obj = {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type is# 'Warning' ? 'W' : 'E',
\ 'type': 'E',
\}
" Take the error type from the output if available.
let l:split_code = split(l:match[4], '/')
if get(l:split_code, 0, '') is# 'Warning'
let l:obj.type = 'W'
endif
if !empty(get(l:split_code, 1))
let l:obj.code = l:split_code[1]
endif
for l:col_match in ale#util#GetMatches(l:text, s:col_end_patterns)
let l:obj.end_col = l:obj.col + len(l:col_match[1]) - 1
endfor

View File

@ -19,13 +19,15 @@ Execute(The eslint handler should parse lines correctly):
\ {
\ 'lnum': 47,
\ 'col': 14,
\ 'text': 'Missing trailing comma. [Warning/comma-dangle]',
\ 'text': 'Missing trailing comma.',
\ 'code': 'comma-dangle',
\ 'type': 'W',
\ },
\ {
\ 'lnum': 56,
\ 'col': 41,
\ 'text': 'Missing semicolon. [Error/semi]',
\ 'text': 'Missing semicolon.',
\ 'code': 'semi',
\ 'type': 'E',
\ },
\ {
@ -259,42 +261,47 @@ Execute(The eslint handler should output end_col values where appropriate):
\ 'lnum': 4,
\ 'col': 3,
\ 'end_col': 15,
\ 'text': 'Parsing error: Unexpected token ''some string'' [Error]',
\ 'text': 'Parsing error: Unexpected token ''some string''',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 70,
\ 'col': 3,
\ 'end_col': 5,
\ 'text': '''foo'' is not defined. [Error/no-undef]',
\ 'text': '''foo'' is not defined.',
\ 'code': 'no-undef',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 71,
\ 'col': 2,
\ 'end_col': 6,
\ 'text': 'Unexpected `await` inside a loop. [Error/no-await-in-loop]',
\ 'text': 'Unexpected `await` inside a loop.',
\ 'code': 'no-await-in-loop',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 72,
\ 'col': 6,
\ 'end_col': 10,
\ 'text': 'Redundant use of `await` on a return value. [Error/no-return-await]',
\ 'text': 'Redundant use of `await` on a return value.',
\ 'code': 'no-return-await',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 73,
\ 'col': 4,
\ 'end_col': 10,
\ 'text': 'Unexpected console statement [Error/no-console]',
\ 'text': 'Unexpected console statement',
\ 'code': 'no-console',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 74,
\ 'col': 4,
\ 'end_col': 11,
\ 'text': 'Unexpected ''debugger'' statement. [Error/no-debugger]',
\ 'text': 'Unexpected ''debugger'' statement.',
\ 'code': 'no-debugger',
\ 'type': 'E',
\ },
\ ],
@ -316,7 +323,7 @@ Execute(The eslint hint about using typescript-eslint-parser):
\ 'lnum': 451,
\ 'col': 2,
\ 'end_col': 2,
\ 'text': 'Parsing error (You may need configure typescript-eslint-parser): Unexpected token ) [Error]',
\ 'text': 'Parsing error (You may need configure typescript-eslint-parser): Unexpected token )',
\ 'type': 'E',
\ },
\ ],
@ -330,7 +337,7 @@ Execute(eslint should warn about ignored files by default):
\ 'lnum': 0,
\ 'col': 0,
\ 'type': 'W',
\ 'text': 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]'
\ 'text': 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.'
\ }],
\ ale#handlers#eslint#Handle(bufnr(''), [
\ '/path/to/some/ignored.js:0:0: File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]',