Skip to content

regexContradictoryAssertions

Reports elements in regular expressions that contradict assertions.

✅ This rule is included in the ts logical presets.

Reports elements in regular expressions that contradict assertions like word boundaries (\b). These contradictions indicate dead code or unintended behavior in the regex pattern.

When a word boundary is between two word characters (or two non-word characters), optional quantifiers following it are always entered.

const pattern = /a\b-?a/;

When a word boundary assertion forces a transition that conflicts with the quantifier’s element, the quantifier can never match.

const pattern = /a\ba*-/;

The rule also checks regex patterns in RegExp constructor calls.

const pattern = new RegExp("a\\b-?a");

This rule is not configurable.

If you intentionally use contradictory assertions for documentation purposes or if you’re working with dynamically constructed regex patterns where the contradictions are not actually problematic, you may disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.