sindresorhus/eslint-plugin-unicorn
Rule proposal: Prevent returning/assigning mutating array methods
Chiusa
#1743 aperta il 1 mar 2022
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
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();