eslint-plugin-ava
Version:
ESLint rules for AVA
107 lines (85 loc) β’ 10.9 kB
Markdown
# eslint-plugin-ava [](https://coveralls.io/github/avajs/eslint-plugin-ava?branch=main)
> ESLint rules for [AVA](https://avajs.dev)
Translations: [FranΓ§ais](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/readme.md)
This plugin is bundled in [XO](https://github.com/xojs/xo). No need to do anything if you're using it.
[**Propose or contribute a new rule β‘**](.github/contributing.md)
## Install
```sh
npm install --save-dev eslint eslint-plugin-ava
```
**Requires ESLint `>=10`, [flat config](https://eslint.org/docs/latest/use/configure/configuration-files), and [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).**
## Usage
Use a [preset config](#recommended-config) or configure each rule in `eslint.config.js`.
```js
import eslintPluginAva from 'eslint-plugin-ava';
export default [
{
plugins: {
ava: eslintPluginAva,
},
rules: {
'ava/assertion-arguments': 'error',
'ava/no-only-test': 'error',
},
},
];
```
## Rules
The rules will only activate in test files.
<!-- begin auto-generated rules list -->
πΌ [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) enabled in.\
β οΈ [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) set to warn in.\
π« [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) disabled in.\
β
Set in the `recommended` [configuration](https://github.com/avajs/eslint-plugin-ava#recommended-config).\
π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
β Deprecated.
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | β |
| :------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------- | :- | :- | :- | :- | :- | :- |
| [assertion-arguments](docs/rules/assertion-arguments.md) | Enforce passing correct arguments to assertions. | β
| | | π§ | | |
| [failing-test-url](docs/rules/failing-test-url.md) | Require a URL in a comment above `test.failing()`. | | | β
| | | |
| [hooks-order](docs/rules/hooks-order.md) | Enforce test hook ordering. | β
| | | π§ | | |
| [max-asserts](docs/rules/max-asserts.md) | Limit the number of assertions in a test. | | | β
| | | |
| [no-async-fn-without-await](docs/rules/no-async-fn-without-await.md) | Require async tests to use `await`. | β
| | | | π‘ | |
| [no-ava-in-dependencies](docs/rules/no-ava-in-dependencies.md) | Disallow AVA in `dependencies`. | β
| | | π§ | | |
| [no-commented-tests](docs/rules/no-commented-tests.md) | Disallow commented-out tests. | | β
| | | | |
| [no-conditional-assertion](docs/rules/no-conditional-assertion.md) | Disallow assertions inside conditional statements. | β
| | | | | |
| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate hook declarations. | β
| | | | | |
| [no-duplicate-modifiers](docs/rules/no-duplicate-modifiers.md) | Disallow duplicate test modifiers. | | | β
| π§ | | β |
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical test titles. | β
| | | | | |
| [no-ignored-test-files](docs/rules/no-ignored-test-files.md) | Disallow tests in ignored files. | β
| | | | | |
| [no-import-test-files](docs/rules/no-import-test-files.md) | Disallow importing test files. | β
| | | | | |
| [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) | Disallow using `deepEqual` with primitives. | β
| | | π§ | | |
| [no-inline-assertions](docs/rules/no-inline-assertions.md) | Disallow inline assertions. | β
| | | π§ | | |
| [no-invalid-modifier-chain](docs/rules/no-invalid-modifier-chain.md) | Disallow invalid modifier chains. | β
| | | π§ | π‘ | |
| [no-negated-assertion](docs/rules/no-negated-assertion.md) | Disallow negated assertions. | β
| | | π§ | | |
| [no-nested-assertions](docs/rules/no-nested-assertions.md) | Disallow nested assertions. | β
| | | | | |
| [no-nested-tests](docs/rules/no-nested-tests.md) | Disallow nested tests. | β
| | | | | |
| [no-only-test](docs/rules/no-only-test.md) | Disallow `test.only()`. | β
| | | | π‘ | |
| [no-skip-assert](docs/rules/no-skip-assert.md) | Disallow skipping assertions. | β
| | | | π‘ | |
| [no-skip-test](docs/rules/no-skip-test.md) | Disallow skipping tests. | β
| | | | π‘ | |
| [no-todo-implementation](docs/rules/no-todo-implementation.md) | Disallow giving `test.todo()` an implementation function. | β
| | | | π‘ | |
| [no-todo-test](docs/rules/no-todo-test.md) | Disallow `test.todo()`. | | β
| | | π‘ | |
| [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) | Disallow unknown test modifiers. | | | β
| | π‘ | β |
| [no-useless-t-pass](docs/rules/no-useless-t-pass.md) | Disallow useless `t.pass()`. | β
| | | | | |
| [prefer-async-await](docs/rules/prefer-async-await.md) | Prefer async/await over returning a Promise. | β
| | | | | |
| [prefer-power-assert](docs/rules/prefer-power-assert.md) | Enforce using only assertions compatible with [power-assert](https://github.com/power-assert-js/power-assert). | | | β
| | | |
| [prefer-t-regex](docs/rules/prefer-t-regex.md) | Prefer `t.regex()` over `RegExp#test()` and `String#match()`. | β
| | | π§ | | |
| [prefer-t-throws](docs/rules/prefer-t-throws.md) | Prefer `t.throws()` or `t.throwsAsync()` over try/catch. | β
| | | | | |
| [require-assertion](docs/rules/require-assertion.md) | Require that tests contain at least one assertion. | β
| | | | | |
| [test-title](docs/rules/test-title.md) | Require tests to have a title. | β
| | | π§ | | |
| [test-title-format](docs/rules/test-title-format.md) | Require test titles to match a pattern. | | | β
| | | |
| [use-t](docs/rules/use-t.md) | Require test functions to use `t` as their parameter. | β
| | | | | |
| [use-t-throws-async-well](docs/rules/use-t-throws-async-well.md) | Require `t.throwsAsync()` and `t.notThrowsAsync()` to be awaited. | β
| | | π§ | | |
| [use-t-well](docs/rules/use-t-well.md) | Disallow incorrect use of `t`. | β
| | | π§ | | |
| [use-test](docs/rules/use-test.md) | Require AVA to be imported as `test`. | β
| | | | | |
| [use-true-false](docs/rules/use-true-false.md) | Prefer `t.true()`/`t.false()` over `t.truthy()`/`t.falsy()`. | β
| | | π§ | | |
<!-- end auto-generated rules list -->
## Recommended config
This plugin exports a [`recommended` config](index.js) that enforces good practices.
```js
import eslintPluginAva from 'eslint-plugin-ava';
export default [
...eslintPluginAva.configs.recommended,
];
```