Skip to content

Commit

Permalink
fix: resolve eslint working directory by looking up config files
Browse files Browse the repository at this point in the history
Closes #4487
  • Loading branch information
Peter Benjamin authored and Peter Benjamin committed Jul 23, 2023
1 parent 29e5ffe commit 86ebb6c
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions autoload/ale/handlers/eslint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86ebb6c

Please sign in to comment.