From fb71514648148ccd657343c0eabd7f0802da67d5 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Wed, 26 Feb 2014 10:31:38 +0200 Subject: [PATCH] Move preprocess functions to their own file. --- autoload/syntastic/preprocess.vim | 79 +++++++++++++++++++++++++++++ plugin/syntastic.vim | 2 +- syntax_checkers/c/cppcheck.vim | 6 +-- syntax_checkers/html/validator.vim | 17 +------ syntax_checkers/java/checkstyle.vim | 31 +---------- syntax_checkers/javascript/jscs.vim | 5 +- syntax_checkers/perl/perl.vim | 17 +------ syntax_checkers/python/pep257.vim | 7 +-- 8 files changed, 88 insertions(+), 76 deletions(-) create mode 100644 autoload/syntastic/preprocess.vim diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim new file mode 100644 index 00000000..f1af35be --- /dev/null +++ b/autoload/syntastic/preprocess.vim @@ -0,0 +1,79 @@ +if exists("g:loaded_syntastic_preprocess_autoload") || !exists("g:loaded_syntastic_plugin") + finish +endif +let g:loaded_syntastic_preprocess_autoload = 1 + +let s:save_cpo = &cpo +set cpo&vim + +" Public functions {{{1 + +function! syntastic#preprocess#checkstyle(errors) " {{{2 + let out = [] + let fname = expand('%') + for err in a:errors + if match(err, '\m') > -1 + let line = str2nr(matchstr(err, '\m\ \[[^]]+\])+\ze:'', "", "")') +endfunction " }}}2 + +function! syntastic#preprocess#killEmpty(errors) " {{{2 + return filter(copy(a:errors), 'v:val != ""') +endfunction " }}}2 + +function! syntastic#preprocess#perl(errors) " {{{2 + let out = [] + + for e in a:errors + let parts = matchlist(e, '\v^(.*)\sat\s(.*)\sline\s(\d+)(.*)$') + if !empty(parts) + call add(out, parts[2] . ':' . parts[3] . ':' . parts[1] . parts[4]) + endif + endfor + + return syntastic#util#unique(out) +endfunction " }}}2 + +function! syntastic#preprocess#validator(errors) " {{{2 + let out = [] + for e in a:errors + let parts = matchlist(e, '\v^"([^"]+)"(.+)') + if len(parts) >= 3 + " URL decode, except leave alone any "+" + let parts[1] = substitute(parts[1], '\m%\(\x\x\)', '\=nr2char("0x".submatch(1))', 'g') + let parts[1] = substitute(parts[1], '\m\\"', '"', 'g') + let parts[1] = substitute(parts[1], '\m\\\\', '\\', 'g') + call add(out, '"' . parts[1] . '"' . parts[2]) + endif + endfor + return out +endfunction " }}}2 + +" }}}1 + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 5e541941..c59e42db 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -417,7 +417,7 @@ function! SyntasticMake(options) " {{{2 call syntastic#log#debug(g:SyntasticDebugLoclist, 'checker output:', err_lines) if has_key(a:options, 'preprocess') - let err_lines = call(a:options['preprocess'], [err_lines]) + let err_lines = call('syntastic#preprocess#' . a:options['preprocess'], [err_lines]) call syntastic#log#debug(g:SyntasticDebugLoclist, 'preprocess:', err_lines) endif lgetexpr err_lines diff --git a/syntax_checkers/c/cppcheck.vim b/syntax_checkers/c/cppcheck.vim index a028e451..e4223cb2 100644 --- a/syntax_checkers/c/cppcheck.vim +++ b/syntax_checkers/c/cppcheck.vim @@ -28,10 +28,6 @@ endif let s:save_cpo = &cpo set cpo&vim -function! SyntaxCheckers_c_cppcheck_Preprocess(errors) - return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")') -endfunction - function! SyntaxCheckers_c_cppcheck_GetLocList() dict let makeprg = self.makeprgBuild({ \ 'args': syntastic#c#ReadConfig(g:syntastic_cppcheck_config_file), @@ -50,7 +46,7 @@ function! SyntaxCheckers_c_cppcheck_GetLocList() dict let loclist = SyntasticMake({ \ 'makeprg': makeprg, \ 'errorformat': errorformat, - \ 'preprocess': 'SyntaxCheckers_c_cppcheck_Preprocess', + \ 'preprocess': 'cppcheck', \ 'returns': [0] }) for e in loclist diff --git a/syntax_checkers/html/validator.vim b/syntax_checkers/html/validator.vim index eb8ab0f5..6a8e503d 100644 --- a/syntax_checkers/html/validator.vim +++ b/syntax_checkers/html/validator.vim @@ -48,21 +48,6 @@ endif let s:save_cpo = &cpo set cpo&vim -function! SyntaxCheckers_html_validator_Preprocess(errors) - let out = [] - for e in a:errors - let parts = matchlist(e, '\v^"([^"]+)"(.+)') - if len(parts) >= 3 - " URL decode, except leave alone any "+" - let parts[1] = substitute(parts[1], '\m%\(\x\x\)', '\=nr2char("0x".submatch(1))', 'g') - let parts[1] = substitute(parts[1], '\m\\"', '"', 'g') - let parts[1] = substitute(parts[1], '\m\\\\', '\\', 'g') - call add(out, '"' . parts[1] . '"' . parts[2]) - endif - endfor - return out -endfunction - function! SyntaxCheckers_html_validator_GetLocList() dict let fname = syntastic#util#shexpand('%') let makeprg = self.getExecEscaped() . ' -s --compressed -F out=gnu -F asciiquotes=yes' . @@ -87,7 +72,7 @@ function! SyntaxCheckers_html_validator_GetLocList() dict return SyntasticMake({ \ 'makeprg': makeprg, \ 'errorformat': errorformat, - \ 'preprocess': 'SyntaxCheckers_html_validator_Preprocess', + \ 'preprocess': 'validator', \ 'returns': [0] }) endfunction diff --git a/syntax_checkers/java/checkstyle.vim b/syntax_checkers/java/checkstyle.vim index b3882314..092d1992 100644 --- a/syntax_checkers/java/checkstyle.vim +++ b/syntax_checkers/java/checkstyle.vim @@ -27,33 +27,6 @@ endif let s:save_cpo = &cpo set cpo&vim -function! SyntaxCheckers_java_checkstyle_Preprocess(errors) - let out = [] - let fname = expand('%') - for err in a:errors - if match(err, '\m') > -1 - let line = str2nr(matchstr(err, '\m\