From 49b0318fa6abe1e9041037aac840464168f81362 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Thu, 11 Apr 2013 23:00:25 +0300 Subject: [PATCH] Cleanup for tidy. Added an user-defined global list of errors to ignore: g:syntastic_html_tidy_ignore_errors. Minor cleanup. --- syntax_checkers/html/tidy.vim | 75 +++++++++++++++++----------------- syntax_checkers/xhtml/tidy.vim | 11 +++-- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/syntax_checkers/html/tidy.vim b/syntax_checkers/html/tidy.vim index b55d1395..018c7151 100644 --- a/syntax_checkers/html/tidy.vim +++ b/syntax_checkers/html/tidy.vim @@ -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", \ " 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 diff --git a/syntax_checkers/xhtml/tidy.vim b/syntax_checkers/xhtml/tidy.vim index 5c2c64c1..a72c2136 100644 --- a/syntax_checkers/xhtml/tidy.vim +++ b/syntax_checkers/xhtml/tidy.vim @@ -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