summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorPeter Renström <renstrom.peter@gmail.com>2017-09-06 16:21:26 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-09-06 15:21:26 +0100
commit03f1c1e81bdf1fd41b535f6a0260d47ba1bf60dc (patch)
tree372ace207ef4b89d9b61b5d0d364dc3e01fd9dfb /autoload
parentc277cdef8cb24512583093d7a9b7d68a14e6d82b (diff)
downloadale-03f1c1e81bdf1fd41b535f6a0260d47ba1bf60dc.zip
Add 'prettier' fixer support to TypeScript, CSS, SCSS and JSON (#910)
* Add prettier fixer support for typescript * Add prettier fixer support for css and scss * Add prettier fixer support for json * Use getbufvar() to get &filetype
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim2
-rw-r--r--autoload/ale/fixers/prettier.vim16
2 files changed, 17 insertions, 1 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index b77ac031..5b1030d9 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -34,7 +34,7 @@ let s:default_registry = {
\ },
\ 'prettier': {
\ 'function': 'ale#fixers#prettier#Fix',
-\ 'suggested_filetypes': ['javascript'],
+\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss'],
\ 'description': 'Apply prettier to a file.',
\ },
\ 'prettier_eslint': {
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index 581536e6..ca1bf608 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -38,6 +38,22 @@ function! ale#fixers#prettier#Fix(buffer) abort
let l:config = s:FindConfig(a:buffer)
let l:use_config = ale#Var(a:buffer, 'javascript_prettier_use_local_config')
\ && !empty(l:config)
+ let l:filetype = getbufvar(a:buffer, '&filetype')
+
+ " Append the --parser flag depending on the current filetype (unless it's
+ " already set in g:javascript_prettier_options).
+ if match(l:options, '--parser') == -1
+ if l:filetype is# 'typescript'
+ let l:parser = 'typescript'
+ elseif l:filetype =~# 'css\|scss'
+ let l:parser = 'postcss'
+ elseif l:filetype is# 'json'
+ let l:parser = 'json'
+ else
+ let l:parser = 'babylon'
+ endif
+ let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--parser ' . l:parser
+ endif
return {
\ 'command': ale#Escape(ale#fixers#prettier#GetExecutable(a:buffer))