Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lo1tuma/eslint-plugin-mocha
ESLint rules for mocha
https://github.com/lo1tuma/eslint-plugin-mocha
eslint eslint-plugin eslintplugin hacktoberfest mocha
Last synced: 7 days ago
JSON representation
ESLint rules for mocha
- Host: GitHub
- URL: https://github.com/lo1tuma/eslint-plugin-mocha
- Owner: lo1tuma
- License: mit
- Created: 2014-07-27T13:18:49.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-08-23T15:12:29.000Z (5 months ago)
- Last Synced: 2025-01-09T05:05:43.145Z (14 days ago)
- Topics: eslint, eslint-plugin, eslintplugin, hacktoberfest, mocha
- Language: JavaScript
- Homepage:
- Size: 1.89 MB
- Stars: 281
- Watchers: 7
- Forks: 61
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-eslint - Enforcing practices - Linting rules for Mocha. (Plugins / Testing Tools)
README
[![NPM Version](https://img.shields.io/npm/v/eslint-plugin-mocha.svg?style=flat)](https://www.npmjs.org/package/eslint-plugin-mocha)
[![GitHub Actions status](https://github.com/lo1tuma/eslint-plugin-mocha/workflows/CI/badge.svg)](https://github.com/lo1tuma/eslint-plugin-mocha/actions)
[![Coverage Status](https://img.shields.io/coveralls/lo1tuma/eslint-plugin-mocha/main.svg?style=flat)](https://coveralls.io/r/lo1tuma/eslint-plugin-mocha)
[![NPM Downloads](https://img.shields.io/npm/dm/eslint-plugin-mocha.svg?style=flat)](https://www.npmjs.org/package/eslint-plugin-mocha)# eslint-plugin-mocha
ESLint rules for [mocha](http://mochajs.org/).
## Install and configure
This plugin requires ESLint `9.0.0` or later.
```bash
npm install --save-dev eslint-plugin-mocha
```### Configuration via `eslint.config.js`
To use this plugin with [the new eslint configuration format (flat config)](https://eslint.org/docs/latest/use/configure/configuration-files-new):
```js
import mochaPlugin from "eslint-plugin-mocha";export default [
mochaPlugin.configs.flat.recommended, // or `mochaPlugin.configs.flat.all` to enable all
// ... Your configurations here
];
```### 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`](https://github.com/switchfly/ember-mocha) or [`mocha-each`](https://github.com/ryym/mocha-each).
**Example:**
```json
{
"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:
```javascript
describeModule("example", function() { ... });
```- A dotted name, e.g. `describe.modifier`, which allows:
```javascript
describe.modifier("example", function() { ... });
```- A name with parentheses, e.g. `forEach().describe`, which allows:
```javascript
forEach([ 1, 2, 3 ])
.describe("example", function(n) { ... });
```- Any combination of the above, e.g. `forEach().describeModule.modifier`, which allows:
```javascript
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:
```json
{
"extends": ["plugin:mocha/recommended"]
}
```### `all`
There's also a configuration that enables all of our rules.
See [Configuring Eslint](http://eslint.org/docs/user-guide/configuring) on [eslint.org](http://eslint.org) for more info.
## Rules
πΌ [Configurations](https://github.com/lo1tuma/eslint-plugin-mocha#configs) enabled in.\
β οΈ [Configurations](https://github.com/lo1tuma/eslint-plugin-mocha#configs) set to warn in.\
π« [Configurations](https://github.com/lo1tuma/eslint-plugin-mocha#configs) disabled in.\
β Set in the `recommended` [configuration](https://github.com/lo1tuma/eslint-plugin-mocha#configs).\
π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ |
| :----------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :- | :- | :- | :- |
| [consistent-spacing-between-blocks](docs/rules/consistent-spacing-between-blocks.md) | Require consistent spacing between blocks | β | | | π§ |
| [handle-done-callback](docs/rules/handle-done-callback.md) | Enforces handling of callbacks for async tests | β | | | |
| [max-top-level-suites](docs/rules/max-top-level-suites.md) | Enforce the number of top-level suites in a single file | β | | | |
| [no-async-describe](docs/rules/no-async-describe.md) | Disallow async functions passed to describe | β | | | π§ |
| [no-empty-description](docs/rules/no-empty-description.md) | Disallow empty test descriptions | β | | | |
| [no-exclusive-tests](docs/rules/no-exclusive-tests.md) | Disallow exclusive tests | | β | | |
| [no-exports](docs/rules/no-exports.md) | Disallow exports from test files | β | | | |
| [no-global-tests](docs/rules/no-global-tests.md) | Disallow global tests | β | | | |
| [no-hooks](docs/rules/no-hooks.md) | Disallow hooks | | | β | |
| [no-hooks-for-single-case](docs/rules/no-hooks-for-single-case.md) | Disallow hooks for a single test or test suite | | | β | |
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | β | | | |
| [no-mocha-arrows](docs/rules/no-mocha-arrows.md) | Disallow arrow functions as arguments to mocha functions | β | | | π§ |
| [no-nested-tests](docs/rules/no-nested-tests.md) | Disallow tests to be nested within other tests | β | | | |
| [no-pending-tests](docs/rules/no-pending-tests.md) | Disallow pending tests | | β | | |
| [no-return-and-callback](docs/rules/no-return-and-callback.md) | Disallow returning in a test or hook function that uses a callback | β | | | |
| [no-return-from-async](docs/rules/no-return-from-async.md) | Disallow returning from an async test or hook | | | β | |
| [no-setup-in-describe](docs/rules/no-setup-in-describe.md) | Disallow setup in describe blocks | β | | | |
| [no-sibling-hooks](docs/rules/no-sibling-hooks.md) | Disallow duplicate uses of a hook at the same level inside a describe | β | | | |
| [no-skipped-tests](docs/rules/no-skipped-tests.md) | Disallow skipped tests | | β | | |
| [no-synchronous-tests](docs/rules/no-synchronous-tests.md) | Disallow synchronous tests | | | β | |
| [no-top-level-hooks](docs/rules/no-top-level-hooks.md) | Disallow top-level hooks | | β | | |
| [prefer-arrow-callback](docs/rules/prefer-arrow-callback.md) | Require using arrow functions for callbacks | | | β | π§ |
| [valid-suite-description](docs/rules/valid-suite-description.md) | Require suite descriptions to match a pre-configured regular expression | | | β | |
| [valid-test-description](docs/rules/valid-test-description.md) | Require test descriptions to match a pre-configured regular expression | | | β | |