Fine‑Tune Your Linting: Using ESLint Overrides to Keep Test Files Clean
ESLint’s <code>overrides</code> let you apply different rule sets to file groups, like disabling <code>no-console</code> in test files while keeping it strict elsewhere. Learn how to configure, verify, and maintain overrides for clean, maintainable code.
08 Feb 2026, 17:09 UTC

Why ESLint Overrides Matter
When a team grows, the one‑size‑fits‑all linting rule set starts to bite. A rule that makes sense for production code—like no-console—can be a nuisance in test files where console.log is a quick debugging aid. ESLint’s overrides key lets you apply a different rule set to a specific group of files without duplicating your entire configuration.
What an Override Is
In .eslintrc.json, overrides is an array. Each object describes a file pattern and the set of rules (or environment settings) that should apply only to those files. The precedence is simple: rules defined in an override replace the same rule from the base config for the matched files.
Typical Use‑Case: Turning Off no-console in Tests
Suppose your project uses Jest. You want no-console to be a hard error in production code, but you’re comfortable with console statements in *.spec.js files. An override looks like this:
{
"env": {
"browser": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"rules": {
"no-console": "error"
},
"overrides": [
{
"files": ["**/*.spec.js"],
"rules": {
"no-console": "off"
},
"env": {
"jest": true
}
}
]
}
In this snippet:
- The base config turns
no-consoleinto an error. - The override matches any file ending in
.spec.js, turns the rule off, and adds Jest globals to the environment.
How to Verify the Override Works
- Create a sample project with a
src/index.jsand atests/app.spec.jsthat both containconsole.logstatements. - Run ESLint from the command line:
The output should list anpx eslint . --ext .jsno-consoleerror only forsrc/index.js. - Confirm the effective config for the test file:
The printed config will shownpx eslint --print-config tests/app.spec.js | grep -A2 "no-console""no-console": "off"for that file.
Trade‑Offs and Limitations
While overrides are powerful, they can also hide real problems if used carelessly:
- Over‑broad patterns (e.g.,
**/*.js) can unintentionally silence rules across the entire codebase. - Large override blocks clutter the config and make it harder to audit which rules apply where. A common practice is to extract shared overrides into separate JSON files and reference them with
extends. - Overrides do not affect
globalsorparserOptionsunless you specify them inside the override object.
Practical Tips for Maintaining Override Clarity
- Keep the
overridesarray short; each object should target a single logical file group. - Document the intent in the comment above each override block.
- Use the
--print-configflag during code reviews to verify that a file’s effective rule set matches expectations. - When a rule is turned off, consider adding a comment in the file to remind future maintainers that the suppression is intentional.
Actionable Takeaway
Start by identifying the file types that need a different linting stance. Add a minimal override for each group, test the configuration with --print-config, and document the reasoning. This keeps your production code strict while giving developers flexibility in test and demo files, improving both code quality and developer experience.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.