lint.vim 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 setwd = 'setwd("' . escape(getcwd(), '"\') . '"); '
  41. let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' .
  42. \ ' -e ' . syntastic#util#shescape(setwd . 'library(lint); ' .
  43. \ 'try(lint(commandArgs(TRUE), ' . g:syntastic_r_lint_styles . '))') .
  44. \ ' --args ' . syntastic#util#shexpand('%')
  45. let errorformat =
  46. \ '%t:%f:%l:%v: %m,' .
  47. \ '%t:%f:%l: %m'
  48. let loclist = SyntasticMake({
  49. \ 'makeprg': makeprg,
  50. \ 'errorformat': errorformat,
  51. \ 'subtype': 'Style',
  52. \ 'preprocess': 'rparse',
  53. \ 'returns': [0] })
  54. for e in loclist
  55. if e['type'] ==? 'F'
  56. " parse error
  57. let e['type'] = 'E'
  58. call remove(e, 'subtype')
  59. endif
  60. endfor
  61. return loclist
  62. endfunction
  63. call g:SyntasticRegistry.CreateAndRegisterChecker({
  64. \ 'filetype': 'r',
  65. \ 'name': 'lint',
  66. \ 'exec': 'R' })
  67. let &cpo = s:save_cpo
  68. unlet s:save_cpo
  69. " vim: set sw=4 sts=4 et fdm=marker: