pattern_fields_ordering
This rule flags an object or record pattern whose named fields are not in the configured order.
A destructuring pattern reads as a small table of what is being pulled out, and the same object is often destructured in several places. When each spelling picks its own order, the reader cannot compare two of them at a glance to see which fields one takes and the other does not.
A positional field in a record pattern is identified by position and is left alone; one unnamed field makes the whole list unorderable rather than partially ordered.
This rule is in the pedantic preset.
if (user case User(name: final n, age: final a)) { print('$n is $a');}if (user case User(age: final a, name: final n)) { print('$n is $a');}Enabling this rule
Section titled “Enabling this rule”Outside preset: pedantic, which uses alphabetical order, this rule reports
nothing until you choose an order:
rules: pattern_fields_ordering: order: alphabeticalOptions
Section titled “Options”many_lints: rules: pattern_fields_ordering: order: alphabeticalrules: pattern_fields_ordering: order: alphabetical| Option | Type | Default | Description |
|---|---|---|---|
order |
string | — |
alphabetical, alphabetical_case_sensitive or by_length. Unset means the rule is silent |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: pattern_fields_ordering: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”record_fields_ordering— Keep record named fields in a configured order.enum_constants_ordering— Keep enum constants in a configured order.arguments_ordering— Keep named arguments in a configured order.initializers_ordering— Keep constructor initializers in field order.