diff options
author | Shannon Moeller <me@shannonmoeller.com> | 2021-06-19 05:03:39 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-19 12:03:39 +0100 |
commit | 397d56f40c9ae606edd70c498efef015753963c6 (patch) | |
tree | bdd646f59f0ff5676ac04dcb6980815c84a4265c | |
parent | a566a5d01b210da7e37a08dabebedb20281abf87 (diff) | |
download | ale-397d56f40c9ae606edd70c498efef015753963c6.zip |
fix(eslint): yarn 2 project cwd (#3684)
* eslint-handler: fix getcwd when there is no node_modules
-rw-r--r-- | autoload/ale/handlers/eslint.vim | 16 | ||||
-rw-r--r-- | test/linter/test_eslint.vader | 11 | ||||
-rw-r--r-- | test/test-files/eslint/yarn2-app/.yarn/sdks/eslint/bin/eslint.js | 0 | ||||
-rw-r--r-- | test/test-files/eslint/yarn2-app/subdir/testfile.js | 0 |
4 files changed, 21 insertions, 6 deletions
diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index 7c492968..374460bc 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -2,10 +2,10 @@ " Description: Functions for working with eslint, for checking or fixing files. let s:executables = [ +\ '.yarn/sdks/eslint/bin/eslint.js', \ 'node_modules/.bin/eslint_d', \ 'node_modules/eslint/bin/eslint.js', \ 'node_modules/.bin/eslint', -\ '.yarn/sdks/eslint/bin/eslint', \] let s:sep = has('win32') ? '\' : '/' @@ -52,14 +52,20 @@ function! ale#handlers#eslint#GetCwd(buffer) abort let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables) if !empty(l:executable) - let l:nmi = strridx(l:executable, 'node_modules') - let l:project_dir = l:executable[0:l:nmi - 2] + let l:modules_index = strridx(l:executable, 'node_modules') + let l:modules_root = l:modules_index > -1 ? l:executable[0:l:modules_index - 2] : '' + + let l:sdks_index = strridx(l:executable, ale#path#Simplify('.yarn/sdks')) + let l:sdks_root = l:sdks_index > -1 ? l:executable[0:l:sdks_index - 2] : '' else let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules') - let l:project_dir = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : '' + let l:modules_root = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : '' + + let l:sdks_dir = ale#path#FindNearestDirectory(a:buffer, ale#path#Simplify('.yarn/sdks')) + let l:sdks_root = !empty(l:sdks_dir) ? fnamemodify(l:sdks_dir, ':h:h:h') : '' endif - return !empty(l:project_dir) ? l:project_dir : '' + return strlen(l:modules_root) > strlen(l:sdks_root) ? l:modules_root : l:sdks_root endfunction function! ale#handlers#eslint#GetCommand(buffer) abort diff --git a/test/linter/test_eslint.vader b/test/linter/test_eslint.vader index 81518af9..4dde5639 100644 --- a/test/linter/test_eslint.vader +++ b/test/linter/test_eslint.vader @@ -66,7 +66,7 @@ Execute(eslint.js executables should be run with node on Windows): \ (has('win32') ? ale#Escape('node.exe') . ' ' : '') \ . ale#Escape(b:executable) . b:args -Execute(eslint.js should be run from a containing project with eslint): +Execute(eslint.js should be run from a containing project with node_modules): call ale#test#SetFilename('../test-files/eslint/react-app/subdir-with-package-json/testfile.js') let b:executable = ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js') @@ -74,3 +74,12 @@ Execute(eslint.js should be run from a containing project with eslint): AssertLinter b:executable, \ (has('win32') ? ale#Escape('node.exe') . ' ' : '') \ . ale#Escape(b:executable) . b:args + +Execute(eslint.js should be run from a containing project with .yarn/sdks): + call ale#test#SetFilename('../test-files/eslint/yarn2-app/subdir/testfile.js') + + let b:executable = ale#path#Simplify(g:dir . '/../test-files/eslint/yarn2-app/.yarn/sdks/eslint/bin/eslint.js') + AssertLinterCwd ale#path#Simplify(g:dir . '/../test-files/eslint/yarn2-app') + AssertLinter b:executable, + \ (has('win32') ? ale#Escape('node.exe') . ' ' : '') + \ . ale#Escape(b:executable) . b:args diff --git a/test/test-files/eslint/yarn2-app/.yarn/sdks/eslint/bin/eslint.js b/test/test-files/eslint/yarn2-app/.yarn/sdks/eslint/bin/eslint.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/eslint/yarn2-app/.yarn/sdks/eslint/bin/eslint.js diff --git a/test/test-files/eslint/yarn2-app/subdir/testfile.js b/test/test-files/eslint/yarn2-app/subdir/testfile.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/eslint/yarn2-app/subdir/testfile.js |