Skip to content

Change Request: Update guard-for-in docs to use Object.hasOwn #16981

@alope107

Description

@alope107

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 inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussiondocumentationRelates to ESLint's documentationruleRelates to ESLint's core rules

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions