目次

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