Skip to main content

pattern-fields-ordering

dart 3.0+
has auto-fix
pro+

Ensures consistent alphabetical order of pattern fields by their names.

Example

❌ Bad:

void fn() {
// LINT: Pattern field names do not match the alphabetical order. Try sorting them.
final Person(name: name, age: age) = _getPerson();
// LINT: Pattern field names do not match the alphabetical order. Try sorting them.
final Person(:name, :age) = _getPerson();
}

class Person {
Person({
required this.name,
required this.age,
});

final String name;
final int age;
}

✅ Good:

void fn() {
final Person(age: age, name: name) = _getPerson();
final Person(:age, :name) = _getPerson();
}