mirror of https://github.com/dense-analysis/ale
Flow: Fix case where 1st msg points to different file (#477)
* Flow: Fix case where 1st msg points to different file * Remove `bufnr` from Flow handler output * Fix the failing test & add a new one
This commit is contained in:
parent
e97dada261
commit
2643f9f119
|
@ -48,8 +48,10 @@ function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
|||
let l:col = 0
|
||||
|
||||
for l:message in l:error.message
|
||||
" Comments have no line of column information
|
||||
if has_key(l:message, 'loc') && l:line ==# 0
|
||||
" Comments have no line of column information, so we skip them.
|
||||
" In certain cases, `l:message.loc.source` points to a different path
|
||||
" than the buffer one, thus we skip this loc information too.
|
||||
if has_key(l:message, 'loc') && l:line ==# 0 && l:message.loc.source ==# expand('#' . a:buffer . ':p')
|
||||
let l:line = l:message.loc.start.line + 0
|
||||
let l:col = l:message.loc.start.column + 0
|
||||
endif
|
||||
|
@ -66,7 +68,6 @@ function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
|||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:line,
|
||||
\ 'col': l:col,
|
||||
\ 'text': l:text,
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
Before:
|
||||
runtime ale_linters/javascript/flow.vim
|
||||
|
||||
After:
|
||||
unlet! g:flow_output
|
||||
unlet! g:expected
|
||||
unlet! g:actual
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The flow handler should process errors correctly.):
|
||||
e! /home/w0rp/Downloads/graphql-js/src/language/parser.js
|
||||
|
||||
let g:flow_output = {
|
||||
\ "flowVersion": "0.39.0",
|
||||
\ "errors": [
|
||||
|
@ -100,27 +111,16 @@ Before:
|
|||
\ "passed": v:false
|
||||
\}
|
||||
|
||||
runtime ale_linters/javascript/flow.vim
|
||||
|
||||
After:
|
||||
unlet! g:flow_output
|
||||
unlet! g:expected
|
||||
unlet! g:actual
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The flow handler should process errors correctly.):
|
||||
let g:actual = ale_linters#javascript#flow#Handle(347, [json_encode(g:flow_output)])
|
||||
let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
|
||||
let g:expected = [
|
||||
\ {
|
||||
\ 'lnum': 417,
|
||||
\ 'bufnr': 347,
|
||||
\ 'type': 'E',
|
||||
\ 'col': 10,
|
||||
\ 'text': 'number: This type is incompatible with the expected return type of array type',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 419,
|
||||
\ 'bufnr': 347,
|
||||
\ 'type': 'W',
|
||||
\ 'col': 3,
|
||||
\ 'text': 'unreachable code:',
|
||||
|
@ -128,3 +128,107 @@ Execute(The flow handler should process errors correctly.):
|
|||
\]
|
||||
|
||||
AssertEqual g:expected, g:actual
|
||||
|
||||
Execute(The flow handler should fetch the correct location for the currently opened file, even when it's not in the first message.):
|
||||
e! /Users/rav/Projects/vim-ale-flow/index.js
|
||||
|
||||
let g:flow_output = {
|
||||
\ "flowVersion": "0.44.0",
|
||||
\ "errors": [{
|
||||
\ "operation": {
|
||||
\ "context": " <Foo foo=\"bar\"/>, document.getElementById('foo')",
|
||||
\ "descr": "React element `Foo`",
|
||||
\ "type": "Blame",
|
||||
\ "loc": {
|
||||
\ "source": "/Users/rav/Projects/vim-ale-flow/index.js",
|
||||
\ "type": "SourceFile",
|
||||
\ "start": {
|
||||
\ "line": 6,
|
||||
\ "column": 3,
|
||||
\ "offset": 92
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "line": 6,
|
||||
\ "column": 18,
|
||||
\ "offset": 108
|
||||
\ }
|
||||
\ },
|
||||
\ "path": "/Users/rav/Projects/vim-ale-flow/index.js",
|
||||
\ "line": 6,
|
||||
\ "endline": 6,
|
||||
\ "start": 3,
|
||||
\ "end": 18
|
||||
\ },
|
||||
\ "kind": "infer",
|
||||
\ "level": "error",
|
||||
\ "message": [{
|
||||
\ "context": "module.exports = function(props: Props) {",
|
||||
\ "descr": "property `bar`",
|
||||
\ "type": "Blame",
|
||||
\ "loc": {
|
||||
\ "source": "/Users/rav/Projects/vim-ale-flow/foo.js",
|
||||
\ "type": "SourceFile",
|
||||
\ "start": {
|
||||
\ "line": 9,
|
||||
\ "column": 34,
|
||||
\ "offset": 121
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "line": 9,
|
||||
\ "column": 38,
|
||||
\ "offset": 126
|
||||
\ }
|
||||
\ },
|
||||
\ "path": "/Users/rav/Projects/vim-ale-flow/foo.js",
|
||||
\ "line": 9,
|
||||
\ "endline": 9,
|
||||
\ "start": 34,
|
||||
\ "end": 38
|
||||
\ }, {
|
||||
\ "context": v:null,
|
||||
\ "descr": "Property not found in",
|
||||
\ "type": "Comment",
|
||||
\ "path": "",
|
||||
\ "line": 0,
|
||||
\ "endline": 0,
|
||||
\ "start": 1,
|
||||
\ "end": 0
|
||||
\ }, {
|
||||
\ "context": " <Foo foo=\"bar\"/>, document.getElementById('foo')",
|
||||
\ "descr": "props of React element `Foo`",
|
||||
\ "type": "Blame",
|
||||
\ "loc": {
|
||||
\ "source": "/Users/rav/Projects/vim-ale-flow/index.js",
|
||||
\ "type": "SourceFile",
|
||||
\ "start": {
|
||||
\ "line": 6,
|
||||
\ "column": 3,
|
||||
\ "offset": 92
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "line": 6,
|
||||
\ "column": 18,
|
||||
\ "offset": 108
|
||||
\ }
|
||||
\ },
|
||||
\ "path": "/Users/rav/Projects/vim-ale-flow/index.js",
|
||||
\ "line": 6,
|
||||
\ "endline": 6,
|
||||
\ "start": 3,
|
||||
\ "end": 18
|
||||
\ }]
|
||||
\ }],
|
||||
\ "passed": v:false
|
||||
\}
|
||||
|
||||
let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
|
||||
let g:expected = [
|
||||
\ {
|
||||
\ 'lnum': 6,
|
||||
\ 'col': 3,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'property `bar`: Property not found in props of React element `Foo` See also: React element `Foo`'
|
||||
\ }
|
||||
\]
|
||||
|
||||
AssertEqual g:expected, g:actual
|
||||
|
|
Loading…
Reference in New Issue