Why this matters
Making the parameter to `==` nullable can introduce unexpected behavior. Always use a non-nullable parameter to prevent null reference errors.
Ensure that parameters to `==` are non-nullable. Avoid using nullable parameters as they can introduce unexpected behavior and null reference errors.
Making the parameter to `==` nullable can introduce unexpected behavior. Always use a non-nullable parameter to prevent null reference errors.
Side-by-side examples engineers can pattern-match during review.
class Person {
final String title;
// ···
bool operator ==(Object? other) =>
other != null && other is Person && title == other.title;
}class Person {
final String title;
// ···
bool operator ==(Object other) => other is Person && title == other.title;
}class Person {
final String title;
// ···
bool operator ==(Object? other) =>
other != null && other is Person && title == other.title;
}class Person {
final String title;
// ···
bool operator ==(Object other) => other is Person && title == other.title;
}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.