{"record":{"id":"fc8f5c854568ca74","repo":"oxc-project/oxc","slug":"prefer-using-obj-name-prototype-method-name","errorCode":null,"errorMessage":"Prefer using `{obj_name}.prototype.{method_name}`.","messagePattern":"Prefer using `(.+?)\\.prototype\\.(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs","lineNumber":15,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse 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    ///","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs#L1-L33","documentation":"Diagnostic from the unicorn/prefer-prototype-methods lint rule. It fires when a method is invoked on a value via a construct that skips the prototype chain unnecessarily — typically calling `{obj_name}.{method_name}` through a throwaway instance (an empty array/object literal) instead of `{obj_name}.prototype.{method_name}`; the prototype form is reliable even when the receiver may be null/undefined or from another realm. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call the method as `{obj_name}.prototype.{method_name}.call(receiver, ...)` or on the known prototype","Avoid creating throwaway instances (`[]`, `{}`) just to reach a method","Apply the rule's auto-fix"],"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"}