Move preprocess functions to their own file.
This commit is contained in:
parent
f490cf6ec9
commit
fb71514648
79
autoload/syntastic/preprocess.vim
Normal file
79
autoload/syntastic/preprocess.vim
Normal file
@ -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<error\>') > -1
|
||||
let line = str2nr(matchstr(err, '\m\<line="\zs\d\+\ze"'))
|
||||
if line == 0
|
||||
continue
|
||||
endif
|
||||
|
||||
let col = str2nr(matchstr(err, '\m\<column="\zs\d\+\ze"'))
|
||||
|
||||
let type = matchstr(err, '\m\<severity="\zs.\ze')
|
||||
if type !~? '^[EW]'
|
||||
let type = 'E'
|
||||
endif
|
||||
|
||||
let message = syntastic#util#decodeXMLEntities(matchstr(err, '\m\<message="\zs[^"]\+\ze"'))
|
||||
|
||||
call add(out, join([fname, type, line, col, message], ':'))
|
||||
elseif match(err, '\m<file name="') > -1
|
||||
let fname = syntastic#util#decodeXMLEntities(matchstr(err, '\v\<file name\="\zs[^"]+\ze"'))
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#cppcheck(errors) " {{{2
|
||||
return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\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:
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<error\>') > -1
|
||||
let line = str2nr(matchstr(err, '\m\<line="\zs\d\+\ze"'))
|
||||
if line == 0
|
||||
continue
|
||||
endif
|
||||
|
||||
let col = str2nr(matchstr(err, '\m\<column="\zs\d\+\ze"'))
|
||||
|
||||
let type = matchstr(err, '\m\<severity="\zs.\ze')
|
||||
if type !~? '^[EW]'
|
||||
let type = 'E'
|
||||
endif
|
||||
|
||||
let message = syntastic#util#decodeXMLEntities(matchstr(err, '\m\<message="\zs[^"]\+\ze"'))
|
||||
|
||||
call add(out, join([fname, type, line, col, message], ':'))
|
||||
elseif match(err, '\m<file name="') > -1
|
||||
let fname = syntastic#util#decodeXMLEntities(matchstr(err, '\v\<file name\="\zs[^"]+\ze"'))
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction
|
||||
|
||||
function! SyntaxCheckers_java_checkstyle_GetLocList() dict
|
||||
|
||||
let fname = syntastic#util#shescape( expand('%:p:h') . '/' . expand('%:t') )
|
||||
@ -73,8 +46,8 @@ function! SyntaxCheckers_java_checkstyle_GetLocList() dict
|
||||
return SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'subtype': 'Style',
|
||||
\ 'preprocess': 'SyntaxCheckers_java_checkstyle_Preprocess' })
|
||||
\ 'preprocess': 'checkstyle',
|
||||
\ 'subtype': 'Style' })
|
||||
endfunction
|
||||
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||
|
@ -17,9 +17,6 @@ let g:loaded_syntastic_javascript_jscs_checker = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" we borrow SyntaxCheckers_java_checkstyle_Preprocess() from java/checkstyle
|
||||
runtime! syntax_checkers/java/*.vim
|
||||
|
||||
function! SyntaxCheckers_javascript_jscs_GetLocList() dict
|
||||
let makeprg = self.makeprgBuild({ 'args_after': '--no-colors --reporter checkstyle' })
|
||||
let errorformat = '%f:%t:%l:%c:%m'
|
||||
@ -27,7 +24,7 @@ function! SyntaxCheckers_javascript_jscs_GetLocList() dict
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'subtype': 'Style',
|
||||
\ 'preprocess': 'SyntaxCheckers_java_checkstyle_Preprocess',
|
||||
\ 'preprocess': 'checkstyle',
|
||||
\ 'postprocess': ['sort'],
|
||||
\ 'returns': [0, 2] })
|
||||
endfunction
|
||||
|
@ -44,19 +44,6 @@ function! SyntaxCheckers_perl_perl_IsAvailable() dict
|
||||
return v:shell_error == 0
|
||||
endfunction
|
||||
|
||||
function! SyntaxCheckers_perl_perl_Preprocess(errors)
|
||||
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
|
||||
|
||||
function! SyntaxCheckers_perl_perl_GetLocList() dict
|
||||
let exe = expand(g:syntastic_perl_interpreter)
|
||||
if type(g:syntastic_perl_lib_path) == type('')
|
||||
@ -78,7 +65,7 @@ function! SyntaxCheckers_perl_perl_GetLocList() dict
|
||||
let errors = SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'preprocess': 'SyntaxCheckers_perl_perl_Preprocess',
|
||||
\ 'preprocess': 'perl',
|
||||
\ 'defaults': {'type': 'E'} })
|
||||
if !empty(errors)
|
||||
return errors
|
||||
@ -91,7 +78,7 @@ function! SyntaxCheckers_perl_perl_GetLocList() dict
|
||||
return SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'preprocess': 'SyntaxCheckers_perl_perl_Preprocess',
|
||||
\ 'preprocess': 'perl',
|
||||
\ 'defaults': {'type': 'W'} })
|
||||
endfunction
|
||||
|
||||
|
@ -13,11 +13,6 @@ let g:loaded_syntastic_python_pep257_checker = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" sanity: kill empty lines here rather than munging errorformat
|
||||
function! SyntaxCheckers_python_pep257_Preprocess(errors)
|
||||
return filter(copy(a:errors), 'v:val != ""')
|
||||
endfunction
|
||||
|
||||
function! SyntaxCheckers_python_pep257_GetLocList() dict
|
||||
let makeprg = self.makeprgBuild({})
|
||||
|
||||
@ -30,7 +25,7 @@ function! SyntaxCheckers_python_pep257_GetLocList() dict
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat,
|
||||
\ 'subtype': 'Style',
|
||||
\ 'preprocess': 'SyntaxCheckers_python_pep257_Preprocess',
|
||||
\ 'preprocess': 'killEmpty',
|
||||
\ 'postprocess': ['compressWhitespace'] })
|
||||
|
||||
" pep257 outputs byte offsets rather than column numbers
|
||||
|
Loading…
Reference in New Issue
Block a user