eslint-plugin-no-only-tests
raw JSON → 3.3.0 verified Sat Apr 25 auth: no javascript
ESLint rule that prevents committing focused tests (`.only`) commonly used in Mocha, Jest, Jasmine, and other JS test frameworks. Version 3.3.0 is the current stable release, maintained actively with regular updates. Unlike general lint rules, it supports multiple test block names and custom focus methods, with opt-in autofixing. It catches `describe.only`, `it.only`, `test.only`, and many other patterns by default, and can be configured for any test framework that uses `.only` or similar focus patterns.
Common errors
error ESLint: 'no-only-tests' is not a valid rule. ↓
cause The rule name is 'no-only-tests/no-only-tests' because it is namespaced under the plugin.
fix
Use 'no-only-tests/no-only-tests' as the rule key.
error Error: Cannot find module 'eslint-plugin-no-only-tests' ↓
cause The package is not installed or ESLint cannot resolve it.
fix
Run
npm install --save-dev eslint-plugin-no-only-tests. error Definition for rule 'no-only-tests/no-only-tests' was not found. ↓
cause The plugin is not listed in the 'plugins' array in your ESLint config.
fix
Add '"plugins": ["no-only-tests"]' to your ESLint configuration.
Warnings
gotcha The rule does not automatically fix `.only` by default; the `fix` option must be explicitly set to `true` to enable autofixing. ↓
fix Set the option `{"fix": true}` in the rule config.
gotcha The `block` option supports prefix matching with a trailing asterisk (e.g., `test*`), but this may cause unexpected matches if not used carefully. ↓
fix Review your block patterns and ensure they only match intended test function names.
breaking In v3.0.0, the rule was moved to a new `no-only-tests/no-only-tests` namespace; previously it was just `no-only-tests`. ↓
fix Update your ESLint config: use `"no-only-tests/no-only-tests"` instead of `"no-only-tests"`.
deprecated The `fix` option as a boolean is deprecated in favor of an object with `fix: true`. ↓
fix Use `{"fix": true}` instead of just `"fix": true`.
Install
npm install eslint-plugin-no-only-tests yarn add eslint-plugin-no-only-tests pnpm add eslint-plugin-no-only-tests Imports
- plugin wrong
const plugin = require('eslint-plugin-no-only-tests')correctimport eslintPluginNoOnlyTests from 'eslint-plugin-no-only-tests' - rules wrong
const rules = require('eslint-plugin-no-only-tests').rulescorrectimport { rules } from 'eslint-plugin-no-only-tests' - rule wrong
"no-only-tests": "error"correct// In .eslintrc: "no-only-tests/no-only-tests": "error"
Quickstart
// .eslintrc.json
{
"plugins": ["no-only-tests"],
"rules": {
"no-only-tests/no-only-tests": "error"
}
}
// Example test file that will cause an error:
describe.only('my suite', () => {
it('test', () => {
// ...
});
});