avoid-generics-shadowing
preset: recommended
Warns when a generic type shadows an existing top-level (class, mixin, typedef or enum) declaration.
Shadowing existing declarations can be extremely confusing when it comes to parameters or variables annotated with a generic type that looks close to a class name.
Example
❌ Bad:
class SomeClass {
// LINT: This generic type shadows an existing type. Try renaming this type.
void method<MyEnum>(MyEnum p) {}
// LINT: This generic type shadows an existing type. Try renaming this type.
AnotherClass anotherMethod<AnotherClass>() {}
}
class AnotherClass {}
enum MyEnum { first }
✅ Good:
class SomeClass {
void method<T>(T p) {} // Correct, different name
R anotherMethod<R>() {} // Correct, different name
}
class AnotherClass {}
enum MyEnum { first }