Skip to main content

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.

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.