unnecessary_null_aware_operator_on_extension_on_nullable
Unnecessary null aware operator on extension on a nullable type.
Details
#Avoid null aware operators for members defined in an extension on a nullable type.
BAD:
extension E on int? {
int m() => 1;
}
f(int? i) => i?.m();
GOOD:
extension E on int? {
int m() => 1;
}
f(int? i) => i.m();
Enable
#To enable the unnecessary_null_aware_operator_on_extension_on_nullable
rule, add unnecessary_null_aware_operator_on_extension_on_nullable
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- unnecessary_null_aware_operator_on_extension_on_nullable
If you're instead using the YAML map syntax to configure linter rules, add unnecessary_null_aware_operator_on_extension_on_nullable: true
under linter > rules:
linter:
rules:
unnecessary_null_aware_operator_on_extension_on_nullable: true
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2025-01-27. View source or report an issue.