-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[linter] New lint to suggest avoid bool == true
and bool == false
#60614
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
@devoncarew @lrhn @natebosch Is this a lint that we'd be likely to add to the recommended set? |
Yes. It's a classic unnecessary code lint. I don't remember if we have something similar for
|
To note, I found this when working on https://dart-review.googlesource.com/c/sdk/+/424560 at
|
This reminds me that (I'm not sure we should, but) we can test boolean operations with the same expression on both sides (immutable expressions, of course - private final fields, local variables, etc):
Also:
This one is more complex but it can help if we are willing to implement (found at flutter/flutter#156928 (comment))
|
Most of the unnecessary code diagnostics are warnings so that they don't need to be enabled by users. Sounds like we should consider making these warnings too.
At one time we had a lint that attempted to identify conditions whose value was always the same. It ended up being a nightmare, so it's going to take a lot of work to convince me that we want to go down that path again.
More complex, but not necessarily harder to read. I don't think I'd want to flag this kind of case, but I could imagine adding an assist to 'Simplify expression' for some cases like this. I'm not convinced that it has enough value to warrant the cost of implementation and maintenance, though, so I'm not proposing that we add it. |
The Everything that applies to |
We have
use_if_null_to_convert_nulls_to_bools
to trigger the first case, but no diagnostic in the other two cases:CC @srawlins @bwilkerson
The text was updated successfully, but these errors were encountered: