diff options
author | w0rp <devw0rp@gmail.com> | 2017-02-10 22:47:56 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-02-10 22:47:56 +0000 |
commit | 49f7ce4f6dbca39a013be6d5714d11a2b882d17c (patch) | |
tree | 7a2335cc70bb7879c9ae4e54a810162ed7ef0dc1 /ale_linters | |
parent | 926cd1a9533a816b0dbd7f6ca2ccbd2cd9cc2399 (diff) | |
download | ale-49f7ce4f6dbca39a013be6d5714d11a2b882d17c.zip |
Fix #246 Don't run flow if there's no .flowconfig
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/javascript/flow.vim | 104 |
1 files changed, 55 insertions, 49 deletions
diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim index f0b81b1d..c1ee4b2d 100644 --- a/ale_linters/javascript/flow.vim +++ b/ale_linters/javascript/flow.vim @@ -8,68 +8,74 @@ let g:ale_javascript_flow_use_global = \ get(g:, 'ale_javascript_flow_use_global', 0) function! ale_linters#javascript#flow#GetExecutable(buffer) abort - if g:ale_javascript_flow_use_global - return g:ale_javascript_flow_executable - endif - - return ale#util#ResolveLocalPath( - \ a:buffer, - \ 'node_modules/.bin/flow', - \ g:ale_javascript_flow_executable - \) + if g:ale_javascript_flow_use_global + return g:ale_javascript_flow_executable + endif + + return ale#util#ResolveLocalPath( + \ a:buffer, + \ 'node_modules/.bin/flow', + \ g:ale_javascript_flow_executable + \) endfunction function! ale_linters#javascript#flow#GetCommand(buffer) abort - return ale_linters#javascript#flow#GetExecutable(a:buffer) - \ . ' check-contents --respect-pragma --json --from ale %s' + 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) + \ . ' check-contents --respect-pragma --json --from ale %s' endfunction function! ale_linters#javascript#flow#Handle(buffer, lines) abort - let l:str = join(a:lines, '') - if l:str ==# '' - return [] - endif - let l:flow_output = json_decode(l:str) + let l:str = join(a:lines, '') - if has_key(l:flow_output, 'errors') + if l:str ==# '' + return [] + endif + + let l:flow_output = json_decode(l:str) let l:output = [] - for l:error in l:flow_output.errors - " 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 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 + for l:error in get(l:flow_output, 'errors', []) + " 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 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 + endfor + + if has_key(l:error, 'operation') + let l:text = l:text . ' See also: ' . l:error.operation.descr endif - 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': l:col, - \ 'text': l:text, - \ 'type': l:error.level ==# 'error' ? 'E' : 'W', - \}) + + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:line, + \ 'vcol': 0, + \ 'col': l:col, + \ 'text': l:text, + \ 'type': l:error.level ==# 'error' ? 'E' : 'W', + \}) endfor return l:output - else - return [] - endif endfunction call ale#linter#Define('javascript', { |