2017-07-18 07:28:20 -04:00
|
|
|
Before:
|
|
|
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
|
|
|
|
|
|
|
After:
|
|
|
|
call ale#test#RestoreDirectory()
|
2017-11-22 11:51:04 -05:00
|
|
|
call ale#semver#ResetVersionCache()
|
2017-07-18 07:28:20 -04:00
|
|
|
|
2017-10-01 15:23:41 -04:00
|
|
|
Execute(The executable path should be correct):
|
2017-07-18 07:28:20 -04:00
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js')
|
|
|
|
|
2017-11-22 11:51:04 -05:00
|
|
|
" eslint_d output with an older eslint version is used here.
|
2017-07-18 07:28:20 -04:00
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2017-10-01 15:23:41 -04:00
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js'))
|
2017-07-18 07:28:20 -04:00
|
|
|
\ . ' --fix %t',
|
|
|
|
\ },
|
2017-11-22 11:51:04 -05:00
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v4.4.1 (eslint_d v5.1.0)'])
|
2017-09-12 04:10:26 -04:00
|
|
|
|
2017-09-11 16:53:45 -04:00
|
|
|
Execute(The lower priority configuration file in a nested directory should be preferred):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
2017-07-18 07:28:20 -04:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2017-10-01 15:23:41 -04:00
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/subdir-with-config/.eslintrc'))
|
2017-07-18 07:28:20 -04:00
|
|
|
\ . ' --fix %t',
|
|
|
|
\ },
|
2017-11-22 11:51:04 -05:00
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), [])
|
2017-09-12 04:10:26 -04:00
|
|
|
|
|
|
|
Execute(package.json should be used as a last resort):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-package-json/testfile.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2017-10-01 15:23:41 -04:00
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js'))
|
2017-09-12 04:10:26 -04:00
|
|
|
\ . ' --fix %t',
|
|
|
|
\ },
|
2017-11-22 11:51:04 -05:00
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), [])
|
2017-09-12 04:10:26 -04:00
|
|
|
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/package.json')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
2017-10-01 15:23:41 -04:00
|
|
|
\ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/node_modules/.bin/eslint'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/package.json'))
|
2017-09-12 04:10:26 -04:00
|
|
|
\ . ' --fix %t',
|
|
|
|
\ },
|
2017-11-22 11:51:04 -05:00
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), [])
|
|
|
|
|
|
|
|
Execute(The version check should be correct):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'chain_with': 'ale#fixers#eslint#ApplyFixForVersion',
|
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' --version'
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#eslint#Fix(bufnr(''))
|
|
|
|
|
|
|
|
Execute(--fix-to-stdout should be used for eslint_d):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/app-with-eslint-d/testfile.js')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/package.json'))
|
|
|
|
\ . ' --fix %t',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), [''])
|
|
|
|
|
|
|
|
" The option should be used when eslint_d is new enough.
|
|
|
|
" We look at the ESLint version instead of the eslint_d version.
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v3.19.0 (eslint_d v4.2.0)'])
|
|
|
|
|
|
|
|
" The option should be used for new versions too.
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'command': (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
|
|
|
|
\ },
|
|
|
|
\ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0'])
|
|
|
|
|
|
|
|
Execute(The version number should be cached):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
|
|
|
|
|
|
|
" Call the second callback with the version output.
|
|
|
|
call ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0'])
|
|
|
|
|
|
|
|
" The version command should be skipped.
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'chain_with': 'ale#fixers#eslint#ApplyFixForVersion',
|
|
|
|
\ 'command': '',
|
|
|
|
\ },
|
2017-09-12 04:10:26 -04:00
|
|
|
\ ale#fixers#eslint#Fix(bufnr(''))
|