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

example.dartdart
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();
}
The super parameter named `height` does not share the same name as the corresponding parameter in the super constructor, `width`.
13 this.color,
14 super.height,
The super parameter named `width` does not share the same name as the corresponding parameter in the super constructor, `height`.
14 super.height,
15 super.width,
The super parameter named `side` does not share the same name as the corresponding parameter in the super constructor, `size`.
19class Square extends Rectangle {
20 Square(super.side) : super.square();
The super parameter named `x` does not share the same name as the corresponding parameter in the super constructor, `a`.
27class Child extends Base {
28 Child(super.x);
The super parameter named `c` does not share the same name as the corresponding parameter in the super constructor, `b`.
31class OptionalChild extends Base {
32 OptionalChild(super.a, [super.c]);
The super parameter named `channel` does not share the same name as the corresponding parameter in the super constructor, `_channel`.
38class PublicChild extends PrivateBase {
39 PublicChild(super.channel);
The super parameter named `height` does not share the same name as the corresponding parameter in the super constructor, `width`.
41
42class PrimaryMismatch(super.height, super.width) extends Rectangle;
The super parameter named `width` does not share the same name as the corresponding parameter in the super constructor, `height`.
41
42class PrimaryMismatch(super.height, super.width) extends Rectangle;
The super parameter named `side` does not share the same name as the corresponding parameter in the super constructor, `size`.
43
44class NamedPrimaryMismatch(super.side) extends Rectangle {

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "matching-super-parameters": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/matching-super-parameters: <reason>