Rules / Style / use-super-parameters
use-super-parameters
Flags a constructor parameter forwarded verbatim to super(...) and used nowhere else.
Since Dart 2.17, a parameter that exists only to be passed straight through to
the superclass constructor can be declared as a super parameter — super.x —
which removes both the parameter declaration and the redundant super(x)
argument. Doing so cuts boilerplate and keeps subclass constructors in sync
with the base class automatically. The rule is conservative: it fires only
when the parameter is used exactly once across the entire constructor (all
initializers plus the body), forwarded either as a plain positional super
argument at the matching index or as a named argument super(x: x). Convert
it to a super. parameter.
Invalid
example.dartdart
// Parameters forwarded verbatim to super and used nowhere else.
class Base {
Base(int a);
Base.two(int a, int b);
Base.named({int? x});
}
class A extends Base {
A(int a) : super(a);
}
class B extends Base {
B(int a, int b) : super.two(a, b);
}
class C extends Base {
C({int? x}) : super.named(x: x);
}
class D extends Base {
D(int a) : super(a);
}
class E extends Base {
E(int a) : super(a);
}
Use a super parameter instead of forwarding a parameter to super.
8class A extends Base {
9 A(int a) : super(a);
∙
Use a super parameter instead of forwarding a parameter to super.
12class B extends Base {
13 B(int a, int b) : super.two(a, b);
∙
Use a super parameter instead of forwarding a parameter to super.
12class B extends Base {
13 B(int a, int b) : super.two(a, b);
∙
Use a super parameter instead of forwarding a parameter to super.
16class C extends Base {
17 C({int? x}) : super.named(x: x);
∙
Use a super parameter instead of forwarding a parameter to super.
20class D extends Base {
21 D(int a) : super(a);
∙
Use a super parameter instead of forwarding a parameter to super.
24class E extends Base {
25 E(int a) : super(a);
∙
Valid
example.dartdart
// Cases that must not be flagged.
class Base {
Base(int a);
Base.two(int a, int b);
}
class A extends Base {
A(int a) : super(a) {
print(a);
}
}
class B extends Base {
B(super.a);
}
class C extends Base {
C(int value) : super(value + 1);
}
class D extends Base {
D(int a, int b) : super.two(b, a);
}
class E extends Base {
E(int a, int b) : super.two(a, b) {
print(a);
print(b);
}
}
How to configure
Set the severity of use-super-parameters in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"style": {
"use-super-parameters": "error"
}
}
}
}