avoid-explicit-pattern-field-name
preset: recommended
Warns when an object pattern has an explicit field name.
In Dart, when a pattern variable name is the same as a field name, the field name can be safely omitted without reducing readability.
Example
❌ Bad:
const iterable = {...};
// LINT: Avoid explicit field names. Try removing the name.
if (iterable case Set(firstOrNull: final firstOrNull)) {}
// LINT: Avoid explicit field names. Try removing the name.
if (iterable case Set(first: final first)) {}
✅ Good:
const iterable = {...};
if (iterable case Set(:final firstOrNull)) {} // Correct, matching field name is omitted
if (iterable case Set(firstOrNull: final alias)) {} // Correct, different name
if (iterable case Set(:final first)) {}
if (iterable case Set(first: final alias)) {}