sindresorhus/eslint-plugin-unicorn

`no-useless-spread` it is not safe to remove spread in `[...foo.concat(bar)]`

已關閉

#2,480 建立於 2024年10月16日

 (4 則留言) (0 個反應) (0 位負責人)JavaScript (468 個分叉)user submission
docshelp wanted

倉庫指標

星標
 (5,022 顆星)
PR 合併指標
 (平均合併 1天 16小時) (30 天內合併 399 個 PR)

描述

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/2b469bee475a8f3f2767f4669864acdd89654017/test/no-useless-spread.mjs#L259

[!NOTE] The concat() method preserves empty slots if any of the source arrays is sparse.

via MDN

const foo = new Array(5);
const bar = new Array(5);

const cat = [...foo.concat(bar)];
// now we got a new array with undefined x 10
// but foo.concat(bar) is empty x 10.
// It's not what we want.

貢獻者指南