Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.28 KB

File metadata and controls

44 lines (32 loc) · 1.28 KB

eslint-plugin-id-denylist-regexp

Drop-in replacement for ESLint's rule id-denylist with support for regular expressions.

Installation

You'll first need to install ESLint:

npm install eslint --save-dev

Next, install eslint-plugin-id-denylist-regexp:

npm install @susiandjames/eslint-plugin-id-denylist-regexp --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-id-denylist-regexp globally.

Usage

Extend your eslint.config.js by the rule susiandjames/id-denylist as follows:

import susiandjames from "@susiandjames/eslint-plugin-id-denylist-regexp";

export default [
  {
    plugins: {
      susiandjames,
    },
    rules: {
      "susiandjames/id-denylist": [
        "warn",
        "/[0-9]+$/", // Disallow identifiers ending with numbers, e.g., `tmp0`
        "/(black|white)list/i", // Disallow identifiers containing the words "blacklist" and "whitelist" independent of their case sensitivity 
      ],
    },
  },
];

Note: Since ESLint's options need to be serializable you have to specify regular expressions as strings with a leading slash instead of using JavaScript's RegExp() constructor.