Handle flow extra errors (#946)

Show more information for Flow errors with :ALEDetail
This commit is contained in:
Florian Beeres 2017-11-11 13:07:08 +01:00 committed by w0rp
parent bb271859ef
commit 1ddc3eec6d
2 changed files with 205 additions and 5 deletions

54
ale_linters/javascript/flow.vim Normal file → Executable file
View file

@ -1,6 +1,9 @@
" Author: Zach Perrault -- @zperrault
" Description: FlowType checking for JavaScript files
" Flow extra errors
" Author: Florian Beeres <yuuki@protonmail.com>
call ale#Set('javascript_flow_executable', 'flow')
call ale#Set('javascript_flow_use_global', 0)
@ -53,6 +56,44 @@ function! s:GetJSONLines(lines) abort
return a:lines[l:start_index :]
endfunction
function! s:ExtraErrorMsg(current, new) abort
let l:newMsg = ''
if a:current is# ''
" extra messages appear to already have a :
let l:newMsg = a:new
else
let l:newMsg = a:current . ' ' . a:new
endif
return l:newMsg
endfunction
function! s:GetDetails(error) abort
let l:detail = ''
for l:extra_error in a:error.extra
if has_key(l:extra_error, 'message')
for l:extra_message in l:extra_error.message
let l:detail = s:ExtraErrorMsg(l:detail, l:extra_message.descr)
endfor
endif
if has_key(l:extra_error, 'children')
for l:child in l:extra_error.children
for l:child_message in l:child.message
let l:detail = l:detail . ' ' . l:child_message.descr
endfor
endfor
endif
endfor
return l:detail
endfunction
function! ale_linters#javascript#flow#Handle(buffer, lines) abort
let l:str = join(s:GetJSONLines(a:lines), '')
@ -91,12 +132,19 @@ function! ale_linters#javascript#flow#Handle(buffer, lines) abort
let l:text = l:text . ' See also: ' . l:error.operation.descr
endif
call add(l:output, {
let l:errorToAdd = {
\ 'lnum': l:line,
\ 'col': l:col,
\ 'text': l:text,
\ 'type': l:error.level is# 'error' ? 'E' : 'W',
\})
\ 'type': has_key(l:error, 'level') && l:error.level is# 'error' ? 'E' : 'W',
\}
if has_key(l:error, 'extra')
let l:errorToAdd.detail = s:GetDetails(l:error)
endif
call add(l:output, l:errorToAdd)
endfor
return l:output