{"record":{"id":"6aa0789c46d5687b","repo":"oxc-project/oxc","slug":"prefer-using-method-from-obj-name-prototype","errorCode":null,"errorMessage":"Prefer using method from `{obj_name}.prototype`.","messagePattern":"Prefer using method from `(.+?)\\.prototype`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs","lineNumber":20,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    ast_util::is_method_call,\n    context::LintContext,\n    rule::Rule,\n    utils::{is_empty_array_expression, is_empty_object_expression, pad_fix_with_token_boundary},\n};\n\nfn known_method(span: Span, obj_name: &str, method_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer using `{obj_name}.prototype.{method_name}`.\"))\n        .with_label(span)\n}\n\nfn unknown_method(span: Span, obj_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer using method from `{obj_name}.prototype`.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferPrototypeMethods;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule prefers borrowing methods from the prototype instead of the instance.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// “Borrowing” a method from an instance of `Array` or `Object` is less clear than getting it from the corresponding prototype.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs#L2-L38","documentation":"Diagnostic from the unicorn/prefer-prototype-methods lint rule. It fires when a method is called on an instance of `{obj_name}` (named in the message) but the rule cannot verify the method exists on that constructor's prototype — for example calling a method on `new Array()`'s instance via an unknown shape — so it recommends referencing the method through `{obj_name}.prototype` to guarantee the call resolves even if the receiver is subclassed or cross-realm. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs:20 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reference the method via `{obj_name}.prototype` instead of relying on the instance shape","Use `.call()`/`.apply()` with an explicit receiver when needed","Restructure the code so the receiver's type is statically clear"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}