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-onlyVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.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.
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.