💼 This rule is enabled in the following configs: 🟢 flat/recommended
, 🔵 recommended
.
🔧 This rule is automatically fixable by the --fix
CLI option.
📖 Rule Details require simplify set operations
This rule aims to optimize patterns by simplifying set operations in character classes (with v
flag).
This rule does not report simple nested negations. (e.g. /[^[^abc]]/v
)
If you want to report simple nested negations, use the regexp/negation rule.
This rule attempts to simplify set operations in the ways listed below:
De Morgan's laws This rule uses De Morgan's laws to look for patterns that can convert multiple negations into a single negation, reports on them, and auto-fix them.
For example, /[[^a]&&[^b]]/v
is equivalent to /[^ab]/v
, and /[[^a][^b]]/v
is equivalent to /[^a&&b]/v
.
See https://en.wikipedia.org/wiki/De_Morgan's_laws.
Conversion from the intersection to the subtraction Intersection sets with complement operands can be converted to difference sets.
The rule looks for character class intersection with negation operands, reports on them, auto-fix them.
For example, /[a&&[^b]]/v
is equivalent to /[a--b]/v
, /[[^a]&&b]/v
is equivalent to /[b--a]/v
.
Difference set with a complement operand on the right side can be converted to intersection sets.
The rule looks for character class subtraction with negation operand on the right side, reports on them, auto-fix them.
For example, /[a--[^b]]/v
is equivalent to /[a&&b]/v
.
This rule's auto-fix does not remove unnecessary brackets. For example, /[[^a]&&[^b]]/v
will be automatically fixed to /[^[a][b]]/v
.
If you want to remove unnecessary brackets (e.g. auto-fixed to /[^ab]/v
), use regexp/no-useless-character-class rule together.
Nothing.
🚀 Version This rule was introduced in eslint-plugin-regexp v2.0.0-next.11
🔍 Implementation RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4