Adds an option g:syntastic_xhtml_tidy_ignore_errors to xhtml/tidy.
Cosmetic code changes.
This commit is contained in:
LCD 47 2013-04-15 11:21:52 +03:00
parent f76ae1cc0f
commit 408287de6f
9 changed files with 67 additions and 54 deletions

View File

@ -6,6 +6,12 @@ let g:loaded_syntastic_util_autoload = 1
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
if !exists("g:syntastic_debug")
let g:syntastic_debug = 0
endif
let s:deprecationNoticesIssued = []
function! syntastic#util#DevNull() function! syntastic#util#DevNull()
if has('win32') if has('win32')
return 'NUL' return 'NUL'
@ -23,7 +29,7 @@ endfunction
"returns "returns
" "
"{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']} "{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
function! syntastic#util#ParseShebang() function! syntastic#util#parseShebang()
for lnum in range(1,5) for lnum in range(1,5)
let line = getline(lnum) let line = getline(lnum)
@ -92,16 +98,6 @@ function! syntastic#util#wideMsg(msg)
let &showcmd=old_showcmd let &showcmd=old_showcmd
endfunction 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 " Check whether a buffer is loaded, listed, and not hidden
function! syntastic#util#bufIsActive(buffer) function! syntastic#util#bufIsActive(buffer)
" convert to number, or hell breaks loose " convert to number, or hell breaks loose
@ -121,6 +117,18 @@ function! syntastic#util#bufIsActive(buffer)
return 0 return 0
endfunction 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 " List of buffers referenced by the location list
function! syntastic#util#unique(list) function! syntastic#util#unique(list)
let seen = {} let seen = {}
@ -130,7 +138,12 @@ function! syntastic#util#unique(list)
return keys(seen) return keys(seen)
endfunction 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) function! syntastic#util#deprecationWarn(msg)
if index(s:deprecationNoticesIssued, a:msg) >= 0 if index(s:deprecationNoticesIssued, a:msg) >= 0
return return

View File

@ -47,9 +47,8 @@ function! SyntaxCheckers_cpp_cpplint_GetLocList()
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
" change error types according to the prescribed threshold " 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 loclist[n]['type'] = loclist[n]['type'] < g:syntastic_cpp_cpplint_thres ? 'W' : 'E'
let n -= 1
endfor endfor
return loclist return loclist

View File

@ -44,15 +44,11 @@ function! SyntaxCheckers_css_prettycss_GetLocList()
\ '%-G%.%#' \ '%-G%.%#'
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) 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"] .= ')' let loclist[n]["text"] .= ')'
endfor endfor
return sort(loclist, 's:CmpLoclist') return sort(loclist, 'syntastic#util#compareErrorItems')
endfunction
function! s:CmpLoclist(a, b)
return a:a['lnum'] - a:b['lnum']
endfunction endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -21,21 +21,11 @@ endfunction
function! SyntaxCheckers_html_w3_GetLocList() 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 '/\<em\>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 makeprg2="curl -s -F output=text -F \"uploaded_file=@".expand('%:p').";type=text/html\" http://validator.w3.org/check \\| sed -n -e '/\<em\>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 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 for n in range(len(loclist))
let bufnum = bufnr("") let loclist[n]['type'] = loclist[n]['lnum'] ? 'E' : 'W'
while n >= 0 endfor
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
return loclist return loclist
endfunction endfunction

View File

@ -52,7 +52,7 @@ function! SyntaxCheckers_perl_perl_GetLocList()
endfunction endfunction
function! s:ExtraMakeprgArgs() function! s:ExtraMakeprgArgs()
let shebang = syntastic#util#ParseShebang() let shebang = syntastic#util#parseShebang()
if index(shebang['args'], '-T') != -1 if index(shebang['args'], '-T') != -1
return ' -Tc' return ' -Tc'
endif endif

View File

@ -46,11 +46,9 @@ function! SyntaxCheckers_perl_perlcritic_GetLocList()
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
" change error types according to the prescribed threshold " change error types according to the prescribed threshold
let n = len(loclist) - 1 for n in range(len(loclist))
while n >= 0
let loclist[n]['type'] = loclist[n]['type'] < g:syntastic_perl_perlcritic_thres ? 'W' : 'E' let loclist[n]['type'] = loclist[n]['type'] < g:syntastic_perl_perlcritic_thres ? 'W' : 'E'
let n -= 1 endfor
endwhile
return loclist return loclist
endfunction endfunction

View File

@ -26,17 +26,11 @@ function! SyntaxCheckers_python_pylint_GetLocList()
let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
let n = len(loclist) - 1 for n in range(len(loclist))
while n >= 0
let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E' let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E'
let n -= 1 endfor
endwhile
return sort(loclist, 's:CmpLoclist') return sort(loclist, 'syntastic#util#compareErrorItems')
endfunction
function! s:CmpLoclist(a, b)
return a:a['lnum'] - a:b['lnum']
endfunction endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -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,' . 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,' : '') . \ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') .
\ '%+Z%p^,%-G%.%#' \ '%+Z%p^,%-G%.%#'
return sort(SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }), 's:CmpLoclist') let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
endfunction return sort(loclist, 'syntastic#util#compareErrorItems')
function! s:CmpLoclist(a, b)
return a:a['lnum'] - a:b['lnum']
endfunction endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -9,12 +9,21 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details. " 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") if exists("g:loaded_syntastic_xhtml_tidy_checker")
finish finish
endif endif
let g:loaded_syntastic_xhtml_tidy_checker=1 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() function! SyntaxCheckers_xhtml_tidy_IsAvailable()
return executable("tidy") return executable("tidy")
endfunction endfunction
@ -38,6 +47,15 @@ function! s:TidyEncOptByFenc()
return get(tidy_opts, &fileencoding, '-utf8') return get(tidy_opts, &fileencoding, '-utf8')
endfunction 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() function! SyntaxCheckers_xhtml_tidy_GetLocList()
let encopt = s:TidyEncOptByFenc() let encopt = s:TidyEncOptByFenc()
let makeprg = syntastic#makeprg#build({ let makeprg = syntastic#makeprg#build({
@ -48,7 +66,15 @@ function! SyntaxCheckers_xhtml_tidy_GetLocList()
\ '%Wline %l column %c - Warning: %m,' . \ '%Wline %l column %c - Warning: %m,' .
\ '%Eline %l column %c - Error: %m,' . \ '%Eline %l column %c - Error: %m,' .
\ '%-G%.%#' \ '%-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 endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({