avoid-collection-equality-checks
- Group
- Correctness
- Path
lint/correctness/avoid-collection-equality-checks- Default
- On (recommended)
- Origin
- Falcon
- Rule
- 32 of 512
Flags equality comparisons between non-constant SDK collections.
List, Set, and Map equality compares identity rather than contents. Use a collection equality helper instead. Comparisons between two constants are exempt, as are unrelated types (covered by unrelated-type-equality-checks), null comparisons, and custom collection classes that may override equality.
Invalid
void compare(List<int> a, List<int> b, Set<int> c, Set<int> d, Map<String, int> e, Map<String, int> f) {
print(a == b);
print(a != b);
print(c == d);
print(e != f);
print(a == const [1]);
print(<int>[1] == <int>[2]);
}void compare(List<int> a, List<int> b, Set<int> c, Set<int> d, Map<String, int> e, Map<String, int> f) { print(a == b); print(a == b); print(a != b); print(a != b); print(c == d); print(c == d); print(e != f); print(e != f); print(a == const [1]); print(a == const [1]); print(<int>[1] == <int>[2]);Valid
void compare(List<int> values, dynamic unknown) {
const a = [1];
const b = [1];
print(a == b);
print(const <int>{1} == const <int>{1});
print(const <String, int>{'x': 1} == const <String, int>{'x': 1});
print(values == null);
print(values == unknown);
print(values == 1);
print(1 == 2);
print(identical(values, values));
}
class ValueList implements List<int> {
@override
bool operator ==(Object other) => other is ValueList;
@override
int get hashCode => 0;
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
void custom(ValueList first, ValueList second) { print(first == second); }
void unrelated(List<int> integers, List<String> strings, Set<int> unique) {
print(integers == strings);
print(integers == unique);
}Configure avoid-collection-equality-checks
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-collection-equality-checks": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-collection-equality-checks: <reason>More correctness rules
- avoid-conditional-hooksrecommendedflutter_hooks
Flags hook calls in conditional branches, short-circuit operands, and loops.
- avoid-constant-assert-conditions
Flags assertions whose Boolean condition is statically constant.
- avoid-constant-conditions
Flags statically constant binary branch, loop, collection, and expression conditions.
- avoid-constant-switches
Flags switch statements and expressions with a statically constant subject.
- avoid-contradictory-expressionsrecommended
Flags pairs of conditions that are always false with
&&or true with||. - avoid-disposing-late-fieldsflutter
Avoid releasing late State fields that may be unset or initialized only by cleanup.
- avoid-duplicate-bloc-event-handlersrecommendedbloc
Flags later registrations of the same event type in a Bloc constructor.
- avoid-duplicate-cascades
Flags repeated field or index assignment targets within one cascade.