{"record":{"id":"ea32b4daa572a4e9","repo":"oxc-project/oxc","slug":"do-not-use-a-reference-value-as-the-fill-value","errorCode":null,"errorMessage":"Do not use a reference value as the fill value.","messagePattern":"Do not use a reference value as the fill value\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_array_fill_with_reference_type.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, BindingPattern, Expression, IdentifierReference},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    ast_util::variable_declaration_kind,\n    ast_util::{get_declaration_of_variable, is_method_call},\n    context::LintContext,\n    rule::Rule,\n    utils::is_regexp_callee,\n};\n\nfn no_array_fill_with_reference_type_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use a reference value as the fill value.\")\n        .with_help(\"Use `Array.from({ length: n }, () => /* new value */)` or `.map(() => /* new value */)` to create a distinct value for each element.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoArrayFillWithReferenceType;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows using reference values as `Array#fill()` values.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// `Array#fill()` reuses the same value for every array element. When the\n    /// fill value is an object, array, class, or most constructed objects, all\n    /// elements point at the same reference and mutating one element mutates the\n    /// shared value observed by the others.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_array_fill_with_reference_type.rs#L1-L37","documentation":"Raised by unicorn/no-array-fill-with-reference-type when `Array.prototype.fill` is called with an argument that is a reference type (object, array, function), so every slot aliases the same instance. The faulting input is the `.fill(referenceValue)` call at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_array_fill_with_reference_type.rs:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use `Array.from({ length: n }, () => createValue())` to create a fresh value per element","Fill with a primitive and populate objects individually","Map over the filled array to clone the reference into each slot"],"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"}