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" 21let g:syntastic_enable_r_lintr_checker = 1 22 23if exists("g:loaded_syntastic_r_lintr_checker") 24 finish 25endif 26let g:loaded_syntastic_r_lintr_checker = 1 27 28if !exists('g:syntastic_r_lintr_linters') 29 let g:syntastic_r_lintr_linters = 'default_linters' 30endif 31 32if !exists('g:syntastic_r_lintr_cache') 33 let g:syntastic_r_lintr_cache = 'FALSE' 34endif 35 36let s:save_cpo = &cpo 37set cpo&vim 38 39function! SyntaxCheckers_r_lintr_GetHighlightRegex(item) 40 let term = matchstr(a:item['text'], "\\m'\\zs[^']\\+\\ze'") 41 return term != '' ? '\V' . escape(term, '\') : '' 42endfunction 43 44function! SyntaxCheckers_r_lintr_IsAvailable() dict 45 if !executable(self.getExec()) 46 return 0 47 endif 48 call system(self.getExecEscaped() . ' --slave --no-restore --no-save -e ' . syntastic#util#shescape('library(lintr)')) 49 return v:shell_error == 0 50endfunction 51 52function! SyntaxCheckers_r_lintr_GetLocList() dict 53 if !exists('g:syntastic_enable_r_lintr_checker') || !g:syntastic_enable_r_lintr_checker 54 call syntastic#log#error('checker r/lintr: checks disabled for security reasons; set g:syntastic_enable_r_lintr_checker to 1 to override') 55 return [] 56 endif 57 58 let setwd = syntastic#util#isRunningWindows() ? 'setwd(''' . escape(getcwd(), '"\') . '''); ' : '' 59 let makeprg = self.getExecEscaped() . ' --slave --no-restore --no-save' . 60 \ ' -e ' . syntastic#util#shescape(setwd . 'suppressPackageStartupMessages(library(lintr)); ' . 61 \ 'lint(cache = ' . g:syntastic_r_lintr_cache . ', commandArgs(TRUE), ' . g:syntastic_r_lintr_linters . ')') . 62 \ ' --args ' . syntastic#util#shexpand('%') 63 64 let errorformat = 65 \ '%W%f:%l:%c: style: %m,' . 66 \ '%W%f:%l:%c: warning: %m,' . 67 \ '%E%f:%l:%c: error: %m,' 68 69 call self.setWantSort(1) 70 71 return SyntasticMake({ 72 \ 'makeprg': makeprg, 73 \ 'errorformat': errorformat, 74 \ 'returns': [0] }) 75endfunction 76 77call g:SyntasticRegistry.CreateAndRegisterChecker({ 78 \ 'filetype': 'r', 79 \ 'name': 'lintr', 80 \ 'exec': 'R' }) 81 82let &cpo = s:save_cpo 83unlet s:save_cpo 84 85" vim: set et sts=4 sw=4: 86