{"record":{"id":"d8fb205d051a7442","repo":"oxc-project/oxc","slug":"using-a-spread-operator-here-creates-a-new-array-u","errorCode":null,"errorMessage":"Using a spread operator here creates a new array unnecessarily.","messagePattern":"Using a spread operator here creates a new array unnecessarily\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs","lineNumber":37,"sourceCode":"    AstNode,\n    ast_util::{\n        get_new_expr_ident_name, is_method_call, is_new_expression, outermost_paren_parent,\n    },\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::Rule,\n};\n\nfn spread_in_list(span: Span, arr_or_obj: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Using a spread operator here creates a new {arr_or_obj} unnecessarily.\"\n    ))\n    .with_help(\"Consider removing the spread operator.\")\n    .with_label(span)\n}\n\nfn spread_in_arguments(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Using a spread operator here creates a new array unnecessarily.\")\n        .with_help(\"Pass arguments directly instead of spreading an array.\")\n        .with_label(span)\n}\n\nfn iterable_to_array(span: Span, ctor_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"`{ctor_name}` accepts an iterable, so it's unnecessary to convert the iterable to an array.\"\n    ))\n    .with_help(\"Consider removing the spread operator.\")\n    .with_label(span)\n}\n\nfn iterable_to_array_in_for_of(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Using a spread operator here creates a new array unnecessarily.\")\n        .with_help(\"`for…of` can iterate over iterable, it's unnecessary to convert to an array.\")\n        .with_label(span)\n}\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs#L19-L55","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-spread`. This variant (`spread_in_arguments`) fires when an array literal is spread as (part of) the arguments of a call or `new` expression: `foo(...[a, b])`. Spreading a freshly written literal just re-lists the arguments, so it can be replaced by passing them directly. An autofix replaces the spread with the literal's elements (or removes it entirely for an empty literal).","triggerScenarios":"`foo(...[a])`, `foo(a, ...[a, b])`, `new Foo(...[a, b])`, `foo(...[])`, `foo(...[,])` (holes preserved as missing arguments), including trailing commas `foo(...[a,],)` and parenthesized forms. Not fired when spreading an identifier `foo(...args)`.","commonSituations":"Code that forwards a fixed set of options, e.g. `setupServer(...[...importHandlers])` or `push(...['p50', 'p75'])`, often from refactors that turned variables into literals. Hits projects with the oxlint correctness category enabled.","solutions":["Pass the elements directly: `foo(...[a, b])` -> `foo(a, b)`.","Apply the rule's autofix; for `foo(...[])` it removes the argument entirely.","If the array is built dynamically, spread the variable instead (`foo(...args)`), which the rule accepts.","Disable inline when the literal-spread is load-bearing (for example generated code)."],"exampleFix":"// before\nfoo(...[a, b]);\nnew Foo(...[a]);\n\n// after\nfoo(a, b);\nnew Foo(a);","handlingStrategy":"validation","validationCode":"# detect call/new spreading an array literal\nrg -n --type js -U '(?:\\w+\\s*\\(|new\\s+\\w+\\s*\\()(?:[^,)]*,\\s*)?\\.\\.\\.\\[' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List arguments directly instead of spreading literals.","Only spread variables or computed arrays (`fn(...args)` is fine).","Watch for this pattern in generated/hand-edited config code; the autofix is safe."],"tags":["lint","oxlint","unicorn","spread","function-calls","arguments","correctness"],"backgroundTag":"useless-spread","analyzedSha":"a3d33dda7cb69da23db4fcaa2c0c05de61e760a1","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}