lint.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "============================================================================
  2. "File: lint.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_r_lint_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_r_lint_checker = 1
  16. if !exists('g:syntastic_r_lint_styles')
  17. let g:syntastic_r_lint_styles = 'lint.style'
  18. endif
  19. if !exists('g:syntastic_r_lint_sort')
  20. let g:syntastic_r_lint_sort = 1
  21. endif
  22. let s:save_cpo = &cpo
  23. set cpo&vim
  24. function! SyntaxCheckers_r_lint_GetHighlightRegex(item)
  25. let term = matchstr(a:item['text'], '\m`\zs[^`]\+\ze`')
  26. if term ==# ''
  27. let term = matchstr(a:item['text'], "\\m'\\zs[^']\\+\\ze'")
  28. endif
  29. return term !=# '' ? '\V' . escape(term, '\') : ''
  30. endfunction
  31. function! SyntaxCheckers_r_lint_IsAvailable() dict
  32. if !executable(self.getExec())
  33. return 0
  34. endif
  35. call syntastic#util#system(self.getExecEscaped() . ' --slave --restore --no-save -e ' . syntastic#util#shescape('library(lint)'))
  36. return v:shell_error == 0
  37. endfunction
  38. function! SyntaxCheckers_r_lint_GetLocList() dict
  39. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  40. let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' .
  41. \ ' -e ' . syntastic#util#shescape(setwd . 'library(lint); ' .
  42. \ 'try(lint(commandArgs(TRUE), ' . g:syntastic_r_lint_styles . '))') .
  43. \ ' --args ' . syntastic#util#shexpand('%')
  44. let errorformat =
  45. \ '%t:%f:%l:%v: %m,' .
  46. \ '%t:%f:%l: %m'
  47. let loclist = SyntasticMake({
  48. \ 'makeprg': makeprg,
  49. \ 'errorformat': errorformat,
  50. \ 'subtype': 'Style',
  51. \ 'preprocess': 'rparse',
  52. \ 'returns': [0] })
  53. for e in loclist
  54. if e['type'] ==? 'F'
  55. " parse error
  56. let e['type'] = 'E'
  57. call remove(e, 'subtype')
  58. endif
  59. endfor
  60. return loclist
  61. endfunction
  62. call g:SyntasticRegistry.CreateAndRegisterChecker({
  63. \ 'filetype': 'r',
  64. \ 'name': 'lint',
  65. \ 'exec': 'R' })
  66. let &cpo = s:save_cpo
  67. unlet s:save_cpo
  68. " vim: set sw=4 sts=4 et fdm=marker: