Skip to main content

prefer-first

has auto-fix
free+

Suggests using first instead of accessing a list by index (list[0]) or calling iterable.elementAt(0).

Example

❌ Bad:

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];

// LINT: Prefer '.first' instead of accessing the element at zero index.
array.elementAt(0);
// LINT: Prefer '.first' instead of accessing the element at zero index.
array[0];

✅ Good:

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];

array.first;