key-ordering¶
What this rule does¶
Requires that the keys within each mapping appear in lexicographic (locale-aware) order.
Why this matters¶
- Predictable diffs. When new keys are inserted in sorted order, diffs are localised to the area of change.
- Reviewability. A consistent key order makes it easy to spot when a key is missing or misnamed.
Configuration¶
| Option | Default | Description |
|---|---|---|
ignored-keys |
[] |
Regular expressions; keys matching any pattern may appear in any order. |
Examples¶
Allowed¶
Reported¶
Allowed (with ignored-keys: ["^x-"])¶
Automatic fixing¶
This rule does not auto-fix; reordering keys can disturb mappings whose order is significant to readers (for example documenting fields in a logical workflow).
Related rules¶
key-duplicates— ordering and uniqueness are commonly enforced together.