linter
linter copied to clipboard
Flag comparisons between non-nullable booleans and literals
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)
/cc @stereotype441 for thoughts on NNBD implications
Sounds good to me!