From 6ad57016c16f89343a219fee62b16ee45bb1dfb4 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Thu, 3 Apr 2014 14:10:30 +0300 Subject: [PATCH] New checker for R: lint. --- README.markdown | 2 +- autoload/syntastic/preprocess.vim | 39 ++++++++++++++++ plugin/syntastic/registry.vim | 1 + syntax_checkers/r/lint.vim | 77 +++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 syntax_checkers/r/lint.vim diff --git a/README.markdown b/README.markdown index 9ef7b7ac..8bc070fe 100644 --- a/README.markdown +++ b/README.markdown @@ -40,7 +40,7 @@ CoffeeScript, Coco, Coq, CSS, Cucumber, CUDA, D, Dart, DocBook, Dust, Elixir, Erlang, eRuby, Fortran, Gentoo metadata, GLSL, Go, Haml, Haskell, Haxe, Handlebars, HSS, HTML, Java, JavaScript, JSON, JSX, LESS, Lex, Limbo, LISP, LLVM intermediate language, Lua, MATLAB, NASM, Objective-C, Objective-C++, -OCaml, Perl, Perl POD, PHP, gettext Portable Object, Puppet, Python, Racket, +OCaml, Perl, Perl POD, PHP, gettext Portable Object, Puppet, Python, Racket, R, reStructuredText, Ruby, Rust, SASS/SCSS, Scala, Slim, Tcl, TeX, Texinfo, Twig, TypeScript, Vala, Verilog, VHDL, VimL, xHtml, XML, XSLT, YACC, YAML, z80, Zope page templates, and zsh. See the [wiki][3] for details about the corresponding diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index f1af35be..4501e3ff 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -56,6 +56,45 @@ function! syntastic#preprocess#perl(errors) " {{{2 return syntastic#util#unique(out) endfunction " }}}2 +function! syntastic#preprocess#rparse(errors) " {{{2 + let errlist = copy(a:errors) + + " remove uninteresting lines and handle continuations + let i = 0 + while i < len(errlist) + if i > 0 && errlist[i][:1] == ' ' && errlist[i] !~ '\m\s\+\^$' + let errlist[i-1] .= errlist[i][1:] + call remove(errlist, i) + elseif errlist[i] !~ '\m^\(Lint:\|Lint checking:\|Error in\) ' + call remove(errlist, i) + else + let i += 1 + endif + endwhile + + let out = [] + let fname = '' + for e in errlist + if match(e, '\m^Lint: ') == 0 + let parts = matchlist(e, '\m^Lint: \(.*\): found on lines \([0-9, ]\+\)\(+\(\d\+\) more\)\=') + if len(parts) >= 3 + for line in split(parts[2], '\m,\s*') + call add(out, 'E:' . fname . ':' . line . ': ' . parts[1]) + endfor + endif + if len(parts) >= 5 && parts[4] != '' + call add(out, 'E:' . fname . ':0: ' . parts[1] . ' - ' . parts[4] . ' messages not shown') + endif + elseif match(e, '\m^Lint checking: ') == 0 + let fname = matchstr(e, '\m^Lint checking: \zs.*') + elseif match(e, '\m^Error in ') == 0 + call add(out, substitute(e, '\m^Error in .\+ : .\+\ze:\d\+:\d\+: ', 'E:' . fname, '')) + endif + endfor + + return out +endfunction " }}}2 + function! syntastic#preprocess#validator(errors) " {{{2 let out = [] for e in a:errors diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index 09ca4c90..cd2d9f23 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -60,6 +60,7 @@ let s:defaultCheckers = { \ 'pod': ['podchecker'], \ 'puppet': ['puppet', 'puppetlint'], \ 'python': ['python', 'flake8', 'pylint'], + \ 'r': ['lint'], \ 'racket': ['racket'], \ 'rst': ['rst2pseudoxml'], \ 'ruby': ['mri'], diff --git a/syntax_checkers/r/lint.vim b/syntax_checkers/r/lint.vim new file mode 100644 index 00000000..912f0f0c --- /dev/null +++ b/syntax_checkers/r/lint.vim @@ -0,0 +1,77 @@ +"============================================================================ +"File: lint.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: LCD 47 +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists("g:loaded_syntastic_r_lint_checker") + finish +endif +let g:loaded_syntastic_r_lint_checker = 1 + +if !exists('g:syntastic_r_lint_styles') + let g:syntastic_r_lint_styles = 'lint.style' +endif + +let s:save_cpo = &cpo +set cpo&vim + +function! SyntaxCheckers_r_lint_GetHighlightRegex(item) + let term = matchstr(a:item['text'], '\m`\zs[^`]\+\ze`') + if term == '' + let term = matchstr(a:item['text'], "\\m'\\zs[^']\\+\\ze'") + endif + return term != '' ? '\V' . escape(term, '\') : '' +endfunction + +function! SyntaxCheckers_r_lint_IsAvailable() dict + if !executable(self.getExec()) + return 0 + endif + call system(self.getExecEscaped() . ' --slave --restore --no-save -e ' . syntastic#util#shescape('library(lint)')) + return v:shell_error == 0 +endfunction + +function! SyntaxCheckers_r_lint_GetLocList() dict + let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' . + \ ' -e ' . syntastic#util#shescape('library(lint); try(lint(commandArgs(TRUE), ' . g:syntastic_r_lint_styles . '))') . + \ ' --args ' . syntastic#util#shexpand('%') + + let errorformat = + \ '%t:%f:%l:%v: %m,' . + \ '%t:%f:%l: %m' + + let loclist = SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'subtype': 'Style', + \ 'preprocess': 'rparse', + \ 'postprocess': ['sort'], + \ 'returns': [0] }) + + for e in loclist + if e['type'] == 'F' + " parse error + let e['type'] = 'E' + call remove(e, 'subtype') + endif + endfor + + return loclist +endfunction + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'r', + \ 'name': 'lint', + \ 'exec': 'R' }) + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: