noDuplicateMapKeys (YAML)
Language YAML
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/noDuplicateMapKeys - This rule doesn’t have a fix.
- The default severity of this rule is error.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noDuplicateMapKeys": "error" } } }}Description
Section titled “Description”Disallow two keys with the same name inside YAML maps.
The YAML specification requires mapping keys to be unique. When a key is repeated, the document becomes ambiguous: tooling disagree on which value wins, with some keeping the first entry, some the last, and others rejecting the document entirely. Duplicate keys are therefore usually a mistake, such as a copy-paste error or an unintended override.
Keys are compared by their resolved scalar value, so quoted and unquoted forms of the same key are treated as duplicates.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”person: name: John Doe 'name': Jane Doe "name": John Smithcode-block.yaml:2:3 lint/nursery/noDuplicateMapKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The key name was already declared.
1 │ person:
> 2 │ name: John Doe
│ ^^^^
3 │ 'name': Jane Doe
4 │ "name": John Smith
ℹ This is where a duplicated key was declared again.
1 │ person:
2 │ name: John Doe
> 3 │ 'name': Jane Doe
│ ^^^^^^
4 │ "name": John Smith
5 │
ℹ This is where a duplicated key was declared again.
2 │ name: John Doe
3 │ 'name': Jane Doe
> 4 │ "name": John Smith
│ ^^^^^^
5 │
ℹ Duplicate keys make the mapping ambiguous, and tools disagree on which value wins.
ℹ Remove or rename the duplicate keys.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
person: { name: John Doe, name: Jane Doe }code-block.yaml:1:11 lint/nursery/noDuplicateMapKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The key name was already declared.
> 1 │ person: { name: John Doe, name: Jane Doe }
│ ^^^^
2 │
ℹ This is where a duplicated key was declared again.
> 1 │ person: { name: John Doe, name: Jane Doe }
│ ^^^^
2 │
ℹ Duplicate keys make the mapping ambiguous, and tools disagree on which value wins.
ℹ Remove or rename the duplicate keys.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
person: name: John Doeperson: { name: John Doe }Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.