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
ファイルのlinter > rulesセクションにmatching_super_parameters
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- matching_super_parameters
特に明記されていない限り、このサイトのドキュメントはDart 3.5.3を反映しています。最終更新日:2024年7月3日。 ソースコードを見る または 問題を報告する。