Skip to main content

avoid-redundant-positional-field-name

added in: 1.5.0
🛠
Dart 3.0+
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 {
final (String,) field;

const MyClass(this.field);

(int x, int y) getPoint() => (1, 1); // LINT

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

✅ Good:

class MyClass {
final (String,) field;

const MyClass(this.field);

(int,) calculate() => (0,);

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

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