diff --git a/docs/rules/no-only-test.md b/docs/rules/no-only-test.md index c026b13..92201c3 100644 --- a/docs/rules/no-only-test.md +++ b/docs/rules/no-only-test.md @@ -4,9 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela It's easy to run only one test with `test.only()` and then forget about it. It's visible in the results, but still easily missed. Forgetting to remove `.only`, means only this one test in the whole file will run, and if not caught, can let serious bugs slip into your codebase. -This rule is fixable. It will remove the `.only` test modifier. - - ## Fail ```js diff --git a/docs/rules/no-skip-test.md b/docs/rules/no-skip-test.md index 57c41ee..a770752 100644 --- a/docs/rules/no-skip-test.md +++ b/docs/rules/no-skip-test.md @@ -4,9 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela It's easy to make a test skipped with `test.skip()` and then forget about it. It's visible in the results, but still easily missed. -This rule is fixable. It will remove the `.skip` test modifier. - - ## Fail ```js diff --git a/readme.md b/readme.md index 97aeb7c..cc80a4e 100644 --- a/readme.md +++ b/readme.md @@ -89,9 +89,9 @@ The rules will only activate in test files. - [no-inline-assertions](docs/rules/no-inline-assertions.md) - Ensure assertions are not called from inline arrow functions. *(fixable)* - [no-invalid-end](docs/rules/no-invalid-end.md) - Ensure `t.end()` is only called inside `test.cb()`. - [no-nested-tests](docs/rules/no-nested-tests.md) - Ensure no tests are nested. -- [no-only-test](docs/rules/no-only-test.md) - Ensure no `test.only()` are present. *(fixable)* +- [no-only-test](docs/rules/no-only-test.md) - Ensure no `test.only()` are present. - [no-skip-assert](docs/rules/no-skip-assert.md) - Ensure no assertions are skipped. -- [no-skip-test](docs/rules/no-skip-test.md) - Ensure no tests are skipped. *(fixable)* +- [no-skip-test](docs/rules/no-skip-test.md) - Ensure no tests are skipped. - [no-statement-after-end](docs/rules/no-statement-after-end.md) - Ensure `t.end()` is the last statement executed. - [no-todo-implementation](docs/rules/no-todo-implementation.md) - Ensure `test.todo()` is not given an implementation function. - [no-todo-test](docs/rules/no-todo-test.md) - Ensure no `test.todo()` is used. diff --git a/rules/no-only-test.js b/rules/no-only-test.js index 57edd26..f0a0dc6 100644 --- a/rules/no-only-test.js +++ b/rules/no-only-test.js @@ -16,13 +16,16 @@ const create = context => { context.report({ node: propertyNode, message: '`test.only()` should not be used.', - fix: fixer => { - return fixer.replaceTextRange.apply(null, util.removeTestModifier({ - modifier: 'only', - node, - context - })); - } + suggest: [{ + desc: 'Remove the `.only`', + fix: fixer => { + return fixer.replaceTextRange.apply(null, util.removeTestModifier({ + modifier: 'only', + node, + context + })); + } + }] }); } }) diff --git a/rules/no-skip-test.js b/rules/no-skip-test.js index b32e0a7..ae9379b 100644 --- a/rules/no-skip-test.js +++ b/rules/no-skip-test.js @@ -16,13 +16,16 @@ const create = context => { context.report({ node: propertyNode, message: 'No tests should be skipped.', - fix: fixer => { - return fixer.replaceTextRange.apply(null, util.removeTestModifier({ - modifier: 'skip', - node, - context - })); - } + suggest: [{ + desc: 'Remove the `.skip`', + fix: fixer => { + return fixer.replaceTextRange.apply(null, util.removeTestModifier({ + modifier: 'skip', + node, + context + })); + } + }] }); } }) diff --git a/test/no-only-test.js b/test/no-only-test.js index 2ec5c5b..cecf9d3 100644 --- a/test/no-only-test.js +++ b/test/no-only-test.js @@ -26,92 +26,119 @@ ruleTester.run('no-only-test', rule, { invalid: [ { code: header + 'test\n\t.only(t => { t.pass(); });', - output: header + 'test\n\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 3 + column: 3, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n\t(t => { t.pass(); });' + }] }] }, { code: header + 'test\n .only(t => { t.pass(); });', - output: header + 'test\n (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 4 + column: 4, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n (t => { t.pass(); });' + }] }] }, { code: header + 'test\t.only(t => { t.pass(); });', - output: header + 'test\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 7 + column: 7, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\t(t => { t.pass(); });' + }] }] }, { code: header + 'test .only(t => { t.pass(); });', - output: header + 'test (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 8 + column: 8, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test (t => { t.pass(); });' + }] }] }, { code: header + 'test.\n\tonly(t => { t.pass(); });', - output: header + 'test\n\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 2 + column: 2, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n\t(t => { t.pass(); });' + }] }] }, { code: header + 'test.\n only(t => { t.pass(); });', - output: header + 'test\n (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 3 + column: 3, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n (t => { t.pass(); });' + }] }] }, { code: header + 'test.only(t => { t.pass(); });', - output: header + 'test(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test(t => { t.pass(); });' + }] }] }, { code: header + 'test.cb.only(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 9 + column: 9, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.only.cb(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] } ] diff --git a/test/no-skip-test.js b/test/no-skip-test.js index f3de151..cd6e60a 100644 --- a/test/no-skip-test.js +++ b/test/no-skip-test.js @@ -24,52 +24,67 @@ ruleTester.run('no-skip-test', rule, { invalid: [ { code: header + 'test.skip(t => { t.pass(); });', - output: header + 'test(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test(t => { t.pass(); });' + }] }] }, { code: header + 'test.cb.skip(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 9 + column: 9, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.skip.cb(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.\n\tskip.cb(t => { t.pass(); t.end(); });', - output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 2 + column: 2, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test .skip .cb(t => { t.pass(); t.end(); });', - output: header + 'test .cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 8 + column: 8, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test .cb(t => { t.pass(); t.end(); });' + }] }] } ]