Skip to content

Commit 32a434a

Browse files
committed
Add no-invalid-modifier-chain rule
Fixes #186
1 parent d87de24 commit 32a434a

9 files changed

Lines changed: 714 additions & 43 deletions

docs/rules/no-duplicate-modifiers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
📝 Disallow duplicate test modifiers.
44

5-
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
5+
❌ This rule is deprecated.
6+
7+
🚫 This rule is _disabled_ in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
68

79
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
810

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ava/no-invalid-modifier-chain
2+
3+
📝 Disallow invalid modifier chains.
4+
5+
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
6+
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).
8+
9+
<!-- end auto-generated rule header -->
10+
11+
Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-invalid-modifier-chain.md)
12+
13+
AVA only allows specific [test modifier](https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md) chains. Using modifiers in the wrong order, combining incompatible modifiers, or using modifiers that don't apply to a given test type will cause runtime errors.
14+
15+
## Examples
16+
17+
```js
18+
import test from 'ava';
19+
20+
// Wrong order
21+
test.only.serial(t => {}); //
22+
test.serial.only(t => {}); //
23+
24+
test.failing.serial(t => {}); //
25+
test.serial.failing(t => {}); //
26+
27+
// Invalid combinations
28+
test.only.skip(t => {}); //
29+
30+
// Invalid modifiers on hooks
31+
test.before.failing(t => {}); //
32+
test.before.only(t => {}); //
33+
test.before(t => {}); //
34+
35+
// Invalid todo chains
36+
test.todo.failing('title'); //
37+
test.todo('title'); //
38+
39+
// Invalid always usage
40+
test.before.always(t => {}); // ❌ `.always` only works with `after`/`afterEach`
41+
test.after.always(t => {}); //
42+
test.afterEach.always(t => {}); //
43+
44+
// Unknown modifiers
45+
test.foo(t => {}); //
46+
test.cb(t => {}); //
47+
48+
// Duplicates
49+
test.serial.serial(t => {}); //
50+
test.serial(t => {}); //
51+
```

docs/rules/no-unknown-modifiers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
📝 Disallow unknown test modifiers.
44

5-
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
5+
❌ This rule is deprecated.
6+
7+
🚫 This rule is _disabled_ in the ✅ `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config).
68

79
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
810

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import noIgnoredTestFiles from './rules/no-ignored-test-files.js';
1313
import noImportTestFiles from './rules/no-import-test-files.js';
1414
import noIncorrectDeepEqual from './rules/no-incorrect-deep-equal.js';
1515
import noInlineAssertions from './rules/no-inline-assertions.js';
16+
import noInvalidModifierChain from './rules/no-invalid-modifier-chain.js';
1617
import noNestedAssertions from './rules/no-nested-assertions.js';
1718
import noNestedTests from './rules/no-nested-tests.js';
1819
import noOnlyTest from './rules/no-only-test.js';
@@ -51,6 +52,7 @@ const rules = {
5152
'no-import-test-files': noImportTestFiles,
5253
'no-incorrect-deep-equal': noIncorrectDeepEqual,
5354
'no-inline-assertions': noInlineAssertions,
55+
'no-invalid-modifier-chain': noInvalidModifierChain,
5456
'no-nested-assertions': noNestedAssertions,
5557
'no-nested-tests': noNestedTests,
5658
'no-only-test': noOnlyTest,
@@ -83,20 +85,21 @@ const recommendedRules = {
8385
],
8486
'ava/no-async-fn-without-await': 'error',
8587
'ava/no-commented-tests': 'warn',
86-
'ava/no-duplicate-modifiers': 'error',
88+
'ava/no-duplicate-modifiers': 'off',
8789
'ava/no-identical-title': 'error',
8890
'ava/no-ignored-test-files': 'error',
8991
'ava/no-import-test-files': 'error',
9092
'ava/no-incorrect-deep-equal': 'error',
9193
'ava/no-inline-assertions': 'error',
94+
'ava/no-invalid-modifier-chain': 'error',
9295
'ava/no-nested-assertions': 'error',
9396
'ava/no-nested-tests': 'error',
9497
'ava/no-only-test': 'error',
9598
'ava/no-skip-assert': 'error',
9699
'ava/no-skip-test': 'error',
97100
'ava/no-todo-implementation': 'error',
98101
'ava/no-todo-test': 'warn',
99-
'ava/no-unknown-modifiers': 'error',
102+
'ava/no-unknown-modifiers': 'off',
100103
'ava/no-useless-t-pass': 'error',
101104
'ava/prefer-async-await': 'error',
102105
'ava/prefer-power-assert': 'off',

0 commit comments

Comments
 (0)