Skip to content

Use suggestions API for no-only-test and no-skip-test #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/rules/no-only-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docs/rules/no-skip-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 10 additions & 7 deletions rules/no-only-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
}
}]
});
}
})
Expand Down
17 changes: 10 additions & 7 deletions rules/no-skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
}
}]
});
}
})
Expand Down
63 changes: 45 additions & 18 deletions test/no-only-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });'
}]
}]
}
]
Expand Down
35 changes: 25 additions & 10 deletions test/no-skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });'
}]
}]
}
]
Expand Down