From c596b6474ee576f3cbd568e7752f655be04eb8a3 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Thu, 29 Oct 2015 17:55:39 +0200 Subject: [PATCH] Stylelint checker: cleanup. --- autoload/syntastic/preprocess.vim | 36 +++++++++++++++++++++++++++++++ plugin/syntastic.vim | 2 +- syntax_checkers/css/stylelint.vim | 15 ++++++------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index 434d3cbc..58fb379e 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -214,6 +214,42 @@ function! syntastic#preprocess#rparse(errors) abort " {{{2 return out endfunction " }}}2 +function! syntastic#preprocess#stylelint(errors) abort " {{{2 + let out = [] + + " CssSyntaxError: /path/to/file.css:2:11: Missed semicolon + let parts = matchlist(a:errors[0], '\v^CssSyntaxError: (.{-1,}):(\d+):(\d+): (.+)') + if len(parts) > 4 + call add(out, 'E:' . join(parts[1:4], ':')) + else + let errs = s:_decode_JSON(join(a:errors, '')) + + let out = [] + if type(errs) == type([]) && len(errs) == 1 && type(errs[0]) == type({}) && + \ has_key(errs[0], 'source') && has_key(errs[0], 'warnings') && type(errs[0]['warnings']) == type([]) + + for e in errs[0]['warnings'] + try + let msg = + \ ['W', 'E'][e['severity']-1] . ':' . + \ errs[0]['source'] . ':' . + \ e['line'] . ':' . + \ e['column'] . ':' . + \ e['text'] + call add(out, msg) + catch /\m^Vim\%((\a\+)\)\=:E716/ + call syntastic#log#warn('checker javascript/flow: unrecognized error format') + let out = [] + break + endtry + endfor + else + call syntastic#log#warn('checker javascript/stylelint: unrecognized error format') + endif + endif + return out +endfunction " }}}2 + function! syntastic#preprocess#tslint(errors) abort " {{{2 return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")') endfunction " }}}2 diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 91170396..74123779 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -19,7 +19,7 @@ if has('reltime') lockvar! g:_SYNTASTIC_START endif -let g:_SYNTASTIC_VERSION = '3.7.0-17' +let g:_SYNTASTIC_VERSION = '3.7.0-20' lockvar g:_SYNTASTIC_VERSION " Sanity checks {{{1 diff --git a/syntax_checkers/css/stylelint.vim b/syntax_checkers/css/stylelint.vim index a96786fb..1d2f40f2 100644 --- a/syntax_checkers/css/stylelint.vim +++ b/syntax_checkers/css/stylelint.vim @@ -20,19 +20,16 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_css_stylelint_GetLocList() dict - let makeprg = self.makeprgBuild({ }) - " Example output: - " CssSyntaxError: /path/to/file.css:2:11: Missed semicolon - " or - " 2:11 Expected single space after ":" (declaration-colon-space-after) - let errorformat = - \ 'CssSyntaxError: %f:%l:%c: %m,' . - \ '%\m%l\:%c%\s%#%m,' + let makeprg = self.makeprgBuild({ 'args_after': '-f json' }) + + let errorformat = '%t:%f:%l:%c:%m' return SyntasticMake({ \ 'makeprg': makeprg, \ 'errorformat': errorformat, - \ 'defaults': {'bufnr': bufnr('')} }) + \ 'subtype': 'Style', + \ 'preprocess': 'stylelint', + \ 'returns': [0, 1, 2] }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({