summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-27 18:31:58 +0100
committerw0rp <devw0rp@gmail.com>2017-05-27 18:31:58 +0100
commit5825a65627a85794442f6e19436b72f34fa56450 (patch)
treeae48a53522f01f18593b263218aa66c33bc53fa7 /autoload
parentc4f22186bd74b85c3ff22fdba2bed7a7d0009148 (diff)
parent62dae1cc6b492a1d408cbc9b961ef4b050d8e357 (diff)
downloadale-5825a65627a85794442f6e19436b72f34fa56450.zip
Merge branch 'add-fixer/prettier'
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim10
-rw-r--r--autoload/ale/handlers/prettier.vim25
-rw-r--r--autoload/ale/handlers/prettier_eslint.vim25
3 files changed, 60 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 59b8997a..6d992c28 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 00000000..f1982ca6
--- /dev/null
+++ b/autoload/ale/handlers/prettier.vim
@@ -0,0 +1,25 @@
+" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
+" w0rp <devw0rp@gmail.com>
+" 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 00000000..8a2c71e1
--- /dev/null
+++ b/autoload/ale/handlers/prettier_eslint.vim
@@ -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