prefer-first-or-null
added in: 1.2.0 style
Warns when the first element of an Iterable or a List is accessed by first
, list[0]
or iterable.elementAt(0)
instead of calling iterable.firstOrNull
.
Example
Bad:
...
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
array.elementAt(0); // LINT
array[0]; // LINT
Good:
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
array.firstOrNull;