Fix #246 Don't run flow if there's no .flowconfig
This commit is contained in:
parent
926cd1a953
commit
49f7ce4f6d
6 changed files with 202 additions and 47 deletions
|
@ -20,31 +20,40 @@ function! ale_linters#javascript#flow#GetExecutable(buffer) abort
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#javascript#flow#GetCommand(buffer) abort
|
function! ale_linters#javascript#flow#GetCommand(buffer) abort
|
||||||
|
let l:flow_config = ale#util#FindNearestFile(a:buffer, '.flowconfig')
|
||||||
|
|
||||||
|
if empty(l:flow_config)
|
||||||
|
" Don't run Flow if we can't find a .flowconfig file.
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
return ale_linters#javascript#flow#GetExecutable(a:buffer)
|
return ale_linters#javascript#flow#GetExecutable(a:buffer)
|
||||||
\ . ' check-contents --respect-pragma --json --from ale %s'
|
\ . ' check-contents --respect-pragma --json --from ale %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
||||||
let l:str = join(a:lines, '')
|
let l:str = join(a:lines, '')
|
||||||
|
|
||||||
if l:str ==# ''
|
if l:str ==# ''
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
let l:flow_output = json_decode(l:str)
|
|
||||||
|
|
||||||
if has_key(l:flow_output, 'errors')
|
let l:flow_output = json_decode(l:str)
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:error in l:flow_output.errors
|
for l:error in get(l:flow_output, 'errors', [])
|
||||||
" Each error is broken up into parts
|
" Each error is broken up into parts
|
||||||
let l:text = ''
|
let l:text = ''
|
||||||
let l:line = 0
|
let l:line = 0
|
||||||
let l:col = 0
|
let l:col = 0
|
||||||
|
|
||||||
for l:message in l:error.message
|
for l:message in l:error.message
|
||||||
" Comments have no line of column information
|
" Comments have no line of column information
|
||||||
if has_key(l:message, 'loc') && l:line ==# 0
|
if has_key(l:message, 'loc') && l:line ==# 0
|
||||||
let l:line = l:message.loc.start.line + 0
|
let l:line = l:message.loc.start.line + 0
|
||||||
let l:col = l:message.loc.start.column + 0
|
let l:col = l:message.loc.start.column + 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:text ==# ''
|
if l:text ==# ''
|
||||||
let l:text = l:message.descr . ':'
|
let l:text = l:message.descr . ':'
|
||||||
else
|
else
|
||||||
|
@ -67,9 +76,6 @@ function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
else
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('javascript', {
|
call ale#linter#Define('javascript', {
|
||||||
|
|
0
test/flow/a/.flowconfig
Normal file
0
test/flow/a/.flowconfig
Normal file
0
test/flow/a/sub/dummy
Normal file
0
test/flow/a/sub/dummy
Normal file
0
test/flow/b/sub/dummy
Normal file
0
test/flow/b/sub/dummy
Normal file
17
test/test_flow_command.vader
Normal file
17
test/test_flow_command.vader
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Before:
|
||||||
|
runtime ale_linters/javascript/flow.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(flow should return a command to run if a .flowconfig file exists):
|
||||||
|
silent! cd /testplugin/test
|
||||||
|
:e! flow/a/sub/dummy
|
||||||
|
|
||||||
|
AssertEqual 'flow check-contents --respect-pragma --json --from ale %s', ale_linters#javascript#flow#GetCommand(bufnr('%'))
|
||||||
|
|
||||||
|
Execute(flow should not return a command to run if no .flowconfig file exists):
|
||||||
|
silent! cd /testplugin/test
|
||||||
|
:e! flow/b/sub/dummy
|
||||||
|
|
||||||
|
AssertEqual '', ale_linters#javascript#flow#GetCommand(bufnr('%'))
|
132
test/test_flow_handler.vader
Normal file
132
test/test_flow_handler.vader
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
Before:
|
||||||
|
let g:flow_output = {
|
||||||
|
\ "flowVersion": "0.39.0",
|
||||||
|
\ "errors": [
|
||||||
|
\ {
|
||||||
|
\ "kind": "infer",
|
||||||
|
\ "level": "error",
|
||||||
|
\ "message": [
|
||||||
|
\ {
|
||||||
|
\ "context": " return 1",
|
||||||
|
\ "descr": "number",
|
||||||
|
\ "type": "Blame",
|
||||||
|
\ "loc": {
|
||||||
|
\ "source": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "type": "SourceFile",
|
||||||
|
\ "start": {
|
||||||
|
\ "line": 417,
|
||||||
|
\ "column": 10,
|
||||||
|
\ "offset": 9503
|
||||||
|
\ },
|
||||||
|
\ "end": {
|
||||||
|
\ "line": 417,
|
||||||
|
\ "column": 10,
|
||||||
|
\ "offset": 9504
|
||||||
|
\ }
|
||||||
|
\ },
|
||||||
|
\ "path": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "line": 417,
|
||||||
|
\ "endline": 417,
|
||||||
|
\ "start": 10,
|
||||||
|
\ "end": 10
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ "context": v:null,
|
||||||
|
\ "descr": "This type is incompatible with the expected return type of",
|
||||||
|
\ "type": "Comment",
|
||||||
|
\ "path": "",
|
||||||
|
\ "line": 0,
|
||||||
|
\ "endline": 0,
|
||||||
|
\ "start": 1,
|
||||||
|
\ "end": 0
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ "context": "function parseArguments(lexer: Lexer<*>): Array<ArgumentNode> {",
|
||||||
|
\ "descr": "array type",
|
||||||
|
\ "type": "Blame",
|
||||||
|
\ "loc": {
|
||||||
|
\ "source": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "type": "SourceFile",
|
||||||
|
\ "start": {
|
||||||
|
\ "line": 416,
|
||||||
|
\ "column": 43,
|
||||||
|
\ "offset": 9472
|
||||||
|
\ },
|
||||||
|
\ "end": {
|
||||||
|
\ "line": 416,
|
||||||
|
\ "column": 61,
|
||||||
|
\ "offset": 9491
|
||||||
|
\ }
|
||||||
|
\ },
|
||||||
|
\ "path": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "line": 416,
|
||||||
|
\ "endline": 416,
|
||||||
|
\ "start": 43,
|
||||||
|
\ "end": 61
|
||||||
|
\ }
|
||||||
|
\ ]
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ "kind": "infer",
|
||||||
|
\ "level": "warning",
|
||||||
|
\ "message": [
|
||||||
|
\ {
|
||||||
|
\ "context": " return peek(lexer, TokenKind.PAREN_L) ?",
|
||||||
|
\ "descr": "unreachable code",
|
||||||
|
\ "type": "Blame",
|
||||||
|
\ "loc": {
|
||||||
|
\ "source": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "type": "SourceFile",
|
||||||
|
\ "start": {
|
||||||
|
\ "line": 419,
|
||||||
|
\ "column": 3,
|
||||||
|
\ "offset": 9508
|
||||||
|
\ },
|
||||||
|
\ "end": {
|
||||||
|
\ "line": 421,
|
||||||
|
\ "column": 7,
|
||||||
|
\ "offset": 9626
|
||||||
|
\ }
|
||||||
|
\ },
|
||||||
|
\ "path": "/home/w0rp/Downloads/graphql-js/src/language/parser.js",
|
||||||
|
\ "line": 419,
|
||||||
|
\ "endline": 421,
|
||||||
|
\ "start": 3,
|
||||||
|
\ "end": 7
|
||||||
|
\ }
|
||||||
|
\ ]
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ "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:expected = [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 417,
|
||||||
|
\ 'bufnr': 347,
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'text': 'number: This type is incompatible with the expected return type of array type',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 419,
|
||||||
|
\ 'bufnr': 347,
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'col': 3,
|
||||||
|
\ 'text': 'unreachable code:',
|
||||||
|
\ },
|
||||||
|
\]
|
||||||
|
|
||||||
|
AssertEqual g:expected, g:actual
|
Reference in a new issue