record_fields_ordering
v1.0.0WarningConfigurableCode Organization
many_lints.yaml
analysis_options.yaml many_lints.yaml
many_lints.yaml
This rule flags a record type whose named fields are not in the configured order.
A record is structurally typed, so its named fields are a set rather than a sequence — ({int a, int b}) and ({int b, int a}) are the same type. That makes their written order pure presentation, and an inconsistent one means the same type reads differently in every place it is spelled out.
Positional fields are never ordered: their position is their identity, and reordering them makes a different type.
This rule is in the pedantic preset.
typedef Result = ({String message, int code});typedef Result = ({int code, String message});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: record_fields_ordering: order: alphabeticalOptions
Section titled “Options”many_lints: rules: record_fields_ordering: order: alphabeticalrules: record_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: record_fields_ordering: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”pattern_fields_ordering— Keep pattern 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.