CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-eslint-plugin-mocha

ESLint plugin providing 24 rules for Mocha testing framework best practices and error detection.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

configurations.mddocs/

Rule Configurations

Pre-configured rule sets that provide quick setup options for different use cases, available in both legacy and modern flat configuration formats.

Capabilities

Plugin Export Structure

The main plugin export providing access to all rules and configurations.

/**
 * Main ESLint plugin export containing rules and configurations for Mocha testing
 */
const mochaPlugin = {
  rules: { [ruleName: string]: ESLintRule },
  configs: {
    recommended: LegacyConfig,
    all: LegacyConfig,
    flat: {
      recommended: FlatConfig,
      all: FlatConfig
    }
  }
};

interface LegacyConfig {
  env: { mocha: boolean };
  plugins: string[];
  rules: { [ruleKey: string]: RuleConfig };
}

interface FlatConfig {
  name: string;
  plugins: { mocha: typeof mochaPlugin };
  languageOptions: { globals: object };
  rules: { [ruleKey: string]: RuleConfig };
}

type RuleConfig = 'off' | 'warn' | 'error' | ['off' | 'warn' | 'error', ...any[]];

Recommended Configuration

Balanced rule set focusing on the most important Mocha best practices and common mistake prevention.

/**
 * Recommended configuration with sensible defaults for most Mocha projects
 */
const recommendedConfig = {
  env: { mocha: true },
  plugins: ['mocha'],
  rules: {
    'mocha/handle-done-callback': 'error',
    'mocha/max-top-level-suites': ['error', { limit: 1 }],
    'mocha/no-async-describe': 'error',
    'mocha/no-exclusive-tests': 'warn',
    'mocha/no-exports': 'error',
    'mocha/no-global-tests': 'error',
    'mocha/no-hooks': 'off',
    'mocha/no-hooks-for-single-case': 'off',
    'mocha/no-identical-title': 'error',
    'mocha/no-mocha-arrows': 'error',
    'mocha/no-nested-tests': 'error',
    'mocha/no-pending-tests': 'warn',
    'mocha/no-return-and-callback': 'error',
    'mocha/no-return-from-async': 'off',
    'mocha/no-setup-in-describe': 'error',
    'mocha/no-sibling-hooks': 'error',
    'mocha/no-skipped-tests': 'warn',
    'mocha/no-synchronous-tests': 'off',
    'mocha/no-top-level-hooks': 'warn',
    'mocha/prefer-arrow-callback': 'off',
    'mocha/valid-suite-description': 'off',
    'mocha/valid-test-description': 'off',
    'mocha/no-empty-description': 'error',
    'mocha/consistent-spacing-between-blocks': 'error'
  }
};

All Rules Configuration

Comprehensive configuration enabling all available rules with 'error' level severity.

/**
 * Configuration enabling all rules for maximum strictness
 */
const allRulesConfig = {
  env: { mocha: true },
  plugins: ['mocha'],
  rules: {
    'mocha/handle-done-callback': 'error',
    'mocha/max-top-level-suites': 'error',
    'mocha/no-async-describe': 'error',
    'mocha/no-exclusive-tests': 'error',
    'mocha/no-exports': 'error',
    'mocha/no-global-tests': 'error',
    'mocha/no-hooks': 'error',
    'mocha/no-hooks-for-single-case': 'error',
    'mocha/no-identical-title': 'error',
    'mocha/no-mocha-arrows': 'error',
    'mocha/no-nested-tests': 'error',
    'mocha/no-pending-tests': 'error',
    'mocha/no-return-and-callback': 'error',
    'mocha/no-return-from-async': 'error',
    'mocha/no-setup-in-describe': 'error',
    'mocha/no-sibling-hooks': 'error',
    'mocha/no-skipped-tests': 'error',
    'mocha/no-synchronous-tests': 'error',
    'mocha/no-top-level-hooks': 'error',
    'mocha/prefer-arrow-callback': 'error',
    'mocha/valid-suite-description': 'error',
    'mocha/valid-test-description': 'error',
    'mocha/no-empty-description': 'error',
    'mocha/consistent-spacing-between-blocks': 'error'
  }
};

Flat Configuration Format

Modern ESLint flat configuration format for ESLint 8.23.0+.

/**
 * Flat configuration objects for modern ESLint setup
 */
const flatConfigs = {
  recommended: {
    name: 'mocha/recommended',
    plugins: { mocha: mochaPlugin },
    languageOptions: { 
      globals: {
        after: false,
        afterEach: false,
        before: false,
        beforeEach: false,
        context: false,
        describe: false,
        it: false,
        mocha: false,
        run: false,
        setup: false,
        specify: false,
        suite: false,
        suiteSetup: false,
        suiteTeardown: false,
        teardown: false,
        test: false,
        xcontext: false,
        xdescribe: false,
        xit: false,
        xspecify: false
      }
    },
    rules: { /* recommended rules */ }
  },
  all: {
    name: 'mocha/all',
    plugins: { mocha: mochaPlugin },
    languageOptions: { 
      globals: { /* same globals as recommended */ }
    },
    rules: { /* all rules */ }
  }
};

Usage Examples

Legacy Configuration Setup

{
  "extends": ["plugin:mocha/recommended"],
  "env": {
    "mocha": true
  }
}

Flat Configuration Setup

import mochaPlugin from 'eslint-plugin-mocha';

export default [
  mochaPlugin.configs.flat.recommended,
  {
    files: ['test/**/*.js'],
    rules: {
      'mocha/no-exclusive-tests': 'error'
    }
  }
];

Mixed Configuration

{
  "extends": ["plugin:mocha/recommended"],
  "rules": {
    "mocha/no-skipped-tests": "error",
    "mocha/max-top-level-suites": ["error", { "limit": 2 }]
  }
}

docs

async-rules.md

configurations.md

execution-rules.md

index.md

quality-rules.md

settings.md

structure-rules.md

style-rules.md

tile.json