unnecessary_ null_ checks
Unnecessary null checks.
Details
#DON'T apply a null check where a nullable value is accepted.
BAD:
dart
f(int? i) {}
m() {
int? j;
f(j!);
}
GOOD:
dart
f(int? i) {}
m() {
int? j;
f(j);
}
Enable
#
To enable the unnecessary_null_checks rule, add unnecessary_null_checks under
linter > rules in your analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- unnecessary_null_checks
If you're instead using the YAML map syntax to configure linter rules,
add unnecessary_null_checks: true under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
unnecessary_null_checks: true
Was this page's content helpful?
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.