avoid_classes_with_only_static_members
静的メンバーのみを含むクラスの定義を避けてください。
このルールはDart 2.0から利用可能です。
詳細
#避けるべき 静的メンバーのみを含むクラスの定義。
ユーティリティまたは静的メソッドを提供するだけの目的でクラスを作成することは推奨されません。Dartでは、この理由から関数クラスの外に存在できます。
悪い例
dart
class DateUtils {
static DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
}
class _Favorites {
static const mammal = 'weasel';
}
良い例
dart
DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
const _favoriteMammal = 'weasel';
使用方法
#avoid_classes_with_only_static_members
ルールを有効にするには、analysis_options.yaml
ファイルのlinter > rulesセクションにavoid_classes_with_only_static_members
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- avoid_classes_with_only_static_members
特に明記されていない限り、このサイトのドキュメントはDart 3.5.3を反映しています。ページ最終更新日:2024年7月3日。 ソースコードを表示 または 問題を報告する。