2017-07-18 11:28:20 +00:00
|
|
|
Before:
|
2019-04-07 13:58:06 +00:00
|
|
|
call ale#assert#SetUpFixerTest('javascript', 'eslint')
|
|
|
|
runtime autoload/ale/handlers/eslint.vim
|
2017-07-18 11:28:20 +00:00
|
|
|
|
|
|
|
After:
|
2019-04-07 13:58:06 +00:00
|
|
|
call ale#assert#TearDownFixerTest()
|
2017-07-18 11:28:20 +00:00
|
|
|
|
2017-10-01 19:23:41 +00:00
|
|
|
Execute(The executable path should be correct):
|
2017-07-18 11:28:20 +00:00
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js')
|
|
|
|
|
2017-11-22 16:51:04 +00:00
|
|
|
" eslint_d output with an older eslint version is used here.
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)']
|
|
|
|
AssertFixer
|
2017-07-18 11:28:20 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js'))
|
2017-07-18 11:28:20 +00:00
|
|
|
\ . ' --fix %t',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-09-12 08:10:26 +00:00
|
|
|
|
2019-05-17 19:45:25 +00:00
|
|
|
Execute(The ESLint fixer shouldn't run if no configuration file can be found):
|
|
|
|
call ale#test#SetFilename('../no-configuration')
|
|
|
|
AssertFixerNotExecuted
|
|
|
|
|
|
|
|
Execute(The ESLint fixer should use a config file option if set for old versions):
|
|
|
|
call ale#test#SetFilename('../no-configuration')
|
|
|
|
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape('eslint') . ' -c /foo.cfg --fix %t',
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape('eslint') . ' --bar -c /foo.cfg --fix %t',
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape('eslint') . ' --config /foo.cfg --fix %t',
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command': ale#Escape('eslint') . ' --bar --config /foo.cfg --fix %t',
|
|
|
|
\ }
|
|
|
|
|
|
|
|
Execute(The ESLint fixer should use a -c file option if set for eslint_d):
|
|
|
|
let b:ale_javascript_eslint_executable = '/bin/eslint_d'
|
|
|
|
GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)']
|
|
|
|
call ale#test#SetFilename('../no-configuration')
|
|
|
|
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
|
|
|
\ 'command': ale#Escape('/bin/eslint_d')
|
|
|
|
\ . ' -c /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
|
|
|
\ 'command': ale#Escape('/bin/eslint_d')
|
|
|
|
\ . ' --bar -c /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
|
|
|
\ 'command': ale#Escape('/bin/eslint_d')
|
|
|
|
\ . ' --config /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
|
|
|
\ 'command': ale#Escape('/bin/eslint_d')
|
|
|
|
\ . ' --bar --config /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
Execute(The ESLint fixer should use a config file option if set for new versions):
|
|
|
|
GivenCommandOutput ['4.9.0']
|
|
|
|
call ale#test#SetFilename('../no-configuration')
|
|
|
|
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
|
|
|
\ 'command': ale#Escape('eslint')
|
|
|
|
\ . ' -c /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
|
|
|
\ 'command': ale#Escape('eslint')
|
|
|
|
\ . ' --bar -c /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
|
|
|
\ 'command': ale#Escape('eslint')
|
|
|
|
\ . ' --config /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
|
|
|
\ 'command': ale#Escape('eslint')
|
|
|
|
\ . ' --bar --config /foo.cfg'
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
|
|
|
|
\ }
|
|
|
|
|
2017-09-11 20:53:45 +00: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 11:28:20 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-07-18 11:28:20 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/subdir-with-config/.eslintrc'))
|
2017-07-18 11:28:20 +00:00
|
|
|
\ . ' --fix %t',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-09-12 08:10:26 +00:00
|
|
|
|
2019-05-17 19:45:25 +00:00
|
|
|
Execute(--config in options should override configuration file detection for old versions):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '--config /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2019-05-17 19:45:25 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' --config /foo.cfg'
|
|
|
|
\ . ' --fix %t',
|
|
|
|
\ }
|
|
|
|
|
|
|
|
let b:ale_javascript_eslint_options = '-c /foo.cfg'
|
|
|
|
|
|
|
|
AssertFixer
|
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2019-05-17 19:45:25 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c /foo.cfg'
|
|
|
|
\ . ' --fix %t',
|
|
|
|
\ }
|
|
|
|
|
2017-09-12 08:10:26 +00: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')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-09-12 08:10:26 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js'))
|
2017-09-12 08:10:26 +00:00
|
|
|
\ . ' --fix %t',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-09-12 08:10:26 +00:00
|
|
|
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/package.json')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-09-12 08:10:26 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
|
|
|
\ 'command':
|
2020-07-01 16:00:21 +00:00
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files'))
|
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/node_modules/.bin/eslint'))
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/package.json'))
|
2017-09-12 08:10:26 +00:00
|
|
|
\ . ' --fix %t',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-11-22 16:51:04 +00:00
|
|
|
|
|
|
|
Execute(The version check should be correct):
|
2019-04-07 13:58:06 +00:00
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js')
|
2017-11-22 16:51:04 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
" We should run the command to get the version the first time.
|
|
|
|
GivenCommandOutput ['4.9.0']
|
|
|
|
AssertFixer [
|
|
|
|
\ (has('win32') ? 'node.exe ' : '')
|
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' --version',
|
2017-11-22 16:51:04 +00:00
|
|
|
\ {
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
2019-04-07 13:58:06 +00:00
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
2017-11-22 16:51:04 +00:00
|
|
|
\ },
|
2019-04-07 13:58:06 +00:00
|
|
|
\]
|
|
|
|
|
|
|
|
AssertFixer [
|
|
|
|
\ {
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2019-04-07 13:58:06 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
|
|
|
\ },
|
|
|
|
\]
|
2017-11-22 16:51:04 +00:00
|
|
|
|
2017-11-22 23:23:14 +00:00
|
|
|
Execute(--fix-dry-run should be used for 4.9.0 and up):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['4.9.0']
|
|
|
|
AssertFixer
|
2017-11-22 23:23:14 +00:00
|
|
|
\ {
|
2020-07-01 16:00:21 +00:00
|
|
|
\ 'command':
|
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app'))
|
|
|
|
\ . (has('win32') ? 'node.exe ' : '')
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
|
2017-11-22 23:23:14 +00:00
|
|
|
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
|
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-11-22 23:23:14 +00:00
|
|
|
|
2017-11-22 16:51:04 +00:00
|
|
|
Execute(--fix-to-stdout should be used for eslint_d):
|
|
|
|
call ale#test#SetFilename('../eslint-test-files/app-with-eslint-d/testfile.js')
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
AssertFixer
|
2017-11-22 16:51:04 +00:00
|
|
|
\ {
|
|
|
|
\ 'read_temporary_file': 1,
|
2017-11-22 17:25:37 +00:00
|
|
|
\ 'command':
|
2020-07-01 16:00:21 +00:00
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d'))
|
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
2017-12-19 18:23:09 +00:00
|
|
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/package.json'))
|
2017-11-22 16:51:04 +00:00
|
|
|
\ . ' --fix %t',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-11-22 16:51:04 +00:00
|
|
|
|
|
|
|
" The option should be used when eslint_d is new enough.
|
|
|
|
" We look at the ESLint version instead of the eslint_d version.
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)']
|
|
|
|
AssertFixer
|
2017-11-22 16:51:04 +00:00
|
|
|
\ {
|
2017-11-22 17:25:37 +00:00
|
|
|
\ 'command':
|
2020-07-01 16:00:21 +00:00
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d'))
|
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
2017-11-22 16:51:04 +00:00
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
|
2017-11-29 10:08:54 +00:00
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-11-22 16:51:04 +00:00
|
|
|
|
|
|
|
" The option should be used for new versions too.
|
2019-04-07 13:58:06 +00:00
|
|
|
GivenCommandOutput ['4.9.0']
|
|
|
|
AssertFixer
|
2017-11-22 16:51:04 +00:00
|
|
|
\ {
|
2017-11-22 17:25:37 +00:00
|
|
|
\ 'command':
|
2020-07-01 16:00:21 +00:00
|
|
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d'))
|
|
|
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'))
|
2017-11-22 16:51:04 +00:00
|
|
|
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
|
2017-11-29 10:08:54 +00:00
|
|
|
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ }
|
2017-11-22 23:23:14 +00:00
|
|
|
|
|
|
|
Execute(The --fix-dry-run post-processor should handle JSON output correctly):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), [])
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), [''])
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{}]'])
|
|
|
|
AssertEqual
|
|
|
|
\ ['foo', 'bar'],
|
|
|
|
\ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{"output": "foo\nbar"}]'])
|
2017-11-29 10:08:54 +00:00
|
|
|
|
|
|
|
Execute(The eslint_d post-processor should permit regular JavaScript content):
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ 'const x = ''Error: foo''',
|
|
|
|
\ 'const y = 3',
|
|
|
|
\ ],
|
|
|
|
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
|
|
|
|
\ 'const x = ''Error: foo''',
|
|
|
|
\ 'const y = 3',
|
|
|
|
\ ])
|
|
|
|
|
|
|
|
Execute(The eslint_d post-processor should handle error messages correctly):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
|
|
|
|
\ 'Error: No ESLint configuration found.',
|
|
|
|
\ ])
|
2018-09-17 16:32:57 +00:00
|
|
|
|
|
|
|
Execute(The eslint_d post-processor should handle failing to connect properly):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
|
|
|
|
\ 'Could not connect',
|
|
|
|
\ ])
|