empty_constructor_bodies
針對空的建構子主體,使用 ;
而非 {}
。
此規則自 Dart 2.0 起可用。
此規則提供快速修正。
詳細資訊
#請務必針對空的建構子主體使用 ;
而非 {}
。
在 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
除非另有說明,否則本網站上的文件反映的是 Dart 3.6.0。頁面最後更新於 2024-07-03。檢視原始碼或回報問題。