matching-super-parameters
Same as matching_super_parameters in Dart lints
- Group
- Style
- Path
lint/style/matching-super-parameters- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 260 of 512
Flags positional super parameters named differently from the super constructor's corresponding parameter.
A positional super.x parameter is forwarded by position, so its name is
free — but giving it a different name from the parameter it fills in the
super constructor misleads readers about which value goes where.
class Rectangle {
final int width, height;
Rectangle(this.width, this.height);
}
class ColoredRectangle extends Rectangle {
ColoredRectangle(
super.height, // flagged: corresponds to `width`
super.width, // flagged: corresponds to `height`
);
}
The super constructor is the one invoked by super(...) / super.name(...)
in the initializer list, or the superclass's unnamed constructor. The rule
stays silent when that constructor cannot be resolved.
Invalid
class Rectangle {
final int width;
final int height;
Rectangle(this.width, this.height);
Rectangle.square(int size)
: width = size,
height = size;
}
class ColoredRectangle extends Rectangle {
final String color;
ColoredRectangle(
this.color,
super.height,
super.width,
);
}
class Square extends Rectangle {
Square(super.side) : super.square();
}
class Base {
Base(int a, [int? b]);
}
class Child extends Base {
Child(super.x);
}
class OptionalChild extends Base {
OptionalChild(super.a, [super.c]);
}
class PrivateBase {
PrivateBase(int _channel);
}
class PublicChild extends PrivateBase {
PublicChild(super.channel);
}
class PrimaryMismatch(super.height, super.width) extends Rectangle;
class NamedPrimaryMismatch(super.side) extends Rectangle {
this : super.square();
} this.color, super.height, super.height, super.width,class Square extends Rectangle { Square(super.side) : super.square();class Child extends Base { Child(super.x);class OptionalChild extends Base { OptionalChild(super.a, [super.c]);class PublicChild extends PrivateBase { PublicChild(super.channel); class PrimaryMismatch(super.height, super.width) extends Rectangle; class PrimaryMismatch(super.height, super.width) extends Rectangle; class NamedPrimaryMismatch(super.side) extends Rectangle {Valid
class Rectangle {
final int width;
final int height;
Rectangle(this.width, this.height);
Rectangle.square(int size)
: width = size,
height = size;
}
class ColoredRectangle extends Rectangle {
final String color;
ColoredRectangle(this.color, super.width, super.height);
}
class Square extends Rectangle {
Square(super.size) : super.square();
}
// Named super parameters are matched by name already.
class Base {
Base({required int a});
}
class Child extends Base {
Child({required super.a});
}
// Ordinary parameters forwarded explicitly are not super parameters.
class Explicit extends Rectangle {
Explicit(int w, int h) : super(w, h);
}
// Unresolvable super constructors stay silent.
class Remote extends SomeUnknownBase {
Remote(super.anything);
}
// More super parameters than the super constructor has: not reported.
class Short {
Short(int a);
}
class PrimaryMatch(super.width, super.height) extends Rectangle;
class NamedPrimaryMatch(super.size) extends Rectangle {
this : super.square();
}Configure matching-super-parameters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"matching-super-parameters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/matching-super-parameters: <reason>More style rules
- member-ordering
member-orderingFlags class members declared out of the configured order.
- missing-whitespace-between-adjacent-strings
missing_whitespace_between_adjacent_stringsrecommendedFlags adjacent string literals that join two words without a space between them.
- newline-before-break
Requires a blank line before a break that follows another statement.
- newline-before-case
Requires a blank line between successive switch statement case clauses.
- newline-before-constructor
Requires a blank line before constructors following another member.
- newline-before-continue
Requires a blank line before a continue that follows another statement.
- newline-before-method
Requires a blank line before method declarations following another member.
- newline-before-return
newline-before-returnFlags
returnstatements that are not preceded by a blank line.