avoid-shadowed-extension-methods
- Group
- Suspicious
- Path
lint/suspicious/avoid-shadowed-extension-methods- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 136 of 512
Flags extension instance methods and accessors hidden by their target's members.
Instance members take precedence over implicit extension invocation, so a colliding extension member needs an explicit extension override to be called. Rename it instead. The target is resolved by declaration identity, including aliases and inherited members; getters, fields and setters can also hide a method. Static extension declarations and other extensions do not compete. Unresolved, dynamic and nullable targets are skipped; type parameters are checked only when their resolved non-nullable bound proves the collision. This checks extension declarations, not local variables inside extensions. SDK members absent from the precise instance-signature inventory are skipped.
Invalid
class Base {
void inherited() {}
}
class Target extends Base {
void run() {}
int get size => 0;
int field = 0;
set setting(int value) {}
}
typedef Alias = Target;
extension Hidden on Target {
void run() {}
void inherited() {}
void size() {}
void field() {}
int get setting => 1;
}
extension Aliased on Alias {
void run() {}
}
extension Bounded<T extends Target> on T {
void inherited() {}
}
extension on Target {
set size(int value) {}
}extension Hidden on Target { void run() {} void run() {} void inherited() {} void inherited() {} void size() {} void size() {} void field() {} void field() {} int get setting => 1;extension Aliased on Alias { void run() {}extension Bounded<T extends Target> on T { void inherited() {}extension on Target { set size(int value) {}Valid
class Target {
void run() {}
static void staticOnly() {}
}
class Unrelated {
void differentOwner() {}
}
extension Renamed on Target {
void customRun() {}
void differentOwner() {}
void staticOnly() {}
static void run() {}
}
extension NullableTarget on Target? {
void run() {}
}
extension DynamicTarget on dynamic {
void run() {}
}
extension First on Target {
void extensionOnly() {}
}
extension Second on Target {
void extensionOnly() {}
}
extension Unbounded<T> on T {
void run() {}
}
class OrdinarySubclass extends Target {
void run() {}
}
extension StaticIntMember on int {
void parse() {}
}
extension StaticBigIntMember on BigInt {
void two() {}
}
extension StaticDurationMember on Duration {
void zero() {}
}Configure avoid-shadowed-extension-methods
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-shadowed-extension-methods": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-shadowed-extension-methods: <reason>More suspicious rules
- avoid-shadowing
Flags local bindings and parameters that hide an enclosing type's member.
- avoid-shadowing-type-parameters
avoid_shadowing_type_parametersrecommendedFlags a type parameter that shadows a type parameter of an enclosing declaration.
- avoid-suspicious-super-overrides
Finds getters hiding fields supplied via the immediate super constructor's
this.formals or declaring primary-constructor parameters. - avoid-throw-in-catch-block
avoid-throw-in-catch-blockFlags
throwstatements inside acatchblock. - avoid-top-level-members-in-teststest
Requires public declarations in test files, except main, to be private.
- avoid-types-as-parameter-names
avoid_types_as_parameter_namesrecommendedFlags implicit formal parameters, catch variables, and type parameters that shadow a type in their enclosing scope.
- avoid-unrelated-type-assertions
avoid-unrelated-type-assertionsrecommendedFlags an
ischeck proven impossible by canonical resolved types. - banned-usage
Ban resolved API references, not identifiers that merely share their spelling.