AVOID using the non-null assertion operator (!
).
BAD:
void foo(String? bar) {
print(bar!.length);
}
GOOD:
void foo(String? bar) {
if (bar == null) throw ArgumentError.notNull('bar');
print(bar.length);
}
GOOD:
void foo(String? bar) {
print(bar?.length);
}
GOOD:
void foo(String? bar) {
if (bar case final bar?) {
print(bar.length);
}
}
To disable this lint in your project add this to your package's analysis_options.yaml file:
analyzer:
plugins:
- custom_lint
custom_lint:
rules:
- avoid_non_null_assertion: false