Skip to content

Commit ae34aea

Browse files
authored
Use suggestions API for no-only-test and no-skip-test (#325)
1 parent f175fd0 commit ae34aea

File tree

7 files changed

+92
-50
lines changed

7 files changed

+92
-50
lines changed

docs/rules/no-only-test.md

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela
44

55
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.
66

7-
This rule is fixable. It will remove the `.only` test modifier.
8-
9-
107
## Fail
118

129
```js

docs/rules/no-skip-test.md

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela
44

55
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.
66

7-
This rule is fixable. It will remove the `.skip` test modifier.
8-
9-
107
## Fail
118

129
```js

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ The rules will only activate in test files.
8989
- [no-inline-assertions](docs/rules/no-inline-assertions.md) - Ensure assertions are not called from inline arrow functions. *(fixable)*
9090
- [no-invalid-end](docs/rules/no-invalid-end.md) - Ensure `t.end()` is only called inside `test.cb()`.
9191
- [no-nested-tests](docs/rules/no-nested-tests.md) - Ensure no tests are nested.
92-
- [no-only-test](docs/rules/no-only-test.md) - Ensure no `test.only()` are present. *(fixable)*
92+
- [no-only-test](docs/rules/no-only-test.md) - Ensure no `test.only()` are present.
9393
- [no-skip-assert](docs/rules/no-skip-assert.md) - Ensure no assertions are skipped.
94-
- [no-skip-test](docs/rules/no-skip-test.md) - Ensure no tests are skipped. *(fixable)*
94+
- [no-skip-test](docs/rules/no-skip-test.md) - Ensure no tests are skipped.
9595
- [no-statement-after-end](docs/rules/no-statement-after-end.md) - Ensure `t.end()` is the last statement executed.
9696
- [no-todo-implementation](docs/rules/no-todo-implementation.md) - Ensure `test.todo()` is not given an implementation function.
9797
- [no-todo-test](docs/rules/no-todo-test.md) - Ensure no `test.todo()` is used.

rules/no-only-test.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ const create = context => {
1616
context.report({
1717
node: propertyNode,
1818
message: '`test.only()` should not be used.',
19-
fix: fixer => {
20-
return fixer.replaceTextRange.apply(null, util.removeTestModifier({
21-
modifier: 'only',
22-
node,
23-
context
24-
}));
25-
}
19+
suggest: [{
20+
desc: 'Remove the `.only`',
21+
fix: fixer => {
22+
return fixer.replaceTextRange.apply(null, util.removeTestModifier({
23+
modifier: 'only',
24+
node,
25+
context
26+
}));
27+
}
28+
}]
2629
});
2730
}
2831
})

rules/no-skip-test.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ const create = context => {
1616
context.report({
1717
node: propertyNode,
1818
message: 'No tests should be skipped.',
19-
fix: fixer => {
20-
return fixer.replaceTextRange.apply(null, util.removeTestModifier({
21-
modifier: 'skip',
22-
node,
23-
context
24-
}));
25-
}
19+
suggest: [{
20+
desc: 'Remove the `.skip`',
21+
fix: fixer => {
22+
return fixer.replaceTextRange.apply(null, util.removeTestModifier({
23+
modifier: 'skip',
24+
node,
25+
context
26+
}));
27+
}
28+
}]
2629
});
2730
}
2831
})

test/no-only-test.js

+45-18
Original file line numberDiff line numberDiff line change
@@ -26,92 +26,119 @@ ruleTester.run('no-only-test', rule, {
2626
invalid: [
2727
{
2828
code: header + 'test\n\t.only(t => { t.pass(); });',
29-
output: header + 'test\n\t(t => { t.pass(); });',
3029
errors: [{
3130
message,
3231
type: 'Identifier',
3332
line: 3,
34-
column: 3
33+
column: 3,
34+
suggestions: [{
35+
desc: 'Remove the `.only`',
36+
output: header + 'test\n\t(t => { t.pass(); });'
37+
}]
3538
}]
3639
},
3740
{
3841
code: header + 'test\n .only(t => { t.pass(); });',
39-
output: header + 'test\n (t => { t.pass(); });',
4042
errors: [{
4143
message,
4244
type: 'Identifier',
4345
line: 3,
44-
column: 4
46+
column: 4,
47+
suggestions: [{
48+
desc: 'Remove the `.only`',
49+
output: header + 'test\n (t => { t.pass(); });'
50+
}]
4551
}]
4652
},
4753
{
4854
code: header + 'test\t.only(t => { t.pass(); });',
49-
output: header + 'test\t(t => { t.pass(); });',
5055
errors: [{
5156
message,
5257
type: 'Identifier',
5358
line: 2,
54-
column: 7
59+
column: 7,
60+
suggestions: [{
61+
desc: 'Remove the `.only`',
62+
output: header + 'test\t(t => { t.pass(); });'
63+
}]
5564
}]
5665
},
5766
{
5867
code: header + 'test .only(t => { t.pass(); });',
59-
output: header + 'test (t => { t.pass(); });',
6068
errors: [{
6169
message,
6270
type: 'Identifier',
6371
line: 2,
64-
column: 8
72+
column: 8,
73+
suggestions: [{
74+
desc: 'Remove the `.only`',
75+
output: header + 'test (t => { t.pass(); });'
76+
}]
6577
}]
6678
},
6779
{
6880
code: header + 'test.\n\tonly(t => { t.pass(); });',
69-
output: header + 'test\n\t(t => { t.pass(); });',
7081
errors: [{
7182
message,
7283
type: 'Identifier',
7384
line: 3,
74-
column: 2
85+
column: 2,
86+
suggestions: [{
87+
desc: 'Remove the `.only`',
88+
output: header + 'test\n\t(t => { t.pass(); });'
89+
}]
7590
}]
7691
},
7792
{
7893
code: header + 'test.\n only(t => { t.pass(); });',
79-
output: header + 'test\n (t => { t.pass(); });',
8094
errors: [{
8195
message,
8296
type: 'Identifier',
8397
line: 3,
84-
column: 3
98+
column: 3,
99+
suggestions: [{
100+
desc: 'Remove the `.only`',
101+
output: header + 'test\n (t => { t.pass(); });'
102+
}]
85103
}]
86104
},
87105
{
88106
code: header + 'test.only(t => { t.pass(); });',
89-
output: header + 'test(t => { t.pass(); });',
90107
errors: [{
91108
message,
92109
type: 'Identifier',
93110
line: 2,
94-
column: 6
111+
column: 6,
112+
suggestions: [{
113+
desc: 'Remove the `.only`',
114+
output: header + 'test(t => { t.pass(); });'
115+
}]
95116
}]
96117
},
97118
{
98119
code: header + 'test.cb.only(t => { t.pass(); t.end(); });',
99-
output: header + 'test.cb(t => { t.pass(); t.end(); });',
100120
errors: [{
101121
message,
102122
type: 'Identifier',
103123
line: 2,
104-
column: 9
124+
column: 9,
125+
suggestions: [{
126+
desc: 'Remove the `.only`',
127+
output: header + 'test.cb(t => { t.pass(); t.end(); });'
128+
}]
105129
}]
106130
},
107131
{
108132
code: header + 'test.only.cb(t => { t.pass(); t.end(); });',
109-
output: header + 'test.cb(t => { t.pass(); t.end(); });',
110133
errors: [{
111134
message,
112135
type: 'Identifier',
113136
line: 2,
114-
column: 6
137+
column: 6,
138+
suggestions: [{
139+
desc: 'Remove the `.only`',
140+
output: header + 'test.cb(t => { t.pass(); t.end(); });'
141+
}]
115142
}]
116143
}
117144
]

test/no-skip-test.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,67 @@ ruleTester.run('no-skip-test', rule, {
2424
invalid: [
2525
{
2626
code: header + 'test.skip(t => { t.pass(); });',
27-
output: header + 'test(t => { t.pass(); });',
2827
errors: [{
2928
message,
3029
type: 'Identifier',
3130
line: 2,
32-
column: 6
31+
column: 6,
32+
suggestions: [{
33+
desc: 'Remove the `.skip`',
34+
output: header + 'test(t => { t.pass(); });'
35+
}]
3336
}]
3437
},
3538
{
3639
code: header + 'test.cb.skip(t => { t.pass(); t.end(); });',
37-
output: header + 'test.cb(t => { t.pass(); t.end(); });',
3840
errors: [{
3941
message,
4042
type: 'Identifier',
4143
line: 2,
42-
column: 9
44+
column: 9,
45+
suggestions: [{
46+
desc: 'Remove the `.skip`',
47+
output: header + 'test.cb(t => { t.pass(); t.end(); });'
48+
}]
4349
}]
4450
},
4551
{
4652
code: header + 'test.skip.cb(t => { t.pass(); t.end(); });',
47-
output: header + 'test.cb(t => { t.pass(); t.end(); });',
4853
errors: [{
4954
message,
5055
type: 'Identifier',
5156
line: 2,
52-
column: 6
57+
column: 6,
58+
suggestions: [{
59+
desc: 'Remove the `.skip`',
60+
output: header + 'test.cb(t => { t.pass(); t.end(); });'
61+
}]
5362
}]
5463
},
5564
{
5665
code: header + 'test.\n\tskip.cb(t => { t.pass(); t.end(); });',
57-
output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });',
5866
errors: [{
5967
message,
6068
type: 'Identifier',
6169
line: 3,
62-
column: 2
70+
column: 2,
71+
suggestions: [{
72+
desc: 'Remove the `.skip`',
73+
output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });'
74+
}]
6375
}]
6476
},
6577
{
6678
code: header + 'test .skip .cb(t => { t.pass(); t.end(); });',
67-
output: header + 'test .cb(t => { t.pass(); t.end(); });',
6879
errors: [{
6980
message,
7081
type: 'Identifier',
7182
line: 2,
72-
column: 8
83+
column: 8,
84+
suggestions: [{
85+
desc: 'Remove the `.skip`',
86+
output: header + 'test .cb(t => { t.pass(); t.end(); });'
87+
}]
7388
}]
7489
}
7590
]

0 commit comments

Comments
 (0)