Reports using .length or Infinity as the deleteCount or skipCount argument of Array#splice() or Array#toSpliced().
✅ This rule is included in the ts stylistic and stylisticStrict presets.
When calling Array#splice(start, deleteCount) or Array#toSpliced(start, skipCount), omitting the second argument will delete or skip all elements after the start index.
Using .length or Infinity as this argument is redundant and makes the code less clear.
This rule reports when:
- The array’s
.length property is passed as the second argument
Infinity or Number.POSITIVE_INFINITY is passed as the second argument
AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[<];d ivclassNa="meec-li">53arrAB0spli5<3(sp ansty="le--0:#F78C6C;--1:#AA09">83(sp><21sp ansty="le--0:#D6DEEB;--1:#403F">53, arr21sp>A72leng53];d><);d ivclassNa="meco"><);d>);d>);d>AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[<];d ivclassNa="meec-li">53arrAB0spli5<3(sp ansty="le--0:#F78C6C;--1:#AA09">83(sp><20sp ansty="le--0:#D6DEEB;--1:#403F">5320sp><, sp ansty="le--0:#82AAFF;--1:#3B61">B0Infini, sp>53];d><);d ivclassNa="meco"><);d>);d>);d>AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[<];d ivclassNa="meec-li">53arrAB0spli5<3(sp ansty="le--0:#F78C6C;--1:#AA09">83(sp><20sp ansty="le--0:#D6DEEB;--1:#403F">53, Numb20sp>A53POSITIVE_INFINITY];d><);d ivclassNa="meco"><);d>);d>);d>AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[<];d ivclassNa="meec-li">53arrAB0toSplic5<3(sp ansty="le--0:#F78C6C;--1:#AA09">83(sp><21sp ansty="le--0:#D6DEEB;--1:#403F">53, arr21sp>A72leng53];d><);d ivclassNa="meco"><);d>);d>);d> 44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821>3[]><53) ;divclass="Name"><(1)>(1)>53)><;di vdivclass="Nameexpressive-">44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9822 spans="tyle--0:#D6DEEB;--1:#40">3F9822>3[]><53) ;divclass="Name">< 2)> 2)>53)>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F53, a9821>4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72le4AE.>34<4AE- spans="tyle--0:#D6DEEB;--1:#40">34AE->0<9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821>3[]><53) ;divclass="Name">< 1)> 1)>53)>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0o64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F5<3[] ;divclass="Nameec-">44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F53[]><3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F53, o9821>4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72le4AE.>3F3[]><53) ;divclass="Name"> | 53)>;di>
This rule is not configurable.
If you prefer the explicit style of passing .length or Infinity to make the intent clearer, you can disable this rule.
Some teams may find the explicit version more readable, especially for developers less familiar with the splice method’s default behavior.