mirror of https://github.com/dense-analysis/ale
Improve elm linter (#637)
* Improve elm linter Some types of errors do not return nice JSON. Show them on the first line instead of showing nothing. * Remove unnecessary properties from elm linter * Add a vader test for elm-make linter * Test non-JSON elm-make errors are shown
This commit is contained in:
parent
93473a4101
commit
c2f69b7750
|
@ -5,6 +5,7 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort
|
|||
let l:output = []
|
||||
let l:is_windows = has('win32')
|
||||
let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
|
||||
let l:unparsed_lines = []
|
||||
for l:line in a:lines
|
||||
if l:line[0] ==# '['
|
||||
let l:errors = json_decode(l:line)
|
||||
|
@ -20,7 +21,6 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort
|
|||
|
||||
if l:file_is_buffer
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:error.region.start.line,
|
||||
\ 'col': l:error.region.start.column,
|
||||
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
||||
|
@ -29,9 +29,20 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort
|
|||
\})
|
||||
endif
|
||||
endfor
|
||||
elseif l:line !=# 'Successfully generated /dev/null'
|
||||
call add(l:unparsed_lines, l:line)
|
||||
endif
|
||||
endfor
|
||||
|
||||
if len(l:unparsed_lines) > 0
|
||||
call add(l:output, {
|
||||
\ 'lnum': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': l:unparsed_lines[0],
|
||||
\ 'detail': join(l:unparsed_lines, "\n")
|
||||
\})
|
||||
endif
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
Before:
|
||||
runtime ale_linters/elm/make.vim
|
||||
|
||||
Execute(The elm-make handler should parse lines correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 33,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'warning overview',
|
||||
\ 'detail': "warning overview\n\nwarning details",
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 404,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'error overview 1',
|
||||
\ 'detail': "error overview 1\n\nerror details 1",
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 406,
|
||||
\ 'col': 5,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'error overview 2',
|
||||
\ 'detail': "error overview 2\n\nerror details 2",
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 406,
|
||||
\ 'col': 5,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'error overview 3',
|
||||
\ 'detail': "error overview 3\n\nerror details 3",
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#elm#make#Handle(347, [
|
||||
\ '[{"tag":"unused import","overview":"warning overview","details":"warning details","region":{"start":{"line":33,"column":1},"end":{"line":33,"column":19}},"type":"warning","file":"' . $TMPDIR . 'Module.elm"}]',
|
||||
\ '[{"tag":"TYPE MISMATCH","overview":"error overview 1","subregion":{"start":{"line":406,"column":5},"end":{"line":408,"column":18}},"details":"error details 1","region":{"start":{"line":404,"column":1},"end":{"line":408,"column":18}},"type":"error","file":"' . $TMPDIR . 'Module.elm"},{"tag":"TYPE MISMATCH","overview":"error overview 2","subregion":{"start":{"line":407,"column":12},"end":{"line":407,"column":17}},"details":"error details 2","region":{"start":{"line":406,"column":5},"end":{"line":407,"column":17}},"type":"error","file":"' . $TMPDIR . 'Module.elm"},{"tag":"TYPE MISMATCH","overview":"error overview 3","subregion":{"start":{"line":406,"column":88},"end":{"line":406,"column":93}},"details":"error details 3","region":{"start":{"line":406,"column":5},"end":{"line":406,"column":93}},"type":"error","file":"' . $TMPDIR . 'Module.elm"}]'
|
||||
\ ])
|
||||
|
||||
Execute(The elm-make handler should put an error on the first line if a line cannot be parsed):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 33,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'warning overview',
|
||||
\ 'detail': "warning overview\n\nwarning details",
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Not JSON',
|
||||
\ 'detail': "Not JSON\nAlso not JSON",
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#elm#make#Handle(347, [
|
||||
\ '[{"tag":"unused import","overview":"warning overview","details":"warning details","region":{"start":{"line":33,"column":1},"end":{"line":33,"column":19}},"type":"warning","file":"' . $TMPDIR . 'Module.elm"}]',
|
||||
\ "Not JSON",
|
||||
\ "Also not JSON",
|
||||
\ ])
|
||||
|
||||
After:
|
||||
unlet! g:config_error_lines
|
||||
call ale#linter#Reset()
|
Loading…
Reference in New Issue