Repository navigation
ref: Prefer spread over Array.from() repo-wide - #1724
Merged
Merged
Conversation
Enable unicorn/prefer-spread at the root and apply it everywhere.
Single-argument Array.from(x), array .slice() copies, and array
.concat() now use spread.
Spread is the stricter choice. TypeScript rejects spreading a
non-iterable, and so does the runtime. Array.from accepts any
{ length } object and returns [] for numbers and ArrayBuffers.
V8 runs both forms through the same fast path. Array.from(x, fn)
and Array.from({ length }) are still allowed.
Turning Array.from(string) into a spread trips
typescript/no-misused-spread. Code-unit checks now use split(""),
which matches their charCodeAt logic. The three places that count
code points on purpose keep the spread with a reasoned suppression.
String#concat in docs-mcp was a false positive and is now a template
literal. Uint8Array test assertions use subarray() so the copy
stays an Array.
Co-Authored-By: BYK <burak.kaya@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
approved these changes
Oct 29, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #1721. That PR standardized the CLI on
Array.from(x). After looking into why the ecosystem defaults to spread, the evidence points the other way, so this enables Oxlint's built-inunicorn/prefer-spreadat the root and applies it across the repo.Why spread
[...x]whenxisn't iterable, and the runtime throws.Array.fromaccepts any{ length }object (it type-checks asunknown[]) and quietly returns[]for numbers andArrayBuffers. Sindre Sorhus gave this as the reason for the rule (unicorn#120): array-likes are a legacy quirk, and iterables are the real protocol.Array.from(iterable)reuses them (v8.dev). On Node 22 here, the two are within noise for arrays, Sets,map.values(), and strings at 10, 1k, and 100k elements. Results for Map entries and generators are mixed, but small.Array.from(x, fn)advantage doesn't show up. Airbnb 4.6 recommends it to avoid an intermediate array. On Node 22,Array.from(set, fn)measured 2–4× slower than[...set].map(fn), because the mapping form skips the fast path. The rule still allows it, but it buys nothing.[...a],[...a, ...b], and[...path, key]read as one family. ref(cli): Prefer Array.from() over spread to copy iterables #1721's rule left a split where a lone spread becameArray.frombut a multi-part spread stayed.Array.fromis the right tool:Array.from({ length: n }, fn), array-likes, and any call with a map function.What changed
.oxlintrc.json:"unicorn/prefer-spread": "error"in the root rules.Array.from(x)and array.slice()copies across the CLI, MCP core, Cloudflare, docs-mcp, test client, and scripts (75 sites). The rest were fixed by hand:.concat()(5 sites): now[...a, ...b]and[...path, key].String#concatinapps/docs-mcp(false positive): now a template literal.Array.from(str)into[...str]trips the already-enabledtypescript/no-misused-spread. The two forms behave the same at runtime, so the lint split is only syntax. I went by what each site means:charCodeAtpredicates in issue-linking,ci-projects.mjs, and the delta-upgrade test helpers) now usesplit(""). That's typescript-eslint's recommended form, and it matches thecharCodeAtlogic exactly.oxlint-disable-next-line.infrastructure.test.tsusesubarray(), so[...]still produces an Array.no-useless-spreadassumes.slice()returns an Array.docs/contributing/coding-guidelines.md.Verification
pnpm run lint(oxlint, oxfmt, ast-grep): cleanpnpm run tsc(all packages): cleantest:ci-projects: 94 passedmainin this sandbox (completions,code-scanner,file-changes,telemetry,upgrade).via BYK.
--
View Junior Session in Sentry