lo1tuma / eslint-plugin-mocha

ESLint rules for mocha
MIT License
279 stars 61 forks source link
eslint eslint-plugin eslintplugin hacktoberfest mocha

NPM Version GitHub Actions status Coverage Status NPM Downloads

eslint-plugin-mocha

ESLint rules for mocha.

Install and configure

This plugin requires ESLint 9.0.0 or later.

npm install --save-dev eslint-plugin-mocha

Configuration via eslint.config.js

To use this plugin with the new eslint configuration format (flat config):

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:

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.

Name                              Description 💼 ⚠️ 🚫 🔧
consistent-spacing-between-blocks Require consistent spacing between blocks 🔧
handle-done-callback Enforces handling of callbacks for async tests
max-top-level-suites Enforce the number of top-level suites in a single file
no-async-describe Disallow async functions passed to describe 🔧
no-empty-description Disallow empty test descriptions
no-exclusive-tests Disallow exclusive tests
no-exports Disallow exports from test files
no-global-tests Disallow global tests
no-hooks Disallow hooks
no-hooks-for-single-case Disallow hooks for a single test or test suite
no-identical-title Disallow identical titles
no-mocha-arrows Disallow arrow functions as arguments to mocha functions 🔧
no-nested-tests Disallow tests to be nested within other tests
no-pending-tests Disallow pending tests
no-return-and-callback Disallow returning in a test or hook function that uses a callback
no-return-from-async Disallow returning from an async test or hook
no-setup-in-describe Disallow setup in describe blocks
no-sibling-hooks Disallow duplicate uses of a hook at the same level inside a describe
no-skipped-tests Disallow skipped tests
no-synchronous-tests Disallow synchronous tests
no-top-level-hooks Disallow top-level hooks
prefer-arrow-callback Require using arrow functions for callbacks 🔧
valid-suite-description Require suite descriptions to match a pre-configured regular expression
valid-test-description Require test descriptions to match a pre-configured regular expression