avoid-nested-records
preset: recommended
Warns when a record type declaration contains a nested record type declaration.
Nesting multiple records can significantly reduce readability.
⚙️ Config
Set acceptable-level
(default is 1
) to configure the acceptable nesting level.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-nested-records:
acceptable-level: 1
Example
❌ Bad:
// LINT: Avoid nested records. Try rewriting the code to remove nesting.
typedef NullableRecord = ((({String str, Future<void> hello}),),);
// LINT: Avoid nested records. Try rewriting the code to remove nesting.
(int, (int, (int,))) triple() => (...);
// LINT: Avoid nested records. Try rewriting the code to remove nesting.
(int, (int, (int, (int,)))) quadruple() => (...);
✅ Good:
typedef NullableRecord = ({String str, Future<void> hello});
(int, int, int) triple() => (...);
(int, int, int, int) quadruple() => (...);