Use the same function for finding the ESLint config for eslint --fix and prettier-eslint

This commit is contained in:
w0rp 2017-09-12 09:20:31 +01:00
parent 661ed6e40b
commit 7f42aedaec
3 changed files with 22 additions and 41 deletions

View File

@ -1,29 +1,9 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing files with eslint.
function! s:FindConfig(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:basename in [
\ '.eslintrc.js',
\ '.eslintrc.yaml',
\ '.eslintrc.yml',
\ '.eslintrc.json',
\ '.eslintrc',
\]
let l:config = ale#path#Simplify(l:path . '/' . l:basename)
if filereadable(l:config)
return l:config
endif
endfor
endfor
return ale#path#FindNearestFile(a:buffer, 'package.json')
endfunction
function! ale#fixers#eslint#Fix(buffer) abort
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
let l:config = s:FindConfig(a:buffer)
let l:config = ale#handlers#eslint#FindConfig(a:buffer)
if empty(l:config)
return 0

View File

@ -11,25 +11,6 @@ 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/dist/index.js',
@ -42,7 +23,7 @@ function! ale#fixers#prettier_eslint#Fix(buffer) abort
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)
\ ? ale#handlers#eslint#FindConfig(a:buffer)
\ : ''
let l:eslint_config_option = !empty(l:config)
\ ? ' --eslint-config-path ' . ale#Escape(l:config)

View File

@ -6,6 +6,26 @@ call ale#Set('javascript_eslint_executable', 'eslint')
call ale#Set('javascript_eslint_use_global', 0)
call ale#Set('javascript_eslint_suppress_eslintignore', 0)
function! ale#handlers#eslint#FindConfig(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:basename in [
\ '.eslintrc.js',
\ '.eslintrc.yaml',
\ '.eslintrc.yml',
\ '.eslintrc.json',
\ '.eslintrc',
\]
let l:config = ale#path#Simplify(l:path . '/' . l:basename)
if filereadable(l:config)
return l:config
endif
endfor
endfor
return ale#path#FindNearestFile(a:buffer, 'package.json')
endfunction
function! ale#handlers#eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_eslint', [
\ 'node_modules/.bin/eslint_d',