empty_constructor_bodies
空のコンストラクタ本体には、{} の代わりに ; を使用してください。
詳細
#「Effective Dart」より
DO 空のコンストラクタ本体には、{} の代わりに ; を使用してください。
Dart では、本体が空のコンストラクタはセミコロンだけで終えることができます。これは const コンストラクタに必要です。一貫性と簡潔さのため、他のコンストラクタも同様にするべきです。
悪い例
dart
class Point {
int x, y;
Point(this.x, this.y) {}
}良い例
dart
class Point {
int x, y;
Point(this.x, this.y);
}有効にする
#empty_constructor_bodies ルールを有効にするには、analysis_options.yaml ファイルの linter > rules の下に empty_constructor_bodies を追加してください。
analysis_options.yaml
yaml
linter:
rules:
- empty_constructor_bodiesもし linter ルールを設定するために YAML マップ構文を使用している場合は、linter > rules の下に empty_constructor_bodies: true を追加してください。
analysis_options.yaml
yaml
linter:
rules:
empty_constructor_bodies: true