summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fixers/prettier.vim73
1 files changed, 33 insertions, 40 deletions
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index e798dfb3..23120777 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -39,51 +39,44 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
let l:parser = ''
- " 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 empty(expand('#' . a:buffer . ':e'))
- " Mimic Prettier's defaults. In cases without a file extension or
- " filetype (scratch buffer), Prettier needs `parser` set to know how
- " to process the buffer.
- if ale#semver#GTE(a:version, [1, 16, 0])
- let l:parser = 'babel'
- else
- let l:parser = 'babylon'
- endif
+ let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.')
- let l:prettier_parsers = {
- \ 'typescript': 'typescript',
- \ 'css': 'css',
- \ 'less': 'less',
- \ 'scss': 'scss',
- \ 'json': 'json',
- \ 'json5': 'json5',
- \ 'graphql': 'graphql',
- \ 'markdown': 'markdown',
- \ 'vue': 'vue',
- \ 'yaml': 'yaml',
- \ 'html': 'html',
- \}
+ if index(l:filetypes, 'handlebars') > -1
+ let l:parser = 'glimmer'
+ endif
- for l:filetype in split(getbufvar(a:buffer, '&filetype'), '\.')
- if has_key(l:prettier_parsers, l:filetype)
- let l:parser = l:prettier_parsers[l:filetype]
- break
- endif
- endfor
+ " Append the --parser flag depending on the current filetype (unless it's
+ " already set in g:javascript_prettier_options).
+ if empty(expand('#' . a:buffer . ':e')) && l:parser is# '' && match(l:options, '--parser') == -1
+ " Mimic Prettier's defaults. In cases without a file extension or
+ " filetype (scratch buffer), Prettier needs `parser` set to know how
+ " to process the buffer.
+ if ale#semver#GTE(a:version, [1, 16, 0])
+ let l:parser = 'babel'
else
- " Append a --parser flag. In cases the filetype has an exprimental
- " support in Prettier and has to be appended manually.
- let l:prettier_experimental_parsers = {
- \ 'html.handlebars': 'glimmer',
- \}
- let l:filetype = getbufvar(a:buffer, '&filetype')
+ let l:parser = 'babylon'
+ endif
- if has_key(l:prettier_experimental_parsers, l:filetype)
- let l:parser = l:prettier_experimental_parsers[l:filetype]
+ let l:prettier_parsers = {
+ \ 'typescript': 'typescript',
+ \ 'css': 'css',
+ \ 'less': 'less',
+ \ 'scss': 'scss',
+ \ 'json': 'json',
+ \ 'json5': 'json5',
+ \ 'graphql': 'graphql',
+ \ 'markdown': 'markdown',
+ \ 'vue': 'vue',
+ \ 'yaml': 'yaml',
+ \ 'html': 'html',
+ \}
+
+ for l:filetype in l:filetypes
+ if has_key(l:prettier_parsers, l:filetype)
+ let l:parser = l:prettier_parsers[l:filetype]
+ break
endif
- endif
+ endfor
endif
if !empty(l:parser)