Flow checker: cleanup.

This commit is contained in:
LCD 47 2014-12-05 13:38:53 +02:00
parent 9dc6b6108c
commit d422c6d825
2 changed files with 82 additions and 15 deletions

View File

@ -59,6 +59,70 @@ function! syntastic#preprocess#cppcheck(errors) " {{{2
return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")') return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")')
endfunction " }}}2 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 function! syntastic#preprocess#killEmpty(errors) " {{{2
return filter(copy(a:errors), 'v:val != ""') return filter(copy(a:errors), 'v:val != ""')
endfunction " }}}2 endfunction " }}}2

View File

@ -21,26 +21,29 @@ endif
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim 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 function! SyntaxCheckers_javascript_flow_GetLocList() dict
let makeprg = self.makeprgBuild({ let makeprg = self.makeprgBuild({
\ 'args': '' }) \ 'exe_after': 'check',
\ 'args_after': '--show-all-errors --json' })
let errorformat = let errorformat =
\ '%E,' . \ '%f:%l:%c:%n: %m,' .
\ '%C%f:%l:%v\,%c: %m,' . \ '%f:%l:%c: %m'
\ '%C%\w%\\+%m,' .
\ '%Z%\s%m,' .
\ '%Z%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 endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({