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.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#F78C6C;--1:#AA09">82<\qsp ansty="le--0:#82AAFF;--1:#3B61">B0{a<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B<0[a] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v>

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

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#F78C6C;--1:#AA09">82<\qsp ansty="le--0:#82AAFF;--1:#3B61">B0{a|bc<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">6109<82\q spans="tyle--0:#82AAFF;--1:#3B">61B0{1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v>

The rule also checks regex patterns in RegExp constructor calls.

AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">482<\\sp ansty="le--0:#ECC48D;--1:#984E">4Dq{a<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#C792EA;--1:#88">441<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">

String disjunctions with only multi-character alternatives are valid.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#F78C6C;--1:#AA09">82<\qsp ansty="le--0:#82AAFF;--1:#3B61">B0{ab|cd<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">

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.