shellcheck.vim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "============================================================================
  2. "File: shellcheck.vim
  3. "Description: Shell script syntax/style checking plugin for syntastic
  4. "============================================================================
  5. if exists('g:loaded_syntastic_sh_shellcheck_checker')
  6. finish
  7. endif
  8. let g:loaded_syntastic_sh_shellcheck_checker = 1
  9. let s:save_cpo = &cpo
  10. set cpo&vim
  11. function! SyntaxCheckers_sh_shellcheck_GetLocList() dict " {{{1
  12. let buf = bufnr('')
  13. let makeprg = self.makeprgBuild({
  14. \ 'args': s:GetShell(buf),
  15. \ 'args_after': '-f gcc' })
  16. let errorformat =
  17. \ '%f:%l:%c: %trror: %m,' .
  18. \ '%f:%l:%c: %tarning: %m,' .
  19. \ '%f:%l:%c: %tote: %m'
  20. let loclist = SyntasticMake({
  21. \ 'makeprg': makeprg,
  22. \ 'errorformat': errorformat,
  23. \ 'returns': [0, 1] })
  24. for e in loclist
  25. if e['type'] ==? 'n'
  26. let e['type'] = 'w'
  27. let e['subtype'] = 'Style'
  28. endif
  29. endfor
  30. return loclist
  31. endfunction " }}}1
  32. " Utilities {{{1
  33. function! s:GetShell(buf) " {{{2
  34. let sh = ''
  35. if syntastic#util#parseShebang(a:buf)['exe'] ==# ''
  36. if syntastic#util#bufRawVar(a:buf, 'is_kornshell', 0) || syntastic#util#bufRawVar(a:buf, 'is_posix', 0)
  37. let sh = 'ksh'
  38. elseif syntastic#util#bufRawVar(a:buf, 'is_bash', 0)
  39. let sh = 'bash'
  40. elseif syntastic#util#bufRawVar(a:buf, 'is_sh', 0)
  41. let sh = 'sh'
  42. endif
  43. endif
  44. return sh !=# '' ? '-s ' . sh : ''
  45. endfunction " }}}2
  46. " }}}1
  47. call g:SyntasticRegistry.CreateAndRegisterChecker({
  48. \ 'filetype': 'sh',
  49. \ 'name': 'shellcheck' })
  50. let &cpo = s:save_cpo
  51. unlet s:save_cpo
  52. " vim: set sw=4 sts=4 et fdm=marker: