prefer-last
Warns when the last element of an Iterable is accessed by iterable[iterable.length - 1]
or iterable.elementAt(iterable.length - 1)
instead of calling iterable.last
.
Example
❌ Bad:
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
list.elementAt(list.length - 1); // LINT: Prefer '.last' instead of accessing the last element by index.
list[list.length - 1]; // LINT: Prefer '.last' instead of accessing the last element by index.
✅ Good:
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
list.last;