regexUnnecessarySetOperands
Reports unnecessary operands in regular expression character class set operations.
✅ This rule is included in the ts logical presets.
Regular expressions with the v flag support character class set operations like intersection (&&) and subtraction (--).
This rule identifies operands in these operations that are unnecessary or produce unexpected results.
The rule detects four types of issues:
- Disjoint intersection: two sets with no common elements intersected together, producing an empty result.
- Subset intersection: a superset operand in an intersection that is redundant.
- Disjoint subtraction: subtracting a set that shares no elements, which has no effect.
- Subset subtraction: subtracting a superset, which produces an empty result.
Examples
Section titled “Examples”/[\w&&\s]/v;/[\w&&\d]/v;/[\w--\s]/v;/[\d--\w]/v;/[[abc]&&[def]]/v;/[\w--\d]/v;/[[a-z]&&[a-m]]/v;/[[a-z]--[aeiou]]/v;/[\w&&\s]/;/[\w\d]/v;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally use set operations that produce empty results for documentation or testing purposes, you may want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-useless-set-operand
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.