目录

empty_constructor_bodies

Use ; instead of {} for empty constructor bodies.

此规则自 Dart 2.0 版本起可用。

_规则集:recommended , flutter _

此规则提供 快速修复

详情

#

From Effective Dart:

DO use ; instead of {} for empty constructor bodies.

In Dart, a constructor with an empty body can be terminated with just a semicolon. This is required for const constructors. For consistency and brevity, other constructors should also do this.

BAD:

dart
class Point {
  int x, y;
  Point(this.x, this.y) {}
}

GOOD:

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