Reports for-in loops without an if statement to filter inherited properties.
✅ This rule is included in the ts preset.
Looping over objects with a for-in loop will include properties inherited through the prototype chain.
This can lead to unexpected items being iterated over when the object inherits from a non-standard prototype.
AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEcons (sp>B0kA7253 object)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0doSomethi sp>53(key {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEcons (sp>B0kA7253 object)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0doSomethi sp>53(key {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEcons (sp>B0kA7253 object)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AE sp>53 (condition) {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0doSomethi sp>53(key {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>);d><3}d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0doSomethingEl sp>53(key3}d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d> 44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AEco53 (>61B<0key spans="tyle--0:#C792EA;--1:#88">40key><4AE spans="tyle--0:#7FDBCA;--1:#09">6E4AE ><72in spans="tyle--0:#D6DEEB;--1:#40">3F53 objec72in>de443F53 (Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53(object, key<)) {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0doSomet >3F53(k)) >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }><}di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AEco53 (>61B<0key spans="tyle--0:#C792EA;--1:#88">40key><4AE spans="tyle--0:#7FDBCA;--1:#09">6E4AE ><72in spans="tyle--0:#D6DEEB;--1:#40">3F53 objec72in>de443F<53 ( spans="tyle--0:#C792EA;--1:#88">453 (><4AE! spans="tyle--0:#D6DEEB;--1:#40">3F53Ob4AE!>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53(object, key<)) {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEcont >3)) >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >de61B0doSomet3F53(k3<);>);>}di><}di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AEco53 (>61B<0key spans="tyle--0:#C792EA;--1:#88">40key><4AE spans="tyle--0:#7FDBCA;--1:#09">6E4AE ><72in spans="tyle--0:#D6DEEB;--1:#40">3F53 objec72in>de443F<53 ( spans="tyle--0:#C5E478;--1:#3B">61B0Ob53 (>4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72proto4AE.>4<4AE. spans="tyle--0:#FAF39F;--1:#11">1111hasOwnProp4AE.>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B04AE.>3F53(object, key<)) {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0doSomet >3F53(k)) >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >3< }> }>}di><}di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AEco53 (>61B<0key spans="tyle--0:#C792EA;--1:#88">40key><4AE spans="tyle--0:#7FDBCA;--1:#09">6E4AE ><72in spans="tyle--0:#D6DEEB;--1:#40">3F53 obje72in>}di><;di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AEco53 (>61B<0key spans="tyle--0:#C792EA;--1:#88">40key><4AE spans="tyle--0:#7FDBCA;--1:#09">6E4AE ><72in spans="tyle--0:#D6DEEB;--1:#40">3F53 objec72in>3< {> {>;di>
This rule is not configurable.
If you are certain that the objects you iterate over do not have inherited properties from custom prototypes, you might choose to disable this rule.
This is common when iterating over plain objects created with object literals or Object.create(null).