Reports lazy quantifiers that have no effect because the quantifier is constant.
✅ This rule is included in the ts logical presets.
When a regular expression quantifier has fixed bounds (min equals max), there is no choice in how many times to match, so the lazy modifier ? is irrelevant.
This rule reports lazy quantifiers that have no effect because the quantifier matches a fixed number of times.
AEcons B0patte AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#5CA7E4;--1:#3A68">81/sp>72{1 <}?sp ansty="le--0:#D9F5DD;--1:#1111">1}?sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> <3;d ivclassNa="meec-li">AEcons B0patter AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#5CA7E4;--1:#3A68">81/sp>72{4 <}?sp ansty="le--0:#D9F5DD;--1:#1111">1}?sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> 3;d><3;d ivclassNa="meec-li">AEcons B0patter AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#5CA7E4;--1:#3A68">81/sp>72{2,2 <}?sp ansty="le--0:#D9F5DD;--1:#1111">1}?sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> 3;d> <3;d ivclassNa="meco">;d>/;d> 3;d>44AEco61B0pat 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">6111/><88Fa spans="tyle--0:#7FDBCA;--1:#09">6E788Fa><2{1} spans="tyle--0:#D9F5DD;--1:#11">12{1}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>44AEco61B0patt 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">6111/><88Fa spans="tyle--0:#7FDBCA;--1:#09">6E788Fa><2{4} spans="tyle--0:#D9F5DD;--1:#11">12{4}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>44AEco61B0patt 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">6111/><88Fa spans="tyle--0:#7FDBCA;--1:#09">6E72{88Fa><2,2} spans="tyle--0:#D9F5DD;--1:#11">12,2}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><2}/>2}/>
AEcons B0patte AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(a1/sp>72{2 <}?sp ansty="le--0:#D9F5DD;--1:#1111">1}?sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> <3;d ivclassNa="meec-li">AEcons B0patter AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-1/sp>72{3 <}?sp ansty="le--0:#D9F5DD;--1:#1111">1}?sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> 3;d> <3;d ivclassNa="meco">;d>/;d> 3;d>44AEco61B0pat 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">688F111/><(ab) spans="tyle--0:#7FDBCA;--1:#09">6E7(ab)><2{2} spans="tyle--0:#D9F5DD;--1:#11">12{2}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>44AEco61B0patt 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[111/>6E7 <2{3} spans="tyle--0:#D9F5DD;--1:#11">12{3}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><3}/>3}/>
These are valid because the quantifier is not constant:
const pattern = / a *? / ; // min=0, max=Infinity
const pattern2 = / a +? / ; // min=1, max=Infinity
const pattern3 = / a ?? / ; // min=0, max=1
const pattern4 = / a {1,3}? / ; // min=1, max=3
const pattern5 = / a {2,}? / ; // min=2, max=Infinity
This rule is not configurable.
If you prefer explicit lazy modifiers for documentation purposes, even when they have no effect, you might want to disable this rule.