From c09f8f576407dae8792eae0af5da969e16958125 Mon Sep 17 00:00:00 2001 From: Pavel Pertsev Date: Wed, 16 Aug 2017 23:33:56 +0300 Subject: Passthrough eslint config to prettier-eslint --- autoload/ale/fixers/prettier_eslint.vim | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/autoload/ale/fixers/prettier_eslint.vim b/autoload/ale/fixers/prettier_eslint.vim index ed5dc96d..e0d0cf7d 100644 --- a/autoload/ale/fixers/prettier_eslint.vim +++ b/autoload/ale/fixers/prettier_eslint.vim @@ -1,24 +1,46 @@ " Author: tunnckoCore (Charlike Mike Reagent) , -" w0rp +" w0rp , morhetz (Pavel Pertsev) " Description: Integration between Prettier and ESLint. +function! s:FindConfig(buffer) abort + for l:filename in [ + \ '.eslintrc.js', + \ '.eslintrc.yaml', + \ '.eslintrc.yml', + \ '.eslintrc.json', + \ '.eslintrc', + \ 'package.json', + \] + let l:config = ale#path#FindNearestFile(a:buffer, l:filename) + + if !empty(l:config) + return l:config + endif + endfor + + return '' +endfunction + 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', '') function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [ - \ 'node_modules/prettier-eslint-cli/index.js', + \ 'node_modules/prettier-eslint-cli/dist/index.js', \ 'node_modules/.bin/prettier-eslint', \]) endfunction function! ale#fixers#prettier_eslint#Fix(buffer, lines) 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 = s:FindConfig(a:buffer) return { - \ 'command': ale#Escape(ale#fixers#prettier_eslint#GetExecutable(a:buffer)) + \ 'command': ale#Escape(l:executable) \ . ' %t' + \ . ' --eslint-config-path ' . ale#Escape(l:config) \ . ' ' . l:options \ . ' --write', \ 'read_temporary_file': 1, -- cgit v1.2.3 From 6e423a94cd428917a5efed6611f46bbc9fe33176 Mon Sep 17 00:00:00 2001 From: Pavel Pertsev Date: Thu, 17 Aug 2017 16:38:02 +0300 Subject: Fix docs for prettier-eslint ver --- README.md | 2 +- doc/ale-javascript.txt | 11 ----------- doc/ale.txt | 2 +- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 67238dcd..fd1ef322 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ formatting. | HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/) | | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) | -| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [prettier](https://github.com/prettier/prettier), prettier-eslint, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) +| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [prettier](https://github.com/prettier/prettier), prettier-eslint >= 4.2.0, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) | JSON | [jsonlint](http://zaa.ch/jsonlint/) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/) | diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 95d2504a..806c7f8c 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -96,17 +96,6 @@ g:ale_javascript_prettier_use_local_config *g:ale_javascript_prettier_use_lo =============================================================================== prettier-eslint *ale-javascript-prettier-eslint* -ALE supports `prettier-eslint` for easy integration with projects, but it is -not recommended for new projects. ALE instead recommends configuring -|g:ale_fixers| to run `'prettier'` and `'eslint'` in a sequence like so: > - - let g:ale_fixers = {'javascript': ['prettier', 'eslint']} -< - -This is because `prettier-eslint` cannot be configured to use the ESLint -configuration file for input given via stdin, which is how ALE integrates with -the tool. - g:ale_javascript_prettier_eslint_executable *g:ale_javascript_prettier_eslint_executable* *b:ale_javascript_prettier_eslint_executable* diff --git a/doc/ale.txt b/doc/ale.txt index dfdb2693..9055d866 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -215,7 +215,7 @@ Notes: * HTML: `HTMLHint`, `proselint`, `tidy` * Idris: `idris` * Java: `checkstyle`, `javac` -* JavaScript: `eslint`, `jscs`, `jshint`, `flow`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo` +* JavaScript: `eslint`, `jscs`, `jshint`, `flow`, `prettier`, `prettier-eslint` >= 4.2.0, `prettier-standard`, `standard`, `xo` * JSON: `jsonlint` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `chktex`, `lacheck`, `proselint` -- cgit v1.2.3 From 05ce86ea33d882af998d1da3b2dcafb3d8a16465 Mon Sep 17 00:00:00 2001 From: Pavel Pertsev Date: Fri, 18 Aug 2017 13:37:08 +0300 Subject: Add prettier-eslint legacy option --- autoload/ale/fixers/prettier_eslint.vim | 8 +++++++- doc/ale-javascript.txt | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/prettier_eslint.vim b/autoload/ale/fixers/prettier_eslint.vim index e0d0cf7d..6fe9f0bc 100644 --- a/autoload/ale/fixers/prettier_eslint.vim +++ b/autoload/ale/fixers/prettier_eslint.vim @@ -24,6 +24,7 @@ endfunction 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) function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [ @@ -37,10 +38,15 @@ function! ale#fixers#prettier_eslint#Fix(buffer, lines) abort let l:executable = ale#fixers#prettier_eslint#GetExecutable(a:buffer) let l:config = s:FindConfig(a:buffer) + let l:eslint_config_option = ' --eslint-config-path ' . ale#Escape(l:config) + if ale#Var(a:buffer, 'javascript_prettier_eslint_legacy') + let l:eslint_config_option = '' + endif + return { \ 'command': ale#Escape(l:executable) \ . ' %t' - \ . ' --eslint-config-path ' . ale#Escape(l:config) + \ . l:eslint_config_option \ . ' ' . l:options \ . ' --write', \ 'read_temporary_file': 1, diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 806c7f8c..3dd9d271 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -96,6 +96,11 @@ g:ale_javascript_prettier_use_local_config *g:ale_javascript_prettier_use_lo =============================================================================== 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* @@ -122,6 +127,14 @@ 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* -- cgit v1.2.3 From 301d30229b10bf08094a6bd368c102cf25753dc9 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 30 Aug 2017 22:23:59 +0100 Subject: Fix doc tag alignment --- doc/ale-javascript.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 3dd9d271..09d7f99d 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -86,8 +86,9 @@ g:ale_javascript_prettier_use_global *g:ale_javascript_prettier_use_global* See |ale-integrations-local-executables| -g:ale_javascript_prettier_use_local_config *g:ale_javascript_prettier_use_local_config* - *b:ale_javascript_prettier_use_local_config* +g:ale_javascript_prettier_use_local_config + *g:ale_javascript_prettier_use_local_config* + *b:ale_javascript_prettier_use_local_config* Type: |Number| Default: `0` @@ -128,8 +129,8 @@ 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* + *g:ale_javascript_prettier_eslint_legacy* + *b:ale_javascript_prettier_eslint_legacy* Type: |Number| Default: `0` @@ -150,8 +151,8 @@ g:ale_javascript_prettier_standard_executable g:ale_javascript_prettier_standard_options - *g:ale_javascript_prettier_standard_options* - *b:ale_javascript_prettier_standard_options* + *g:ale_javascript_prettier_standard_options* + *b:ale_javascript_prettier_standard_options* Type: |String| Default: `''` @@ -159,8 +160,8 @@ g:ale_javascript_prettier_standard_options g:ale_javascript_prettier_standard_use_global - *g:ale_javascript_prettier_standard_use_global* - *b:ale_javascript_prettier_standard_use_global* + *g:ale_javascript_prettier_standard_use_global* + *b:ale_javascript_prettier_standard_use_global* Type: |Number| Default: `0` -- cgit v1.2.3 From f36f38c960eab386ad1a2752ae3d6265875a3cff Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 30 Aug 2017 22:49:46 +0100 Subject: Cover the prettier-eslint changes with tests, and fix some problems --- autoload/ale/fixers/prettier_eslint.vim | 29 +++++---- .../app-with-eslint-d/node_modules/.bin/eslint_d | 0 .../eslint-test-files/node_modules/.bin/eslint | 0 .../eslint-test-files/other-app/subdir/testfile.js | 0 .../eslint-test-files/react-app/.eslintrc.js | 0 .../react-app/node_modules/eslint/bin/eslint.js | 0 .../react-app/node_modules/standard/bin/cmd.js | 0 .../node_modules/stylelint/bin/stylelint.js | 0 .../react-app/subdir/testfile.css | 0 .../eslint-test-files/react-app/subdir/testfile.js | 0 .../test_prettier_eslint_fixer.callback.vader | 76 ++++++++++++++++++++++ 11 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d create mode 100644 test/fixers/eslint-test-files/node_modules/.bin/eslint create mode 100644 test/fixers/eslint-test-files/other-app/subdir/testfile.js create mode 100644 test/fixers/eslint-test-files/react-app/.eslintrc.js create mode 100644 test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js create mode 100644 test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js create mode 100644 test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js create mode 100644 test/fixers/eslint-test-files/react-app/subdir/testfile.css create mode 100644 test/fixers/eslint-test-files/react-app/subdir/testfile.js create mode 100644 test/fixers/test_prettier_eslint_fixer.callback.vader diff --git a/autoload/ale/fixers/prettier_eslint.vim b/autoload/ale/fixers/prettier_eslint.vim index 6fe9f0bc..dbf0424c 100644 --- a/autoload/ale/fixers/prettier_eslint.vim +++ b/autoload/ale/fixers/prettier_eslint.vim @@ -2,6 +2,15 @@ " w0rp , morhetz (Pavel Pertsev) " Description: Integration between Prettier and ESLint. +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() + function! s:FindConfig(buffer) abort for l:filename in [ \ '.eslintrc.js', @@ -21,11 +30,6 @@ function! s:FindConfig(buffer) abort return '' endfunction -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) - function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [ \ 'node_modules/prettier-eslint-cli/dist/index.js', @@ -33,21 +37,22 @@ function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort \]) endfunction -function! ale#fixers#prettier_eslint#Fix(buffer, lines) abort +function! ale#fixers#prettier_eslint#Fix(buffer) 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 = s:FindConfig(a:buffer) - let l:eslint_config_option = ' --eslint-config-path ' . ale#Escape(l:config) - if ale#Var(a:buffer, 'javascript_prettier_eslint_legacy') - let l:eslint_config_option = '' - endif + let l:config = !ale#Var(a:buffer, 'javascript_prettier_eslint_legacy') + \ ? s:FindConfig(a:buffer) + \ : '' + let l:eslint_config_option = !empty(l:config) + \ ? ' --eslint-config-path ' . ale#Escape(l:config) + \ : '' return { \ 'command': ale#Escape(l:executable) \ . ' %t' \ . l:eslint_config_option - \ . ' ' . l:options + \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' --write', \ 'read_temporary_file': 1, \} diff --git a/test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d b/test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/node_modules/.bin/eslint b/test/fixers/eslint-test-files/node_modules/.bin/eslint new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/other-app/subdir/testfile.js b/test/fixers/eslint-test-files/other-app/subdir/testfile.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/.eslintrc.js b/test/fixers/eslint-test-files/react-app/.eslintrc.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js b/test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js b/test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js b/test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/subdir/testfile.css b/test/fixers/eslint-test-files/react-app/subdir/testfile.css new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/eslint-test-files/react-app/subdir/testfile.js b/test/fixers/eslint-test-files/react-app/subdir/testfile.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/test_prettier_eslint_fixer.callback.vader b/test/fixers/test_prettier_eslint_fixer.callback.vader new file mode 100644 index 00000000..56daf93f --- /dev/null +++ b/test/fixers/test_prettier_eslint_fixer.callback.vader @@ -0,0 +1,76 @@ +Before: + call ale#test#SetDirectory('/testplugin/test/fixers') + + 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() + +After: + Restore + + 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() + +Execute(The default command should be correct): + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': + \ ale#Escape('prettier-eslint') + \ . ' %t' + \ . ' --write' + \ }, + \ ale#fixers#prettier_eslint#Fix(bufnr('')) + +Execute(Additional options should be used when set): + let b:ale_javascript_prettier_eslint_options = '--foobar' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': + \ ale#Escape('prettier-eslint') + \ . ' %t' + \ . ' --foobar --write' + \ }, + \ ale#fixers#prettier_eslint#Fix(bufnr('')) + +Execute(Configuration files should be detected): + call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': + \ ale#Escape('prettier-eslint') + \ . ' %t' + \ . ' --eslint-config-path ' . ale#Escape(g:dir . '/eslint-test-files/react-app/.eslintrc.js') + \ . ' --write' + \ }, + \ ale#fixers#prettier_eslint#Fix(bufnr('')) + +Execute(Configuration files should be disabled if the legacy option is on): + call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js') + let b:ale_javascript_prettier_eslint_legacy = 1 + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': + \ ale#Escape('prettier-eslint') + \ . ' %t' + \ . ' --write' + \ }, + \ ale#fixers#prettier_eslint#Fix(bufnr('')) -- cgit v1.2.3