diff options
author | Kevin Locke <kevin@kevinlocke.name> | 2020-07-01 16:00:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 17:00:21 +0100 |
commit | b3c6db173a019c37c83d4600c0c68872e91086dd (patch) | |
tree | 43ffae10ce9732f286b75679c937d642f9a1ac1c /autoload | |
parent | 834d6f9c48ce349a4c3d72e98bd0de81aaa84042 (diff) | |
download | ale-b3c6db173a019c37c83d4600c0c68872e91086dd.zip |
Run ESLint fixer from project root, where possible (#3096)
* Split eslint#GetCdString from eslint#GetCommand
Move the code for finding the project root and building the cd string
into a separate function so that it can be reused in the eslint fixer.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
* Run ESLint fixer from project root dir
To match the ESLint linter, as changed in 9ee57d43 (which I forgot to
apply to the fixer, whoops).
Fixes: #3094
Closes: #3095
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/eslint.vim | 9 | ||||
-rw-r--r-- | autoload/ale/handlers/eslint.vim | 19 |
2 files changed, 18 insertions, 10 deletions
diff --git a/autoload/ale/fixers/eslint.vim b/autoload/ale/fixers/eslint.vim index 62e692b1..f725875c 100644 --- a/autoload/ale/fixers/eslint.vim +++ b/autoload/ale/fixers/eslint.vim @@ -53,7 +53,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort " Use --fix-to-stdout with eslint_d if l:executable =~# 'eslint_d$' && ale#semver#GTE(a:version, [3, 19, 0]) return { - \ 'command': ale#node#Executable(a:buffer, l:executable) + \ 'command': ale#handlers#eslint#GetCdString(a:buffer) + \ . ale#node#Executable(a:buffer, l:executable) \ . ale#Pad(l:options) \ . ' --stdin-filename %s --stdin --fix-to-stdout', \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput', @@ -63,7 +64,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort " 4.9.0 is the first version with --fix-dry-run if ale#semver#GTE(a:version, [4, 9, 0]) return { - \ 'command': ale#node#Executable(a:buffer, l:executable) + \ 'command': ale#handlers#eslint#GetCdString(a:buffer) + \ . ale#node#Executable(a:buffer, l:executable) \ . ale#Pad(l:options) \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', @@ -71,7 +73,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort endif return { - \ 'command': ale#node#Executable(a:buffer, l:executable) + \ 'command': ale#handlers#eslint#GetCdString(a:buffer) + \ . ale#node#Executable(a:buffer, l:executable) \ . ale#Pad(l:options) \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '') \ . ' --fix %t', diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index 156b939f..c7c47d78 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -37,11 +37,9 @@ function! ale#handlers#eslint#GetExecutable(buffer) abort \]) endfunction -function! ale#handlers#eslint#GetCommand(buffer) abort - let l:executable = ale#handlers#eslint#GetExecutable(a:buffer) - - let l:options = ale#Var(a:buffer, 'javascript_eslint_options') - +" Given a buffer, return a command prefix string which changes directory +" as necessary for running ESLint. +function! ale#handlers#eslint#GetCdString(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 @@ -50,9 +48,16 @@ function! ale#handlers#eslint#GetCommand(buffer) abort " 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 + return !empty(l:project_dir) ? ale#path#CdString(l:project_dir) : '' +endfunction + +function! ale#handlers#eslint#GetCommand(buffer) abort + let l:executable = ale#handlers#eslint#GetExecutable(a:buffer) + + let l:options = ale#Var(a:buffer, 'javascript_eslint_options') + + return ale#handlers#eslint#GetCdString(a:buffer) \ . ale#node#Executable(a:buffer, l:executable) \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' -f json --stdin --stdin-filename %s' |