Skip to main content

avoid-one-field-records

added in: 1.5.0
Dart 3.0+
Pro+

Warns when a record has only one field.

Record are designed to group data without introducing a class, but a record with only one field acts as unnecessary wrapper.

Example

❌ Bad:

// LINT: Avoid records with only one field. Try adding more fields or removing the record.
final record = ('hello',);

// LINT: Avoid records with only one field. Try adding more fields or removing the record.
(String,) function() => ('hi',);

✅ Good:

final record = ('hello', 'world'); // Correct, two fields

String function() => 'hi'; // Correct, just String