summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-05-17 20:45:25 +0100
committerw0rp <devw0rp@gmail.com>2019-05-17 20:45:25 +0100
commite6745a38118068dbfe8246041de17a5f5c5bf149 (patch)
treef743d54b6f9df970d1fb8665d8d6e27f077d2f73 /autoload
parente5ea809094fd1d521ac88516f5b4b6870e656f3a (diff)
downloadale-e6745a38118068dbfe8246041de17a5f5c5bf149.zip
Fix #1989 - Use ESlint options for fixers too
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/assert.vim12
-rw-r--r--autoload/ale/fixers/eslint.vim18
2 files changed, 27 insertions, 3 deletions
diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim
index ed90792d..dac5efb7 100644
--- a/autoload/ale/assert.vim
+++ b/autoload/ale/assert.vim
@@ -96,6 +96,13 @@ function! ale#assert#Fixer(expected_result) abort
AssertEqual a:expected_result, l:result
endfunction
+function! ale#assert#FixerNotExecuted() abort
+ let l:buffer = bufnr('')
+ let l:result = s:ProcessDeferredCommands(s:FixerFunction(l:buffer))[-1]
+
+ Assert empty(l:result), "The fixer will be executed when it shouldn't be"
+endfunction
+
function! ale#assert#LinterNotExecuted() abort
let l:buffer = bufnr('')
let l:linter = s:GetLinter()
@@ -158,6 +165,7 @@ endfunction
function! ale#assert#SetUpFixerTestCommands() abort
command! -nargs=+ GivenCommandOutput :call ale#assert#GivenCommandOutput(<args>)
command! -nargs=+ AssertFixer :call ale#assert#Fixer(<args>)
+ command! -nargs=0 AssertFixerNotExecuted :call ale#assert#FixerNotExecuted()
endfunction
" A dummy function for making sure this module is loaded.
@@ -316,4 +324,8 @@ function! ale#assert#TearDownFixerTest() abort
if exists(':AssertFixer')
delcommand AssertFixer
endif
+
+ if exists(':AssertFixerNotExecuted')
+ delcommand AssertFixerNotExecuted
+ endif
endfunction
diff --git a/autoload/ale/fixers/eslint.vim b/autoload/ale/fixers/eslint.vim
index 0f57cba6..62e692b1 100644
--- a/autoload/ale/fixers/eslint.vim
+++ b/autoload/ale/fixers/eslint.vim
@@ -35,9 +35,18 @@ endfunction
function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
- let l:config = ale#handlers#eslint#FindConfig(a:buffer)
+ let l:options = ale#Var(a:buffer, 'javascript_eslint_options')
- if empty(l:config)
+ " Use the configuration file from the options, if configured.
+ if l:options =~# '\v(^| )-c|(^| )--config'
+ let l:config = ''
+ let l:has_config = 1
+ else
+ let l:config = ale#handlers#eslint#FindConfig(a:buffer)
+ let l:has_config = !empty(l:config)
+ endif
+
+ if !l:has_config
return 0
endif
@@ -45,6 +54,7 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
if l:executable =~# 'eslint_d$' && ale#semver#GTE(a:version, [3, 19, 0])
return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
+ \ . ale#Pad(l:options)
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
\}
@@ -54,6 +64,7 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
if ale#semver#GTE(a:version, [4, 9, 0])
return {
\ 'command': 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',
\}
@@ -61,7 +72,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
- \ . ' -c ' . ale#Escape(l:config)
+ \ . ale#Pad(l:options)
+ \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
\ . ' --fix %t',
\ 'read_temporary_file': 1,
\}