use_if_null_to_convert_nulls_to_bools

Group: style

Maturity: stable

Dart SDK: >= 2.13.0 • (Linter v1.0.0)

Since info is static, may be stale

View all Lint Rules

Using the Linter

From Effective Dart:

Use if-null operators to convert nulls to bools.

BAD:

if (nullableBool == true) {
}
if (nullableBool != false) {
}

GOOD:

if (nullableBool ?? false) {
}
if (nullableBool ?? true) {
}

Usage

To enable the use_if_null_to_convert_nulls_to_bools lint, add use_if_null_to_convert_nulls_to_bools under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - use_if_null_to_convert_nulls_to_bools