目录

prefer_bool_in_asserts

Prefer using a boolean as the assert condition.

此规则已从最新的 Dart 版本中移除。

详情

#

NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.

DO use a boolean for assert conditions.

Not using booleans in assert conditions can lead to code where it isn't clear what the intention of the assert statement is.

BAD:

dart
assert(() {
  f();
  return true;
});

GOOD:

dart
assert(() {
  f();
  return true;
}());

使用方法

#

要启用 prefer_bool_in_asserts 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 prefer_bool_in_asserts

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_bool_in_asserts