Skip to content

bfanger/eslint-plugin-only-warn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-only-warn

status

Downgrade ESLint errors to warnings.

Installation

npm install --save-dev eslint-plugin-only-warn

Usage

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"]
}

--max-warnings=0

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.

Git integration

Use Husky and lint-staged to prevent committing code that contain eslint warnings.

Why only 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)