Skip to content

named_positional_record_field

Reports a name on a positional field of a record type, which no code can read. Delete the name, or make the field named.

Tier
advisory
Scope
Dart
Lowest preset
strict
Fix
deletes the name

The name of a positional field in a record type: count in (int count, String) tally().

It does not report named fields (({int count, String label})), whose names are how they are read, or record values and patterns.

The fix deletes the name, and is not offered where a comment stands before it. To read the field by its name, make it named, as in the example: that changes every place that builds or reads the record. A name that only documents a returned pair goes in a doc comment.

The name is not part of the type: the field is still $1, and tally().count does not compile. A name that reads like a getter, and is none, promises what the record does not give.

Violating
(int count, String label) tally() => (1, 'items');
Corrected
({int count, String label}) tally() => (count: 1, label: 'items');

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: named_positional_record_field

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