mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Make shellcheck respect ale_warn_about_trailing_whitespace
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
This commit is contained in:
@@ -63,6 +63,12 @@ function! ale#handlers#shellcheck#GetCommand(buffer, version) abort
|
|||||||
\ . ' -f ' . l:format . ' -'
|
\ . ' -f ' . l:format . ' -'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:ShouldIgnoreErrorCode(buffer, code) abort
|
||||||
|
" Skip warnings for trailing whitespace if the option is off.
|
||||||
|
return a:code is# 'SC1101'
|
||||||
|
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:HandleShellcheckJSON(buffer, lines) abort
|
function! s:HandleShellcheckJSON(buffer, lines) abort
|
||||||
try
|
try
|
||||||
let l:errors = json_decode(a:lines[0])
|
let l:errors = json_decode(a:lines[0])
|
||||||
@@ -87,11 +93,17 @@ function! s:HandleShellcheckJSON(buffer, lines) abort
|
|||||||
let l:type = 'W'
|
let l:type = 'W'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let l:code = 'SC' . l:error['code']
|
||||||
|
|
||||||
|
if s:ShouldIgnoreErrorCode(a:buffer, l:code)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
let l:item = {
|
let l:item = {
|
||||||
\ 'lnum': l:error['line'],
|
\ 'lnum': l:error['line'],
|
||||||
\ 'type': l:type,
|
\ 'type': l:type,
|
||||||
\ 'text': l:error['message'],
|
\ 'text': l:error['message'],
|
||||||
\ 'code': 'SC' . l:error['code'],
|
\ 'code': l:code,
|
||||||
\ 'detail': l:error['message'] . "\n\nFor more information:\n https://www.shellcheck.net/wiki/SC" . l:error['code'],
|
\ 'detail': l:error['message'] . "\n\nFor more information:\n https://www.shellcheck.net/wiki/SC" . l:error['code'],
|
||||||
\}
|
\}
|
||||||
|
|
||||||
@@ -107,7 +119,6 @@ function! s:HandleShellcheckJSON(buffer, lines) abort
|
|||||||
let l:item.end_lnum = l:error['endLine']
|
let l:item.end_lnum = l:error['endLine']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
" If the filename is something like <stdin>, <nofile> or -, then
|
" If the filename is something like <stdin>, <nofile> or -, then
|
||||||
" this is an error for the file we checked.
|
" this is an error for the file we checked.
|
||||||
if has_key(l:error, 'file')
|
if has_key(l:error, 'file')
|
||||||
@@ -135,11 +146,17 @@ function! s:HandleShellcheckGCC(buffer, lines) abort
|
|||||||
let l:type = 'W'
|
let l:type = 'W'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let l:code = l:match[6]
|
||||||
|
|
||||||
|
if s:ShouldIgnoreErrorCode(a:buffer, l:code)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
let l:item = {
|
let l:item = {
|
||||||
\ 'lnum': str2nr(l:match[2]),
|
\ 'lnum': str2nr(l:match[2]),
|
||||||
\ 'type': l:type,
|
\ 'type': l:type,
|
||||||
\ 'text': l:match[5],
|
\ 'text': l:match[5],
|
||||||
\ 'code': l:match[6],
|
\ 'code': l:code,
|
||||||
\ 'detail': l:match[5] . "\n\nFor more information:\n https://www.shellcheck.net/wiki/" . l:match[6],
|
\ 'detail': l:match[5] . "\n\nFor more information:\n https://www.shellcheck.net/wiki/" . l:match[6],
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
Before:
|
Before:
|
||||||
runtime ale_linters/shell/shellcheck.vim
|
Save g:ale_warn_about_trailing_whitespace
|
||||||
|
|
||||||
After:
|
After:
|
||||||
call ale#linter#Reset()
|
Restore
|
||||||
|
|
||||||
Execute(The shellcheck handler should handle basic errors or warnings <0.7.0):
|
Execute(The shellcheck handler should handle basic errors or warnings <0.7.0):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
@@ -150,3 +150,58 @@ Execute(The shellcheck handler should handle info and style >=0.7.0):
|
|||||||
\ ]
|
\ ]
|
||||||
\ }'
|
\ }'
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(shellcheck errors for trailing whitespace should show by default):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 8,
|
||||||
|
\ 'col': 12,
|
||||||
|
\ 'code': 'SC1101',
|
||||||
|
\ 'end_lnum': 8,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'end_col': 11,
|
||||||
|
\ 'text': 'Delete trailing spaces after \ to break line (or use quotes for literal space).',
|
||||||
|
\ 'detail': 'Delete trailing spaces after \ to break line (or use quotes for literal space).' . "\n\nFor more information:\n https://www.shellcheck.net/wiki/" . 'SC1101',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale#handlers#shellcheck#Handle(bufnr(''), [0, 7, 0], [
|
||||||
|
\ '{
|
||||||
|
\ "comments": [
|
||||||
|
\ {
|
||||||
|
\ "file": "-",
|
||||||
|
\ "line": 8,
|
||||||
|
\ "endLine": 8,
|
||||||
|
\ "column": 12,
|
||||||
|
\ "endColumn": 12,
|
||||||
|
\ "level": "error",
|
||||||
|
\ "code":1101,
|
||||||
|
\ "message":"Delete trailing spaces after \\ to break line (or use quotes for literal space).",
|
||||||
|
\ "fix":null
|
||||||
|
\ }
|
||||||
|
\ ]
|
||||||
|
\ }',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(shellcheck errors for trailing whitepsace should be able to be silenced by ale_warn_about_trailing_whitespace):
|
||||||
|
let g:ale_warn_about_trailing_whitespace = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale#handlers#shellcheck#Handle(bufnr(''), [0, 7, 0], [
|
||||||
|
\ '{
|
||||||
|
\ "comments": [
|
||||||
|
\ {
|
||||||
|
\ "file": "-",
|
||||||
|
\ "line": 8,
|
||||||
|
\ "endLine": 8,
|
||||||
|
\ "column": 12,
|
||||||
|
\ "endColumn": 12,
|
||||||
|
\ "level": "error",
|
||||||
|
\ "code":1101,
|
||||||
|
\ "message":"Delete trailing spaces after \\ to break line (or use quotes for literal space).",
|
||||||
|
\ "fix":null
|
||||||
|
\ }
|
||||||
|
\ ]
|
||||||
|
\ }',
|
||||||
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user