sindresorhus/eslint-plugin-unicorn

Rule proposal: `prefer-change-array-by-copy`

Open

#1,514 建立於 2021年9月8日

在 GitHub 查看
 (14 留言) (14 反應) (0 負責人)JavaScript (5,022 star) (468 fork)user submission
help wantednew rule

描述

"Change Array by copy" proposal

Fail

array.reverse();
array.sort();
const array = [...foo];
array.splice(0, 1);
const array = [...foo];
array[1] = 'changed';

Pass

array = array.toReversed();
array = array.toSorted();
const array = foo.toSpliced(0, 1);
const array = foo.with(1, 'changed');

貢獻者指南