A rule suggesting to replace `Object.prototype.hasOwnProperty.call` with `Object.hasOwn`
See original GitHub issuePlease describe what the rule should do:
Starting V8 v.9.3, Object.prototype.hasOwnProperty.call
can be replaced with an alias/syntax sugar Object.hasOwn
, which is much more read-friendly. Further information: https://v8.dev/features/object-has-own
What new ECMAScript feature does this rule relate to?
Promoting using of an alias/syntax sugar Object.hasOwn
instead of Object.prototype.hasOwnProperty.call
.
What category of rule is this? (place an “X” next to just one item)
[ ] Warns about a potential error (problem) [X] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about: The original code:
if (Object.prototype.hasOwnProperty.call(object, 'foo')) {
// `object` has property `foo`.
}
Should be replaced with:
if (Object.hasOwn(object, 'foo')) {
// `object` has property `foo`.
}
Why should this rule be included in ESLint (instead of a plugin)? Applying this rule you can make your application’s code cleaner.
Are you willing to submit a pull request to implement this rule? No.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:46 (26 by maintainers)
@bmish oh cool! We do typically introduce new rules to help people transition from old ways of doing things to new ways of doing things, so we might still end up with it as a core rule. Let’s get a few more thoughts on this. (Especially since there isn’t a great way to discover such rules and plug-ins.)
I’m in favor of this rule, and I think it should also report
{}.hasOwnProperty.call(object, 'foo')
.