prefer-object-has-own
Prefer Object.hasOwn(...) over Object.prototype.hasOwnProperty.call(...).
Targeted pattern scopeโ
This rule targets property-ownership checks using hasOwnProperty.call.
What this rule reportsโ
This rule reports legacy Object.prototype.hasOwnProperty.call(...) patterns.
Why this rule existsโ
Object.hasOwn(...) is shorter, clearer, and less error-prone.
โ Incorrectโ
Object.prototype.hasOwnProperty.call(record, "id");
โ Correctโ
Object.hasOwn(record, "id");
Behavior and migration notesโ
This rule forwards options and behavior to ESLint core
prefer-object-has-own.
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
prefer-object-has-own(ESLint core)
Additional examplesโ
Object.prototype.hasOwnProperty.call(config, "port");
// โ reported
Object.hasOwn(config, "port");
// โ
valid
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/prefer-object-has-own": "error",
},
},
];
When not to use itโ
Disable this rule if you must support runtimes without Object.hasOwn(...) and
cannot polyfill it.
Package documentationโ
Rule catalog ID: R060
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.