avoid_non_null_assertion
Rule which warns about usages of bang operator ("!") as it may result in unexpected runtime exceptions.
Types with index operator (like [Map], IMap, BuiltMap) can be ignored
using ignored_types config parameter.
Example config:
solid_lints:
diagnostics:
avoid_non_null_assertion:
ignored_types:
- Map
- IMap
- BuiltMap
Example
BAD:
Object? object;
int? number;
final map = {'key': 'value'};
final int computed = 1 + number!; // LINT
object!.method(); // LINT
map['key']!; // LINT (unless Map is in ignored_types)
GOOD:
Object? object;
int? number;
if (number != null) {
final int computed = 1 + number;
}
object?.method();
// Allowed if Map is in ignored_types
final map = {'key': 'value'};
map['key']!;
Parameters
ignored_types (String | List<String> | Map<String, Object?>)
Types that would be ignored by avoid-non-null-assertion rule
Example:
solid_lints:
diagnostics:
avoid_non_null_assertion:
ignored_types:
- Map
- IMap
Map<String, String> map;
map['key']!; // OK