diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index 2fafc782..c73eb6ce 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -6,6 +6,12 @@ let g:loaded_syntastic_util_autoload = 1 let s:save_cpo = &cpo set cpo&vim +if !exists("g:syntastic_debug") + let g:syntastic_debug = 0 +endif + +let s:deprecationNoticesIssued = [] + function! syntastic#util#DevNull() if has('win32') return 'NUL' @@ -23,7 +29,7 @@ endfunction "returns " "{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']} -function! syntastic#util#ParseShebang() +function! syntastic#util#parseShebang() for lnum in range(1,5) let line = getline(lnum) @@ -92,16 +98,6 @@ function! syntastic#util#wideMsg(msg) let &showcmd=old_showcmd endfunction -if !exists("g:syntastic_debug") - let g:syntastic_debug = 0 -endif - -function! syntastic#util#debug(msg) - if g:syntastic_debug - echomsg "(Syntastic debug) - " . a:msg - endif -endfunction - " Check whether a buffer is loaded, listed, and not hidden function! syntastic#util#bufIsActive(buffer) " convert to number, or hell breaks loose @@ -121,6 +117,18 @@ function! syntastic#util#bufIsActive(buffer) return 0 endfunction +" Used to sort error lists +function! syntastic#util#compareErrorItems(a, b) + if a:a['lnum'] != a:b['lnum'] + return a:a['lnum'] - a:b['lnum'] + elseif a:a['type'] !=? a:b['type'] + " errors take precedence over warnings + return a:a['type'] ==? 'e' ? -1 : 1 + else + return a:a['col'] - a:b['col'] + endif +endfunction + " List of buffers referenced by the location list function! syntastic#util#unique(list) let seen = {} @@ -130,7 +138,12 @@ function! syntastic#util#unique(list) return keys(seen) endfunction -let s:deprecationNoticesIssued = [] +function! syntastic#util#debug(msg) + if g:syntastic_debug + echomsg "syntastic: debug: " . a:msg + endif +endfunction + function! syntastic#util#deprecationWarn(msg) if index(s:deprecationNoticesIssued, a:msg) >= 0 return diff --git a/syntax_checkers/cpp/cpplint.vim b/syntax_checkers/cpp/cpplint.vim index 6172749e..48cf415b 100644 --- a/syntax_checkers/cpp/cpplint.vim +++ b/syntax_checkers/cpp/cpplint.vim @@ -47,9 +47,8 @@ function! SyntaxCheckers_cpp_cpplint_GetLocList() let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) " change error types according to the prescribed threshold - for n in range(0, len(loclist) - 1) + for n in range(len(loclist)) let loclist[n]['type'] = loclist[n]['type'] < g:syntastic_cpp_cpplint_thres ? 'W' : 'E' - let n -= 1 endfor return loclist diff --git a/syntax_checkers/css/prettycss.vim b/syntax_checkers/css/prettycss.vim index 51a90a9c..764f9aee 100644 --- a/syntax_checkers/css/prettycss.vim +++ b/syntax_checkers/css/prettycss.vim @@ -44,15 +44,11 @@ function! SyntaxCheckers_css_prettycss_GetLocList() \ '%-G%.%#' let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) - for n in range(0, len(loclist) - 1) + for n in range(len(loclist)) let loclist[n]["text"] .= ')' endfor - return sort(loclist, 's:CmpLoclist') -endfunction - -function! s:CmpLoclist(a, b) - return a:a['lnum'] - a:b['lnum'] + return sort(loclist, 'syntastic#util#compareErrorItems') endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/html/w3.vim b/syntax_checkers/html/w3.vim index 18e774c5..073f5862 100644 --- a/syntax_checkers/html/w3.vim +++ b/syntax_checkers/html/w3.vim @@ -21,21 +21,11 @@ endfunction function! SyntaxCheckers_html_w3_GetLocList() let makeprg2="curl -s -F output=text -F \"uploaded_file=@".expand('%:p').";type=text/html\" http://validator.w3.org/check \\| sed -n -e '/\Line\.\*/ \{ N; s/\\n//; N; s/\\n//; /msg/p; \}' -e ''/msg_warn/p'' -e ''/msg_info/p'' \\| sed -e 's/[ ]\\+/ /g' -e 's/\<[\^\>]\*\>//g' -e 's/\^[ ]//g'" let errorformat2='Line %l\, Column %c: %m' - let loclist = SyntasticMake({ 'makeprg': makeprg2, 'errorformat': errorformat2 }) + let loclist = SyntasticMake({ 'makeprg': makeprg2, 'errorformat': errorformat2, 'defaults': {'bufnr': bufnr("")} }) - let n = len(loclist) - 1 - let bufnum = bufnr("") - while n >= 0 - let i = loclist[n] - let i['bufnr'] = bufnum - - if i['lnum'] == 0 - let i['type'] = 'w' - else - let i['type'] = 'e' - endif - let n -= 1 - endwhile + for n in range(len(loclist)) + let loclist[n]['type'] = loclist[n]['lnum'] ? 'E' : 'W' + endfor return loclist endfunction diff --git a/syntax_checkers/perl/perl.vim b/syntax_checkers/perl/perl.vim index 86a6689c..e9eabdc9 100644 --- a/syntax_checkers/perl/perl.vim +++ b/syntax_checkers/perl/perl.vim @@ -52,7 +52,7 @@ function! SyntaxCheckers_perl_perl_GetLocList() endfunction function! s:ExtraMakeprgArgs() - let shebang = syntastic#util#ParseShebang() + let shebang = syntastic#util#parseShebang() if index(shebang['args'], '-T') != -1 return ' -Tc' endif diff --git a/syntax_checkers/perl/perlcritic.vim b/syntax_checkers/perl/perlcritic.vim index d98ae8bd..45a6cec2 100644 --- a/syntax_checkers/perl/perlcritic.vim +++ b/syntax_checkers/perl/perlcritic.vim @@ -46,11 +46,9 @@ function! SyntaxCheckers_perl_perlcritic_GetLocList() let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) " change error types according to the prescribed threshold - let n = len(loclist) - 1 - while n >= 0 + for n in range(len(loclist)) let loclist[n]['type'] = loclist[n]['type'] < g:syntastic_perl_perlcritic_thres ? 'W' : 'E' - let n -= 1 - endwhile + endfor return loclist endfunction diff --git a/syntax_checkers/python/pylint.vim b/syntax_checkers/python/pylint.vim index 67608c77..37fc7bec 100644 --- a/syntax_checkers/python/pylint.vim +++ b/syntax_checkers/python/pylint.vim @@ -26,17 +26,11 @@ function! SyntaxCheckers_python_pylint_GetLocList() let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) - let n = len(loclist) - 1 - while n >= 0 + for n in range(len(loclist)) let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E' - let n -= 1 - endwhile + endfor - return sort(loclist, 's:CmpLoclist') -endfunction - -function! s:CmpLoclist(a, b) - return a:a['lnum'] - a:b['lnum'] + return sort(loclist, 'syntastic#util#compareErrorItems') endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/tex/chktex.vim b/syntax_checkers/tex/chktex.vim index 989eb583..67b6e432 100644 --- a/syntax_checkers/tex/chktex.vim +++ b/syntax_checkers/tex/chktex.vim @@ -44,11 +44,8 @@ function! SyntaxCheckers_tex_chktex_GetLocList() let errorformat = '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' . \ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') . \ '%+Z%p^,%-G%.%#' - return sort(SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }), 's:CmpLoclist') -endfunction - -function! s:CmpLoclist(a, b) - return a:a['lnum'] - a:b['lnum'] + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) + return sort(loclist, 'syntastic#util#compareErrorItems') endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/xhtml/tidy.vim b/syntax_checkers/xhtml/tidy.vim index a72c2136..dc1b480c 100644 --- a/syntax_checkers/xhtml/tidy.vim +++ b/syntax_checkers/xhtml/tidy.vim @@ -9,12 +9,21 @@ " See http://sam.zoy.org/wtfpl/COPYING for more details. " "============================================================================ +" +" Checker option: +" +" - g:syntastic_xhtml_tidy_ignore_errors (list; default: []) +" list of errors to ignore if exists("g:loaded_syntastic_xhtml_tidy_checker") finish endif let g:loaded_syntastic_xhtml_tidy_checker=1 +if !exists('g:syntastic_xhtml_tidy_ignore_errors') + let g:syntastic_xhtml_tidy_ignore_errors = [] +endif + function! SyntaxCheckers_xhtml_tidy_IsAvailable() return executable("tidy") endfunction @@ -38,6 +47,15 @@ function! s:TidyEncOptByFenc() return get(tidy_opts, &fileencoding, '-utf8') endfunction +function! s:IgnoreErrror(text) + for i in g:syntastic_xhtml_tidy_ignore_errors + if stridx(a:text, i) != -1 + return 1 + endif + endfor + return 0 +endfunction + function! SyntaxCheckers_xhtml_tidy_GetLocList() let encopt = s:TidyEncOptByFenc() let makeprg = syntastic#makeprg#build({ @@ -48,7 +66,15 @@ function! SyntaxCheckers_xhtml_tidy_GetLocList() \ '%Wline %l column %c - Warning: %m,' . \ '%Eline %l column %c - Error: %m,' . \ '%-G%.%#' - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) + + for n in range(len(loclist)) + if loclist[n]['valid'] && s:IgnoreErrror(loclist[n]['text']) == 1 + let loclist[n]['valid'] = 0 + endif + endfor + + return loclist endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({