From d422c6d8255d8a04c3b74be881dd6caffb718137 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Fri, 5 Dec 2014 13:38:53 +0200 Subject: [PATCH] Flow checker: cleanup. --- autoload/syntastic/preprocess.vim | 64 +++++++++++++++++++++++++++++ syntax_checkers/javascript/flow.vim | 33 ++++++++------- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index 4ce15f10..441b388f 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -59,6 +59,70 @@ function! syntastic#preprocess#cppcheck(errors) " {{{2 return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")') endfunction " }}}2 +" @vimlint(EVL102, 1, l:true) +" @vimlint(EVL102, 1, l:false) +" @vimlint(EVL102, 1, l:null) +function! syntastic#preprocess#flow(errors) " {{{2 + " JSON artifacts + let true = 1 + let false = 0 + let null = '' + + " A hat tip to Marc Weber for this trick + " http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763 + try + let errs = eval(join(a:errors, '')) + catch + let errs = {} + endtry + + let out = [] + if type(errs) == type({}) && has_key(errs, 'errors') && type(errs['errors']) == type([]) + for e in errs['errors'] + if type(e) == type({}) && has_key(e, 'message') && type(e['message']) == type([]) && len(e['message']) + let m = e['message'][0] + let t = e['message'][1:] + + try + let msg = + \ m['path'] . ':' . + \ m['line'] . ':' . + \ m['start'] . ':' . + \ (m['line'] ==# m['endline'] ? m['end'] . ':' : '') . + \ ' ' . m['descr'] + + if len(t) + let msg .= ' ' . join(map(t, + \ 'v:val["descr"] . " (" . v:val["path"] . ":" . v:val["line"] . ":" . v:val["start"] . ' . + \ '"," . (v:val["line"] !=# v:val["endline"] ? v:val["endline"] . ":" : "") . ' . + \ 'v:val["end"] . ")"')) + endif + + let msg = substitute(msg, '\r', '', 'g') + let msg = substitute(msg, '\n', ' ', 'g') + + call add(out, msg) + catch /\m^Vim\%((\a\+)\)\=:E716/ + call syntastic#log#warn('checker javascript/flow: unknown error format') + let out = [] + break + endtry + else + call syntastic#log#warn('checker javascript/flow: unknown error format') + let out = [] + break + endif + endfor + else + call syntastic#log#warn('checker javascript/flow: unknown error format') + endif + + return out +endfunction " }}}2 +" @vimlint(EVL102, 0, l:true) +" @vimlint(EVL102, 0, l:false) +" @vimlint(EVL102, 0, l:null) + function! syntastic#preprocess#killEmpty(errors) " {{{2 return filter(copy(a:errors), 'v:val != ""') endfunction " }}}2 diff --git a/syntax_checkers/javascript/flow.vim b/syntax_checkers/javascript/flow.vim index 119ae52f..ef9ae152 100644 --- a/syntax_checkers/javascript/flow.vim +++ b/syntax_checkers/javascript/flow.vim @@ -21,26 +21,29 @@ endif let s:save_cpo = &cpo set cpo&vim -function! SyntaxCheckers_javascript_flow_IsAvailable() dict - if !executable(self.getExec()) - return 0 - endif - - return executable(self.getExec()) -endfunction - function! SyntaxCheckers_javascript_flow_GetLocList() dict let makeprg = self.makeprgBuild({ - \ 'args': '' }) + \ 'exe_after': 'check', + \ 'args_after': '--show-all-errors --json' }) let errorformat = - \ '%E,' . - \ '%C%f:%l:%v\,%c: %m,' . - \ '%C%\w%\\+%m,' . - \ '%Z%\s%m,' . - \ '%Z%m' + \ '%f:%l:%c:%n: %m,' . + \ '%f:%l:%c: %m' - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + let loclist = SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'preprocess': 'flow', + \ 'defaults': {'type': 'E'} }) + + for e in loclist + if get(e, 'col', 0) && get(e, 'nr', 0) + let e['hl'] = '\%>' . (e['col'] - 1) . 'c\%<' . (e['nr'] + 1) . 'c' + let e['nr'] = 0 + endif + endfor + + return loclist endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({