eslint-plugin-regexp
raw JSON → 3.1.0 verified Sat Apr 25 auth: no javascript
ESLint plugin for finding RegExp mistakes and enforcing style guide violations. Current stable version is v3.1.0 (requires ESLint >=9.38.0 and Node.js >=20.19.0). Released regularly with minor and patch updates. Key differentiators: 80+ rules covering regex syntax, optimization, and style; TypeScript type declarations included; supports ES2025 features like duplicate named capturing groups; provides recommended and all configs; exclusively supports ESLint Flat Config since v3.0.0 (drops Legacy Config).
Common errors
error Error: Cannot find module 'eslint-plugin-regexp' ↓
cause Package not installed or incorrect import path.
fix
Run 'npm install --save-dev eslint-plugin-regexp' and ensure import path is correct.
error Configuration for rule "regexp/..." is invalid: Value "error" is unexpected. ↓
cause Rule name missing 'regexp/' prefix.
fix
Use full rule name like 'regexp/no-useless-escape'.
error ESLint couldn't find the plugin "eslint-plugin-regexp". ↓
cause Plugin not registered in flat config 'plugins' array.
fix
Add 'plugins: { regexp: regexpPlugin }' to your config object.
Warnings
breaking v3.0.0: Dropped support for ESLint v8 and Legacy Config (.eslintrc). Only Flat Config (eslint.config.js) is supported. ↓
fix Migrate to ESLint v9 and use eslint.config.js with import statement.
gotcha The 'all' config changes with every minor/major version. Not suitable for production. ↓
fix Use 'recommended' config for stable rule set.
deprecated v2.10.0: Deprecated old rule 'regexp/...' without explicit notice. ↓
fix Update to v3 and follow flat config patterns.
gotcha Rule names must be prefixed with 'regexp/' in config, e.g., 'regexp/no-useless-escape'. ↓
fix Use full rule name including prefix.
breaking v3.0.0: Minimum Node.js version bumped to 20.19.0, 22.13.0, or >=24. ↓
fix Update Node.js to supported version.
Install
npm install eslint-plugin-regexp yarn add eslint-plugin-regexp pnpm add eslint-plugin-regexp Imports
- regexpPlugin (default) wrong
const regexpPlugin = require('eslint-plugin-regexp')correctimport regexpPlugin from 'eslint-plugin-regexp' - configs (recommended) wrong
require('eslint-plugin-regexp').configs.recommendedcorrectregexpPlugin.configs.recommended - rules wrong
rules: { 'regexp/no-useless-escape': 'error' } without pluginscorrectplugins: { regexp: regexpPlugin }, rules: { 'regexp/no-useless-escape': 'error' }
Quickstart
// eslint.config.js
import regexpPlugin from 'eslint-plugin-regexp';
export default [
regexpPlugin.configs.recommended,
{
rules: {
'regexp/prefer-regexp-exec': 'warn',
'regexp/no-useless-escape': 'error',
},
},
];