Reports character classes that match no characters.
✅ This rule is included in the ts logical and logicalStrict presets.
Reports empty character classes in regular expressions.
An empty character class [] matches nothing and always fails, which is usually a mistake.
An empty character class matches nothing.
AEconsB0patteAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1/sp ansty="le--0:#82AAFF;--1:#3B61">B01/sp><[]sp ansty="le--0:#D9F5DD;--1:#1111">1[]sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61B111/><0[a] spans="tyle--0:#D9F5DD;--1:#11">10[a]><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
An empty character class in a larger pattern causes the entire match to fail.
AEconsB0patteAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1/sp ansty="le--0:#5CA7E4;--1:#3A68">81/sp>B0<[]sp ansty="le--0:#5CA7E4;--1:#3A68">8[]sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">68111/><8Fab spans="tyle--0:#D9F5DD;--1:#11">18Fab><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
The rule also checks regex patterns in RegExp constructor calls.
AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4D1"sp><[]sp ansty="le--0:#D9F5DD;--1:#1111">1[]sp><1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re4AE >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D[111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name"><]")>]")>53)>
A negated empty character class [^] matches any character and is valid.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B1/sp><0[sp ansty="le--0:#7FDBCA;--1:#096E">70[sp><2^sp ansty="le--0:#82AAFF;--1:#3B61">B2^sp><0]sp ansty="le--0:#D9F5DD;--1:#1111">10]sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d>
This rule is not configurable.
If you intentionally use empty character classes as a way to create a pattern that never matches (e.g., for testing purposes), you might prefer to disable this rule.