Skip to main content

list-all-equatable-fields

added in: 1.2.0
warning
🛠

Warns when a field is not added to props getter of a class that extends Equatable or EquatableMixin.

note

This rule is specific to equatable package. Enable it only if you use this package.

info

The fix for this rule is available only in "Teams" version.

Example

❌ Bad:

class AnotherPerson extends Equatable {
const AnotherPerson(this.name, this.age);

final String name;

final int age;


List<Object> get props => [name]; // LINT
}

class AndAnotherPerson extends Equatable {
static final someProp = 'hello';

const AndAnotherPerson(this.name);

final String name;


List<Object> get props => [name];
}

class SubPerson extends AndAnotherPerson {
const SubPerson(this.value, String name) : super();

final int value;


List<Object> get props {
return super.props..addAll([]); // LINT
}
}

class EquatableDateTimeSubclass extends EquatableDateTime {
final int century;

EquatableDateTimeSubclass(
this.century,
int year, [
int month = 1,
int day = 1,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0,
]) : super(year, month, day, hour, minute, second, millisecond, microsecond);


List<Object> get props => super.props..addAll([]); // LINT
}

✅ Good:

class AnotherPerson extends Equatable {
const AnotherPerson(this.name, this.age);

final String name;

final int age;


List<Object> get props => [name, age];
}

class AndAnotherPerson extends Equatable {
static final someProp = 'hello';

const AndAnotherPerson(this.name);

final String name;


List<Object> get props => [name];
}

class SubPerson extends AndAnotherPerson {
const SubPerson(this.value, String name) : super();

final int value;


List<Object> get props {
return super.props..addAll([value]);
}
}

class EquatableDateTimeSubclass extends EquatableDateTime {
final int century;

EquatableDateTimeSubclass(
this.century,
int year, [
int month = 1,
int day = 1,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0,
]) : super(year, month, day, hour, minute, second, millisecond, microsecond);


List<Object> get props => super.props..addAll([century]);
}