Merge branch 'fix-prettier-eslint-fixer'
This commit is contained in:
		
						commit
						1d86a724f2
					
				@ -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/) |
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
    \}
 | 
			
		||||
 | 
			
		||||
@ -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`
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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`
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/node_modules/.bin/eslint
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/node_modules/.bin/eslint
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/standard/bin/cmd.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								test/fixers/eslint-test-files/react-app/subdir/testfile.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/fixers/eslint-test-files/react-app/subdir/testfile.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										76
									
								
								test/fixers/test_prettier_eslint_fixer.callback.vader
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								test/fixers/test_prettier_eslint_fixer.callback.vader
									
									
									
									
									
										Normal file
									
								
							@ -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(''))
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user