{"record":{"id":"cdc61191816245d8","repo":"oxc-project/oxc","slug":"disallow-use-of-object-prototype-hasownproperty-c","errorCode":null,"errorMessage":"Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`.","messagePattern":"Disallow use of `Object\\.prototype\\.hasOwnProperty\\.call\\(\\)` and prefer use of `Object\\.hasOwn\\(\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_object_has_own.rs","lineNumber":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, MemberExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::static_ident;\n\nuse crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};\n\nfn prefer_object_has_own_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`.\"\n    ).with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferObjectHasOwn;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`\n    ///\n    /// ### Why is this bad?\n    ///\n    /// It is very common to write code like:\n    /// ```javascript\n    /// if (Object.prototype.hasOwnProperty.call(object, \"foo\")) {\n    ///     console.log(\"has property foo\");","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_object_has_own.rs#L1-L31","documentation":"Diagnostic from the oxlint `prefer-object-has-own` rule. It flags the legacy pattern `Object.prototype.hasOwnProperty.call(obj, key)` and recommends the ES2022 static `Object.hasOwn(obj, key)` (prefer_object_has_own.rs:13-18). The rule matches method calls via is_method_call (imported in the file), covering `{}.hasOwnProperty.call(...)` shapes reached through member expressions.","triggerScenarios":"Enable the rule and write `Object.prototype.hasOwnProperty.call(config, \"key\")`, a pattern widely used because plain `obj.hasOwnProperty(key)` is unsafe (prototype pollution / inherited props).","commonSituations":"Utility belt code predating ES2022; configs enabling the rule while the code must also run on Node < 16.9 / old browsers without Object.hasOwn; polyfill-less projects; code copied from MDN's older examples. If your support matrix lacks Object.hasOwn, keep the rule off or polyfill.","solutions":["Replace with `Object.hasOwn(obj, key)` (behaviorally equivalent for this use).","If older runtimes must be supported, add a tiny polyfill for Object.hasOwn and still migrate the call sites, or disable the rule until support drops.","For plain own-property checks in modern code only, direct migration is safe; verify with your browserslist/engines field.","Inline-disable the rare case that intentionally tests the legacy pattern."],"exampleFix":"// before\nif (Object.prototype.hasOwnProperty.call(config, \"debug\")) { ... }\n\n// after\nif (Object.hasOwn(config, \"debug\")) { ... }","handlingStrategy":"validation","validationCode":"// feature-detect before migrating if you support old runtimes\nconst hasOwn = Object.hasOwn ?? ((o, k) => Object.prototype.hasOwnProperty.call(o, k));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `Object.hasOwn(obj, key)` in all new code (Node >= 16.9, modern browsers).","Check engines/browserslist before enabling the rule in a shared config.","Never call `obj.hasOwnProperty(k)` directly — inherited-property pitfalls apply regardless."],"tags":["oxlint","eslint","es2022","objects","modernization"],"backgroundTag":"eslint-object-has-own","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}