-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update unnecessary_statements
to report tear-offs but not getters
#57718
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
Comments
Thanks. I took a shot at implementing, but I'm not too happy with the result I added code for three cases: PrefixExpression, PrefixedIdentifier and SimpleIdentifier. To guesstimate if something is a tearoff I just check if bestType is FunctionType. But this has two problems: It causes false positives for getters than return functions; I can live with that. Thanks! |
We should be able to improve this by making the conditions more specific. It sounds like we just need to include a condition to see whether the element associated with the node is a getter. |
I'm late to the party but have a few thoughts to add: This discussion is almost exactly like another one: constructors. I personally don't think this is good code:
but it happens more than you'd think, especially in tests when people are asserting that constructors can throw. This reminds me a lot of the reasons why we're removing getters! If we make an I will throw out one wart here. It's not a problem as currently written but it could maybe? become one. Currently the lint is careful to lint different branches of a ternary and short-circuited operators:
It's not necessarily invalid to switch that around to lint a ternary only when both branches are themselves unnecessary.
Especially when you consider that there are a number of branching operators in dart ( This would become an open doorway to the lints we break out of Currently it will be fine:
but if we wanted to say, make a new lint named I don't think it will happen. But I think its an interesting risk to splitting apart |
In dart-archive/linter#1014, @bwilkerson offered:
and I agree.
The text was updated successfully, but these errors were encountered: