Cleanup for tidy.

Added an user-defined global list of errors to ignore:
g:syntastic_html_tidy_ignore_errors.
Minor cleanup.
This commit is contained in:
LCD 47 2013-04-11 23:00:25 +03:00
parent 85d4631002
commit 49b0318fa6
2 changed files with 45 additions and 41 deletions

View File

@ -9,11 +9,24 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details. " See http://sam.zoy.org/wtfpl/COPYING for more details.
" "
"============================================================================ "============================================================================
"
" Checker option:
"
" - g:syntastic_html_tidy_ignore_errors (list; default: [])
" list of errors to ignore
if exists("g:loaded_syntastic_html_tidy_checker") if exists("g:loaded_syntastic_html_tidy_checker")
finish finish
endif endif
let g:loaded_syntastic_html_tidy_checker=1 let g:loaded_syntastic_html_tidy_checker = 1
if !exists('g:syntastic_html_tidy_ignore_errors')
let g:syntastic_html_tidy_ignore_errors = []
endif
function! SyntaxCheckers_html_tidy_IsAvailable()
return executable('tidy')
endfunction
" TODO: join this with xhtml.vim for DRY's sake? " TODO: join this with xhtml.vim for DRY's sake?
function! s:TidyEncOptByFenc() function! s:TidyEncOptByFenc()
@ -48,57 +61,45 @@ let s:ignore_html_errors = [
\ "attribute \"[+", \ "attribute \"[+",
\ "unescaped & or unknown entity", \ "unescaped & or unknown entity",
\ "<input> attribute \"type\" has invalid value \"search\"" \ "<input> attribute \"type\" has invalid value \"search\""
\] \ ]
function! s:ValidateError(text) function! s:IgnoreErrror(text)
let valid = 0 for i in s:ignore_html_errors + g:syntastic_html_tidy_ignore_errors
for i in s:ignore_html_errors
if stridx(a:text, i) != -1 if stridx(a:text, i) != -1
let valid = 1 return 1
break
endif endif
endfor endfor
return valid return 0
endfunction endfunction
function s:Args() function s:Args()
let args = s:TidyEncOptByFenc() let args = s:TidyEncOptByFenc() .
let args .= " --new-blocklevel-tags " . shellescape('section, article, aside, hgroup, header, footer, nav, figure, figcaption') \ ' --new-blocklevel-tags ' . shellescape('section, article, aside, hgroup, header, footer, nav, figure, figcaption') .
let args .= " --new-inline-tags " . shellescape('video, audio, source, embed, mark, progress, meter, time, ruby, rt, rp, canvas, command, details, datalist') \ ' --new-inline-tags ' . shellescape('video, audio, source, embed, mark, progress, meter, time, ruby, rt, rp, canvas, command, details, datalist') .
let args .= " --new-empty-tags " . shellescape('wbr, keygen') \ ' --new-empty-tags ' . shellescape('wbr, keygen') .
let args .= " -e" \ ' -e'
return args return args
endfunction endfunction
function! SyntaxCheckers_html_tidy_IsAvailable()
return executable('tidy')
endfunction
function! SyntaxCheckers_html_tidy_GetLocList() function! SyntaxCheckers_html_tidy_GetLocList()
let makeprg = syntastic#makeprg#build({ let makeprg = syntastic#makeprg#build({
\ 'exe': 'tidy', \ 'exe': 'tidy',
\ 'args': s:Args(), \ 'args': s:Args(),
\ 'tail': '2>&1', \ 'tail': '2>&1',
\ 'subchecker': 'tidy' }) \ 'subchecker': 'tidy' })
let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#' let errorformat =
\ '%Wline %l column %c - Warning: %m,' .
\ '%Eline %l column %c - Error: %m,' .
\ '%-G%.%#'
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} })
" process loclist since we need to add some info and filter out valid HTML5 " filter out valid HTML5 from the errors
" from the errors for n in range(len(loclist))
let n = len(loclist) - 1 if loclist[n]['valid'] && s:IgnoreErrror(loclist[n]['text']) == 1
let bufnum = bufnr("") let loclist[n]['valid'] = 0
while n >= 0
let i = loclist[n]
" filter out valid HTML5
if s:ValidateError(i['text']) == 1
unlet loclist[n]
else
"the file name isnt in the output so stick in the buf num manually
let i['bufnr'] = bufnum
endif endif
let n -= 1 endfor
endwhile
return loclist return loclist
endfunction endfunction

View File

@ -41,10 +41,13 @@ 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({
\ 'exe': 'tidy', \ 'exe': 'tidy',
\ 'args': encopt . ' -xml -e', \ 'args': encopt . ' -xml -e',
\ 'subchecker': 'tidy' }) \ 'subchecker': 'tidy' })
let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#' let errorformat=
\ '%Wline %l column %c - Warning: %m,' .
\ '%Eline %l column %c - Error: %m,' .
\ '%-G%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} })
endfunction endfunction