{"id":13144,"library":"eslint-plugin-mocha-no-only","title":"ESLint Plugin for Mocha .only() Prevention","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/lewazo/eslint-mocha-no-only","tags":["javascript","eslint","eslintplugin","eslint-plugin","mocha","no-only"],"install":[{"cmd":"npm install eslint-plugin-mocha-no-only","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-mocha-no-only","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-mocha-no-only","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency, required to run ESLint rules and lint JavaScript/TypeScript code.","package":"eslint","optional":false}],"imports":[{"note":"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.","wrong":"import { rules } from \"eslint-plugin-mocha-no-only\";","symbol":"mochaNoOnly","correct":"import mochaNoOnly from \"eslint-plugin-mocha-no-only\";"},{"note":"When configuring the rule, you must use the full ID including the plugin namespace 'mochaNoOnly/'.","wrong":"rules: { \"mocha-no-only\": [\"error\"] }","symbol":"\"mochaNoOnly/mocha-no-only\"","correct":"rules: { \"mochaNoOnly/mocha-no-only\": [\"error\"] }"},{"note":"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.","wrong":"import mochaNoOnly from 'eslint-plugin-mocha-no-only'","symbol":"require('eslint-plugin-mocha-no-only')","correct":"module.exports = { plugins: ['mocha-no-only'], rules: { 'mocha-no-only/mocha-no-only': 'error' } };"}],"quickstart":{"code":"import globals from \"globals\";\nimport pluginJs from \"@eslint/js\";\nimport mochaNoOnly from \"eslint-plugin-mocha-no-only\";\n\nexport default [\n  // Base configuration (applies globally)\n  {\n    languageOptions: { globals: globals.node }, // Or globals.browser depending on your environment\n    // You can add other global configurations here\n  },\n  // Apply mocha-no-only specifically to test files\n  {\n    files: [\"test/**/*.js\", \"test/**/*.ts\", \"**/__tests__/**/*.js\"],\n    plugins: { mochaNoOnly }, // Reference the imported plugin\n    rules: { \"mochaNoOnly/mocha-no-only\": [\"error\"] }\n  },\n  // Recommended ESLint JavaScript rules (optional, if desired)\n  pluginJs.configs.recommended,\n];","lang":"typescript","description":"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."},"warnings":[{"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.","message":"ESLint 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.","severity":"breaking","affected_versions":">=1.2.0"},{"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.","message":"Forgetting 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.","severity":"gotcha","affected_versions":"*"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"<1.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The ESLint plugin `eslint-plugin-mocha-no-only` is not correctly registered or installed in your project.","error":"ESLint: Rule 'mochaNoOnly/mocha-no-only' was not found."},{"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.","cause":"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.","error":"error: Do not use `only()` in tests (mochaNoOnly/mocha-no-only)"},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'plugins')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}