Skip to content

record_inside_record

Reports a record type with a field that is itself a record type. Give the inner record a name with a typedef, or use a class.

Tier
advisory
Scope
Dart
Lowest preset
strict
Fix
none

A written record type with a field that is itself a record type, nullable or not: (int, (String, bool)), ({(int, int) range}). The violation covers the outer record type. A record nested deeper is reported once, with the outermost.

It does not report:

  • a record inside a type argument: (int, List<(int, int)>);
  • an inner record named by a typedef;
  • a record value without a written type.

The inner values are read as $2.$1 or range.$2, and no name says what the inner record holds.

Violating
(int, (String, bool)) parse() => (1, ('a', true));
Corrected
typedef Flagged = (String, bool);
(int, Flagged) parse() => (1, ('a', true));

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Why it stays as written here.
// ignore: record_inside_record

// ignore_for_file: assay/record_inside_record silences it in a whole file, and the prefixed // ignore: assay/record_inside_record works too. See Suppressions.