-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve no-array-mutation: allow slice().sort(...) #88
Comments
In this case we would have to detect that the intention was not to mutate even though an mutative method was called ( |
Agreed about using utility functions being undesirable. Beyond the import concern, they're a big readability impact because you have to pass the array as a param instead of chaining it, which is ugly if e.g. there are already several preceding map()/filter()/etc calls being chained. Adding an option for this behavior seems reasonable to make everyone happy. I can probably find time to make a PR for this if/when you're okay with the idea, but I'm just as happy if someone else does it. |
I would say we would want to go for a more generic approach than simply allowing I can look into making a PR for this tonight sometime. |
@RebeccaStevens That sounds like a nice approach! Do you still think it should be an option or should the rule always work like this? |
Hmmmmm, I'm not sure actually. |
I've created a PR for this. I went with adding this as an option called Let me know if you can think of a better name for this option. |
I was going to say |
@jonaskello const foo = () => [3, 1, 2];
const sortedFoo = foo().sort(); Although this doesn't use one of the built in array accessor methods, Pros
Cons
Should I open a new issue for this? |
I'm trying to think of the use cases for this addition. The current implementation allows the built-in |
Is it possible to improve
no-array-mutation
(added in #84) to allow code like this?Since
slice()
creates a copy this is effectively immutable, but it still triggers the lint rule. As a result, my code is littered with// tslint:disable-next-line:no-array-mutation
, which isn't ideal.(I'm assuming that there isn't a better way to sort an array that I'm not aware of.)
The text was updated successfully, but these errors were encountered: