Downgrade ESLint errors to warnings.
npm install --save-dev eslint-plugin-only-warn
Using flat config files:
// eslint.config.js
import "eslint-plugin-only-warn";
export default [
...
Or, when the package.json that doesn't have "type": "module"
:
require("eslint-plugin-only-warn");
ESLint 8.x and earlier
Add only-warn
to the plugins section of your .eslintrc
configuration file:
{
"plugins": ["only-warn"]
}
Add --max-warnings=0 to the eslint command in package.json
"lint": "eslint --max-warnings=0 ...",
Adding the option allows git hooks or CI pipelines to detect failed linting rules.
Because the cli now has a nonzero exitcode when it encountered linting warnings.
Use Husky and lint-staged to prevent committing code that contain eslint warnings.
- Don't waste time thinking or discussing about when a rule should be an error or a warning, focus on enabling of disabling a rule
- Warnings look different in editors, this allows you to quickly see that some tweaking is required, but your code still runs (ESLint rules generally don't block the code from executing and fatal errors are still reported as error)
- Prevents noise, disallowing warnings to be committed in a codebase prevents clutter in the output of ESLint (use special eslint comments for the instances when you need an exception to the rules)