avoid-long-records
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-number
(default is 6
) to configure the number of record fields after which the rule should trigger.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-long-records:
max-number: 6
Example
❌ Bad:
final record =
('hello', 'world', 'and', 'this', 'is', 'also', 'a field'); // LINT: Avoid records with too many fields. Try reducing the number of fields.
class MyClass {
final (String, {int named}) field;
const MyClass(this.field);
// LINT: Avoid records with too many fields. Try reducing the number of fields.
(int, int, String, int, double, num, num) getData() => (...);
}
✅ 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() => (...);
}