summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/eslint.vim13
1 files changed, 12 insertions, 1 deletions
diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim
index 7ef63785..156b939f 100644
--- a/autoload/ale/handlers/eslint.vim
+++ b/autoload/ale/handlers/eslint.vim
@@ -42,7 +42,18 @@ function! ale#handlers#eslint#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'javascript_eslint_options')
- return ale#node#Executable(a:buffer, l:executable)
+ " 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
+ " Identify project root from presence of node_modules dir.
+ " Note: If node_modules not present yet, can't load local deps anyway.
+ 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:cd_command = !empty(l:project_dir) ? ale#path#CdString(l:project_dir) : ''
+
+ return l:cd_command
+ \ . ale#node#Executable(a:buffer, l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -f json --stdin --stdin-filename %s'
endfunction