matching_super_parameters
使用相符的超類別參數名稱。
此規則自 Dart 3.0 起提供。
詳細資訊
#務必使用與對應的超類別建構子的參數名稱相符的超類別參數名稱。
不良範例
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
檔案中,將 matching_super_parameters
新增至 linter > rules 底下。
analysis_options.yaml
yaml
linter:
rules:
- matching_super_parameters
除非另有說明,否則本網站上的文件反映的是 Dart 3.6.0。頁面最後更新於 2024-07-03。檢視原始碼或回報問題。