mirror of
https://github.com/dense-analysis/ale
synced 2025-01-14 19:14:58 +00:00
Passthrough eslint config to prettier-eslint
This commit is contained in:
parent
33278f0fce
commit
c09f8f5764
@ -1,24 +1,46 @@
|
||||
" 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.
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user