Skip to content

Commit d094df5

Browse files
committed
Add suggestions and fixes to more rules
Fixes #281
1 parent e576871 commit d094df5

11 files changed

Lines changed: 129 additions & 19 deletions

docs/rules/no-duplicate-modifiers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
66

7+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
8+
79
<!-- end auto-generated rule header -->
810

911
Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-duplicate-modifiers.md)

docs/rules/no-only-test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
66

7-
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
7+
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
88

99
<!-- end auto-generated rule header -->
1010

docs/rules/no-skip-test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
66

7-
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
7+
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
88

99
<!-- end auto-generated rule header -->
1010

docs/rules/no-todo-implementation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
66

7+
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8+
79
<!-- end auto-generated rule header -->
810

911
Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-todo-implementation.md)

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ The rules will only activate in test files.
4242

4343
<!-- begin auto-generated rules list -->
4444

45-
💼 Configurations enabled in.\
46-
⚠️ Configurations set to warn in.\
47-
🚫 Configurations disabled in.\
48-
✅ Set in the `recommended` configuration.\
45+
💼 [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) enabled in.\
46+
⚠️ [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) set to warn in.\
47+
🚫 [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) disabled in.\
48+
✅ Set in the `recommended` [configuration](https://github.com/avajs/eslint-plugin-ava#recommended-config).\
4949
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
5050
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
5151

rules/no-duplicate-modifiers.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ const create = context => {
2020
return;
2121
}
2222

23+
const {sourceCode} = context;
24+
2325
for (let index = 1; index < testModifiers.length; index++) {
2426
if (testModifiers[index - 1].name === testModifiers[index].name) {
27+
const duplicate = testModifiers[index];
2528
context.report({
26-
node: testModifiers[index],
29+
node: duplicate,
2730
messageId: MESSAGE_ID,
28-
data: {name: testModifiers[index].name},
31+
data: {name: duplicate.name},
32+
fix(fixer) {
33+
const dotToken = sourceCode.getTokenBefore(duplicate);
34+
return fixer.removeRange([dotToken.range[0], duplicate.range[1]]);
35+
},
2936
});
3037
}
3138
}
@@ -42,6 +49,7 @@ export default {
4249
recommended: true,
4350
url: util.getDocsUrl(import.meta.filename),
4451
},
52+
fixable: 'code',
4553
schema: [],
4654
messages: {
4755
[MESSAGE_ID]: 'Duplicate test modifier `.{{name}}`.',

rules/no-only-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default {
4141
recommended: true,
4242
url: util.getDocsUrl(import.meta.filename),
4343
},
44-
fixable: 'code',
4544
hasSuggestions: true,
4645
schema: [],
4746
messages: {

rules/no-skip-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default {
4141
recommended: true,
4242
url: util.getDocsUrl(import.meta.filename),
4343
},
44-
fixable: 'code',
4544
hasSuggestions: true,
4645
schema: [],
4746
messages: {

rules/no-todo-implementation.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {visitIf} from 'enhance-visitors';
2+
import {isCommaToken} from '@eslint-community/eslint-utils';
23
import util from '../util.js';
34
import createAvaRule from '../create-ava-rule.js';
45

56
const MESSAGE_ID = 'no-todo-implementation';
7+
const MESSAGE_ID_REMOVE_TODO = 'no-todo-implementation-remove-todo';
8+
const MESSAGE_ID_REMOVE_IMPLEMENTATION = 'no-todo-implementation-remove-implementation';
69

710
const create = context => {
811
const ava = createAvaRule();
@@ -13,9 +16,33 @@ const create = context => {
1316
ava.isTestNode,
1417
])(node => {
1518
if (ava.hasTestModifier('todo') && node.arguments.some(argument => util.isFunctionExpression(argument))) {
19+
const {sourceCode} = context;
20+
const functionArgument = node.arguments.find(argument => util.isFunctionExpression(argument));
21+
1622
context.report({
1723
node,
1824
messageId: MESSAGE_ID,
25+
suggest: [
26+
{
27+
messageId: MESSAGE_ID_REMOVE_TODO,
28+
fix: fixer => fixer.replaceTextRange(...util.removeTestModifier({
29+
modifier: 'todo',
30+
node,
31+
context,
32+
})),
33+
},
34+
{
35+
messageId: MESSAGE_ID_REMOVE_IMPLEMENTATION,
36+
fix(fixer) {
37+
const commaToken = sourceCode.getTokenBefore(functionArgument, {filter: token => isCommaToken(token)});
38+
if (commaToken) {
39+
return fixer.removeRange([commaToken.range[0], functionArgument.range[1]]);
40+
}
41+
42+
return fixer.remove(functionArgument);
43+
},
44+
},
45+
],
1946
});
2047
}
2148
}),
@@ -31,9 +58,12 @@ export default {
3158
recommended: true,
3259
url: util.getDocsUrl(import.meta.filename),
3360
},
61+
hasSuggestions: true,
3462
schema: [],
3563
messages: {
3664
[MESSAGE_ID]: '`test.todo()` should not be passed an implementation function.',
65+
[MESSAGE_ID_REMOVE_TODO]: 'Remove the `.todo` modifier to make it a regular test.',
66+
[MESSAGE_ID_REMOVE_IMPLEMENTATION]: 'Remove the implementation function to keep it as a todo.',
3767
},
3868
},
3969
};

test/no-duplicate-modifiers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const modifiers = [
2626
const valid = modifiers.map(modifier => `${header}test.${modifier}(t => {});`);
2727
const invalid = modifiers.map(modifier => ({
2828
code: `${header}test.${modifier}.${modifier}(t => {});`,
29+
output: `${header}test.${modifier}(t => {});`,
2930
errors: [
3031
{
3132
messageId: 'no-duplicate-modifiers',

0 commit comments

Comments
 (0)