ESLint rules for AVA
$ npm install --save-dev eslint eslint-plugin-ava
Configure it in package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"env": {
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"ava"
],
"rules": {
"ava/max-asserts": ["off", 5],
"ava/no-cb-test": "off",
"ava/no-identical-title": "error",
"ava/no-ignored-test-files": "error",
"ava/no-invalid-end": "error",
"ava/no-only-test": "error",
"ava/no-skip-assert": "error",
"ava/no-skip-test": "error",
"ava/no-statement-after-end": "error",
"ava/no-todo-test": "warn",
"ava/no-unknown-modifiers": "error",
"ava/prefer-power-assert": "off",
"ava/test-ended": "error",
"ava/test-title": ["error", "if-multiple"],
"ava/use-t": "error",
"ava/use-test": "error"
}
}
}
The rules will only activate in test files.
- max-asserts - Limit the number of assertions in a test.
- no-cb-test - Ensure no
test.cb()
is used. - no-identical-title - Ensure no tests have the same title.
- no-ignored-test-files - Ensure no tests are written in ignored files.
- no-invalid-end - Ensure
t.end()
is only called insidetest.cb()
. - no-only-test - Ensure no
test.only()
are present. - no-skip-assert - Ensure no assertions are skipped.
- no-skip-test - Ensure no tests are skipped.
- no-statement-after-end - Ensure
t.end()
is the last statement executed. - no-todo-test - Ensure no
test.todo()
is used. - no-unknown-modifiers - Prevent the use of unknown test modifiers.
- prefer-power-assert - Allow only use of the asserts that have no power-assert alternative.
- test-ended - Ensure callback tests are explicitly ended.
- test-title - Ensure tests have a title.
- use-t - Ensure test functions use
t
as their parameter. - use-test - Ensure that AVA is imported with
test
as the variable name.
This plugin exports a recommended
configuration that enforces good practices.
To enable this configuration use the extends
property in your package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"extends": "plugin:ava/recommended",
"plugins": [
"ava"
]
}
}
See ESLint documentation for more information about extending configuration files.
Note: This configuration will also enable the correct parser options and environment.
MIT © Sindre Sorhus