匹配超类参数
使用匹配的超类参数名称。
详细信息
#请务必使用与对应超类构造函数参数名称匹配的超类参数名称。
错误示例
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.
);
}
正确示例
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,
);
}
启用
#要启用 matching_super_parameters
规则,请在您的 analysis_options.yaml
文件中的 linter > rules 下添加 matching_super_parameters
analysis_options.yaml
yaml
linter:
rules:
- matching_super_parameters
如果您使用 YAML 映射语法配置 linter 规则,请在 linter > rules 下添加 matching_super_parameters: true
analysis_options.yaml
yaml
linter:
rules:
matching_super_parameters: true