use_if_null_to_convert_nulls_to_bools
Use ??
operators to convert null
s to bool
s.
This rule is available as of Dart 2.13.
Details
#From Effective Dart:
Use ??
operators to convert null
s to bool
s.
BAD:
dart
if (nullableBool == true) {
}
if (nullableBool != false) {
}
GOOD:
dart
if (nullableBool ?? false) {
}
if (nullableBool ?? true) {
}
Usage
#To enable the use_if_null_to_convert_nulls_to_bools
rule,
add use_if_null_to_convert_nulls_to_bools
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- use_if_null_to_convert_nulls_to_bools
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。