メインコンテンツにスキップ

matching_super_parameters

安定版

スーパーパラメータ名を一致させます。

詳細

#

実行してください。対応するスーパークラスコンストラクタのパラメータ名と一致するスーパーパラメータ名を使用します。

悪い例

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 > rules の下に matching_super_parameters: true を追加してください。

analysis_options.yaml
yaml
linter:
  rules:
    matching_super_parameters: true