{"record":{"id":"382fc32a8684cd4f","repo":"oxc-project/oxc","slug":"do-not-use-new-array-singleargument","errorCode":null,"errorMessage":"Do not use `new Array(singleArgument)`.","messagePattern":"Do not use `new Array\\(singleArgument\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_new_array.rs","lineNumber":17,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode, ast_util,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::Rule,\n};\n\nfn no_new_array_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use `new Array(singleArgument)`.\")\n        .with_help(r\"It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the argument is the only element, use `[element]`.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoNewArray;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow `new Array()`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// When using the `Array` constructor with one argument, it's not clear whether the argument is meant to be the length of the array or the only element.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_new_array.rs#L1-L35","documentation":"Raised by unicorn/no-new-array when `new Array(singleArgument)` is used with exactly one argument, because the semantics are ambiguous: a number sets the length, any other value becomes the sole element. The faulting input is the single-argument `new Array()` call at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_new_array.rs:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["If the argument is the length, use `Array.from({ length: n })`","If it is the only element, use an array literal `[value]`"],"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"}