Fix #1122 - Handle notes for shellcheck errors again, and use type 'I' for notes
This commit is contained in:
parent
a5f7f51c9a
commit
6c112dd1cc
@ -70,6 +70,41 @@ function! ale_linters#sh#shellcheck#GetCommand(buffer, version_output) abort
|
||||
\ . ' -f gcc -'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sh#shellcheck#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
if l:match[4] is# 'error'
|
||||
let l:type = 'E'
|
||||
elseif l:match[4] is# 'note'
|
||||
let l:type = 'I'
|
||||
else
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
let l:item = {
|
||||
\ 'lnum': str2nr(l:match[2]),
|
||||
\ 'type': l:type,
|
||||
\ 'text': l:match[5],
|
||||
\}
|
||||
|
||||
if !empty(l:match[3])
|
||||
let l:item.col = str2nr(l:match[3])
|
||||
endif
|
||||
|
||||
" If the filename is something like <stdin>, <nofile> or -, then
|
||||
" this is an error for the file we checked.
|
||||
if l:match[1] isnot# '-' && l:match[1][0] isnot# '<'
|
||||
let l:item['filename'] = l:match[1]
|
||||
endif
|
||||
|
||||
call add(l:output, l:item)
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('sh', {
|
||||
\ 'name': 'shellcheck',
|
||||
\ 'executable_callback': 'ale_linters#sh#shellcheck#GetExecutable',
|
||||
@ -77,5 +112,5 @@ call ale#linter#Define('sh', {
|
||||
\ {'callback': 'ale_linters#sh#shellcheck#VersionCheck'},
|
||||
\ {'callback': 'ale_linters#sh#shellcheck#GetCommand'},
|
||||
\ ],
|
||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||
\ 'callback': 'ale_linters#sh#shellcheck#Handle',
|
||||
\})
|
||||
|
40
test/handler/test_shellcheck_handler.vader
Normal file
40
test/handler/test_shellcheck_handler.vader
Normal file
@ -0,0 +1,40 @@
|
||||
Before:
|
||||
runtime ale_linters/shell/shellcheck.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The shellcheck handler should handle basic errors or warnings):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'In POSIX sh, ''let'' is not supported. [SC2039]',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 3,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Don''t put spaces around the = in assignments. [SC1068]',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#sh#shellcheck#Handle(bufnr(''), [
|
||||
\ '-:2:1: warning: In POSIX sh, ''let'' is not supported. [SC2039]',
|
||||
\ '-:2:3: error: Don''t put spaces around the = in assignments. [SC1068]',
|
||||
\ ])
|
||||
|
||||
Execute(The shellcheck handler should handle notes):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 3,
|
||||
\ 'col': 3,
|
||||
\ 'type': 'I',
|
||||
\ 'text': 'Double quote to prevent globbing and word splitting. [SC2086]',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#sh#shellcheck#Handle(bufnr(''), [
|
||||
\ '-:3:3: note: Double quote to prevent globbing and word splitting. [SC2086]',
|
||||
\ ])
|
Loading…
Reference in New Issue
Block a user