diff options
author | w0rp <devw0rp@gmail.com> | 2017-07-22 19:21:30 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-07-22 19:21:30 +0100 |
commit | 78e37dabb7ae96691dc10d994125e143c6b50c57 (patch) | |
tree | 71e003887f1396cd2311e47f1892aa91995ede9c | |
parent | ee6dabcc4e2f64c7a035a2e7da3bc13285013d88 (diff) | |
download | ale-78e37dabb7ae96691dc10d994125e143c6b50c57.zip |
Fix #794 - Filter out any preceding lines of Flow output which aren't JSON
-rw-r--r-- | ale_linters/javascript/flow.vim | 20 | ||||
-rw-r--r-- | test/handler/test_flow_handler.vader | 16 |
2 files changed, 34 insertions, 2 deletions
diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim index 2e778c5a..f3e5deff 100644 --- a/ale_linters/javascript/flow.vim +++ b/ale_linters/javascript/flow.vim @@ -40,10 +40,26 @@ function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort \ . ' --json --from ale %s' endfunction +" Filter lines of flow output until we find the first line where the JSON +" output starts. +function! s:GetJSONLines(lines) abort + let l:start_index = 0 + + for l:line in a:lines + if l:line[:0] ==# '{' + break + endif + + let l:start_index += 1 + endfor + + return a:lines[l:start_index :] +endfunction + function! ale_linters#javascript#flow#Handle(buffer, lines) abort - let l:str = join(a:lines, '') + let l:str = join(s:GetJSONLines(a:lines), '') - if l:str ==# '' + if empty(l:str) return [] endif diff --git a/test/handler/test_flow_handler.vader b/test/handler/test_flow_handler.vader index 46b52229..288610b0 100644 --- a/test/handler/test_flow_handler.vader +++ b/test/handler/test_flow_handler.vader @@ -7,6 +7,22 @@ After: unlet! g:actual call ale#linter#Reset() +Execute(The flow handler should throw away non-JSON lines): + AssertEqual + \ [], + \ ale_linters#javascript#flow#Handle(bufnr(''), [ + \ 'Already up-to-date.', + \ '{"flowVersion":"0.50.0","errors":[],"passed":true}', + \ ]) + AssertEqual + \ [], + \ ale_linters#javascript#flow#Handle(bufnr(''), [ + \ 'foo', + \ 'bar', + \ 'baz', + \ '{"flowVersion":"0.50.0","errors":[],"passed":true}', + \ ]) + Execute(The flow handler should process errors correctly.): silent! noautocmd file /home/w0rp/Downloads/graphql-js/src/language/parser.js |