mirror of https://github.com/dense-analysis/ale
Fix #1989 - Use ESlint options for fixers too
This commit is contained in:
parent
e5ea809094
commit
e6745a3811
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
\}
|
||||
|
|
|
@ -351,6 +351,7 @@ given the above setup are as follows.
|
|||
|
||||
`GivenCommandOutput [...]` - Define output for ale#command#Run.
|
||||
`AssertFixer results` - Check the fixer results
|
||||
`AssertFixerNotExecuted` - Check that fixers will not be executed.
|
||||
|
||||
|
||||
===============================================================================
|
||||
|
|
|
@ -19,6 +19,131 @@ Execute(The executable path should be correct):
|
|||
\ . ' --fix %t',
|
||||
\ }
|
||||
|
||||
Execute(The ESLint fixer shouldn't run if no configuration file can be found):
|
||||
call ale#test#SetFilename('../no-configuration')
|
||||
AssertFixerNotExecuted
|
||||
|
||||
Execute(The ESLint fixer should use a config file option if set for old versions):
|
||||
call ale#test#SetFilename('../no-configuration')
|
||||
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('eslint') . ' -c /foo.cfg --fix %t',
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('eslint') . ' --bar -c /foo.cfg --fix %t',
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('eslint') . ' --config /foo.cfg --fix %t',
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('eslint') . ' --bar --config /foo.cfg --fix %t',
|
||||
\ }
|
||||
|
||||
Execute(The ESLint fixer should use a -c file option if set for eslint_d):
|
||||
let b:ale_javascript_eslint_executable = '/bin/eslint_d'
|
||||
GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)']
|
||||
call ale#test#SetFilename('../no-configuration')
|
||||
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
||||
\ 'command': ale#Escape('/bin/eslint_d')
|
||||
\ . ' -c /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
||||
\ 'command': ale#Escape('/bin/eslint_d')
|
||||
\ . ' --bar -c /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
||||
\ 'command': ale#Escape('/bin/eslint_d')
|
||||
\ . ' --config /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
||||
\ 'command': ale#Escape('/bin/eslint_d')
|
||||
\ . ' --bar --config /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
||||
\ }
|
||||
|
||||
Execute(The ESLint fixer should use a config file option if set for new versions):
|
||||
GivenCommandOutput ['4.9.0']
|
||||
call ale#test#SetFilename('../no-configuration')
|
||||
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
||||
\ 'command': ale#Escape('eslint')
|
||||
\ . ' -c /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
||||
\ 'command': ale#Escape('eslint')
|
||||
\ . ' --bar -c /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
||||
\ 'command': ale#Escape('eslint')
|
||||
\ . ' --config /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
||||
\ 'command': ale#Escape('eslint')
|
||||
\ . ' --bar --config /foo.cfg'
|
||||
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
||||
\ }
|
||||
|
||||
Execute(The lower priority configuration file in a nested directory should be preferred):
|
||||
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
||||
|
||||
|
@ -31,6 +156,31 @@ Execute(The lower priority configuration file in a nested directory should be pr
|
|||
\ . ' --fix %t',
|
||||
\ }
|
||||
|
||||
Execute(--config in options should override configuration file detection for old versions):
|
||||
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
||||
|
||||
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': (has('win32') ? 'node.exe ' : '')
|
||||
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
||||
\ . ' --config /foo.cfg'
|
||||
\ . ' --fix %t',
|
||||
\ }
|
||||
|
||||
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': (has('win32') ? 'node.exe ' : '')
|
||||
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
||||
\ . ' -c /foo.cfg'
|
||||
\ . ' --fix %t',
|
||||
\ }
|
||||
|
||||
Execute(package.json should be used as a last resort):
|
||||
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-package-json/testfile.js')
|
||||
|
||||
|
|
Loading…
Reference in New Issue