1 | # eslint-plugin-ava [![Coverage Status](https://coveralls.io/repos/github/avajs/eslint-plugin-ava/badge.svg?branch=main)](https://coveralls.io/github/avajs/eslint-plugin-ava?branch=main)
|
2 |
|
3 | > ESLint rules for [AVA](https://avajs.dev)
|
4 |
|
5 | Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/readme.md)
|
6 |
|
7 | This plugin is bundled in [XO](https://github.com/xojs/xo). No need to do anything if you're using it.
|
8 |
|
9 | [**Propose or contribute a new rule β‘**](.github/contributing.md)
|
10 |
|
11 | ## Install
|
12 |
|
13 | ```sh
|
14 | npm install --save-dev eslint eslint-plugin-ava
|
15 | ```
|
16 |
|
17 | ## Usage
|
18 |
|
19 | Configure it in `package.json`.
|
20 |
|
21 | ```json
|
22 | {
|
23 | "name": "my-awesome-project",
|
24 | "eslintConfig": {
|
25 | "env": {
|
26 | "es6": true
|
27 | },
|
28 | "parserOptions": {
|
29 | "ecmaVersion": "latest",
|
30 | "sourceType": "module"
|
31 | },
|
32 | "plugins": [
|
33 | "ava"
|
34 | ],
|
35 | "rules": {
|
36 | "ava/assertion-arguments": "error",
|
37 | "ava/...": "error"
|
38 | }
|
39 | }
|
40 | }
|
41 | ```
|
42 |
|
43 | ## Rules
|
44 |
|
45 | The rules will only activate in test files.
|
46 |
|
47 |
|
48 |
|
49 | πΌ [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) enabled in.\
|
50 | β οΈ [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) set to warn in.\
|
51 | π« [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) disabled in.\
|
52 | β
Set in the `recommended` [configuration](https://github.com/avajs/eslint-plugin-ava#recommended-config).\
|
53 | π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
54 | π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
55 |
|
56 | | NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ |
|
57 | | :------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- | :- | :- | :- | :- | :- |
|
58 | | [assertion-arguments](docs/rules/assertion-arguments.md) | Enforce passing correct arguments to assertions. | β
| | | π§ | |
|
59 | | [hooks-order](docs/rules/hooks-order.md) | Enforce test hook ordering. | β
| | | π§ | |
|
60 | | [max-asserts](docs/rules/max-asserts.md) | Enforce a limit on the number of assertions in a test. | | | β
| | |
|
61 | | [no-async-fn-without-await](docs/rules/no-async-fn-without-await.md) | Ensure that async tests use `await`. | β
| | | | |
|
62 | | [no-duplicate-modifiers](docs/rules/no-duplicate-modifiers.md) | Ensure tests do not have duplicate modifiers. | β
| | | | |
|
63 | | [no-identical-title](docs/rules/no-identical-title.md) | Ensure no tests have the same title. | β
| | | | |
|
64 | | [no-ignored-test-files](docs/rules/no-ignored-test-files.md) | Ensure no tests are written in ignored files. | β
| | | | |
|
65 | | [no-import-test-files](docs/rules/no-import-test-files.md) | Ensure no test files are imported anywhere. | β
| | | | |
|
66 | | [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) | Disallow using `deepEqual` with primitives. | β
| | | π§ | |
|
67 | | [no-inline-assertions](docs/rules/no-inline-assertions.md) | Ensure assertions are not called from inline arrow functions. | β
| | | π§ | |
|
68 | | [no-nested-tests](docs/rules/no-nested-tests.md) | Ensure no tests are nested. | β
| | | | |
|
69 | | [no-only-test](docs/rules/no-only-test.md) | Ensure no `test.only()` are present. | β
| | | π§ | π‘ |
|
70 | | [no-skip-assert](docs/rules/no-skip-assert.md) | Ensure no assertions are skipped. | β
| | | | |
|
71 | | [no-skip-test](docs/rules/no-skip-test.md) | Ensure no tests are skipped. | β
| | | π§ | π‘ |
|
72 | | [no-todo-implementation](docs/rules/no-todo-implementation.md) | Ensure `test.todo()` is not given an implementation function. | β
| | | | |
|
73 | | [no-todo-test](docs/rules/no-todo-test.md) | Ensure no `test.todo()` is used. | | β
| | | |
|
74 | | [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) | Disallow the use of unknown test modifiers. | β
| | | | |
|
75 | | [prefer-async-await](docs/rules/prefer-async-await.md) | Prefer using async/await instead of returning a Promise. | β
| | | | |
|
76 | | [prefer-power-assert](docs/rules/prefer-power-assert.md) | Enforce the use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative. | | | β
| | |
|
77 | | [prefer-t-regex](docs/rules/prefer-t-regex.md) | Prefer using `t.regex()` to test regular expressions. | β
| | | π§ | |
|
78 | | [test-title](docs/rules/test-title.md) | Ensure tests have a title. | β
| | | | |
|
79 | | [test-title-format](docs/rules/test-title-format.md) | Ensure test titles have a certain format. | | | β
| | |
|
80 | | [use-t](docs/rules/use-t.md) | Ensure test functions use `t` as their parameter. | β
| | | | |
|
81 | | [use-t-throws-async-well](docs/rules/use-t-throws-async-well.md) | Ensure that `t.throwsAsync()` and `t.notThrowsAsync()` are awaited. | β
| | | π§ | |
|
82 | | [use-t-well](docs/rules/use-t-well.md) | Disallow the incorrect use of `t`. | β
| | | π§ | |
|
83 | | [use-test](docs/rules/use-test.md) | Ensure that AVA is imported with `test` as the variable name. | β
| | | | |
|
84 | | [use-true-false](docs/rules/use-true-false.md) | Ensure that `t.true()`/`t.false()` are used instead of `t.truthy()`/`t.falsy()`. | β
| | | | |
|
85 |
|
86 |
|
87 |
|
88 | ## Recommended config
|
89 |
|
90 | This plugin exports a [`recommended` config](index.js) that enforces good practices.
|
91 |
|
92 | Enable it in your `package.json` with the `extends` option:
|
93 |
|
94 | ```json
|
95 | {
|
96 | "name": "my-awesome-project",
|
97 | "eslintConfig": {
|
98 | "extends": "plugin:ava/recommended"
|
99 | }
|
100 | }
|
101 | ```
|
102 |
|
103 | See the [ESLint docs](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending config files.
|
104 |
|
105 | **Note**: This config will also enable the correct [parser options](https://eslint.org/docs/user-guide/configuring#specifying-parser-options) and [environment](https://eslint.org/docs/user-guide/configuring#specifying-environments).
|