Support both prettier and prettier-eslint
This commit is contained in:
parent
8e8113ff6f
commit
62dae1cc6b
@ -17,16 +17,21 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['javascript'],
|
\ 'suggested_filetypes': ['javascript'],
|
||||||
\ 'description': 'Apply eslint --fix to a file.',
|
\ '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': {
|
\ 'isort': {
|
||||||
\ 'function': 'ale#handlers#python#ISort',
|
\ 'function': 'ale#handlers#python#ISort',
|
||||||
\ 'suggested_filetypes': ['python'],
|
\ 'suggested_filetypes': ['python'],
|
||||||
\ 'description': 'Sort Python imports with isort.',
|
\ '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': {
|
\ 'remove_trailing_lines': {
|
||||||
\ 'function': 'ale#fix#generic#RemoveTrailingBlankLines',
|
\ 'function': 'ale#fix#generic#RemoveTrailingBlankLines',
|
||||||
\ 'suggested_filetypes': [],
|
\ 'suggested_filetypes': [],
|
||||||
|
@ -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>
|
call ale#Set('javascript_prettier_executable', 'prettier')
|
||||||
" Description: Integration between Prettier and ESLint.
|
call ale#Set('javascript_prettier_use_global', 0)
|
||||||
|
|
||||||
" 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
|
function! ale#handlers#prettier#GetExecutable(buffer) abort
|
||||||
if ale#Var(a:buffer, 'javascript_prettier_use_global')
|
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
|
||||||
return ale#Var(a:buffer, 'javascript_prettier_executable')
|
\ 'node_modules/prettier-cli/index.js',
|
||||||
endif
|
\ 'node_modules/.bin/prettier',
|
||||||
|
\])
|
||||||
" 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
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! ale#handlers#prettier#Fix(buffer, lines) abort
|
function! ale#handlers#prettier#Fix(buffer, lines) abort
|
||||||
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
|
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
|
||||||
|
|
||||||
|
25
autoload/ale/handlers/prettier_eslint.vim
Normal file
25
autoload/ale/handlers/prettier_eslint.vim
Normal 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
|
@ -45,16 +45,12 @@ prettier *ale-javascript-prettier*
|
|||||||
g:ale_javascript_prettier_executable *g:ale_javascript_prettier_executable*
|
g:ale_javascript_prettier_executable *g:ale_javascript_prettier_executable*
|
||||||
*b:ale_javascript_prettier_executable*
|
*b:ale_javascript_prettier_executable*
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `'prettier-eslint'`
|
Default: `'prettier'`
|
||||||
|
|
||||||
ALE will first discover the prettier-eslint path in an ancestor node_modules
|
ALE will first discover the prettier path in an ancestor node_modules
|
||||||
directory. If no such path exists, this variable will be used instead.
|
directory. If no such path exists, this variable will be used instead.
|
||||||
|
|
||||||
This variable can be set to change the path to prettier-eslint or if you want
|
If you wish to use only a globally installed version of prettier set
|
||||||
to use the original Prettier CLI.
|
|
||||||
|
|
||||||
If you wish to use only a globally installed version of prettier or
|
|
||||||
prettier-eslint, set the set
|
|
||||||
|g:ale_javascript_prettier_use_global| to `1`.
|
|g:ale_javascript_prettier_use_global| to `1`.
|
||||||
|
|
||||||
|
|
||||||
@ -66,16 +62,50 @@ g:ale_javascript_prettier_options *g:ale_javascript_prettier_options
|
|||||||
This variable can be set to pass additional options to prettier.
|
This variable can be set to pass additional options to prettier.
|
||||||
|
|
||||||
|
|
||||||
g:ale_javascript_prettier_use_global *g:ale_javascript_eslint_use_global*
|
g:ale_javascript_prettier_use_global *g:ale_javascript_prettier_use_global*
|
||||||
*b:ale_javascript_eslint_use_global*
|
*b:ale_javascript_prettier_use_global*
|
||||||
Type: |Number|
|
Type: |Number|
|
||||||
Default: `0`
|
Default: `0`
|
||||||
|
|
||||||
This variable controls whether or not ALE will search for a local path for
|
This variable controls whether or not ALE will search for a local path for
|
||||||
prettier-eslint-cli first. If this variable is set to `1`,
|
prettier first. If this variable is set to `1`, then ALE will always use the
|
||||||
then ALE will always use the global version of Prettier or Prettier-ESLint,
|
global version of Prettier.
|
||||||
depending on g:ale_javascript_prettier_executable, in preference to
|
|
||||||
locally installed versions of Prettier / Prettier-ESLint in node_modules.
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
prettier-eslint *ale-javascript-prettier-eslint*
|
||||||
|
|
||||||
|
g:ale_javascript_prettier_eslint_executable
|
||||||
|
*g:ale_javascript_prettier_eslint_executable*
|
||||||
|
*b:ale_javascript_prettier_eslint_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'prettier-eslint'`
|
||||||
|
|
||||||
|
ALE will first discover the prettier-eslint path in an ancestor node_modules
|
||||||
|
directory. If no such path exists, this variable will be used instead.
|
||||||
|
|
||||||
|
If you wish to use only a globally installed version of prettier-eslint set
|
||||||
|
|g:ale_javascript_prettier_eslint_use_global| to `1`.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_javascript_prettier_eslint_options
|
||||||
|
*g:ale_javascript_prettier_eslint_options*
|
||||||
|
*b:ale_javascript_prettier_eslint_options*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options to prettier-eslint.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_javascript_prettier_eslint_use_global
|
||||||
|
*g:ale_javascript_prettier_eslint_use_global*
|
||||||
|
*b:ale_javascript_prettier_eslint_use_global*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
This variable controls whether or not ALE will search for a local path for
|
||||||
|
prettier-eslint first. If this variable is set to `1`, then ALE will always
|
||||||
|
use the global version of Prettier-eslint.
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
16
doc/ale.txt
16
doc/ale.txt
@ -10,7 +10,7 @@ CONTENTS *ale-contents*
|
|||||||
2. Supported Languages & Tools..........|ale-support|
|
2. Supported Languages & Tools..........|ale-support|
|
||||||
3. Global Options.......................|ale-options|
|
3. Global Options.......................|ale-options|
|
||||||
4. Fixing Problems......................|ale-fix|
|
4. Fixing Problems......................|ale-fix|
|
||||||
5. Linter Options and Recommendations...|ale-linter-options|
|
5. Integration Documentation............|ale-integrations|
|
||||||
asm...................................|ale-asm-options|
|
asm...................................|ale-asm-options|
|
||||||
gcc.................................|ale-asm-gcc|
|
gcc.................................|ale-asm-gcc|
|
||||||
c.....................................|ale-c-options|
|
c.....................................|ale-c-options|
|
||||||
@ -47,6 +47,8 @@ CONTENTS *ale-contents*
|
|||||||
eslint..............................|ale-javascript-eslint|
|
eslint..............................|ale-javascript-eslint|
|
||||||
flow................................|ale-javascript-flow|
|
flow................................|ale-javascript-flow|
|
||||||
jshint..............................|ale-javascript-jshint|
|
jshint..............................|ale-javascript-jshint|
|
||||||
|
prettier............................|ale-javascript-prettier|
|
||||||
|
prettier-eslint.....................|ale-javascript-prettier-eslint|
|
||||||
standard............................|ale-javascript-standard|
|
standard............................|ale-javascript-standard|
|
||||||
xo..................................|ale-javascript-xo|
|
xo..................................|ale-javascript-xo|
|
||||||
kotlin................................|ale-kotlin-options|
|
kotlin................................|ale-kotlin-options|
|
||||||
@ -770,14 +772,14 @@ from the file.
|
|||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
5. Linter Options and Recommendations *ale-linter-options*
|
5. Integration Documentation *ale-integrations*
|
||||||
|
|
||||||
Linter options are documented in individual help files. See the table of
|
Linter and fixer options are documented in individual help files. See the
|
||||||
contents at |ale-contents|.
|
table of contents at |ale-contents|.
|
||||||
|
|
||||||
Every linter variable can be set globally, or individually for each buffer.
|
Every option for programs can be set globally, or individually for each
|
||||||
For example, `b:ale_python_flake8_executable` will override any values
|
buffer. For example, `b:ale_python_flake8_executable` will override any
|
||||||
set for `g:ale_python_flake8_executable`.
|
values set for `g:ale_python_flake8_executable`.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user