summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authortunnckoCore <mameto2011@gmail.com>2017-05-22 01:03:33 +0300
committerw0rp <devw0rp@gmail.com>2017-05-27 18:03:14 +0100
commit8e8113ff6f742572d02e52d33070ec374111c6d6 (patch)
tree1f4beb7920a1e7420c0c5ade4b6bf505243d6f9d /autoload
parentc4f22186bd74b85c3ff22fdba2bed7a7d0009148 (diff)
downloadale-8e8113ff6f742572d02e52d33070ec374111c6d6.zip
feat(fixer): add Prettier fixer (using Prettier-ESLint CLI) + docs
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/handlers/prettier.vim49
2 files changed, 54 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 59b8997a..282f3a08 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/handlers/prettier.vim b/autoload/ale/handlers/prettier.vim
new file mode 100644
index 00000000..ce85dc59
--- /dev/null
+++ b/autoload/ale/handlers/prettier.vim
@@ -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