-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[linter] noop_primitive_operations #59684
Comments
While it might make sense to lint the use of void main() {
var l = [1, 2, 3];
print(identical(l, l.toList()));
} it will print So, invoking If we were to decide to extend the lint (or create a new one) to catch this case, it should also catch the use of |
Is there any reason why you decided to make toList on a list, not a no opt? I suspect the use of toList on a list has been more often a mistake than something intentional |
I've just recently discovered that behaviour. I mostly use the spread operator or I noticed that all the other noop operations are on primitive types and that means that they basically can't have two instances with the same values if they are not So I understand the gist now, but I do agree this is not as intuitive for someone new to the language. |
It would also be a good addition for cases where you had a method that returned an iterable and you were using |
@lrhn For the design of |
The Since a If you want "a new list, but only if this isn't already a list", you need to check whether you already have a list. There is no built-in feature which does that, because the usual reasons one may have for wanting a list to begin with are either to have your own copy that you can trust not to change (and a list is just the simplest data structure for that), or you want to do random access (like sorting or similar), and then you usually still don't want the length to change while you're random-accessing. Or you want to iterate more than once, but then you also want/expect the two iterations to have the same elements. And if you really, really just want a list, even if someone might change it (you'll just tell them not to), maybe the parameter should be typed as |
toList
on a list should be considered anoop_primitive_operations
and be added to the linterThe text was updated successfully, but these errors were encountered: