Support both prettier and prettier-eslint

This commit is contained in:
w0rp
2017-05-27 18:31:52 +01:00
parent 8e8113ff6f
commit 62dae1cc6b
5 changed files with 97 additions and 59 deletions

View File

@@ -17,16 +17,21 @@ 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'],
\ 'description': 'Sort Python imports with isort.',
\ },
\ 'prettier': {
\ 'function': 'ale#handlers#prettier#Fix',
\ 'suggested_filetypes': ['javascript'],
\ 'description': 'Apply prettier to a file.',
\ },
\ 'prettier_eslint': {
\ 'function': 'ale#handlers#prettier_eslint#Fix',
\ 'suggested_filetypes': ['javascript'],
\ 'description': 'Apply prettier-eslint to a file.',
\ },
\ 'remove_trailing_lines': {
\ 'function': 'ale#fix#generic#RemoveTrailingBlankLines',
\ 'suggested_filetypes': [],

View File

@@ -1,41 +1,17 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@gmail.com>
" Description: Integration of Prettier with ALE.
" 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', '')
call ale#Set('javascript_prettier_executable', 'prettier')
call ale#Set('javascript_prettier_use_global', 0)
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')
\)
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
\ 'node_modules/prettier-cli/index.js',
\ 'node_modules/.bin/prettier',
\])
endfunction
function! ale#handlers#prettier#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')

View File

@@ -0,0 +1,25 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@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)
function! ale#handlers#prettier_eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
\ 'node_modules/prettier-eslint-cli/index.js',
\ 'node_modules/.bin/prettier-eslint',
\])
endfunction
function! ale#handlers#prettier_eslint#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
return {
\ 'command': ale#Escape(ale#handlers#prettier_eslint#GetExecutable(a:buffer))
\ . ' %t'
\ . ' ' . ale#Escape(l:options)
\ . ' --write',
\ 'read_temporary_file': 1,
\}
endfunction