diff options
author | ghsang <66662835+ghsang@users.noreply.github.com> | 2024-05-31 16:30:37 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-31 09:30:37 +0200 |
commit | adaa7f6f62366e5ed8aa76e79ca74f32a3b196b3 (patch) | |
tree | 3e4dc1882a1fa170b96e4c7291438040516f769d | |
parent | c88bddfa83dbb96c2f57426794ed98a0e181ea7e (diff) | |
download | ale-adaa7f6f62366e5ed8aa76e79ca74f32a3b196b3.zip |
Fix eslint cwd strategy (#4781)
Change eslint cwd to follow configuration file paths.
-rw-r--r-- | autoload/ale/handlers/eslint.vim | 26 | ||||
-rw-r--r-- | test/fixers/test_eslint_fixer_callback.vader | 43 | ||||
-rw-r--r-- | test/linter/test_eslint.vader | 7 | ||||
-rw-r--r-- | test/test-files/eslint/yarn2-app/.eslintrc.js (renamed from test/test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d) | 0 |
4 files changed, 6 insertions, 70 deletions
diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index f08ae7c4..eea06f51 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -45,31 +45,7 @@ endfunction " Given a buffer, return an appropriate working directory for ESLint. function! ale#handlers#eslint#GetCwd(buffer) abort - " ESLint 6 loads plugins/configs/parsers from the project root - " By default, the project root is simply the CWD of the running process. - " https://github.com/eslint/rfcs/blob/master/designs/2018-simplified-package-loading/README.md - " https://github.com/dense-analysis/ale/issues/2787 - " - " If eslint is installed in a directory which contains the buffer, assume - " it is the ESLint project root. Otherwise, use nearest node_modules. - " Note: If node_modules not present yet, can't load local deps anyway. - let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables) - - if !empty(l:executable) - 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: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 strlen(l:modules_root) > strlen(l:sdks_root) ? l:modules_root : l:sdks_root + return ale#path#Dirname(ale#handlers#eslint#FindConfig(a:buffer)) endfunction function! ale#handlers#eslint#GetCommand(buffer) abort diff --git a/test/fixers/test_eslint_fixer_callback.vader b/test/fixers/test_eslint_fixer_callback.vader index 4a1dc47c..2a20243c 100644 --- a/test/fixers/test_eslint_fixer_callback.vader +++ b/test/fixers/test_eslint_fixer_callback.vader @@ -167,7 +167,7 @@ Execute(The lower priority configuration file in a nested directory should be pr AssertFixer \ { \ 'read_temporary_file': 1, - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'), + \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'), \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config/.eslintrc')) @@ -182,7 +182,7 @@ Execute(--config in options should override configuration file detection for old AssertFixer \ { \ 'read_temporary_file': 1, - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'), + \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'), \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' --config /foo.cfg' @@ -194,7 +194,7 @@ Execute(--config in options should override configuration file detection for old AssertFixer \ { \ 'read_temporary_file': 1, - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'), + \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'), \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' -c /foo.cfg' @@ -235,7 +235,7 @@ Execute(The version check should be correct): \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' --version', \ { - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'), + \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'), \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', @@ -245,7 +245,7 @@ Execute(The version check should be correct): AssertFixer [ \ { - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'), + \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'), \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js')) \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', @@ -266,39 +266,6 @@ Execute(--fix-dry-run should be used for 4.9.0 and up): \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', \ } -Execute(--fix-to-stdout should be used for eslint_d): - call ale#test#SetFilename('../test-files/eslint/app-with-eslint-d/testfile.js') - - AssertFixer - \ { - \ 'read_temporary_file': 1, - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d'), - \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d')) - \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/package.json')) - \ . ' --fix %t', - \ } - - " The option should be used when eslint_d is new enough. - " We look at the ESLint version instead of the eslint_d version. - GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)'] - AssertFixer - \ { - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d'), - \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d')) - \ . ' --stdin-filename %s --stdin --fix-to-stdout', - \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput', - \ } - - " The option should be used for new versions too. - GivenCommandOutput ['4.9.0'] - AssertFixer - \ { - \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d'), - \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d')) - \ . ' --stdin-filename %s --stdin --fix-to-stdout', - \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput', - \ } - Execute(The --fix-dry-run post-processor should handle JSON output correctly): AssertEqual \ [], diff --git a/test/linter/test_eslint.vader b/test/linter/test_eslint.vader index 4dde5639..f4f2e309 100644 --- a/test/linter/test_eslint.vader +++ b/test/linter/test_eslint.vader @@ -50,13 +50,6 @@ Execute(use-global should override other app directories): AssertLinterCwd ale#path#Simplify(g:dir . '/../test-files/eslint') AssertLinter b:executable, ale#Escape(b:executable) . b:args -Execute(eslint_d should be detected correctly): - call ale#test#SetFilename('../test-files/eslint/app-with-eslint-d/testfile.js') - - let b:executable = ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d') - AssertLinterCwd ale#path#Simplify(g:dir . '/../test-files/eslint/app-with-eslint-d') - AssertLinter b:executable, ale#Escape(b:executable) . b:args - Execute(eslint.js executables should be run with node on Windows): call ale#test#SetFilename('../test-files/eslint/react-app/subdir/testfile.js') diff --git a/test/test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d b/test/test-files/eslint/yarn2-app/.eslintrc.js index e69de29b..e69de29b 100644 --- a/test/test-files/eslint/app-with-eslint-d/node_modules/.bin/eslint_d +++ b/test/test-files/eslint/yarn2-app/.eslintrc.js |