-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lint that warns about comparing boolean expressions against literals #58533
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
Except in cases where the non-literal operand has the type |
This makes sense to me, specifically if |
For the bool case, I prefer EDIT: and related lint (Sorry for the derail!) @munificent: any additional thoughts? |
If you willing to try a custom analyzer plugin called Dart Code Metrics, we have this rule implemented https://dartcodemetrics.dev/docs/rules/common/no-boolean-literal-compare among with other useful lint rules. |
That's really neat! However, I still think it will be far more beneficial if this rule was included inside the base analyzer since not everyone can use a custom analyzer plugin. |
Could you elaborate on that? It's really important for us to eliminate all blockers from our side. |
I'm 100% on board with this lint. I'm actually surprised we don't have it already. |
Just my two cents, please take it with a grain of salt: In my opinion, most of the reasons aren't technical. Some organizations may be reluctant to adopt it simply due to internal policies. (Libraries must be audited etc.). Another issue is that in my opinion, most people may not be even aware that dart-code-metrics exist. They can't really use something if they aren't even aware that it exists. Personally I didn't even know that the dart-code-metrics existed before you mentioned it in this issue haha. Sorry for being off-topic. |
Thank you very much for the answer! I completely agree with that and it's what we're trying to solve right now. Sorry for the off-topic too. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the rule you'd like to see implemented
Comparing boolean expressions against a boolean literal is almost always a code smell. Less experienced developers are more likely to perform such comparisons. Therefore, I think it will be beneficial to have a lint that warns against such comparisons.
In my opinion, the lint should be applied inside all conditional expressions and maybe even all comparisons.
The lint would also need to take into account if the boolean literal is on the LHS of the comparison.
The text was updated successfully, but these errors were encountered: