mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-16 01:07:06 +08:00
Add 'prettier' fixer support to TypeScript, CSS, SCSS and JSON (#910)
* Add prettier fixer support for typescript * Add prettier fixer support for css and scss * Add prettier fixer support for json * Use getbufvar() to get &filetype
This commit is contained in:
@@ -34,7 +34,7 @@ let s:default_registry = {
|
||||
\ },
|
||||
\ 'prettier': {
|
||||
\ 'function': 'ale#fixers#prettier#Fix',
|
||||
\ 'suggested_filetypes': ['javascript'],
|
||||
\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss'],
|
||||
\ 'description': 'Apply prettier to a file.',
|
||||
\ },
|
||||
\ 'prettier_eslint': {
|
||||
|
||||
@@ -38,6 +38,22 @@ function! ale#fixers#prettier#Fix(buffer) abort
|
||||
let l:config = s:FindConfig(a:buffer)
|
||||
let l:use_config = ale#Var(a:buffer, 'javascript_prettier_use_local_config')
|
||||
\ && !empty(l:config)
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
|
||||
" 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 l:filetype is# 'typescript'
|
||||
let l:parser = 'typescript'
|
||||
elseif l:filetype =~# 'css\|scss'
|
||||
let l:parser = 'postcss'
|
||||
elseif l:filetype is# 'json'
|
||||
let l:parser = 'json'
|
||||
else
|
||||
let l:parser = 'babylon'
|
||||
endif
|
||||
let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--parser ' . l:parser
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(ale#fixers#prettier#GetExecutable(a:buffer))
|
||||
|
||||
Reference in New Issue
Block a user