diff options
-rw-r--r-- | ale_linters/javascript/eslint.vim | 11 | ||||
-rw-r--r-- | test/eslint-test-files/node_modules/.bin/eslint | 0 | ||||
-rw-r--r-- | test/eslint-test-files/other-app/subdir/testfile.js | 0 | ||||
-rw-r--r-- | test/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js | 0 | ||||
-rw-r--r-- | test/eslint-test-files/react-app/subdir/testfile.js | 0 | ||||
-rw-r--r-- | test/test_eslint_executable_detection.vader | 56 |
6 files changed, 67 insertions, 0 deletions
diff --git a/ale_linters/javascript/eslint.vim b/ale_linters/javascript/eslint.vim index ac88dd00..3bf88316 100644 --- a/ale_linters/javascript/eslint.vim +++ b/ale_linters/javascript/eslint.vim @@ -15,6 +15,17 @@ function! ale_linters#javascript#eslint#GetExecutable(buffer) abort return g:ale_javascript_eslint_executable endif + " Look for the kinds of paths that create-react-app generates first. + let l:executable = ale#util#ResolveLocalPath( + \ a:buffer, + \ 'node_modules/eslint/bin/eslint.js', + \ '' + \) + + if !empty(l:executable) + return l:executable + endif + return ale#util#ResolveLocalPath( \ a:buffer, \ 'node_modules/.bin/eslint', diff --git a/test/eslint-test-files/node_modules/.bin/eslint b/test/eslint-test-files/node_modules/.bin/eslint new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/eslint-test-files/node_modules/.bin/eslint diff --git a/test/eslint-test-files/other-app/subdir/testfile.js b/test/eslint-test-files/other-app/subdir/testfile.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/eslint-test-files/other-app/subdir/testfile.js diff --git a/test/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js b/test/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js diff --git a/test/eslint-test-files/react-app/subdir/testfile.js b/test/eslint-test-files/react-app/subdir/testfile.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/eslint-test-files/react-app/subdir/testfile.js diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader new file mode 100644 index 00000000..e963ae1c --- /dev/null +++ b/test/test_eslint_executable_detection.vader @@ -0,0 +1,56 @@ +Before: + let g:ale_javascript_eslint_executable = 'eslint_d' + + silent! cd /testplugin/test + let g:dir = getcwd() + + runtime ale_linters/javascript/eslint.vim + +After: + let g:ale_javascript_eslint_executable = 'eslint' + let g:ale_javascript_eslint_use_global = 0 + + silent execute 'cd ' . g:dir + unlet! g:dir + + call ale#linter#Reset() + +Execute(create-react-app directories should be detected correctly): + new eslint-test-files/react-app/subdir/testfile.js + + AssertEqual + \ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js', + \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + + :q + +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 + + AssertEqual + \ 'eslint_d', + \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + + :q + +Execute(other app directories should be detected correctly): + new eslint-test-files/other-app/subdir/testfile.js + + AssertEqual + \ g:dir . '/eslint-test-files/node_modules/.bin/eslint', + \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + + :q + +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 + + AssertEqual + \ 'eslint_d', + \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + + :q |