summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-27 17:11:03 +0100
committerw0rp <devw0rp@gmail.com>2017-05-27 17:11:03 +0100
commitc4f22186bd74b85c3ff22fdba2bed7a7d0009148 (patch)
treea6445b94d5bb6c2077da913192ca4430bce23dfe /autoload
parentb934dc52b6b9bee11fcc4034724f2ed71d918606 (diff)
downloadale-c4f22186bd74b85c3ff22fdba2bed7a7d0009148.zip
Refactor running of local Node programs with a helper function
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/eslint.vim18
-rw-r--r--autoload/ale/node.vim22
2 files changed, 24 insertions, 16 deletions
diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim
index 17852119..080005a6 100644
--- a/autoload/ale/handlers/eslint.vim
+++ b/autoload/ale/handlers/eslint.vim
@@ -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
diff --git a/autoload/ale/node.vim b/autoload/ale/node.vim
new file mode 100644
index 00000000..54b53fb9
--- /dev/null
+++ b/autoload/ale/node.vim
@@ -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