Skip to content

regexUnnecessaryDisjunctions

Reports single-character alternatives in string disjunctions.

✅ This rule is included in the ts logical presets.

Reports single-character alternatives inside \q{...} string disjunctions in regular expressions using the v flag. When a string disjunction alternative contains only one character, that character can be placed directly in the surrounding character class instead.

A string disjunction containing only a single-character alternative is unnecessary.

const pattern = /[\q{a}]/v;

When a string disjunction has both single-character and multi-character alternatives, the single-character ones can be extracted.

const pattern = /[\q{a|bc}]/v;

The rule also checks regex patterns in RegExp constructor calls.

const pattern = new RegExp("[\\q{a}]", "v");

String disjunctions with only multi-character alternatives are valid.

const pattern = /[\q{ab|cd}]/v;

This rule is not configurable.

If you prefer to keep single-character alternatives inside \q{...} for consistency or readability, you might prefer to disable this rule.

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