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
Unless stated otherwise, the documentation on this site reflects Dart 3.5.3. Page last updated on 2024-07-03. View source or report an issue.