avoid-unnecessary-type-assertions
preset: recommended
Warns about unnecessary usage of the is
operator, and whereType
and whereNotNull
methods.
Example​
Example 1: check is same type​
class Example {
final myList = <int>[1, 2, 3];
void main() {
final result = myList is List<int>; // LINT
myList.whereType<int>();
}
}
Example 2: whereType method​
main(){
['1', '2'].whereType<String?>(); // LINT
}
Example 3: patterns​
class Animal {}
class HomeAnimal extends Animal {}
void main() {
final animal = Animal();
if (animal case HomeAnimal result) {}
if (animal case HomeAnimal()) {}
if (animal case Animal result) {} // LINT
if (animal case Animal()) {} // LINT
}