Registry / testing / eslint-plugin-mocha-no-only

eslint-plugin-mocha-no-only

JSON →
library1.2.0jsnpmunverified

This ESLint plugin, `eslint-plugin-mocha-no-only`, enforces a rule that prohibits the use of Mocha's `.only()` method on test keywords like `describe`, `context`, `it`, `specify`, `suite`, and `test`. Its primary purpose is to prevent developers from accidentally committing code that only runs a subset of their test suite, which can lead to false-positive CI/CD builds. The current stable version is `1.2.0`, which introduced support for ESLint v9.0.0 and updated internal dependencies. While there isn't a strict release cadence, the project is actively maintained to ensure compatibility with recent ESLint versions. It differentiates itself by providing a dedicated, straightforward solution for a common oversight in Mocha testing workflows, ensuring comprehensive test execution.

testing
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This import is for the plugin module itself, used in the 'plugins' object of the new ESLint flat configuration (eslint.config.js) since ESLint v9.

import mochaNoOnly from "eslint-plugin-mocha-no-only";

When configuring the rule, you must use the full ID including the plugin namespace 'mochaNoOnly/'.

rules: { "mochaNoOnly/mocha-no-only": ["error"] }

For older CommonJS-based .eslintrc.js configurations (pre-ESLint v9), the plugin is typically added to the 'plugins' array by its name and resolved by ESLint.

module.exports = { plugins: ['mocha-no-only'], rules: { 'mocha-no-only/mocha-no-only': 'error' } };

Demonstrates how to set up `eslint-plugin-mocha-no-only` within the new ESLint flat configuration system (eslint.config.js), targeting only test files to prevent accidental `.only()` calls.

import globals from "globals"; import pluginJs from "@eslint/js"; import mochaNoOnly from "eslint-plugin-mocha-no-only"; export default [ // Base configuration (applies globally) { languageOptions: { globals: globals.node }, // Or globals.browser depending on your environment // You can add other global configurations here }, // Apply mocha-no-only specifically to test files { files: ["test/**/*.js", "test/**/*.ts", "**/__tests__/**/*.js"], plugins: { mochaNoOnly }, // Reference the imported plugin rules: { "mochaNoOnly/mocha-no-only": ["error"] } }, // Recommended ESLint JavaScript rules (optional, if desired) pluginJs.configs.recommended, ];
Debug
Known footguns
breakingESLint v9 introduced a new flat configuration system (eslint.config.js) that is incompatible with the older .eslintrc.* files. While `eslint-plugin-mocha-no-only` v1.2.0 supports ESLint v9, users migrating to ESLint v9 must update their configuration files accordingly.
gotchaForgetting to remove `.only()` from Mocha tests can lead to false-positive CI builds, giving a misleading impression of full test suite success when only a subset of tests were executed.
gotchaWhen using older CommonJS-based ESLint configurations (`.eslintrc.js`), the plugin must be installed as a dev dependency and listed in the `plugins` array. The new flat configuration system (supported from `v1.2.0`) uses ESM imports for the plugin itself.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources