mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-09 03:01:31 +08:00
feat(fixer): add Prettier fixer (using Prettier-ESLint CLI) + docs
This commit is contained in:
@@ -17,6 +17,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['javascript'],
|
||||
\ 'description': 'Apply eslint --fix to a file.',
|
||||
\ },
|
||||
\ 'prettier': {
|
||||
\ 'function': 'ale#handlers#prettier#Fix',
|
||||
\ 'suggested_filetypes': ['javascript'],
|
||||
\ 'description': 'Apply prettier (with ESLint integration) to file',
|
||||
\ },
|
||||
\ 'isort': {
|
||||
\ 'function': 'ale#handlers#python#ISort',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
|
||||
49
autoload/ale/handlers/prettier.vim
Normal file
49
autoload/ale/handlers/prettier.vim
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>
|
||||
" Description: Integration between Prettier and ESLint.
|
||||
|
||||
" Here we use `prettier-eslint` intetionally,
|
||||
" because from v4 it is direct mirror of `prettier` - mimics
|
||||
" it's flags and etc.
|
||||
|
||||
let g:ale_javascript_prettier_executable =
|
||||
\ get(g:, 'ale_javascript_prettier_executable', 'prettier-eslint')
|
||||
|
||||
let g:ale_javascript_prettier_options =
|
||||
\ get(g:, 'ale_javascript_prettier_options', '')
|
||||
|
||||
function! ale#handlers#prettier#GetExecutable(buffer) abort
|
||||
if ale#Var(a:buffer, 'javascript_prettier_use_global')
|
||||
return ale#Var(a:buffer, 'javascript_prettier_executable')
|
||||
endif
|
||||
|
||||
" Look for the kinds of paths that create-react-app generates first.
|
||||
let l:executable = ale#path#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/prettier-eslint-cli/index.js',
|
||||
\ ''
|
||||
\)
|
||||
|
||||
if !empty(l:executable)
|
||||
return l:executable
|
||||
endif
|
||||
|
||||
return ale#path#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/.bin/prettier-eslint',
|
||||
\ ale#Var(a:buffer, 'javascript_prettier_executable')
|
||||
\)
|
||||
endfunction
|
||||
|
||||
|
||||
function! ale#handlers#prettier#Fix(buffer, lines) abort
|
||||
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(ale#handlers#prettier#GetExecutable(a:buffer))
|
||||
\ . ' %t'
|
||||
\ . ' ' . ale#Escape(l:options)
|
||||
\ . ' --write',
|
||||
\ 'read_temporary_file': 1,
|
||||
\}
|
||||
endfunction
|
||||
Reference in New Issue
Block a user