Skip to main content

avoid-redundant-positional-field-name

added in: 1.5.0
🛠
Dart 3.0+
Pro+
preset: recommended

Warns when a record positional field has a name.

Record positional field names do not affect code suggestions, but add extra noise with little benefit. Consider using named fields instead.

warning

This rule is not compatible with match-positional-field-names-on-assignment.

Example

❌ Bad:

class MyClass {
(int x, int y) getPoint() => (1, 1); // LINT: Adding a name to the positional field has no effect. Try converting to named or removing the name.

(int x, {int y}) getPointPartiallyNamed() => (1, y: 1); // LINT: Adding a name to the positional field has no effect. Try converting to named or removing the name.
}

✅ Good:

class MyClass {
(int,) calculate() => (0,);

({int x, int y}) getPointNamed() => (x: 1, y: 1); // Correct, both fields are named

({int x, int y}) getPointPartiallyNamed() => (x: 1, y: 1);
}