Merge pull request #2563 from dcyriller/fixer-prettier-glimmer

prettier: Support experimental languages (Handlebars)
This commit is contained in:
w0rp
2019-06-13 11:08:21 +01:00
committed by GitHub
4 changed files with 30 additions and 2 deletions

View File

@@ -39,9 +39,15 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options') let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
let l:parser = '' let l:parser = ''
let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.')
if index(l:filetypes, 'handlebars') > -1
let l:parser = 'glimmer'
endif
" Append the --parser flag depending on the current filetype (unless it's " Append the --parser flag depending on the current filetype (unless it's
" already set in g:javascript_prettier_options). " already set in g:javascript_prettier_options).
if empty(expand('#' . a:buffer . ':e')) && match(l:options, '--parser') == -1 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 " Mimic Prettier's defaults. In cases without a file extension or
" filetype (scratch buffer), Prettier needs `parser` set to know how " filetype (scratch buffer), Prettier needs `parser` set to know how
" to process the buffer. " to process the buffer.
@@ -65,7 +71,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
\ 'html': 'html', \ 'html': 'html',
\} \}
for l:filetype in split(getbufvar(a:buffer, '&filetype'), '\.') for l:filetype in l:filetypes
if has_key(l:prettier_parsers, l:filetype) if has_key(l:prettier_parsers, l:filetype)
let l:parser = l:prettier_parsers[l:filetype] let l:parser = l:prettier_parsers[l:filetype]
break break

View File

@@ -2,6 +2,13 @@
ALE Handlebars Integration *ale-handlebars-options* 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* ember-template-lint *ale-handlebars-embertemplatelint*

View File

@@ -2042,6 +2042,7 @@ documented in additional help files.
hackfmt...............................|ale-hack-hackfmt| hackfmt...............................|ale-hack-hackfmt|
hhast.................................|ale-hack-hhast| hhast.................................|ale-hack-hhast|
handlebars..............................|ale-handlebars-options| handlebars..............................|ale-handlebars-options|
prettier..............................|ale-handlebars-prettier|
ember-template-lint...................|ale-handlebars-embertemplatelint| ember-template-lint...................|ale-handlebars-embertemplatelint|
haskell.................................|ale-haskell-options| haskell.................................|ale-haskell-options|
brittany..............................|ale-haskell-brittany| brittany..............................|ale-haskell-brittany|

View File

@@ -280,6 +280,20 @@ Execute(Should set --parser based on first filetype of multiple filetypes):
\ . ' --stdin-filepath %s --stdin', \ . ' --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): Execute(The prettier_d post-processor should permit regular JavaScript content):
AssertEqual AssertEqual
\ [ \ [