UNPKG

8.9 kBMarkdownView Raw
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
5Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/readme.md)
6
7This 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
14npm install --save-dev eslint eslint-plugin-ava
15```
16
17## Usage
18
19Configure 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
45The rules will only activate in test files.
46
47<!-- begin auto-generated rules list -->
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<!-- end auto-generated rules list -->
87
88## Recommended config
89
90This plugin exports a [`recommended` config](index.js) that enforces good practices.
91
92Enable 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
103See 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).