tree: 3497b8c4c4bc64a73b2af277ee0fb82a54ebbd78
  1. ast/
  2. mocha/
  3. node_modules/
  4. rules/
  5. LICENSE
  6. list.js
  7. package.json
  8. plugin.d.ts
  9. plugin.js
  10. readme.md
  11. record.js
  12. settings.js
node_modules/eslint-plugin-mocha/readme.md

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 eslint flat configuration format:

import mochaPlugin from "eslint-plugin-mocha";

export default [
    mochaPlugin.configs.recommended, // or `mochaPlugin.configs.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 or mocha-each.

    Example:

    {
        "rules": {
            "mocha/no-pending-tests": "error",
            "mocha/no-exclusive-tests": "error"
        },
        "settings": {
            "mocha/additionalCustomNames": [
                {
                    "name": "describeModule",
                    "type": "suite",
                    "interface": "BDD"
                },
                {
                    "name": "testModule",
                    "type": "testCase",
                    "interface": "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) { ... });
      
  • interface: This allows to select either TDD, BDD (default) or exports. When using exports mocha variables are resolved from named import statements instead of global variables.

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-interfaceEnforces consistent use of mocha interfaces
consistent-spacing-between-blocksRequire consistent spacing between blocks🔧
handle-done-callbackEnforces handling of callbacks for async tests
max-top-level-suitesEnforce the number of top-level suites in a single file
no-async-suiteDisallow async functions passed to a suite🔧
no-empty-titleDisallow empty test descriptions
no-exclusive-testsDisallow exclusive tests
no-exportsDisallow exports from test files
no-global-testsDisallow global tests
no-hooksDisallow hooks
no-hooks-for-single-caseDisallow hooks for a single test or test suite
no-identical-titleDisallow identical titles
no-mocha-arrowsDisallow arrow functions as arguments to mocha functions🔧
no-nested-testsDisallow tests to be nested within other tests
no-pending-testsDisallow pending tests
no-return-and-callbackDisallow returning in a test or hook function that uses a callback
no-return-from-asyncDisallow returning from an async test or hook
no-setup-in-describeDisallow setup in describe blocks
no-sibling-hooksDisallow duplicate uses of a hook at the same level inside a suite
no-synchronous-testsDisallow synchronous tests
no-top-level-hooksDisallow top-level hooks
prefer-arrow-callbackRequire using arrow functions for callbacks🔧
valid-suite-titleRequire suite descriptions to match a pre-configured regular expression
valid-test-titleRequire test descriptions to match a pre-configured regular expression