matching_super_parameters
Use matching super parameter names.
This rule is available as of Dart 3.0.
Details
#DO use super parameter names that match their corresponding super constructor's parameter names.
BAD:
dart
class Rectangle {
final int width;
final int height;
Rectangle(this.width, this.height);
}
class ColoredRectangle extends Rectangle {
final Color color;
ColoredRectangle(
this.color,
super.height, // Bad, actually corresponds to the `width` parameter.
super.width, // Bad, actually corresponds to the `height` parameter.
);
}
GOOD:
dart
class Rectangle {
final int width;
final int height;
Rectangle(this.width, this.height);
}
class ColoredRectangle extends Rectangle {
final Color color;
ColoredRectangle(
this.color,
super.width,
super.height,
);
}
Usage
#To enable the matching_super_parameters
rule,
add matching_super_parameters
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- matching_super_parameters
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。