-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer should lint if a statement consists of only an ==
expression
#30793
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
I keep meaning to argue for my lint rule that catches this dart-archive/linter#756 but haven't really invested the time to push through controversy. Will gladly note that this caused a bug for you there :) |
@MichaelRFairhurst I just want to know that this rule has a near zero false positive rate. Some of the cases you proposed catching can clearly have side-effects, and the false positive rate might just be high enough to make the lint useless. Should be easy enough to validate by running the lint over some reasonable code. (Technically, even |
Oh man, yeah, a lint to just flag every "useless" line would be fantastic. FWIW, we would enable such a lint on Flutter's codebase in a second. I'm curious to see what errors it reports today! We'd be happy to have our code base be a place to test for false positives. |
Flutter was one of the code bases I suggested as a test. |
Yes -- I should say, I have not yet run the tests that Brian suggested. And a good test I might add. So its not fair to say that controversy blocked me, but rather, that the possibility of controversy blocked me. Which is on me and me only. Edit: but it is still on my list of things to get to. |
Well I definitely am eager to see the results of running it on Flutter, whether or not you do anything with it afterwards! |
I'll try to consider this an impetus to not leave it there dying :) I also didn't know how to run such a test, but I've started the process of figuring that out by asking Brian on the PR :) And I'll assign myself here. Edit: Seems I can't assign anyone on tickets here |
Looks like the main false-positive is calling a constructor. That should be treated like calling a method (e.g. |
I'd also take that as an argument that a constructor that you call for its side-effect should probably have been a static method. Creating an object and immediately discarding it is, at the very least, confusing.
|
In general I agree. The cases I found when spot-checking the above fall into the following buckets:
These all seem like valid use cases. I think therefore that the lint should be changed to allow calling |
Big thanks to @a14n for running on flutter for me! I agree with your findings @Hixie , especially "Calling constructors that have side-effects from tests, to verify what the side-effects are. If we were to take a reference, the analyzer would complain we had an unused variable." Seems like a simple reasonable change to allow constructors. I'll get to that by EOD |
Almost missed my EOD deadline! that PR has been updated. |
Brian merged this PR. After the next linter+sdk release, simply use the rule |
I would like the following to flag a lint:
It would have caught a bug that was reported today (it's especially hard to tell that something fishy is going on when both "a" and "false" are actually much longer expressions).
The text was updated successfully, but these errors were encountered: