Cover the prettier-eslint changes with tests, and fix some problems
This commit is contained in:
@@ -2,6 +2,15 @@
|
||||
" w0rp <devw0rp@gmail.com>, morhetz (Pavel Pertsev) <morhetz@gmail.com>
|
||||
" 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,
|
||||
\}
|
||||
|
||||
Reference in New Issue
Block a user