lintr.vim 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "============================================================================
  2. "File: lintr.vim
  3. "Description: Syntax checking plugin for syntastic
  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 buf = bufnr('')
  47. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  48. let makeprg = self.getExecEscaped() . ' --slave --no-restore --no-save' .
  49. \ ' -e ' . syntastic#util#shescape(setwd . 'suppressPackageStartupMessages(library(lintr)); ' .
  50. \ 'lint(cache = ' . g:syntastic_r_lintr_cache . ', commandArgs(TRUE), ' . g:syntastic_r_lintr_linters . ')') .
  51. \ ' --args ' . syntastic#util#shescape(bufname(buf))
  52. let errorformat =
  53. \ '%W%f:%l:%c: style: %m,' .
  54. \ '%W%f:%l:%c: warning: %m,' .
  55. \ '%E%f:%l:%c: error: %m,'
  56. call self.setWantSort(1)
  57. return SyntasticMake({
  58. \ 'makeprg': makeprg,
  59. \ 'errorformat': errorformat,
  60. \ 'returns': [0] })
  61. endfunction
  62. call g:SyntasticRegistry.CreateAndRegisterChecker({
  63. \ 'filetype': 'r',
  64. \ 'name': 'lintr',
  65. \ 'exec': 'R',
  66. \ 'enable': 'enable_r_lintr_checker'})
  67. let &cpo = s:save_cpo
  68. unlet s:save_cpo
  69. " vim: set sw=4 sts=4 et fdm=marker: