summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
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))