Skip to content

noDuplicateMapKeys (YAML)

Language YAML
biome.json
{
"linter": {
"rules": {
"nursery": {
"noDuplicateMapKeys": "error"
}
}
}
}

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.

person:
name: John Doe
'name': Jane Doe
"name": John Smith
code-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 Doe
person: { name: John Doe }