Skip to content

Enforces adding a comment before disabling an ESLint rule

License

Notifications You must be signed in to change notification settings

coleturner/eslint-plugin-why

Repository files navigation

eslint-plugin-why

Enforces adding a comment before disabling an ESLint rule.

Trying to understand why someone ignored that lint rule? Need an explanation for what the heck is going on? Add eslint-plugin-why.

demo

So you don't have to ask why later:

demo

Installation

Install the plugin

$ npm install eslint-plugin-why --save-dev

Configuration

Add the following preset to your ESLint configuration:

  "extends": [
    "plugin:why/error"
  ]

But if you find it too aggressive, there's a preset that uses warnings instead of errors:

  "extends": [
    "plugin:why/warning"
  ]

Or you can add the rule yourself:

  "rules": {
    "why/tell-me-why": "error"
  }

Rule: why/tell-me-why

fun gif

Good Examples

// eslint-why some people just want to watch the world burn
// eslint-disable-next-line semi
someCodeHere();
/*
    eslint-why
    because I like unexpected surprises
*/
// eslint-disable-next-line semi
someCodeHere();

Bad Examples

No why comment:

someCodeHere();

// eslint-disable-next-line semi
someCodeThere();

Why comment is too far away:

// eslint-why because testing in production is the only way we do

console.log("I like turtles");

// eslint-disable-next-line semi
someCodeHere();

Why comment is empty:

// eslint-why
// eslint-disable-next-line semi
someCodeHere();

Savage attempt to disable the why rule:

// eslint-disable-next-line why/tell-me-why
// eslint-disable-next-line semi
someCodeHere();

Contributors

About

Enforces adding a comment before disabling an ESLint rule

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published