summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-30 22:49:55 +0100
committerw0rp <devw0rp@gmail.com>2017-08-30 22:49:55 +0100
commit1d86a724f2f54212d1230fcb2195220f5b3727f9 (patch)
treefcf568ebb9d39cb3c4058fac7fb1fbf84ddd203a
parent33278f0fceccb69082b1a2b20e4200cb87f60e4c (diff)
parentf36f38c960eab386ad1a2752ae3d6265875a3cff (diff)
downloadale-1d86a724f2f54212d1230fcb2195220f5b3727f9.zip
Merge branch 'fix-prettier-eslint-fixer'
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fixers/prettier_eslint.vim49
-rw-r--r--doc/ale-javascript.txt35
-rw-r--r--doc/ale.txt2
-rw-r--r--test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d0
-rw-r--r--test/fixers/eslint-test-files/node_modules/.bin/eslint0
-rw-r--r--test/fixers/eslint-test-files/other-app/subdir/testfile.js0
-rw-r--r--test/fixers/eslint-test-files/react-app/.eslintrc.js0
-rw-r--r--test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js0
-rw-r--r--test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js0
-rw-r--r--test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js0
-rw-r--r--test/fixers/eslint-test-files/react-app/subdir/testfile.css0
-rw-r--r--test/fixers/eslint-test-files/react-app/subdir/testfile.js0
-rw-r--r--test/fixers/test_prettier_eslint_fixer.callback.vader76
14 files changed, 138 insertions, 26 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/autoload/ale/fixers/prettier_eslint.vim b/autoload/ale/fixers/prettier_eslint.vim
index ed5dc96d..dbf0424c 100644
--- a/autoload/ale/fixers/prettier_eslint.vim
+++ b/autoload/ale/fixers/prettier_eslint.vim
@@ -1,25 +1,58 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
-" w0rp <devw0rp@gmail.com>
+" w0rp <devw0rp@gmail.com>, morhetz (Pavel Pertsev) <morhetz@gmail.com>
" Description: Integration between Prettier and 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_options', '')
+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',
+ \ '.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
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
+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 = !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(ale#fixers#prettier_eslint#GetExecutable(a:buffer))
+ \ 'command': ale#Escape(l:executable)
\ . ' %t'
- \ . ' ' . l:options
+ \ . l:eslint_config_option
+ \ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --write',
\ 'read_temporary_file': 1,
\}
diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt
index 95d2504a..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`
@@ -96,16 +97,10 @@ 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.
+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*
@@ -133,6 +128,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*
@@ -148,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: `''`
@@ -157,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`
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`
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/node_modules/.bin/eslint
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/other-app/subdir/testfile.js
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/.eslintrc.js
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/subdir/testfile.css
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
--- /dev/null
+++ b/test/fixers/eslint-test-files/react-app/subdir/testfile.js
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(''))