Reports .reverse() calls on arrays that mutate the original array.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
The .reverse() method mutates the original array in place.
Using .toReversed() instead returns a new reversed array without modifying the original, making code more predictable and avoiding unintended side effects.
AEconsB0valuAE< =sp ansty="le--0:#D6DEEB;--1:#403F">53 =sp>< [sp ansty="le--0:#F78C6C;--1:#AA09">8 [sp><21sp ansty="le--0:#D6DEEB;--1:#403F">5321sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><22sp ansty="le--0:#D6DEEB;--1:#403F">5322sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><23sp ansty="le--0:#D6DEEB;--1:#403F">5323sp><];d ivclassNa="meec-li">AEconsB0reversAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53valu= sp>AB0rever53(];d><);d ivclassNa="meco"><);d>);d>);d>AEconsB0iteAE< =sp ansty="le--0:#D6DEEB;--1:#403F">53 =sp>< [sp ansty="le--0:#D9F5DD;--1:#1111">1 [sp><1"sp ansty="le--0:#ECC48D;--1:#984E">41"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><, sp ansty="le--0:#D9F5DD;--1:#1111">1, sp><1"sp ansty="le--0:#ECC48D;--1:#984E">41"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><, sp ansty="le--0:#D9F5DD;--1:#1111">1, sp><1"sp ansty="le--0:#ECC48D;--1:#984E">41"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><];d ivclassNa="meec-li">B0doSomethi53(iteAB0rever53()];d><);d ivclassNa="meco"><);d>);d>);d>AEconsB0daAE< =sp ansty="le--0:#D6DEEB;--1:#403F">53 =sp>< [sp ansty="le--0:#F78C6C;--1:#AA09">8 [sp><21sp ansty="le--0:#D6DEEB;--1:#403F">5321sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><22sp ansty="le--0:#D6DEEB;--1:#403F">5322sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><23sp ansty="le--0:#D6DEEB;--1:#403F">5323sp><];d ivclassNa="meec-li">AEconsB0resuAE< =sp ansty="le--0:#D6DEEB;--1:#403F">53 =sp>< [sp ansty="le--0:#7FDBCA;--1:#096E">72. [sp><..sp ansty="le--0:#D6DEEB;--1:#403F">53datAB0rever53(];d><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0va443F<53 [ spans="tyle--0:#F78C6C;--1:#AA">053 [><9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9822 spans="tyle--0:#D6DEEB;--1:#40">3F9822><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9823 spans="tyle--0:#D6DEEB;--1:#40">3F9823><53] ;divclass="Nameec-">44AEco61B0reve44A3F53va4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0toReve4AE.>3F553]><3() ;divclass="Name">3()><;di vdivclass="Nameexpressive-">44AEco61B0i443F<53 [ spans="tyle--0:#D9F5DD;--1:#11">153 [><111" spans="tyle--0:#ECC48D;--1:#98">4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53, spans="tyle--0:#D9F5DD;--1:#11">153, ><111" spans="tyle--0:#ECC48D;--1:#98">4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53, spans="tyle--0:#D9F5DD;--1:#11">153, ><111" spans="tyle--0:#ECC48D;--1:#98">4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53] ;divclass="Nameec-">61B0doSomet3F53(i4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0toReve4AE.>3F5353]><()) ;divclass="Name"><())>())>())>;di><;di vdivclass="Nameexpressive-">44AEco61B0va443F<53 [ spans="tyle--0:#F78C6C;--1:#AA">053 [><9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9822 spans="tyle--0:#D6DEEB;--1:#40">3F9822><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9823 spans="tyle--0:#D6DEEB;--1:#40">3F9823><53] ;divclass="Nameec-">3F53va4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0rev4AE.>3F553]><3() ;divclass="Name">3()>;di>
This rule is not configurable.
If you intentionally want to mutate the original array in place, or if you’re working in an environment that doesn’t support .toReversed() (ES2023+), you may want to disable this rule.
Note that .reverse() is still allowed when used as a standalone expression statement since the mutation is likely intentional in that case.