Skip to main content

avoid-long-records

added in: 1.5.0
⚙️
Dart 3.0+

Records with high number of fields are difficult to reuse and maintain because they are usually responsible for more than one thing.

Consider creating a class or splitting the record instead.

⚙️ Config

Set max-amount (default is 6) to configure the number of record fields after which the rule should trigger.

dart_code_metrics:
...
rules:
...
- avoid-long-records:
max-amount: 6

Example

❌ Bad:

final record =
('hello', 'world', 'and', 'this', 'is', 'also', 'a field'); // LINT

class MyClass {
final (String, {int named}) field;

const MyClass(this.field);

(int, int, String, int, double, num, num) getData() => (...); // LINT
}

✅ Good:

final record = ('hello', 'world', 'and');
final another = ('this', 'is', 'also', 'a field');

class MyClass {
final (String, {int named}) field;

const MyClass(this.field);

MyDataClass getData() => (...);
}