2017-08-29 11:05:19 -04:00
|
|
|
Before:
|
|
|
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
|
|
|
Save g:ale_javascript_prettier_executable
|
|
|
|
Save g:ale_javascript_prettier_options
|
|
|
|
|
|
|
|
" Use an invalid global executable, so we don't match it.
|
|
|
|
let g:ale_javascript_prettier_executable = 'xxxinvalid'
|
|
|
|
let g:ale_javascript_prettier_options = ''
|
|
|
|
|
|
|
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
|
|
|
silent cd ..
|
|
|
|
silent cd command_callback
|
|
|
|
let g:dir = getcwd()
|
|
|
|
|
|
|
|
After:
|
|
|
|
let g:ale_has_override = {}
|
2017-11-22 08:46:11 -05:00
|
|
|
|
2017-08-29 11:05:19 -04:00
|
|
|
call ale#test#RestoreDirectory()
|
2017-11-22 08:46:11 -05:00
|
|
|
call ale#semver#ResetVersionCache()
|
2017-08-29 11:05:19 -04:00
|
|
|
|
|
|
|
Execute(The prettier callback should return the correct default values):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write',
|
|
|
|
\ },
|
2017-11-22 08:46:11 -05:00
|
|
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|
2017-08-29 11:05:19 -04:00
|
|
|
|
2017-11-22 08:46:11 -05:00
|
|
|
Execute(The --config option should not be set automatically):
|
2017-08-29 11:05:19 -04:00
|
|
|
let g:ale_javascript_prettier_use_local_config = 1
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write',
|
|
|
|
\ },
|
2017-11-22 08:46:11 -05:00
|
|
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|
2017-08-29 11:05:19 -04: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')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' %t'
|
2017-11-22 08:46:11 -05:00
|
|
|
\ . ' --no-semi'
|
2017-09-06 10:21:26 -04:00
|
|
|
\ . ' --write',
|
|
|
|
\ },
|
2017-11-22 08:46:11 -05:00
|
|
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|
2017-09-06 10:21:26 -04:00
|
|
|
|
2017-11-22 08:46:11 -05:00
|
|
|
Execute(The version check should be correct):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/testfile.js')
|
2017-09-06 10:21:26 -04:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
2017-11-22 08:46:11 -05:00
|
|
|
\ 'chain_with': 'ale#fixers#prettier#ApplyFixForVersion',
|
2017-09-06 10:21:26 -04:00
|
|
|
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
|
2017-11-22 08:46:11 -05:00
|
|
|
\ . ' --version',
|
2017-09-06 10:21:26 -04:00
|
|
|
\ },
|
|
|
|
\ ale#fixers#prettier#Fix(bufnr(''))
|
|
|
|
|
2017-11-22 08:46:11 -05: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 10:21:26 -04:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
2017-11-22 08:46:11 -05:00
|
|
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --no-semi'
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2017-09-06 10:21:26 -04:00
|
|
|
\ },
|
2017-11-22 08:46:11 -05:00
|
|
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
2017-09-06 10:21:26 -04:00
|
|
|
|
2017-11-22 08:46:11 -05:00
|
|
|
Execute(The version number should be cached):
|
|
|
|
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
|
2017-10-20 21:29:57 -04:00
|
|
|
|
2017-11-22 08:46:11 -05:00
|
|
|
" Call the second callback with the version output.
|
|
|
|
call ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
|
2017-10-20 21:29:57 -04:00
|
|
|
|
2017-11-22 12:44:21 -05:00
|
|
|
" Call it again without the version output. We should use the newer command.
|
2017-10-20 21:29:57 -04:00
|
|
|
AssertEqual
|
|
|
|
\ {
|
2017-11-22 08:46:11 -05:00
|
|
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape(g:ale_javascript_prettier_executable)
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
2017-10-20 21:29:57 -04:00
|
|
|
\ },
|
2017-11-22 08:46:11 -05:00
|
|
|
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|
2018-06-18 17:40:57 -04:00
|
|
|
|
|
|
|
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'])
|