From 86ebb6c70e93db66e4c21e8ab334f012ece52f51 Mon Sep 17 00:00:00 2001 From: Peter Benjamin Date: Sun, 23 Jul 2023 13:25:50 -0700 Subject: [PATCH] fix: resolve eslint working directory by looking up config files Closes #4487 --- autoload/ale/handlers/eslint.vim | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index 374460bc52..c7b8ae4b6f 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -18,6 +18,7 @@ call ale#Set('javascript_eslint_suppress_missing_config', 0) function! ale#handlers#eslint#FindConfig(buffer) abort for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h')) for l:basename in [ + \ 'eslint.config.js', \ '.eslintrc.js', \ '.eslintrc.yaml', \ '.eslintrc.yml', @@ -49,23 +50,25 @@ function! ale#handlers#eslint#GetCwd(buffer) abort " 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) + " let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables) + let l:nearest_config = ale#handlers#eslint#FindConfig(a:buffer) + return fnamemodify(l:nearest_config, ':p:h') - 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] : '' + " 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_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 + " 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 strlen(l:modules_root) > strlen(l:sdks_root) ? l:modules_root : l:sdks_root endfunction function! ale#handlers#eslint#GetCommand(buffer) abort