diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-22 14:46:14 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-22 14:46:14 +0000 |
commit | 4b4762697c03e3b82b032d442289deaac9bd38e6 (patch) | |
tree | 520f13470839c1c95a23e071ca3abc8f9e12f4cc | |
parent | 382cb4d5389725bf85865a87359d6ab744fb35f4 (diff) | |
download | ale-4b4762697c03e3b82b032d442289deaac9bd38e6.zip |
#1095 Use --stdin-filepath where available for prettier-eslint
-rw-r--r-- | autoload/ale/fixers/prettier_eslint.vim | 30 | ||||
-rw-r--r-- | doc/ale-javascript.txt | 13 | ||||
-rw-r--r-- | test/fixers/test_prettier_eslint_fixer.callback.vader | 55 |
3 files changed, 74 insertions, 24 deletions
diff --git a/autoload/ale/fixers/prettier_eslint.vim b/autoload/ale/fixers/prettier_eslint.vim index 524c52d1..5dd9102e 100644 --- a/autoload/ale/fixers/prettier_eslint.vim +++ b/autoload/ale/fixers/prettier_eslint.vim @@ -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_use_global', 0) call ale#Set('javascript_prettier_eslint_options', '') - call ale#Set('javascript_prettier_eslint_legacy', 0) endfunction call ale#fixers#prettier_eslint#SetOptionDefaults() @@ -19,16 +18,43 @@ function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort endfunction 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: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) \ : '' let l:eslint_config_option = !empty(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 { \ 'command': ale#Escape(l:executable) \ . ' %t' diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 365dfa62..3934dfb2 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -171,11 +171,6 @@ g:ale_javascript_prettier_use_global *g:ale_javascript_prettier_use_global* =============================================================================== 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* *b:ale_javascript_prettier_eslint_executable* @@ -202,14 +197,6 @@ g:ale_javascript_prettier_eslint_use_global 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* diff --git a/test/fixers/test_prettier_eslint_fixer.callback.vader b/test/fixers/test_prettier_eslint_fixer.callback.vader index b48a7085..1ff11fe7 100644 --- a/test/fixers/test_prettier_eslint_fixer.callback.vader +++ b/test/fixers/test_prettier_eslint_fixer.callback.vader @@ -4,12 +4,10 @@ Before: Save g:ale_javascript_prettier_eslint_executable Save g:ale_javascript_prettier_eslint_use_global 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_use_global unlet! g:ale_javascript_prettier_eslint_options - unlet! g:ale_javascript_prettier_eslint_legacy call ale#fixers#prettier_eslint#SetOptionDefaults() @@ -19,9 +17,9 @@ After: unlet! b:ale_javascript_prettier_eslint_executable unlet! b:ale_javascript_prettier_eslint_use_global unlet! b:ale_javascript_prettier_eslint_options - unlet! b:ale_javascript_prettier_eslint_legacy call ale#test#RestoreDirectory() + call ale#semver#ResetVersionCache() Execute(The default command should be correct): AssertEqual @@ -32,7 +30,7 @@ Execute(The default command should be correct): \ . ' %t' \ . ' --write' \ }, - \ ale#fixers#prettier_eslint#Fix(bufnr('')) + \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), []) Execute(Additional options should be used when set): let b:ale_javascript_prettier_eslint_options = '--foobar' @@ -45,9 +43,9 @@ Execute(Additional options should be used when set): \ . ' %t' \ . ' --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') 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')) \ . ' --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') - let b:ale_javascript_prettier_eslint_legacy = 1 AssertEqual \ { @@ -73,4 +70,44 @@ Execute(Configuration files should be disabled if the legacy option is on): \ . ' %t' \ . ' --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('')) + +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(''), []) |