ESLint plugin for finding RegExp mistakes and RegExp style guide violations.
npx @tessl/cli install tessl/npm-eslint-plugin-regexp@2.10.0ESLint Plugin RegExp provides a comprehensive suite of 82+ specialized linting rules for detecting regular expression mistakes and enforcing RegExp style guide violations. It helps developers avoid common pitfalls when working with regular expressions, including finding wrong usage patterns, enforcing consistent regular expression styles, and providing optimization hints.
npm install eslint-plugin-regexp// ES modules
import { configs, rules, meta } from "eslint-plugin-regexp";// CommonJS
const { configs, rules, meta } = require("eslint-plugin-regexp");// ESLint configuration (.eslintrc.js)
module.exports = {
plugins: ["regexp"],
extends: ["plugin:regexp/recommended"],
rules: {
"regexp/no-unused-capturing-group": "error",
"regexp/confusing-quantifier": "warn"
}
};
// ESLint flat config (eslint.config.js)
import regexp from "eslint-plugin-regexp";
export default [
{
plugins: { regexp },
...regexp.configs["flat/recommended"]
}
];ESLint Plugin RegExp is built around several key components:
Core plugin setup and pre-configured rule sets for different use cases. Essential for integrating the plugin into your ESLint workflow.
interface PluginConfigs {
recommended: ESLintConfig;
all: ESLintConfig;
"flat/all": FlatESLintConfig;
"flat/recommended": FlatESLintConfig;
}
const configs: PluginConfigs;Critical rules that catch potential errors, bugs, and issues that could cause runtime failures or unexpected behavior in regular expressions.
interface RuleModule {
meta: RuleMeta;
create: (context: RuleContext) => RuleListener;
}
interface RuleMeta {
type: "problem" | "suggestion" | "layout";
docs: {
description: string;
category: string;
recommended: boolean;
url: string;
};
fixable?: "code" | "whitespace";
schema: JSONSchema4;
}Rules that enforce coding standards, performance optimizations, and maintainability improvements for regular expressions.
interface RuleContext {
getSourceCode(): SourceCode;
report(descriptor: ReportDescriptor): void;
options: any[];
settings: { [name: string]: any };
}
interface ReportDescriptor {
node: ESTree.Node;
message: string;
fix?: (fixer: RuleFixer) => Fix | null;
}Rules that enforce consistent formatting, naming conventions, and stylistic choices for regular expressions to improve code readability.
interface RuleFixer {
insertTextAfter(node: ESTree.Node, text: string): Fix;
insertTextBefore(node: ESTree.Node, text: string): Fix;
remove(node: ESTree.Node): Fix;
replaceText(node: ESTree.Node, text: string): Fix;
}
interface Fix {
range: [number, number];
text: string;
}Package information and metadata utilities for integrating with build tools and development workflows.
interface Meta {
name: string;
version: string;
}
const meta: Meta;