oxc-project/oxc · warning · OxcDiagnostic
Using a spread operator here creates a new array…
Error message
Using a spread operator here creates a new array unnecessarily.
What it means
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).
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).
Example fix
// before foo(...[a, b]); new Foo(...[a]); // after foo(a, b); new Foo(a);
Defensive patterns
Strategy: validation
Validate before calling
# detect call/new spreading an array literal rg -n --type js -U '(?:\w+\s*\(|new\s+\w+\s*\()(?:[^,)]*,\s*)?\.\.\.\[' src/
Prevention
- 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.
When it happens
Trigger: `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)`.
Common situations: 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.
Related errors
- ` ` accepts an iterable, so it's unnecessary to convert the…
- Empty fallbacks in spreads are unnecessary
- Using a spread operator here creates a new
- Using a spread operator here creates a new
- Found a useless array length check
AI-assisted analysis of oxc-project/oxc@a3d33dda7c (2026-08-20).
Data as JSON: /api/errors/d8fb205d051a7442.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs:37
AstNode,
ast_util::{
get_new_expr_ident_name, is_method_call, is_new_expression, outermost_paren_parent,
},
context::LintContext,
fixer::{RuleFix, RuleFixer},
rule::Rule,
};
fn spread_in_list(span: Span, arr_or_obj: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"Using a spread operator here creates a new {arr_or_obj} unnecessarily."
))
.with_help("Consider removing the spread operator.")
.with_label(span)
}
fn spread_in_arguments(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Using a spread operator here creates a new array unnecessarily.")
.with_help("Pass arguments directly instead of spreading an array.")
.with_label(span)
}
fn iterable_to_array(span: Span, ctor_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"`{ctor_name}` accepts an iterable, so it's unnecessary to convert the iterable to an array."
))
.with_help("Consider removing the spread operator.")
.with_label(span)
}
fn iterable_to_array_in_for_of(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Using a spread operator here creates a new array unnecessarily.")
.with_help("`for…of` can iterate over iterable, it's unnecessary to convert to an array.")
.with_label(span)
}
View on GitHub (pinned to a3d33dda7c)