{"record":{"id":"d14a064c18aa7272","repo":"oxc-project/oxc","slug":"ctor-name-accepts-an-iterable-so-it-s-unneces","errorCode":null,"errorMessage":"`{ctor_name}` accepts an iterable, so it's unnecessary to convert the iterable to an array.","messagePattern":"`(.+?)` accepts an iterable, so it's unnecessary to convert the iterable to an array\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs","lineNumber":43,"sourceCode":"    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\nfn iterable_to_array_in_yield_star(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Using a spread operator here creates a new array unnecessarily.\")\n        .with_help(\"`yield*` can delegate to another iterable, so it's unnecessary to convert the iterable to an array.\")\n        .with_label(span)\n}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs#L25-L61","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-spread`. This variant (`iterable_to_array`) fires when a single spread of an iterable is wrapped in an array literal just to feed a consumer that accepts iterables natively: `new Set/Map/WeakSet/WeakMap([...])`, typed-array constructors, `Promise.all/allSettled/any/race([...])`, `Array.from([...])`, `TypedArray.from([...])`, and `Object.fromEntries([...])`. The `{ctor_name}` placeholder carries the consumer, e.g. `new Map(…)` or `Promise.all(…)`. An autofix removes the array wrapper and spread.","triggerScenarios":"`new Map([...iterable])`, `new Set([...iterable])`, `new WeakMap([...iterable])`, `new BigUint64Array([...iterable], byteOffset, length)`, `Promise.all([...iterable])`, `Promise.allSettled([...iterable])`, `Promise.any([...iterable])`, `Promise.race([...iterable])`, `Array.from([...iterable])`, `Uint8Array.from([...iterable])`, `Object.fromEntries([...iterable])`, including trailing commas. Not fired for namespaced callees (`new foo.Map(...)`), computed members (`Promise[all](...)`), or extra/mixed arguments like `new Map([...iterable], extraArgument)`.","commonSituations":"Wrapping Set/Map contents before construction out of array-era habit, and `Promise.all([...set])` patterns. Appears when the oxlint correctness category or unicorn plugin is enabled.","solutions":["Pass the iterable directly: `new Set([...iterable])` -> `new Set(iterable)`, `Promise.all([...items])` -> `Promise.all(items)`.","Apply the rule's autofix.","Keep the array wrapper only when you mix in extra elements (`[...iterable, extra]` is not flagged).","For non-iterable sources (plain objects), keep the current code; the rule only skips what it can prove."],"exampleFix":"// before\nconst set = new Set([...iterable]);\nconst results = await Promise.all([...tasks]);\n\n// after\nconst set = new Set(iterable);\nconst results = await Promise.all(tasks);","handlingStrategy":"validation","validationCode":"# detect iterable-accepting consumers receiving [...x]\nrg -n --type js -U '(?:new (?:Weak)?(?:Set|Map)|(?:Int8|Uint8|Float64|BigUint64)Array|Promise\\.(?:all|allSettled|any|race)|Array\\.from|Object\\.fromEntries)\\(\\[\\.\\.\\.' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass Sets, Maps, generators, and iterables straight into constructors and Promise combinators.","Reserve `[...x]` for consumers that truly require arrays (indexing, sort, JSON.stringify).","Enable unicorn/no-useless-spread in CI; its autofix is deterministic for this case."],"tags":["lint","oxlint","unicorn","spread","iterable","promise","set","map","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"}