From 3840cebbc49a64a93e1a6674158f0d7e5372f9f1 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 25 May 2017 22:34:59 +0100 Subject: [PATCH] Automatically use eslint_d for eslint, when available --- autoload/ale/handlers/eslint.vim | 27 +++++++++---------- .../node_modules/.bin/eslint_d | 0 test/test_eslint_executable_detection.vader | 17 +++++++++--- 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 test/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index eb7459b..1785211 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -9,22 +9,21 @@ function! ale#handlers#eslint#GetExecutable(buffer) abort return ale#Var(a:buffer, 'javascript_eslint_executable') endif - " Look for the kinds of paths that create-react-app generates first. - let l:executable = ale#path#ResolveLocalPath( - \ a:buffer, + " Look for eslint_d first, then the path React uses, then the basic + " eslint path. + for l:path in [ + \ 'node_modules/.bin/eslint_d', \ 'node_modules/eslint/bin/eslint.js', - \ '' - \) - - if !empty(l:executable) - return l:executable - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, \ 'node_modules/.bin/eslint', - \ ale#Var(a:buffer, 'javascript_eslint_executable') - \) + \] + 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/test/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d b/test/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d new file mode 100644 index 0000000..e69de29 diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader index 03bb89e..254150a 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -16,7 +16,7 @@ After: call ale#linter#Reset() Execute(create-react-app directories should be detected correctly): - new eslint-test-files/react-app/subdir/testfile.js + silent noautocmd new eslint-test-files/react-app/subdir/testfile.js AssertEqual \ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js', @@ -27,7 +27,7 @@ Execute(create-react-app directories should be detected correctly): Execute(use-global should override create-react-app detection): let g:ale_javascript_eslint_use_global = 1 - new eslint-test-files/react-app/subdir/testfile.js + silent noautocmd new eslint-test-files/react-app/subdir/testfile.js AssertEqual \ 'eslint_d', @@ -36,7 +36,7 @@ Execute(use-global should override create-react-app detection): :q Execute(other app directories should be detected correctly): - new eslint-test-files/other-app/subdir/testfile.js + silent noautocmd new eslint-test-files/other-app/subdir/testfile.js AssertEqual \ g:dir . '/eslint-test-files/node_modules/.bin/eslint', @@ -47,10 +47,19 @@ Execute(other app directories should be detected correctly): Execute(use-global should override other app directories): let g:ale_javascript_eslint_use_global = 1 - new eslint-test-files/other-app/subdir/testfile.js + silent noautocmd new eslint-test-files/other-app/subdir/testfile.js AssertEqual \ 'eslint_d', \ ale#handlers#eslint#GetExecutable(bufnr('')) :q + +Execute(eslint_d should be detected correctly): + silent noautocmd new eslint-test-files/app-with-eslint-d/testfile.js + + AssertEqual + \ g:dir . '/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d', + \ ale#handlers#eslint#GetExecutable(bufnr('')) + + :q