Closed tomsquest closed 5 years ago
Try this code:
myArray.reduce((acc, item) => {
// stuff here
return [
...acc,
item
];
}, []);
Yeah, that what I used. I thought that tslint-immutable could let a local array be pushed (even if the accumulator is not really local).
Is this different from ignore-local
(which is not available on no-array-mutation
?
All though I agree that being able to mutate an array locally makes sense in the example you gave, there is no easy way to detect the difference between that use case and a general use case.
The reason ignore-local
isn't available for this rule is because pretty much every use of an array is local - It's not that often that you would use an array outside of a function.
Thanks @RebeccaStevens. No problem, and spreading the array is very similar.
Given
"no-array-mutation": [true, "ignore-new-array"]
Giventslint-immutable": "6.0.1"
When using the following code:Then a linting error is returned
Mutating an array is not allowed.
.What is the appropriate way to push to a "local" array (the accumulator) with
no-array-mutation
enabled?