sindresorhus/eslint-plugin-unicorn
Rule proposal: Prevent returning/assigning mutating array methods
Geschlossen
#1.743 geöffnet am 01.03.2022
help wantednew rule
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 4h 30m) (26 gemergte PRs in 30 T)
Beschreibung
Description
Prevent returning or assigning mutating array methods, to improve readability and also protect against accidentally mutating an array in-place when you shouldn't. Array#sort(), Array#fill(), Array#reverse().
Fail
console.log(foo.sort());
const sorted = foo.sort();
Pass
foo.sort();
console.log(foo);
foo.sort();
I guess we should also allow the case where there's an intermediate array?
const sorted = foo.map(…).sort();