linter icon indicating copy to clipboard operation
linter copied to clipboard

Flag comparisons between non-nullable booleans and literals

Open jamesderlin opened this issue 6 years ago • 2 comments

In many other programming languages, things like someBooleanExpression == true are a code smell and should be simplified to just someBooleanExpression. It's simpler and is easier to read.

I've seen a lot of Dart code that does that, but changing those sites is tricky since it's often unclear whether someBooleanExpression is potentially null. (For such cases, someBooleanExpression ?? false is a clearer way to express that intent, but I digress.)

When NNBD is enabled, it would be nice if the linter could flag == or != comparisons between non-nullable bools and boolean literals so that such sites could be cleaned up if possible.

Examples With non-nullable bools:

someBool == true or true == someBool (equivalent to someBool) someBool != false or false != someBool (equivalent to someBool) someBool == false or false == someBool (equivalent to !someBool) someBool != true or true != someBool (equivalent to !someBool)

jamesderlin avatar Sep 04 '19 16:09 jamesderlin

/cc @stereotype441 for thoughts on NNBD implications

pq avatar Sep 04 '19 16:09 pq

Sounds good to me!

stereotype441 avatar Sep 04 '19 17:09 stereotype441