-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Closed
Labels
acceptedThere is consensus among the team that this change meets the criteria for inclusionThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionThis issue has been archived; please open a new issue for any further discussiondocumentationRelates to ESLint's documentationRelates to ESLint's documentationruleRelates to ESLint's core rulesRelates to ESLint's core rules
Description
ESLint version
v8.36.0
What problem do you want to solve?
The docs for guard-for-in currently only show how to guard a for-in loop using Object.prototype.hasOwnProperty
or {}.hasOwnProperty
. However, as of ES2022, it is best practice to use Object.hasOwn
instead (see prefer-object-has-own).
What do you think is the correct solution?
To show best practices, I propose adding the following as the first example in the examples of correct code:
for (key in foo) {
if (Object.hasOwn(foo, key)) {
doSomething(key);
}
}
Participation
- I am willing to submit a pull request for this change.
Additional comments
I'm happy to make a PR for this small change if it's desired 🙂
Metadata
Metadata
Assignees
Labels
acceptedThere is consensus among the team that this change meets the criteria for inclusionThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionThis issue has been archived; please open a new issue for any further discussiondocumentationRelates to ESLint's documentationRelates to ESLint's documentationruleRelates to ESLint's core rulesRelates to ESLint's core rules
Type
Projects
Status
Complete