Javascript prettier filetype detect fix (#1769)
Support fixing YAML and HTML files with prettier for files without file extensions.
This commit is contained in:
parent
649934230b
commit
cb8ad9fbd8
@ -36,12 +36,23 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version_output) abort
|
|||||||
" 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')) && match(l:options, '--parser') == -1
|
||||||
let l:prettier_parsers = ['typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue']
|
let l:prettier_parsers = {
|
||||||
let l:parser = 'babylon'
|
\ 'typescript': 'typescript',
|
||||||
|
\ 'css': 'css',
|
||||||
|
\ 'less': 'less',
|
||||||
|
\ 'scss': 'scss',
|
||||||
|
\ 'json': 'json',
|
||||||
|
\ 'json5': 'json5',
|
||||||
|
\ 'graphql': 'graphql',
|
||||||
|
\ 'markdown': 'markdown',
|
||||||
|
\ 'vue': 'vue',
|
||||||
|
\ 'yaml': 'yaml',
|
||||||
|
\}
|
||||||
|
let l:parser = ''
|
||||||
|
|
||||||
for l:filetype in split(getbufvar(a:buffer, '&filetype'), '\.')
|
for l:filetype in split(getbufvar(a:buffer, '&filetype'), '\.')
|
||||||
if index(l:prettier_parsers, l:filetype) > -1
|
if has_key(l:prettier_parsers, l:filetype)
|
||||||
let l:parser = l:filetype
|
let l:parser = l:prettier_parsers[l:filetype]
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
@ -222,6 +222,20 @@ Execute(Should set --parser based on filetype, Vue):
|
|||||||
\ },
|
\ },
|
||||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||||
|
|
||||||
|
Execute(Should set --parser based on filetype, YAML):
|
||||||
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||||
|
|
||||||
|
set filetype=yaml
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||||
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||||
|
\ . ' --parser yaml'
|
||||||
|
\ . ' --stdin-filepath %s --stdin',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||||
|
|
||||||
Execute(Should set --parser based on first filetype of multiple filetypes):
|
Execute(Should set --parser based on first filetype of multiple filetypes):
|
||||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user