Skip to content

record_fields_ordering

v1.0.0WarningConfigurableCode Organization

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});

Outside preset: pedantic, which uses alphabetical order, this rule reports nothing until you choose an order:

many_lints.yaml
rules:
record_fields_ordering:
order: alphabetical
analysis_options.yaml
many_lints:
rules:
record_fields_ordering:
order: alphabetical
Option Type Default Description
order string alphabetical, alphabetical_case_sensitive or by_length. Unset means the rule is silent

To disable this rule:

many_lints.yaml
rules:
record_fields_ordering: false

To keep the rule on but skip certain paths, use per-rule exclude.