Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-invalid-modifier-chain rule #309

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
45 changes: 45 additions & 0 deletions docs/rules/no-invalid-modifier-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Ensure valid modifier chains in tests and hooks

Translations: [Fran莽ais](https://github.com/avajs/ava-docs/blob/master/fr_FR/related/eslint-plugin-ava/docs/rules/no-invalid-modifier-chain.md)

Disallow the invalid combinations, order, and names of modifiers in tests and hooks.


## Fail

```js
const test = require('ava');

// Mispelled .todo
test.todu(t => {})
// Modifiers can't be repeated
test.failing.failing(t => {})
// .todo can't be chained (except after .serial)
test.todo.only(t => {})
// .failing can only be suceeded by .only and .skip
test.failing.serial(t => {})
// .only must be last
test.only.skip(t => {})
// .skip must be last
test.skip.only(t => {})
// .always is only available in .after* hooks
test.before.always(t => {})
// .always must suceed .after
test.always.after(t => {})
// .only is not available in hooks
test.before.only(t => {})
```


## Pass

```js
const test = require('ava');

test(t => {});
test.serial(t => {})
test.serial.todo(t => {})
test.failing.only(t => {})
test.serial.cb.skip(t => {})
test.after.always.cb.skip(t => {})
```
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'ava/no-incorrect-deep-equal': 'error',
'ava/no-inline-assertions': 'error',
'ava/no-invalid-end': 'error',
'ava/no-invalid-modifier-chain': 'error',
'ava/no-nested-tests': 'error',
'ava/no-only-test': 'error',
'ava/no-skip-assert': 'error',
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Configure it in `package.json`.
"ava/no-incorrect-deep-equal": "error",
"ava/no-inline-assertions": "error",
"ava/no-invalid-end": "error",
"ava/no-invalid-modifier-chain": "error",
"ava/no-nested-tests": "error",
"ava/no-only-test": "error",
"ava/no-skip-assert": "error",
Expand Down Expand Up @@ -91,6 +92,7 @@ The rules will only activate in test files.
- [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) - Avoid using `deepEqual` with primitives. *(fixable)*
- [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-invalid-modifier-chain](docs/rules/no-invalid-modifier-chain.md) - Ensure valid modifier chains in tests and hooks
- [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-skip-assert](docs/rules/no-skip-assert.md) - Ensure no assertions are skipped.
Expand Down
Loading