Fix #783 - Do not run Flow with home directory configuration files by default

This commit is contained in:
w0rp 2017-11-21 14:37:01 +00:00
parent ac7f69063d
commit 3ef98f42bd
3 changed files with 46 additions and 14 deletions

View File

@ -1,24 +1,12 @@
" Author: Zach Perrault -- @zperrault
" Author: Florian Beeres <yuuki@protonmail.com>
" Description: FlowType checking for JavaScript files
" Flow extra errors
" Author: Florian Beeres <yuuki@protonmail.com>
call ale#Set('javascript_flow_executable', 'flow')
call ale#Set('javascript_flow_use_home_config', 0)
call ale#Set('javascript_flow_use_global', 0)
function! ale_linters#javascript#flow#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_flow', [
\ 'node_modules/.bin/flow',
\])
endfunction
function! ale_linters#javascript#flow#VersionCheck(buffer) abort
return ale#Escape(ale_linters#javascript#flow#GetExecutable(a:buffer))
\ . ' --version'
endfunction
function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort
let l:flow_config = ale#path#FindNearestFile(a:buffer, '.flowconfig')
if empty(l:flow_config)
@ -26,7 +14,35 @@ function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort
return ''
endif
" Don't run Flow with a configuration file from the home directory by
" default, which can eat all of your RAM.
if fnamemodify(l:flow_config, ':h') is? $HOME
\&& !ale#Var(a:buffer, 'javascript_flow_use_home_config')
return ''
endif
return ale#node#FindExecutable(a:buffer, 'javascript_flow', [
\ 'node_modules/.bin/flow',
\])
endfunction
function! ale_linters#javascript#flow#VersionCheck(buffer) abort
let l:executable = ale_linters#javascript#flow#GetExecutable(a:buffer)
if empty(l:executable)
return ''
endif
return ale#Escape(l:executable) . ' --version'
endfunction
function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort
let l:executable = ale_linters#javascript#flow#GetExecutable(a:buffer)
if empty(l:executable)
return ''
endif
let l:version = ale#semver#GetVersion(l:executable, a:version_lines)
" If we can parse the version number, then only use --respect-pragma

View File

@ -27,6 +27,11 @@ endfunction
" Check if files are executable, and if they are, remember that they are
" for subsequent calls. We'll keep checking until programs can be executed.
function! ale#engine#IsExecutable(buffer, executable) abort
if empty(a:executable)
" Don't log the executable check if the executable string is empty.
return 0
endif
if has_key(s:executable_cache_map, a:executable)
return 1
endif

View File

@ -84,6 +84,17 @@ g:ale_javascript_flow_executable *g:ale_javascript_flow_executable*
See |ale-integrations-local-executables|
g:ale_javascript_flow_use_home_config *g:ale_javascript_flow_use_home_config*
*b:ale_javascript_flow_use_home_config*
Type: |Number|
Default: `0`
When set to `1`, ALE will allow Flow to be executed with configuration files
from your home directory. ALE will not run Flow with home directory
configuration files by default, as doing so can lead to Vim consuming all of
your RAM and CPU power.
g:ale_javascript_flow_use_global *g:ale_javascript_flow_use_global*
*b:ale_javascript_flow_use_global*
Type: |Number|