avoid-positional-record-field-access
Warns when a record positional field is accessed via $
.
Accessing record positional fields via $1
, $2
, etc. might look like a great shortcut to write less code, but it also brings readability issues for others who read the code.
Instead, consider destructuring (final (x, y) = ...
) the record first or converting its fields to named fields.
Example
❌ Bad:
void function() {
final record = (
'hello',
'world',
);
final first = record.$1; // LINT
final second = record.$2; // LINT
}
✅ Good:
void function() {
final record = (
first: 'hello',
second: 'world',
);
final first = record.first;
final second = record.second;
final another = (
'hello',
'world',
);
final (first, second) = another;
}