Reports inconsistent styles for checking element existence using index methods.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
Enforces consistent style for element existence checks with indexOf(), lastIndexOf(), findIndex(), and findLastIndex().
Prefer using index === -1 to check if an element does not exist and index !== -1 to check if an element does exist.
These methods return -1 when an element is not found, so checking against -1 is more explicit and precise than using broad comparisons like < 0 or >= 0.
AEconsB0indAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53valu= sp>AB0index5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dte1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meec-li">AE53 (indeA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">83 sp><20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>);d>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#919F9F;--1:#5D63">76// not fou sp> {d>5<3}d ivclassNa="meco"><}d>}d>3}d>AEconsB0indAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53valu= sp>AB0index5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dte1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meec-li">AE53 (indeAE<>=sp ansty="le--0:#D6DEEB;--1:#403F">5>=sp><3 sp ansty="le--0:#F78C6C;--1:#AA09">83 sp><20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>);d>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#919F9F;--1:#5D63">76// fou sp> {d>5<3}d ivclassNa="meco">= 0) { // found"><}d>}d>3}d>AEconsB0indAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53valu= sp>AB0index5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dte1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meec-li">AE53 (indeAsp ansty="le--0:#D6DEEB;--1:#403F">5sp><3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<21sp ansty="le--0:#D6DEEB;--1:#403F">53)21sp>);d>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#919F9F;--1:#5D63">76// fou sp> {d>5<3}d ivclassNa="meco"> -1) { // found"><}d>}d>3}d> 44AEco61B0i44A3F53va4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ind4AE.>31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Nameec-">443F53 (in44A34<4AE- spans="tyle--0:#F78C6C;--1:#AA">04AE-><9821 spans="tyle--0:#D6DEEB;--1:#40">3F59821>53)><3) {divclass="Nameec-">de6376// not f3) >3<}di vdivclass="Nameexpressive-">44AEco61B0i44A3F53va4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ind4AE.>31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Nameec-">443F53 (in44A34<4AE- spans="tyle--0:#F78C6C;--1:#AA">04AE-><9821 spans="tyle--0:#D6DEEB;--1:#40">3F59821>53)><3) {divclass="Nameec-">de6376// f3) >3}di><}di vdivclass="Nameexpressive-">443F53 (va4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0findI4AE.>31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v111(>1<111) spans="tyle--0:#D6DEEB;--1:#40">3111)>44 spans="tyle--0:#D6DEEB;--1:#40">3F53 va>4<4AE> spans="tyle--0:#D6DEEB;--1:#40">34AE>>09<8210 spans="tyle--0:#D6DEEB;--1:#40">3F8210><53) spans="tyle--0:#C792EA;--1:#88">44A53) >34<4AE- spans="tyle--0:#F78C6C;--1:#AA">04AE-><9821 spans="tyle--0:#D6DEEB;--1:#40">3F59821><3) {divclass="Nameec-">de6376// not f3) >3 value > 10) === -1) { // not fou">}di>
This rule is not configurable.
If your codebase has an established convention using < 0 or >= 0 for index checks, you may disable this rule.
Some developers find the comparison style more readable in certain contexts.