guard-for-in
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"guard-for-in": "error",
},
},
];for (key in foo) {
doSomething(key);
}for (key in foo) {
if (Object.hasOwn(foo, key)) {
doSomething(key);
}
}
for (key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
for (key in foo) {
if ({}.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}Examples from the ESLint documentation.
guard-for-in
eslint
export default [
{
rules: {
"guard-for-in": "error",
},
},
];guard-for-in
eslint plugin · style
{
"rules": {
"guard-for-in": "error"
}
}suspicious/useGuardForIn
suspicious · since 1.9.4
{
"linter": {
"rules": {
"suspicious": {
"useGuardForIn": "error"
}
}
}
}Enforce the use of variables within the scope they are defined
Require var declarations be placed at the top of their containing scope
Require grouped accessor pairs in object literals and classes
Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead
Disallow returning values from Promise executor functions