avoid-referencing-subclasses
- Group
- Suspicious
- Path
lint/suspicious/avoid-referencing-subclasses- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 127 of 512
Keeps base classes independent from their transitive subclasses.
ignored-annotations replaces the default ["freezed", "Freezed", "unfreezed"].
Annotation names match the final name segment exactly, including case.
Invalid
class Base {
Child? field;
Child make() => throw 0;
void accept(Child value) {}
List<Grandchild> children = [];
Object create() => Child();
int staticValue() => Child.value;
bool test(Object value) => value is Child;
}
class Child extends Base { static int value = 1; }
class Grandchild extends Child {}
const FREEZED = 0;
@FREEZED
class ExactCaseBase {
ExactCaseChild? child;
}
class ExactCaseChild extends ExactCaseBase {}
mixin class MixinBase {
MixedSubclass? child;
}
class MixedSubclass with MixinBase {}class Base { Child? field; Child? field; Child make() => throw 0; Child make() => throw 0; void accept(Child value) {} void accept(Child value) {} List<Grandchild> children = []; List<Grandchild> children = []; Object create() => Child(); Object create() => Child(); int staticValue() => Child.value; int staticValue() => Child.value; bool test(Object value) => value is Child;class ExactCaseBase { ExactCaseChild? child;mixin class MixinBase { MixedSubclass? child;Valid
class Base {
Base? parent;
Unrelated? value;
Object factory(Object Child) => Child;
T generic<T>(T value) => value;
void shadow() {
final Child = () => Object();
Child();
}
Child genericShadow<Child>(Child value) => value;
}
class Child extends Base {}
class Unrelated {}
const freezed = 0;
@freezed
class GeneratedBase { GeneratedChild? child; }
class GeneratedChild extends GeneratedBase {}
class GenericBase<GenericChild> { GenericChild? value; }
class GenericChild extends GenericBase<int> {}
abstract class Repo { factory Repo() = RepoImpl; }
class RepoImpl implements Repo {}
class ConstraintBase { ConstrainedMixin? value; }
mixin ConstrainedMixin on ConstraintBase {}
class InterfaceBase { ViaInterface? value; }
class InterfaceOnly implements InterfaceBase {}
class ViaInterface extends InterfaceOnly {}
class Freezed { const Freezed({String? unionKey}); }
const unfreezed = 0;
@Freezed(unionKey: 'type')
class ConfiguredUnion { ConfiguredCase? value; }
class ConfiguredCase extends ConfiguredUnion {}
@unfreezed
class MutableUnion { MutableCase? value; }
class MutableCase extends MutableUnion {}Configure avoid-referencing-subclasses
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-referencing-subclasses": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-referencing-subclasses: <reason>More suspicious rules
- avoid-returning-null-for-void
avoid_returning_null_for_voidrecommendedFlags
return null;(and=> nullbodies) in synchronousvoidfunctions and asynchronousFuture<void>functions. - avoid-shadowed-extension-methods
Flags extension instance methods and accessors hidden by their target's members.
- 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.