Refactor running of local Node programs with a helper function
This commit is contained in:
@@ -5,25 +5,11 @@ call ale#Set('javascript_eslint_executable', 'eslint')
|
||||
call ale#Set('javascript_eslint_use_global', 0)
|
||||
|
||||
function! ale#handlers#eslint#GetExecutable(buffer) abort
|
||||
if ale#Var(a:buffer, 'javascript_eslint_use_global')
|
||||
return ale#Var(a:buffer, 'javascript_eslint_executable')
|
||||
endif
|
||||
|
||||
" Look for eslint_d first, then the path React uses, then the basic
|
||||
" eslint path.
|
||||
for l:path in [
|
||||
return ale#node#FindExecutable(a:buffer, 'javascript_eslint', [
|
||||
\ 'node_modules/.bin/eslint_d',
|
||||
\ 'node_modules/eslint/bin/eslint.js',
|
||||
\ 'node_modules/.bin/eslint',
|
||||
\]
|
||||
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
|
||||
|
||||
if !empty(l:executable)
|
||||
return l:executable
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ale#Var(a:buffer, 'javascript_eslint_executable')
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! s:FindConfig(buffer) abort
|
||||
|
||||
22
autoload/ale/node.vim
Normal file
22
autoload/ale/node.vim
Normal file
@@ -0,0 +1,22 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Functions for working with Node executables.
|
||||
|
||||
" Given a buffer number, a base variable name, and a list of paths to search
|
||||
" for in ancestor directories, detect the executable path for a Node program.
|
||||
"
|
||||
" The use_global and executable options for the relevant program will be used.
|
||||
function! ale#node#FindExecutable(buffer, base_var_name, path_list) abort
|
||||
if ale#Var(a:buffer, a:base_var_name . '_use_global')
|
||||
return ale#Var(a:buffer, a:base_var_name . '_executable')
|
||||
endif
|
||||
|
||||
for l:path in a:path_list
|
||||
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
|
||||
|
||||
if !empty(l:executable)
|
||||
return l:executable
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ale#Var(a:buffer, a:base_var_name . '_executable')
|
||||
endfunction
|
||||
Reference in New Issue
Block a user