sindresorhus/eslint-plugin-unicorn

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

Geschlossen

#1.514 geöffnet am 08.09.2021

 (14 Kommentare) (14 Reaktionen) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
help wantednew rule

Repository-Metriken

Stars
 (5.022 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)

Beschreibung

"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');

Contributor Guide