for-in
loops should include an if
statement JS-0051 49 fs.readFileSync(path.join(process.cwd(), 'wafRules.json')).toString()
50 )
51
52 for (const key in this.types) { 53 this.types[this.types[key]] = key 54 } 55 rulesJson.forEach((rule: _Rule) => {
56 this.rules[rule.id] = {
57 reg: new RegExp(rule.reg),
Looping over objects with a for in
loop will include properties that are inherited through the prototype chain.
This behavior can lead to unexpected keys in your for loop.
for (const key in foo) {
doSomething(key);
}
for (const key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
for (const key of Object.keys(foo)) {
doSomething(key);
}