list_all_equatable_fields
v0.4.0 Warning Fix Collection & Type
Classes that extend Equatable or use EquatableMixin must include all declared instance fields in the props getter. Missing fields means two instances with different values for those fields will be considered equal, leading to hard-to-find bugs.
Why use this rule
Section titled “Why use this rule”Forgetting to add a field to props silently breaks equality comparisons. Two objects that differ only in the missing field will appear equal, which can cause incorrect behavior in collections, state management, and testing.
See also: equatable package
import 'package:equatable/equatable.dart';
// Missing 'age' from propsclass BadPerson extends Equatable { const BadPerson(this.name, this.age); final String name; final int age;
@override List<Object?> get props => [name];}
// Missing all fields from propsclass BadEmpty extends Equatable { const BadEmpty(this.x, this.y); final double x; final double y;
@override List<Object?> get props => [];}
// Using EquatableMixin with missing fieldclass BadMixinPerson with EquatableMixin { BadMixinPerson(this.name, this.email); final String name; final String email;
@override List<Object?> get props => [name];}import 'package:equatable/equatable.dart';
// All fields are listed in propsclass GoodPerson extends Equatable { const GoodPerson(this.name, this.age); final String name; final int age;
@override List<Object?> get props => [name, age];}
// All fields listed with EquatableMixinclass GoodMixinPerson with EquatableMixin { GoodMixinPerson(this.name, this.email); final String name; final String email;
@override List<Object?> get props => [name, email];}
// Static fields are correctly excludedclass PersonWithStatic extends Equatable { const PersonWithStatic(this.name); final String name; static const maxNameLength = 100;
@override List<Object?> get props => [name];}
// No fields means empty props is fineclass EmptyEquatable extends Equatable { const EmptyEquatable();
@override List<Object?> get props => [];}Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: list_all_equatable_fields: false