跳到主要內容

sort_constructors_first

穩定
提供修正

在其他成員之前排序建構子宣告。

詳細資訊

#

務必在其他成員之前排序建構子宣告。

不良範例

dart
abstract class Visitor {
  double value;
  visitSomething(Something s);
  Visitor();
}

良好範例

dart
abstract class Animation<T> {
  const Animation(this.value);
  double value;
  void addListener(VoidCallback listener);
}

啟用

#

若要啟用 sort_constructors_first 規則,請在您的 analysis_options.yaml 檔案中,於 linter > rules 下方新增 sort_constructors_first

analysis_options.yaml
yaml
linter:
  rules:
    - sort_constructors_first

如果您改為使用 YAML map 語法來設定 linter 規則,請在 linter > rules 下方新增 sort_constructors_first: true

analysis_options.yaml
yaml
linter:
  rules:
    sort_constructors_first: true