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.

npm install eslint-plugin-mocha-no-only
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-MOCH
E
eslint-plugin-mocha-no-only
testingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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.

mochaNoOnly
import mochaNoOnly from "eslint-plugin-mocha-no-only";
import { rules } from "eslint-plugin-mocha-no-only";
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.
"mochaNoOnly/mocha-no-only"
rules: { "mochaNoOnly/mocha-no-only": ["error"] }
rules: { "mocha-no-only": ["error"] }
When configuring the rule, you must use the full ID including the plugin namespace 'mochaNoOnly/'.
require('eslint-plugin-mocha-no-only')
module.exports = { plugins: ['mocha-no-only'], rules: { 'mocha-no-only/mocha-no-only': 'error' } };
import mochaNoOnly from 'eslint-plugin-mocha-no-only'
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.

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 issues
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.
fix
Migrate your ESLint configuration from .eslintrc.* files to the new `eslint.config.js` format. Refer to the ESLint v9 migration guide and the plugin's README for examples on configuring the plugin in the new system.
affects: >=1.2.0
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.
fix
Ensure this plugin is configured with an 'error' severity in your ESLint setup and integrated into your CI pre-commit hooks or build process to catch these issues early before code is merged.
affects: *
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.
fix
For CommonJS projects, install with `npm install eslint-plugin-mocha-no-only --save-dev` and add `'mocha-no-only'` to the `plugins` array in your `.eslintrc.js`. For modern projects, consider upgrading ESLint and using the `eslint.config.js` flat config system.
affects: <1.2.0
Errors
Common errors & fixes
ESLint: Rule 'mochaNoOnly/mocha-no-only' was not found.
The ESLint plugin `eslint-plugin-mocha-no-only` is not correctly registered or installed in your project.
fix
In `eslint.config.js`, ensure you have `import mochaNoOnly from "eslint-plugin-mocha-no-only"` and the plugin is included in the `plugins` object (e.g., `{ plugins: { mochaNoOnly } }`). For older configs, verify `'mocha-no-only'` is present in your `plugins` array in `.eslintrc.*` and the package is installed.
error: Do not use `only()` in tests (mochaNoOnly/mocha-no-only)
The ESLint rule is correctly configured and has identified an instance of `.only()` being used in a Mocha test file, which the plugin is designed to prevent.
fix
Remove the `.only()` method call from the `describe`, `it`, `context`, or other Mocha keywords. If this is for temporary local debugging, use an ESLint disable comment (e.g., `// eslint-disable-next-line mochaNoOnly/mocha-no-only`) but ensure it's removed before committing.
TypeError: Cannot read properties of undefined (reading 'plugins')
This error typically occurs when attempting to use the new ESLint flat configuration (e.g., `eslint.config.js`) with an ESLint version older than v9, which does not support the new format.
fix
Upgrade your ESLint dependency to v9 or higher by running `npm install eslint@latest --save-dev`. Alternatively, if you cannot upgrade ESLint, you must revert to the older `.eslintrc.*` configuration file format.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
eslintrequiredPeer dependency, required to run ESLint rules and lint JavaScript/TypeScript code.
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-plugin-mocha-no-only — npm install eslint-plugin-mocha-no-only · libregistry