mirror of https://github.com/dense-analysis/ale
prettier: Support experimental languages
Such as handlebars
This commit is contained in:
parent
7b78f2b846
commit
3e4b8ea466
|
@ -41,7 +41,8 @@ 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
|
||||
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.
|
||||
|
@ -71,6 +72,18 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
|
|||
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
|
||||
endif
|
||||
endif
|
||||
|
||||
if !empty(l:parser)
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
ALE Handlebars Integration *ale-handlebars-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
prettier *ale-handlebars-prettier*
|
||||
|
||||
See |ale-javascript-prettier| for information about the available options.
|
||||
Uses glimmer parser by default.
|
||||
|
||||
|
||||
===============================================================================
|
||||
ember-template-lint *ale-handlebars-embertemplatelint*
|
||||
|
||||
|
|
|
@ -2034,6 +2034,7 @@ documented in additional help files.
|
|||
hackfmt...............................|ale-hack-hackfmt|
|
||||
hhast.................................|ale-hack-hhast|
|
||||
handlebars..............................|ale-handlebars-options|
|
||||
prettier..............................|ale-handlebars-prettier|
|
||||
ember-template-lint...................|ale-handlebars-embertemplatelint|
|
||||
haskell.................................|ale-haskell-options|
|
||||
brittany..............................|ale-haskell-brittany|
|
||||
|
|
|
@ -280,6 +280,20 @@ Execute(Should set --parser based on first filetype of multiple filetypes):
|
|||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ }
|
||||
|
||||
Execute(Should set --parser for experimental language, Handlebars):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile.hbs')
|
||||
|
||||
set filetype=html.handlebars
|
||||
|
||||
GivenCommandOutput ['1.6.0']
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#path#CdString(expand('%:p:h'))
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser glimmer'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ }
|
||||
|
||||
Execute(The prettier_d post-processor should permit regular JavaScript content):
|
||||
AssertEqual
|
||||
\ [
|
||||
|
|
Loading…
Reference in New Issue