{"record":{"id":"7789e0d4fdd472e0","repo":"oxc-project/oxc","slug":"avoid-passing-a-function-reference-directly-to-ite","errorCode":null,"errorMessage":"Avoid passing a function reference directly to iterator methods","messagePattern":"Avoid passing a function reference directly to iterator methods","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_array_callback_reference.rs","lineNumber":15,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, match_member_expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode, ast_util::is_method_call, context::LintContext, rule::Rule,\n    utils::is_import_from_module,\n};\n\nfn no_array_callback_reference_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Avoid passing a function reference directly to iterator methods\")\n        .with_help(\n            \"Wrap the function in an arrow function to explicitly pass only the element argument\",\n        )\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoArrayCallbackReference;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevents passing a function reference directly to iterator methods.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Passing functions to iterator methods can cause issues when the function is changed\n    /// without realizing that the iterator passes 2 more parameters to it (index and array).","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_array_callback_reference.rs#L1-L33","documentation":"Raised by unicorn/no-array-callback-reference when a bare function reference (e.g. passing `JSON.stringify` or a named function) is passed directly to an array iterator method like `.map(fn)`. The rule flags calls during run(); the faulting input is the argument function reference at the labeled span. It is not an exception — it is a lint report about implicit extra-argument hazards.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_array_callback_reference.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap the reference in an arrow function: `.map(x => fn(x))` so only the element is passed","Use a dedicated arrow when the callback receives (element, index, array) and only the element should reach the referenced function"],"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-14T05:17:10.506Z"}