avoid-map-keys-contains
preset: recommended
Warns when Map's .keys.contains
is used instead of containsKey
.
.keys.contains
is 6000 times slower than containsKey
and should be avoided.
Example
❌ Bad:
void main() {
final map = {'hello': 'world'};
// LINT: Avoid '.keys.contains'. Try using '.containsKey' instead.
map.keys.contains('hello');
}
✅ Good:
void main() {
final map = {'hello': 'world'};
map.containsKey('hello'); // Correct, uses 'containsKey'
}