prefer-overriding-parent-equality
preset: recommended
Warns when a parent class implements hashCode
and ==
, but the child class does not implement them.
Not providing an implementation in the child class can lead to tricky bugs where equality checks don't work as expected.
Example
❌ Bad:
class SomeClass {
int get hashCode => 1;
bool operator ==(Object other) {
return super == other;
}
}
// LINT
class AnotherClass extends SomeClass {
final String value;
AnotherClass(this.value);
}
✅ Good:
class SomeClass {
int get hashCode => 1;
bool operator ==(Object other) {
return super == other;
}
}
class CorrectClass extends SomeClass {
final String value;
CorrectClass(this.value);
int get hashCode => 1;
bool operator ==(Object other) {
return super == other;
}
}