#1095 Use --stdin-filepath where available for prettier-eslint
This commit is contained in:
parent
382cb4d538
commit
4b4762697c
@ -6,7 +6,6 @@ function! ale#fixers#prettier_eslint#SetOptionDefaults() abort
|
|||||||
call ale#Set('javascript_prettier_eslint_executable', 'prettier-eslint')
|
call ale#Set('javascript_prettier_eslint_executable', 'prettier-eslint')
|
||||||
call ale#Set('javascript_prettier_eslint_use_global', 0)
|
call ale#Set('javascript_prettier_eslint_use_global', 0)
|
||||||
call ale#Set('javascript_prettier_eslint_options', '')
|
call ale#Set('javascript_prettier_eslint_options', '')
|
||||||
call ale#Set('javascript_prettier_eslint_legacy', 0)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#fixers#prettier_eslint#SetOptionDefaults()
|
call ale#fixers#prettier_eslint#SetOptionDefaults()
|
||||||
@ -19,16 +18,43 @@ function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#prettier_eslint#Fix(buffer) abort
|
function! ale#fixers#prettier_eslint#Fix(buffer) abort
|
||||||
|
let l:executable = ale#fixers#prettier_eslint#GetExecutable(a:buffer)
|
||||||
|
|
||||||
|
let l:command = ale#semver#HasVersion(l:executable)
|
||||||
|
\ ? ''
|
||||||
|
\ : ale#Escape(l:executable) . ' --version'
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command,
|
||||||
|
\ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion',
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#prettier_eslint#ApplyFixForVersion(buffer, version_output) abort
|
||||||
let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
|
let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
|
||||||
let l:executable = ale#fixers#prettier_eslint#GetExecutable(a:buffer)
|
let l:executable = ale#fixers#prettier_eslint#GetExecutable(a:buffer)
|
||||||
|
|
||||||
let l:config = !ale#Var(a:buffer, 'javascript_prettier_eslint_legacy')
|
let l:version = ale#semver#GetVersion(l:executable, a:version_output)
|
||||||
|
|
||||||
|
" 4.2.0 is the first version with --eslint-config-path
|
||||||
|
let l:config = ale#semver#GTE(l:version, [4, 2, 0])
|
||||||
\ ? ale#handlers#eslint#FindConfig(a:buffer)
|
\ ? ale#handlers#eslint#FindConfig(a:buffer)
|
||||||
\ : ''
|
\ : ''
|
||||||
let l:eslint_config_option = !empty(l:config)
|
let l:eslint_config_option = !empty(l:config)
|
||||||
\ ? ' --eslint-config-path ' . ale#Escape(l:config)
|
\ ? ' --eslint-config-path ' . ale#Escape(l:config)
|
||||||
\ : ''
|
\ : ''
|
||||||
|
|
||||||
|
" 4.4.0 is the first version with --stdin-filepath
|
||||||
|
if ale#semver#GTE(l:version, [4, 4, 0])
|
||||||
|
return {
|
||||||
|
\ 'command': ale#path#BufferCdString(a:buffer)
|
||||||
|
\ . ale#Escape(l:executable)
|
||||||
|
\ . l:eslint_config_option
|
||||||
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
|
\ . ' --stdin-filepath %s --stdin',
|
||||||
|
\}
|
||||||
|
endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . ' %t'
|
\ . ' %t'
|
||||||
|
@ -171,11 +171,6 @@ g:ale_javascript_prettier_use_global *g:ale_javascript_prettier_use_global*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
prettier-eslint *ale-javascript-prettier-eslint*
|
prettier-eslint *ale-javascript-prettier-eslint*
|
||||||
|
|
||||||
ALE supports `prettier-eslint` >= 4.2.0. Using lower version is not recommended
|
|
||||||
because it cannot be configured to use the ESLint configuration file for input
|
|
||||||
given via stdin. However ALE could be set up on your own risk with older
|
|
||||||
versions with |g:ale_javascript_prettier_eslint_legacy|
|
|
||||||
|
|
||||||
g:ale_javascript_prettier_eslint_executable
|
g:ale_javascript_prettier_eslint_executable
|
||||||
*g:ale_javascript_prettier_eslint_executable*
|
*g:ale_javascript_prettier_eslint_executable*
|
||||||
*b:ale_javascript_prettier_eslint_executable*
|
*b:ale_javascript_prettier_eslint_executable*
|
||||||
@ -202,14 +197,6 @@ g:ale_javascript_prettier_eslint_use_global
|
|||||||
|
|
||||||
See |ale-integrations-local-executables|
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
g:ale_javascript_prettier_eslint_legacy
|
|
||||||
*g:ale_javascript_prettier_eslint_legacy*
|
|
||||||
*b:ale_javascript_prettier_eslint_legacy*
|
|
||||||
Type: |Number|
|
|
||||||
Default: `0`
|
|
||||||
|
|
||||||
Fallback option for `prettier-eslint` < 4.2.0
|
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
prettier-standard *ale-javascript-prettier-standard*
|
prettier-standard *ale-javascript-prettier-standard*
|
||||||
|
@ -4,12 +4,10 @@ Before:
|
|||||||
Save g:ale_javascript_prettier_eslint_executable
|
Save g:ale_javascript_prettier_eslint_executable
|
||||||
Save g:ale_javascript_prettier_eslint_use_global
|
Save g:ale_javascript_prettier_eslint_use_global
|
||||||
Save g:ale_javascript_prettier_eslint_options
|
Save g:ale_javascript_prettier_eslint_options
|
||||||
Save g:ale_javascript_prettier_eslint_legacy
|
|
||||||
|
|
||||||
unlet! g:ale_javascript_prettier_eslint_executable
|
unlet! g:ale_javascript_prettier_eslint_executable
|
||||||
unlet! g:ale_javascript_prettier_eslint_use_global
|
unlet! g:ale_javascript_prettier_eslint_use_global
|
||||||
unlet! g:ale_javascript_prettier_eslint_options
|
unlet! g:ale_javascript_prettier_eslint_options
|
||||||
unlet! g:ale_javascript_prettier_eslint_legacy
|
|
||||||
|
|
||||||
call ale#fixers#prettier_eslint#SetOptionDefaults()
|
call ale#fixers#prettier_eslint#SetOptionDefaults()
|
||||||
|
|
||||||
@ -19,9 +17,9 @@ After:
|
|||||||
unlet! b:ale_javascript_prettier_eslint_executable
|
unlet! b:ale_javascript_prettier_eslint_executable
|
||||||
unlet! b:ale_javascript_prettier_eslint_use_global
|
unlet! b:ale_javascript_prettier_eslint_use_global
|
||||||
unlet! b:ale_javascript_prettier_eslint_options
|
unlet! b:ale_javascript_prettier_eslint_options
|
||||||
unlet! b:ale_javascript_prettier_eslint_legacy
|
|
||||||
|
|
||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
call ale#semver#ResetVersionCache()
|
||||||
|
|
||||||
Execute(The default command should be correct):
|
Execute(The default command should be correct):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
@ -32,7 +30,7 @@ Execute(The default command should be correct):
|
|||||||
\ . ' %t'
|
\ . ' %t'
|
||||||
\ . ' --write'
|
\ . ' --write'
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
||||||
|
|
||||||
Execute(Additional options should be used when set):
|
Execute(Additional options should be used when set):
|
||||||
let b:ale_javascript_prettier_eslint_options = '--foobar'
|
let b:ale_javascript_prettier_eslint_options = '--foobar'
|
||||||
@ -45,9 +43,9 @@ Execute(Additional options should be used when set):
|
|||||||
\ . ' %t'
|
\ . ' %t'
|
||||||
\ . ' --foobar --write'
|
\ . ' --foobar --write'
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
||||||
|
|
||||||
Execute(Configuration files should be detected):
|
Execute(--eslint-config-path should be set for 4.2.0 and up):
|
||||||
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
@ -59,11 +57,10 @@ Execute(Configuration files should be detected):
|
|||||||
\ . ' --eslint-config-path ' . ale#Escape(ale#path#Winify(g:dir . '/eslint-test-files/react-app/.eslintrc.js'))
|
\ . ' --eslint-config-path ' . ale#Escape(ale#path#Winify(g:dir . '/eslint-test-files/react-app/.eslintrc.js'))
|
||||||
\ . ' --write'
|
\ . ' --write'
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.2.0'])
|
||||||
|
|
||||||
Execute(Configuration files should be disabled if the legacy option is on):
|
Execute(--eslint-config-path shouldn't be used for older versions):
|
||||||
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
||||||
let b:ale_javascript_prettier_eslint_legacy = 1
|
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
@ -73,4 +70,44 @@ Execute(Configuration files should be disabled if the legacy option is on):
|
|||||||
\ . ' %t'
|
\ . ' %t'
|
||||||
\ . ' --write'
|
\ . ' --write'
|
||||||
\ },
|
\ },
|
||||||
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
||||||
|
|
||||||
|
Execute(The version check should be correct):
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion',
|
||||||
|
\ 'command': ale#Escape('prettier-eslint') . ' --version',
|
||||||
|
\ },
|
||||||
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The new --stdin-filepath option should be used when the version is new enough):
|
||||||
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||||
|
\ . ale#Escape('prettier-eslint')
|
||||||
|
\ . ' --eslint-config-path ' . ale#Escape(ale#path#Winify(g:dir . '/eslint-test-files/react-app/.eslintrc.js'))
|
||||||
|
\ . ' --stdin-filepath %s --stdin',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0'])
|
||||||
|
|
||||||
|
Execute(The version number should be cached):
|
||||||
|
call ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0'])
|
||||||
|
|
||||||
|
" The version command should be skipped.
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion',
|
||||||
|
\ 'command': '',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
" The newer command should be used.
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||||
|
\ . ale#Escape('prettier-eslint')
|
||||||
|
\ . ' --stdin-filepath %s --stdin',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
||||||
|
Loading…
Reference in New Issue
Block a user