prefer-contains
Suggests using .contains
instead of .indexOf
when checking for the presence of an element.
Example
❌ Bad:
void fn() {
final list = [1, 2, 3];
if (list.indexOf(1) == 2) {}
if (list.indexOf(1) == -1) {} // LINT
if (list.indexOf(1) != -1) {} // LINT
}
✅ Good:
void fn() {
final list = [1, 2, 3];
if (list.indexOf(1) == 2) {}
if (!list.contains(1)) {}
if (list.contains(1)) {}
}