lintr.vim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "============================================================================
  2. "File: lintr.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Jim Hester <james.f.hester 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. "
  13. " Security:
  14. "
  15. " This checker runs the code in your file. This is probably fine if you
  16. " wrote the file yourself, but it can be a problem if you're trying to
  17. " check third party files. If you are 100% willing to let Vim run the
  18. " code in your file, set g:syntastic_enable_r_lintr_checker to 1 in
  19. " your vimrc to enable this checker:
  20. "
  21. " let g:syntastic_enable_r_lintr_checker = 1
  22. if exists("g:loaded_syntastic_r_lintr_checker")
  23. finish
  24. endif
  25. let g:loaded_syntastic_r_lintr_checker = 1
  26. if !exists('g:syntastic_r_lintr_linters')
  27. let g:syntastic_r_lintr_linters = 'default_linters'
  28. endif
  29. if !exists('g:syntastic_r_lintr_cache')
  30. let g:syntastic_r_lintr_cache = 'FALSE'
  31. endif
  32. let s:save_cpo = &cpo
  33. set cpo&vim
  34. function! SyntaxCheckers_r_lintr_GetHighlightRegex(item)
  35. let term = matchstr(a:item['text'], "\\m'\\zs[^']\\+\\ze'")
  36. return term != '' ? '\V' . escape(term, '\') : ''
  37. endfunction
  38. function! SyntaxCheckers_r_lintr_IsAvailable() dict
  39. if !executable(self.getExec())
  40. return 0
  41. endif
  42. call system(self.getExecEscaped() . ' --slave --no-restore --no-save -e ' . syntastic#util#shescape('library(lintr)'))
  43. return v:shell_error == 0
  44. endfunction
  45. function! SyntaxCheckers_r_lintr_GetLocList() dict
  46. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  47. let makeprg = self.getExecEscaped() . ' --slave --no-restore --no-save' .
  48. \ ' -e ' . syntastic#util#shescape(setwd . 'suppressPackageStartupMessages(library(lintr)); ' .
  49. \ 'lint(cache = ' . g:syntastic_r_lintr_cache . ', commandArgs(TRUE), ' . g:syntastic_r_lintr_linters . ')') .
  50. \ ' --args ' . syntastic#util#shexpand('%')
  51. let errorformat =
  52. \ '%W%f:%l:%c: style: %m,' .
  53. \ '%W%f:%l:%c: warning: %m,' .
  54. \ '%E%f:%l:%c: error: %m,'
  55. call self.setWantSort(1)
  56. return SyntasticMake({
  57. \ 'makeprg': makeprg,
  58. \ 'errorformat': errorformat,
  59. \ 'returns': [0] })
  60. endfunction
  61. call g:SyntasticRegistry.CreateAndRegisterChecker({
  62. \ 'filetype': 'r',
  63. \ 'name': 'lintr',
  64. \ 'exec': 'R',
  65. \ 'enable': 'enable_r_lintr_checker'})
  66. let &cpo = s:save_cpo
  67. unlet s:save_cpo
  68. " vim: set sw=4 sts=4 et fdm=marker: