mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-30 14:45:29 +08:00
Set --parser option in Prettier's fixer (#1620)
* Set `--parser` option in Prettier's fixer * Add expected `--parser` option to tests * Disable Prettier `--parser` detection if file extension exists * Manually default Prettier `--parser` to "babylon" * Add `--parser` test for TypeScript * Add tests for Prettier `--parser` * Add JSON5 to the suggested fixer for Prettier
This commit is contained in:
@@ -95,3 +95,143 @@ Execute(The version number should be cached):
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|
||||
|
||||
Execute(Should set --parser based on filetype, TypeScript):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=typescript
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser typescript'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, CSS):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=css
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser css'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, LESS):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=less
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser less'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, SCSS):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=scss
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser scss'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, JSON):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=json
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser json'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, JSON5):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=json5
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser json5'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, GraphQL):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=graphql
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser graphql'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, Markdown):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=markdown
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser markdown'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on filetype, Vue):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=vue
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser vue'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
Execute(Should set --parser based on first filetype of multiple filetypes):
|
||||
call ale#test#SetFilename('../prettier-test-files/testfile')
|
||||
|
||||
set filetype=css.scss
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
||||
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
||||
\ . ' --parser css'
|
||||
\ . ' --stdin-filepath %s --stdin',
|
||||
\ },
|
||||
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
||||
|
||||
0
test/prettier-test-files/testfile
Normal file
0
test/prettier-test-files/testfile
Normal file
Reference in New Issue
Block a user