eslint-plugin-regex

raw JSON →
1.10.0 verified Sat Apr 25 auth: no javascript

ESLint plugin that provides custom rules using regular expressions, allowing developers to quickly define custom lint rules without writing full ESLint rules. Version 1.10.0, actively maintained. Key differentiator: enables inline regex-based checks (invalid/required patterns) with rich options (file filters, auto-fix for invalid, custom messages). No TypeScript support. Minimal learning curve.

error Error: Failed to load plugin 'regex': Cannot find module 'eslint-plugin-regex'
cause Plugin not installed or eslint cannot resolve it.
fix
Run 'npm install eslint-plugin-regex --save-dev' and ensure it is in node_modules.
error ESLint: Configuration for rule "regex/invalid" is invalid: value is not an array.
cause Rule config must be an array with severity and options.
fix
Set config as ["error", ["pattern"]].
gotcha Patterns are case-sensitive by default; no flag to make case-insensitive.
fix Write patterns with both cases, e.g., /[Ff]oo/ or use (?i) syntax if supported by JS regex engine.
gotcha The 'regex' plugin name is taken, so you cannot use it alongside another plugin with the same name.
fix Prefix with npm scope, e.g., '@scope/eslint-plugin-regex' if needed.
gotcha The 'replacement' option for regex/invalid only works with literal strings; cannot use functions.
fix Use a custom ESLint rule if function replacement is required.
npm install eslint-plugin-regex
yarn add eslint-plugin-regex
pnpm add eslint-plugin-regex

Shows how to configure eslint-plugin-regex to disallow console.log and debugger, and require 'use strict'.

// .eslintrc.json
{
  "plugins": ["regex"],
  "rules": {
    "regex/invalid": [
      "error", [
        "console\\.log",
        "debugger"
      ]
    ],
    "regex/required": [
      "error", [
        "\\"use strict\\""
      ]
    ]
  }
}