2017-08-30 17:49:46 -04:00
|
|
|
Before:
|
|
|
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
|
|
|
|
|
|
|
Save g:ale_javascript_prettier_eslint_executable
|
|
|
|
Save g:ale_javascript_prettier_eslint_use_global
|
|
|
|
Save g:ale_javascript_prettier_eslint_options
|
|
|
|
|
|
|
|
unlet! g:ale_javascript_prettier_eslint_executable
|
|
|
|
unlet! g:ale_javascript_prettier_eslint_use_global
|
|
|
|
unlet! g:ale_javascript_prettier_eslint_options
|
|
|
|
|
|
|
|
call ale#fixers#prettier_eslint#SetOptionDefaults()
|
|
|
|
|
|
|
|
After:
|
|
|
|
Restore
|
|
|
|
|
|
|
|
unlet! b:ale_javascript_prettier_eslint_executable
|
|
|
|
unlet! b:ale_javascript_prettier_eslint_use_global
|
|
|
|
unlet! b:ale_javascript_prettier_eslint_options
|
|
|
|
|
|
|
|
call ale#test#RestoreDirectory()
|
2017-11-22 09:46:14 -05:00
|
|
|
call ale#semver#ResetVersionCache()
|
2017-08-30 17:49:46 -04:00
|
|
|
|
|
|
|
Execute(The default command should be correct):
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
|
|
|
\ ale#Escape('prettier-eslint')
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write'
|
|
|
|
\ },
|
2017-11-22 09:46:14 -05:00
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
2017-08-30 17:49:46 -04:00
|
|
|
|
|
|
|
Execute(Additional options should be used when set):
|
|
|
|
let b:ale_javascript_prettier_eslint_options = '--foobar'
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
|
|
|
\ ale#Escape('prettier-eslint')
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --foobar --write'
|
|
|
|
\ },
|
2017-11-22 09:46:14 -05:00
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
2017-08-30 17:49:46 -04:00
|
|
|
|
2017-11-22 09:46:14 -05:00
|
|
|
Execute(--eslint-config-path should be set for 4.2.0 and up):
|
2017-08-30 17:49:46 -04:00
|
|
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
|
|
|
\ ale#Escape('prettier-eslint')
|
|
|
|
\ . ' %t'
|
2017-12-19 13:23:09 -05:00
|
|
|
\ . ' --eslint-config-path ' . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/.eslintrc.js'))
|
2017-08-30 17:49:46 -04:00
|
|
|
\ . ' --write'
|
|
|
|
\ },
|
2017-11-22 09:46:14 -05:00
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.2.0'])
|
2017-08-30 17:49:46 -04:00
|
|
|
|
2017-11-22 09:46:14 -05:00
|
|
|
Execute(--eslint-config-path shouldn't be used for older versions):
|
2017-08-30 17:49:46 -04:00
|
|
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
|
|
|
\ ale#Escape('prettier-eslint')
|
|
|
|
\ . ' %t'
|
|
|
|
\ . ' --write'
|
|
|
|
\ },
|
2017-11-22 09:46:14 -05:00
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|
|
|
|
|
|
|
|
Execute(The version check should be correct):
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion',
|
|
|
|
\ 'command': ale#Escape('prettier-eslint') . ' --version',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
|
|
|
|
|
|
|
Execute(The new --stdin-filepath option should be used when the version is new enough):
|
|
|
|
call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape('prettier-eslint')
|
2017-12-19 13:23:09 -05:00
|
|
|
\ . ' --eslint-config-path ' . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/.eslintrc.js'))
|
2017-11-22 09:46:14 -05:00
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0'])
|
|
|
|
|
|
|
|
Execute(The version number should be cached):
|
|
|
|
call ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0'])
|
|
|
|
|
|
|
|
" The version command should be skipped.
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion',
|
|
|
|
\ 'command': '',
|
|
|
|
\ },
|
2017-08-30 17:49:46 -04:00
|
|
|
\ ale#fixers#prettier_eslint#Fix(bufnr(''))
|
2017-11-22 09:46:14 -05:00
|
|
|
|
|
|
|
" The newer command should be used.
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape('prettier-eslint')
|
|
|
|
\ . ' --stdin-filepath %s --stdin',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), [])
|