2013-10-29 14:24:07 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: shellcheck.vim
|
|
|
|
"Description: Shell script syntax/style checking plugin for syntastic.vim
|
|
|
|
"============================================================================
|
|
|
|
|
|
|
|
if exists("g:loaded_syntastic_sh_shellcheck_checker")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_sh_shellcheck_checker = 1
|
|
|
|
|
|
|
|
function! SyntaxCheckers_sh_shellcheck_Preprocess(json)
|
|
|
|
" A hat tip to Mark Weber for this trick
|
|
|
|
" http://stackoverflow.com/a/19105763
|
|
|
|
let errors = eval(join(a:json, ''))
|
|
|
|
|
|
|
|
call filter(errors, 'v:val["level"] =~? ''\v^(error|warning|style)$''')
|
|
|
|
return map(errors, 'v:val["level"][0] . ":" . v:val["line"] . ":" . v:val["column"] . ":" . v:val["message"]')
|
|
|
|
endfunction
|
|
|
|
|
2013-11-01 10:46:57 -04:00
|
|
|
function! SyntaxCheckers_sh_shellcheck_GetLocList() dict
|
2013-11-04 16:00:51 -05:00
|
|
|
let makeprg = self.getExec() . ' < ' . syntastic#util#shexpand('%')
|
2013-10-29 14:24:07 -04:00
|
|
|
|
|
|
|
let errorformat = '%t:%l:%v:%m'
|
|
|
|
|
|
|
|
let loclist = SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
|
|
|
\ 'preprocess': 'SyntaxCheckers_sh_shellcheck_Preprocess',
|
|
|
|
\ 'defaults': {'bufnr': bufnr("")},
|
|
|
|
\ 'returns': [0] })
|
|
|
|
|
|
|
|
for e in loclist
|
|
|
|
if e['type'] ==? 's'
|
|
|
|
let e['type'] = 'w'
|
|
|
|
let e['subtype'] = 'Style'
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return loclist
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'sh',
|
2013-10-28 11:30:25 -04:00
|
|
|
\ 'name': 'shellcheck',
|
|
|
|
\ 'exec': 'jsoncheck' })
|