luacheck.vim 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "============================================================================
  2. "File: luacheck.vim
  3. "Description: Lua static analysis using luacheck
  4. "Maintainer: Thiago Bastos <tbastos@tbastos.com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "============================================================================
  11. if exists('g:loaded_syntastic_lua_luacheck_checker')
  12. finish
  13. endif
  14. let g:loaded_syntastic_lua_luacheck_checker = 1
  15. let s:save_cpo = &cpo
  16. set cpo&vim
  17. function! SyntaxCheckers_lua_luacheck_GetHighlightRegex(item)
  18. let term = matchstr(a:item['text'], '\m''\zs\S\+\ze''')
  19. if term !=# ''
  20. return '\V\<' . escape(term, '\') . '\>'
  21. endif
  22. let term = matchstr(a:item['text'], '\m\(accessing undefined\|setting non-standard global\|' .
  23. \ 'setting non-module global\|unused global\) variable \zs\S\+')
  24. if term ==# ''
  25. let term = matchstr(a:item['text'], '\mvariable \zs\S\+\ze was previously defined')
  26. endif
  27. if term ==# ''
  28. let term = matchstr(a:item['text'], '\munused \(variable\|argument\|loop variable\) \zs\S\+')
  29. endif
  30. if term ==# ''
  31. let term = matchstr(a:item['text'], '\m\(value assigned to variable\|value of argument\|' .
  32. \ 'value of loop variable\) \zs\S\+')
  33. endif
  34. if term ==# ''
  35. let term = matchstr(a:item['text'], '\mvariable \zs\S\+\ze is never set')
  36. endif
  37. return term !=# '' ? '\V\<' . escape(term, '\') . '\>' : ''
  38. endfunction
  39. function! SyntaxCheckers_lua_luacheck_GetLocList() dict
  40. let makeprg = self.makeprgBuild({ 'args_after': '--no-color' })
  41. let errorformat =
  42. \ '%f:%l:%c: %m,'.
  43. \ '%-G%.%#'
  44. return SyntasticMake({
  45. \ 'makeprg': makeprg,
  46. \ 'errorformat': errorformat,
  47. \ 'subtype': 'Style',
  48. \ 'defaults': { 'type': 'W' },
  49. \ 'returns': [0, 1, 2] })
  50. endfunction
  51. call g:SyntasticRegistry.CreateAndRegisterChecker({
  52. \ 'filetype': 'lua',
  53. \ 'name': 'luacheck' })
  54. let &cpo = s:save_cpo
  55. unlet s:save_cpo
  56. " vim: set sw=4 sts=4 et fdm=marker: