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:

final record = ('hello',); // LINT

(String,) function() => ('hi',); // LINT

class MyClass {
final (String,) field; // LINT

const MyClass(this.field);

(int,) getPoint() => (0,); // LINT
}

✅ Good:

final record = ('hello', 'world');

String function() => 'hi';

class MyClass {
final String field;

const MyClass(this.field);

(int, int) getPoint() => (1, 1);
}