key-duplicates¶
What this rule does¶
Reports duplicate keys in a single mapping. Optionally also reports
duplicated << merge keys.
Why this matters¶
- Silent overwrites. When two entries share a key, most YAML parsers keep only one of them; the other's value is silently discarded.
- Schema validation. Some downstream consumers reject documents with duplicate keys outright, so catching the duplication early avoids surprises in production.
Configuration¶
| Option | Default | Description |
|---|---|---|
forbid-duplicated-merge-keys |
false |
Also report duplicate << merge keys in the same mapping. |
Examples¶
Allowed¶
Reported¶
Reported (with forbid-duplicated-merge-keys: true)¶
Automatic fixing¶
This rule does not auto-fix; resolving a duplicate requires deciding which value is canonical.
Related rules¶
key-ordering— enforces alphabetical key order, which makes duplicates harder to introduce accidentally.anchors— covers a related class of ambiguity for anchor/alias declarations.