no_literal_bool_comparisons
Don't compare boolean expressions to boolean literals.
This rule is available as of Dart 3.0.
This rule has a quick fix available.
Details
#From Effective Dart:
DON'T use true
or false
in equality operations.
This lint applies only if the expression is of a non-nullable bool
type.
BAD:
dart
if (someBool == true) {
print('true!');
}
while (someBool == false) {
print('still false!');
}
GOOD:
dart
if (someBool) {
print('true!');
}
while (!someBool) {
print('still false!');
}
Usage
#To enable the no_literal_bool_comparisons
rule,
add no_literal_bool_comparisons
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- no_literal_bool_comparisons
除非另有说明,文档之所提及适用于 Dart 3.5.3 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。