vimlint.vim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "============================================================================
  2. "File: vimlint.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: LCD 47 <lcd047 at gmail dot 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. "============================================================================
  12. if exists('g:loaded_syntastic_vim_vimlint_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_vim_vimlint_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_vim_vimlint_GetHighlightRegex(item) " {{{1
  19. let term = matchstr(a:item['text'], '\m `\zs[^`]\+\ze`')
  20. if term !=# ''
  21. let col = get(a:item, 'col', 0)
  22. if col && term[0:1] ==# 'l:'
  23. if getline(a:item.lnum)[col-1:col] !=# 'l:'
  24. let term = term[2:]
  25. endif
  26. endif
  27. return col ? '\%>' . (col - 1) . 'c\%<' . (col + strlen(term)) . 'c' : '\V' . escape(term, '\')
  28. endif
  29. return ''
  30. endfunction " }}}1
  31. function! SyntaxCheckers_vim_vimlint_IsAvailable() dict " {{{1
  32. let vimlparser = globpath(&runtimepath, 'autoload/vimlparser.vim', 1)
  33. let vimlint = globpath(&runtimepath, 'autoload/vimlint.vim', 1)
  34. call self.log("globpath(&runtimepath, 'autoload/vimlparser.vim', 1) = " . string(vimlparser) . ', ' .
  35. \ "globpath(&runtimepath, 'autoload/vimlint.vim', 1) = " . string(vimlint))
  36. return vimlparser !=# '' && vimlint !=# ''
  37. endfunction " }}}1
  38. function! SyntaxCheckers_vim_vimlint_GetLocList() dict " {{{1
  39. " EVL102: unused variable v
  40. " EVL103: unused argument v
  41. " EVL104: variable may not be initialized on some execution path: v
  42. " EVL105: global variable v is defined without g:
  43. " EVL106: local variable v is used without l:
  44. " EVL201: unreachable code
  45. " EVL204: constant in conditional context
  46. " EVL205: missing scriptencoding
  47. " value 3: the message is a warning
  48. "
  49. " References: :help vimlint-errorcode and :help vimlint-variables
  50. let param = {
  51. \ 'output': function('s:vimlintOutput'),
  52. \ 'quiet': 1,
  53. \ 'EVL102': 3,
  54. \ 'EVL103': 3,
  55. \ 'EVL104': 3,
  56. \ 'EVL105': 3,
  57. \ 'EVL106': 3,
  58. \ 'EVL201': 3,
  59. \ 'EVL204': 3,
  60. \ 'EVL205': 3 }
  61. if exists('g:syntastic_vimlint_options') || exists('b:syntastic_vimlint_options')
  62. let opts = syntastic#util#var('vimlint_options')
  63. if type(opts) == type({})
  64. let options = filter(copy(opts), 'v:key =~# "\\m^EVL"')
  65. call extend(param, options, 'force')
  66. endif
  67. endif
  68. call self.log('options =', param)
  69. return vimlint#vimlint(expand('%', 1), param)
  70. endfunction " }}}1
  71. " Utilities {{{1
  72. " @vimlint(EVL103, 1, a:filename)
  73. function! s:vimlintOutput(filename, pos, ev, eid, mes, obj) " {{{2
  74. call add(a:obj.error, {
  75. \ 'bufnr': bufnr(''),
  76. \ 'lnum': a:pos.lnum,
  77. \ 'col': a:pos.col,
  78. \ 'vcol': 0,
  79. \ 'type': a:ev[0],
  80. \ 'text': '[' . a:eid . '] ' . a:mes,
  81. \ 'valid': a:pos.lnum > 0 })
  82. endfunction " }}}2
  83. " @vimlint(EVL103, 0, a:filename)
  84. " }}}1
  85. call g:SyntasticRegistry.CreateAndRegisterChecker({
  86. \ 'filetype': 'vim',
  87. \ 'name': 'vimlint' })
  88. let &cpo = s:save_cpo
  89. unlet s:save_cpo
  90. " vim: set sw=4 sts=4 et fdm=marker: