avoid-long-records
added in: 1.5.0
warning
Dart 3.0Records 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.
Use max-amount
configuration (default is 6
), to set up the number of record fields after which the rule should trigger.
⚙️ Config example
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() => (...);
}