regexUnnecessaryNestedAssertions
Reports trivially nested assertions in regular expressions that can be simplified.
✅ This rule is included in the ts logical presets.
Regular expression lookarounds are trivially nested when it contains exactly one element that is itself an assertion (anchor or another lookaround of the same direction). Such lookarounds are unnecessary and can be simplified. This rule reports those lookarounds.
Examples
Section titled “Examples”const const pattern: RegExp
pattern = /(?=$)/;const const boundary: RegExp
boundary = /(?=\b)/;const const pattern: RegExp
pattern = /(?=(?=a))/;const const behind: RegExp
behind = /(?<=(?<=a))/;const const pattern: RegExp
pattern = new var RegExp: RegExpConstructornew (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("(?=$)");const const boundary: RegExp
boundary = var RegExp: RegExpConstructor(pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("(?=\\b)");const const pattern: RegExp
pattern = /$/;const const boundary: RegExp
boundary = /\b/;const const pattern: RegExp
pattern = /(?=a)/;const const behind: RegExp
behind = /(?<=a)/;const const pattern: RegExp
pattern = new var RegExp: RegExpConstructornew (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("$");const const boundary: RegExp
boundary = var RegExp: RegExpConstructor(pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("\\b");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally keep nested regular expression structures for code clarity or documentation purposes, you might prefer to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 around the world by
the Flint team and contributors.