用于查找正则表达式错误和风格指南违规的 ESLint 插件。
eslint-plugin-regexp is ESLint plugin for finding RegExp mistakes and RegExp style guide violations.
This ESLint plugin provides linting rules relate to better ways to help you avoid problems when using RegExp.
You can check on the Online DEMO.
See documents.
npm install --save-dev eslint eslint-plugin-regexpRequirements
- ESLint v9.38.0 and above
- Node.js v20.19.0, v22.13.0, v24 and above
Add regexp to the plugins section of your eslint.config.js configuration file (you can omit the eslint-plugin- prefix)
and either use one of the two configurations available (recommended or all) or configure the rules you want:
The plugin.configs.recommended config enables a subset of the rules that should be most useful to most users.
See lib/configs/rules/recommended.ts for more details.
// eslint.config.js
import regexpPlugin from "eslint-plugin-regexp"
export default [
regexpPlugin.configs.recommended,
];Override/add specific rules configurations. See also: http://eslint.org/docs/user-guide/configuring.
// eslint.config.js
import regexpPlugin from "eslint-plugin-regexp"
export default [
{
plugins: { regexp: regexpPlugin },
rules: {
// Override/add rules settings here, such as:
"regexp/rule-name": "error"
}
}
];The plugin.configs.all config enables all rules. It's meant for testing, not for production use because it changes with every minor and major version of the plugin. Use it at your own risk.
See lib/configs/rules/all.ts for more details.
Configurations enabled in.
⚠️ Configurations set to warn in.
Set in the flat/recommended configuration.
Set in the recommended configuration.
Automatically fixable by the --fix CLI option.
Manually fixable by editor suggestions.
| Name | Description | ⚠️ | |||
|---|---|---|---|---|---|
| no-contradiction-with-assertion | disallow elements that contradict assertions | ||||
| no-control-character | disallow control characters | ||||
| no-dupe-disjunctions | disallow duplicate disjunctions | ||||
| no-empty-alternative | disallow alternatives without elements | ||||
| no-empty-capturing-group | disallow capturing group that captures empty. | ||||
| no-empty-character-class | disallow character classes that match no characters | ||||
| no-empty-group | disallow empty group | ||||
| no-empty-lookarounds-assertion | disallow empty lookahead assertion or empty lookbehind assertion | ||||
| no-escape-backspace | disallow escape backspace ([\b]) |
||||
| no-invalid-regexp | disallow invalid regular expression strings in RegExp constructors |
||||
| no-lazy-ends | disallow lazy quantifiers at the end of an expression | ||||
| no-misleading-capturing-group | disallow capturing groups that do not behave as one would expect | ||||
| no-misleading-unicode-character | disallow multi-code-point characters in character classes and quantifiers | ||||
| no-missing-g-flag | disallow missing g flag in patterns used in String#matchAll and String#replaceAll |
||||
| no-optional-assertion | disallow optional assertions | ||||
| no-potentially-useless-backreference | disallow backreferences that reference a group that might not be matched | ||||
| no-super-linear-backtracking | disallow exponential and polynomial backtracking | ||||
| no-super-linear-move | disallow quantifiers that cause quadratic moves | ||||
| no-useless-assertions | disallow assertions that are known to always accept (or reject) | ||||
| no-useless-backreference | disallow useless backreferences in regular expressions | ||||
| no-useless-dollar-replacements | disallow useless $ replacements in replacement string |
||||
| strict | disallow not strictly valid regular expressions |
| Name | Description | ⚠️ | |||
|---|---|---|---|---|---|
| confusing-quantifier | disallow confusing quantifiers | ||||
| control-character-escape | enforce consistent escaping of control characters | ||||
| negation | enforce use of escapes on negation | ||||
| no-dupe-characters-character-class | disallow duplicate characters in the RegExp character class | ||||
| no-empty-string-literal | disallow empty string literals in character classes | ||||
| no-extra-lookaround-assertions | disallow unnecessary nested lookaround assertions | ||||
| no-invisible-character | disallow invisible raw character | ||||
| no-legacy-features | disallow legacy RegExp features | ||||
| no-non-standard-flag | disallow non-standard flags | ||||
| [no-obscure-ra |
暂无开放 Issues,或尚未同步最近议题。