2017-08-29 15:05:19 +00:00
|
|
|
Before:
|
2019-04-07 13:58:06 +00:00
|
|
|
call ale#assert#SetUpFixerTest('javascript', 'prettier')
|
2020-08-16 20:19:07 +00:00
|
|
|
Save g:ale_command_wrapper
|
|
|
|
|
|
|
|
let g:ale_command_wrapper = ''
|
2017-08-29 15:05:19 +00:00
|
|
|
|
|
|
|
silent cd ..
|
|
|
|
silent cd command_callback
|
|
|
|
let g:dir = getcwd()
|
|
|
|
|
|
|
|
After:
|
2019-04-07 13:58:06 +00:00
|
|
|
call ale#assert#TearDownFixerTest()
|
2017-11-22 13:46:11 +00:00
|
|
|
|
2017-08-29 15:05:19 +00:00
|
|
|
Execute(The prettier callback should return the correct default values):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile.js')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-08-29 15:05:19 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-08-29 15:05:19 +00:00
|
|
|
|
2017-11-22 13:46:11 +00:00
|
|
|
Execute(The --config option should not be set automatically):
|
2017-08-29 15:05:19 +00:00
|
|
|
let g:ale_javascript_prettier_use_local_config = 1
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-08-29 15:05:19 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-08-29 15:05:19 +00:00
|
|
|
|
|
|
|
Execute(The prettier callback should include custom prettier options):
|
|
|
|
let g:ale_javascript_prettier_options = '--no-semi'
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-08-29 15:05:19 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
2017-11-22 13:46:11 +00:00
|
|
|
\ . ' --no-semi'
|
2017-09-06 14:21:26 +00:00
|
|
|
\ . ' --write',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-09-06 14:21:26 +00:00
|
|
|
|
2017-11-22 13:46:11 +00:00
|
|
|
Execute(The version check should be correct):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile.js')
|
2017-09-06 14:21:26 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer [
|
|
|
|
\ ale#Escape('prettier') . ' --version',
|
|
|
|
\ {'read_temporary_file': 1, 'command': ale#Escape('prettier') . ' %t --write'}
|
|
|
|
\]
|
2017-09-06 14:21:26 +00:00
|
|
|
|
2017-11-22 13:46:11 +00:00
|
|
|
Execute(--stdin-filepath should be used when prettier is new enough):
|
|
|
|
let g:ale_javascript_prettier_options = '--no-semi'
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
2017-09-06 14:21:26 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2017-09-06 14:21:26 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2017-11-22 13:46:11 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --no-semi'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-09-06 14:21:26 +00:00
|
|
|
|
2017-11-22 13:46:11 +00:00
|
|
|
Execute(The version number should be cached):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
2017-10-21 01:29:57 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
|
|
|
\ }
|
2017-10-21 01:29:57 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput []
|
|
|
|
AssertFixer
|
2017-10-21 01:29:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2017-11-22 13:46:11 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
2019-01-22 10:24:15 +00:00
|
|
|
Execute(Should set --parser to `babylon` by default, < 1.16.0):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=javascript
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2019-01-22 10:24:15 +00:00
|
|
|
\ {
|
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser babylon'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2019-01-22 10:24:15 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser to `babel` by default, >= 1.16.0):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=javascript
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.16.0']
|
|
|
|
AssertFixer
|
2019-01-22 10:24:15 +00:00
|
|
|
\ {
|
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser babel'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2019-01-22 10:24:15 +00:00
|
|
|
|
2018-06-18 21:40:57 +00:00
|
|
|
Execute(Should set --parser based on filetype, TypeScript):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=typescript
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser typescript'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, CSS):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=css
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser css'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, LESS):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=less
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser less'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, SCSS):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=scss
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser scss'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, JSON):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=json
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser json'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, JSON5):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=json5
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser json5'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, GraphQL):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=graphql
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser graphql'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, Markdown):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=markdown
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser markdown'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, Vue):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=vue
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser vue'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-06-18 21:40:57 +00:00
|
|
|
|
2018-08-02 19:20:19 +00:00
|
|
|
Execute(Should set --parser based on filetype, YAML):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=yaml
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-08-02 19:20:19 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-08-02 19:20:19 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser yaml'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-11-12 06:58:34 +00:00
|
|
|
|
|
|
|
Execute(Should set --parser based on filetype, HTML):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=html
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-11-12 06:58:34 +00:00
|
|
|
\ {
|
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser html'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-08-02 19:20:19 +00:00
|
|
|
|
2018-06-18 21:40:57 +00:00
|
|
|
Execute(Should set --parser based on first filetype of multiple filetypes):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile')
|
|
|
|
|
|
|
|
set filetype=css.scss
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['1.6.0']
|
|
|
|
AssertFixer
|
2018-06-18 21:40:57 +00:00
|
|
|
\ {
|
2018-10-23 14:20:27 +00:00
|
|
|
\ 'command': ale#path#CdString(expand('%:p:h'))
|
2018-06-18 21:40:57 +00:00
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --parser css'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2018-08-09 16:56:53 +00:00
|
|
|
|
2019-06-06 16:06:23 +00:00
|
|
|
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',
|
|
|
|
\ }
|
|
|
|
|
2018-08-09 16:56:53 +00:00
|
|
|
Execute(The prettier_d post-processor should permit regular JavaScript content):
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ 'const x = ''Error: foo''',
|
|
|
|
\ 'const y = 3',
|
|
|
|
\ ],
|
|
|
|
\ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
|
|
|
|
\ 'const x = ''Error: foo''',
|
|
|
|
\ 'const y = 3',
|
|
|
|
\ ])
|
|
|
|
|
|
|
|
Execute(The prettier_d post-processor should handle error messages correctly):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
|
|
|
|
\ 'SyntaxError: Unexpected token, expected "," (36:28)',
|
|
|
|
\ ])
|