From d700da8cb803237d313a7cfa1824b610b3435a0a Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Mon, 21 Nov 2016 12:53:18 +0300 Subject: [PATCH] Flow linter improvements (#176) * Fix flow linter to provide filename of the buffer Related #173 * Fix flow linter not to fail on empty response * Various improvement to message parsing --- ale_linters/javascript/flow.vim | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim index d23d2f3..f3a1210 100644 --- a/ale_linters/javascript/flow.vim +++ b/ale_linters/javascript/flow.vim @@ -21,11 +21,15 @@ endfunction function! ale_linters#javascript#flow#GetCommand(buffer) abort return ale_linters#javascript#flow#GetExecutable(a:buffer) - \ . ' check-contents --respect-pragma --json --from ale' + \ . ' check-contents --respect-pragma --json --from ale %s' endfunction function! ale_linters#javascript#flow#Handle(buffer, lines) - let l:flow_output = json_decode(join(a:lines, '')) + let l:str = join(a:lines, '') + if l:str ==# '' + return [] + endif + let l:flow_output = json_decode(l:str) if has_key(l:flow_output, 'errors') let l:output = [] @@ -34,19 +38,29 @@ function! ale_linters#javascript#flow#Handle(buffer, lines) " Each error is broken up into parts let l:text = '' let l:line = 0 + let l:col = 0 for l:message in l:error.message " Comments have no line of column information - if l:message.line + 0 - let l:line = l:message.line + 0 + if has_key(l:message, 'loc') && l:line ==# 0 + let l:line = l:message.loc.start.line + 0 + let l:col = l:message.loc.start.column + 0 + endif + if l:text ==# '' + let l:text = l:message.descr . ':' + else + let l:text = l:text . ' ' . l:message.descr endif - let l:text = l:text . ' ' . l:message.descr endfor + if has_key(l:error, 'operation') + let l:text = l:text . ' See also: ' . l:error.operation.descr + endif + call add(l:output, { \ 'bufnr': a:buffer, \ 'lnum': l:line, \ 'vcol': 0, - \ 'col': 0, + \ 'col': l:col, \ 'text': l:text, \ 'type': l:error.level ==# 'error' ? 'E' : 'W', \})