![NPM Downloads](https://img.shields.io/npm/dm/eslint-plugin-mocha.svg?style=flat)
eslint-plugin-mocha
ESLint rules for mocha.
Install and configure
This plugin requires ESLint 4.0.0
or later.
npm install --save-dev eslint-plugin-mocha
.eslintrc.json
Then add a reference to this plugin and selected rules in your eslint config:
{
"plugins": [
"mocha"
]
}
eslint.config.js
(requires eslint >= 8.23.0)
To use this plugin with the new eslint configuration format (flat config):
import mochaPlugin from 'eslint-plugin-mocha';
export default [
mochaPlugin.configs.flat.recommended
];
Plugin Settings
This plugin supports the following settings, which are used by multiple rules:
-
additionalCustomNames
: This allows rules to check additional function names when looking for suites or test cases. This might be used with a custom Mocha extension, such as ember-mocha
or mocha-each
.
Example:
{
"rules": {
"mocha/no-skipped-tests": "error",
"mocha/no-exclusive-tests": "error"
},
"settings": {
"mocha/additionalCustomNames": [
{ "name": "describeModule", "type": "suite", "interfaces": [ "BDD" ] },
{ "name": "testModule", "type": "testCase", "interfaces": [ "TDD" ] }
]
}
}
The name
property can be in any of the following forms:
-
A plain name e.g. describeModule
, which allows:
describeModule("example", function() { ... });
-
A dotted name, e.g. describe.modifier
, which allows:
describe.modifier("example", function() { ... });
-
A name with parentheses, e.g. forEach().describe
, which allows:
forEach([ 1, 2, 3 ])
.describe("example", function(n) { ... });
-
Any combination of the above, e.g. forEach().describeModule.modifier
, which allows:
forEach([ 1, 2, 3 ])
.describeModule.modifier("example", function(n) { ... });
Configs
recommended
This plugin exports a recommended config that enforces good practices.
Enable it with the extends option:
{
"extends": [
"plugin:mocha/recommended"
]
}
all
There's also a configuration that enables all of our rules.
See Configuring Eslint on eslint.org for more info.
Rules
💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🚫 Configurations disabled in.
✅ Set in the recommended
configuration.
🔧 Automatically fixable by the --fix
CLI option.