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.
"
"============================================================================
"
" Checker option:
"
" - g:syntastic_html_tidy_ignore_errors (list; default: [])
" list of errors to ignore
if exists("g:loaded_syntastic_html_tidy_checker")
finish
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?
function! s:TidyEncOptByFenc()
@ -48,57 +61,45 @@ let s:ignore_html_errors = [
\ "attribute \"[+",
\ "unescaped & or unknown entity",
\ "<input> attribute \"type\" has invalid value \"search\""
\]
\ ]
function! s:ValidateError(text)
let valid = 0
for i in s:ignore_html_errors
function! s:IgnoreErrror(text)
for i in s:ignore_html_errors + g:syntastic_html_tidy_ignore_errors
if stridx(a:text, i) != -1
let valid = 1
break
return 1
endif
endfor
return valid
return 0
endfunction
function s:Args()
let args = s:TidyEncOptByFenc()
let args .= " --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')
let args .= " --new-empty-tags " . shellescape('wbr, keygen')
let args .= " -e"
let args = s:TidyEncOptByFenc() .
\ ' --new-blocklevel-tags ' . shellescape('section, article, aside, hgroup, header, footer, nav, figure, figcaption') .
\ ' --new-inline-tags ' . shellescape('video, audio, source, embed, mark, progress, meter, time, ruby, rt, rp, canvas, command, details, datalist') .
\ ' --new-empty-tags ' . shellescape('wbr, keygen') .
\ ' -e'
return args
endfunction
function! SyntaxCheckers_html_tidy_IsAvailable()
return executable('tidy')
endfunction
function! SyntaxCheckers_html_tidy_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'tidy',
\ 'args': s:Args(),
\ 'tail': '2>&1',
\ 'subchecker': 'tidy' })
let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#'
\ 'exe': 'tidy',
\ 'args': s:Args(),
\ 'tail': '2>&1',
\ 'subchecker': 'tidy' })
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
" from the errors
let n = len(loclist) - 1
let bufnum = bufnr("")
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
" filter out valid HTML5 from the errors
for n in range(len(loclist))
if loclist[n]['valid'] && s:IgnoreErrror(loclist[n]['text']) == 1
let loclist[n]['valid'] = 0
endif
let n -= 1
endwhile
endfor
return loclist
endfunction

View File

@ -41,10 +41,13 @@ endfunction
function! SyntaxCheckers_xhtml_tidy_GetLocList()
let encopt = s:TidyEncOptByFenc()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'tidy',
\ 'args': encopt . ' -xml -e',
\ 'subchecker': 'tidy' })
let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#'
\ 'exe': 'tidy',
\ 'args': encopt . ' -xml -e',
\ 'subchecker': 'tidy' })
let errorformat=
\ '%Wline %l column %c - Warning: %m,' .
\ '%Eline %l column %c - Error: %m,' .
\ '%-G%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} })
endfunction