diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 59b8997..6d992c2 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -22,6 +22,16 @@ let s:default_registry = { \ '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': [], diff --git a/autoload/ale/handlers/prettier.vim b/autoload/ale/handlers/prettier.vim new file mode 100644 index 0000000..f1982ca --- /dev/null +++ b/autoload/ale/handlers/prettier.vim @@ -0,0 +1,25 @@ +" Author: tunnckoCore (Charlike Mike Reagent) , +" w0rp +" Description: Integration of Prettier with ALE. + +call ale#Set('javascript_prettier_executable', 'prettier') +call ale#Set('javascript_prettier_use_global', 0) + +function! ale#handlers#prettier#GetExecutable(buffer) abort + 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') + + return { + \ 'command': ale#Escape(ale#handlers#prettier#GetExecutable(a:buffer)) + \ . ' %t' + \ . ' ' . ale#Escape(l:options) + \ . ' --write', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/autoload/ale/handlers/prettier_eslint.vim b/autoload/ale/handlers/prettier_eslint.vim new file mode 100644 index 0000000..8a2c71e --- /dev/null +++ b/autoload/ale/handlers/prettier_eslint.vim @@ -0,0 +1,25 @@ +" Author: tunnckoCore (Charlike Mike Reagent) , +" w0rp +" 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 diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 561a84d..2eab117 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -39,6 +39,75 @@ g:ale_javascript_eslint_use_global *g:ale_javascript_eslint_use_global* eslint in node_modules. +------------------------------------------------------------------------------- +prettier *ale-javascript-prettier* + +g:ale_javascript_prettier_executable *g:ale_javascript_prettier_executable* + *b:ale_javascript_prettier_executable* + Type: |String| + Default: `'prettier'` + + ALE will first discover the prettier 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 set + |g:ale_javascript_prettier_use_global| to `1`. + + +g:ale_javascript_prettier_options *g:ale_javascript_prettier_options* + *b:ale_javascript_prettier_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to prettier. + + +g:ale_javascript_prettier_use_global *g:ale_javascript_prettier_use_global* + *b:ale_javascript_prettier_use_global* + Type: |Number| + Default: `0` + + This variable controls whether or not ALE will search for a local path for + prettier first. If this variable is set to `1`, then ALE will always use the + global version of Prettier. + + +------------------------------------------------------------------------------- +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. + + ------------------------------------------------------------------------------- flow *ale-javascript-flow* diff --git a/doc/ale.txt b/doc/ale.txt index 5dd8d05..514ba73 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -10,7 +10,7 @@ CONTENTS *ale-contents* 2. Supported Languages & Tools..........|ale-support| 3. Global Options.......................|ale-options| 4. Fixing Problems......................|ale-fix| - 5. Linter Options and Recommendations...|ale-linter-options| + 5. Integration Documentation............|ale-integrations| asm...................................|ale-asm-options| gcc.................................|ale-asm-gcc| c.....................................|ale-c-options| @@ -47,6 +47,8 @@ CONTENTS *ale-contents* eslint..............................|ale-javascript-eslint| flow................................|ale-javascript-flow| jshint..............................|ale-javascript-jshint| + prettier............................|ale-javascript-prettier| + prettier-eslint.....................|ale-javascript-prettier-eslint| standard............................|ale-javascript-standard| xo..................................|ale-javascript-xo| 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 -contents at |ale-contents|. +Linter and fixer options are documented in individual help files. See the +table of contents at |ale-contents|. -Every linter variable can be set globally, or individually for each buffer. -For example, `b:ale_python_flake8_executable` will override any values -set for `g:ale_python_flake8_executable`. +Every option for programs can be set globally, or individually for each +buffer. For example, `b:ale_python_flake8_executable` will override any +values set for `g:ale_python_flake8_executable`. ===============================================================================