summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorCyrille David <cyrille@qonto.eu>2019-06-06 18:06:23 +0200
committerCyrille David <dcyriller@gmail.com>2019-06-06 22:04:32 +0200
commit3e4b8ea466efca0d05c9952b80f00f96f5dd0e4e (patch)
treeffe270612ac3ced8ef854615a495fa181e9ec702 /autoload
parent7b78f2b846e2f3443dcb2ceacee54eb99e37f040 (diff)
downloadale-3e4b8ea466efca0d05c9952b80f00f96f5dd0e4e.zip
prettier: Support experimental languages
Such as handlebars
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fixers/prettier.vim67
1 files changed, 40 insertions, 27 deletions
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index b7f0ecd7..e798dfb3 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -41,36 +41,49 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
" 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')) && 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
- let l:parser = 'babylon'
- endif
+ 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:prettier_parsers = {
- \ 'typescript': 'typescript',
- \ 'css': 'css',
- \ 'less': 'less',
- \ 'scss': 'scss',
- \ 'json': 'json',
- \ 'json5': 'json5',
- \ 'graphql': 'graphql',
- \ 'markdown': 'markdown',
- \ 'vue': 'vue',
- \ 'yaml': 'yaml',
- \ 'html': 'html',
- \}
+ 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 split(getbufvar(a:buffer, '&filetype'), '\.')
- if has_key(l:prettier_parsers, l:filetype)
- let l:parser = l:prettier_parsers[l:filetype]
- break
+ 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
+ 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')
+
+ if has_key(l:prettier_experimental_parsers, l:filetype)
+ let l:parser = l:prettier_experimental_parsers[l:filetype]
endif
- endfor
+ endif
endif
if !empty(l:parser)