Why this matters
Using constant patterns with type literals can lead to incorrect assumptions and unintended behavior.
Do not use constant patterns with type literals as it can lead to unexpected behavior. Prefer direct type checking instead.
Using constant patterns with type literals can lead to incorrect assumptions and unintended behavior.
Side-by-side examples engineers can pattern-match during review.
bool isANumber(Object? o) {
if (o case num) {
return true;
}
return false;
}bool isANumber(Object? o) {
if (o case num _) {
return true;
}
return false;
}bool isANumber(Object? o) {
if (o case num) {
return true;
}
return false;
}bool isANumber(Object? o) {
if (o case num _) {
return true;
}
return false;
}From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.