Skip to content

noDuplicateObjectKeys

¥Summary

  • 规则生效日期:v1.0.0

    ¥Rule available since: v1.0.0

  • 诊断类别:lint/suspicious/noDuplicateObjectKeys

    ¥Diagnostic Category: lint/suspicious/noDuplicateObjectKeys

  • 此规则为推荐规则,默认启用。

    ¥This rule is recommended, which means is enabled by default.

  • 此规则没有修复方案。

    ¥This rule doesn’t have a fix.

  • 此规则的默认严重级别为 error

    ¥The default severity of this rule is error.

¥How to configure

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
}

¥Description

禁止在对象内部使用两个同名的键。

¥Disallow two keys with the same name inside objects.

¥Examples

¥Invalid

{
"title": "New title",
"title": "Second title"
}
code-block.json:2:3 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The key title was already declared.

1 │ {
> 2 │ “title”: “New title”,
^^^^^^^
3 │ “title”: “Second title”
4 │ }

This is where a duplicated key was declared again.

1 │ {
2 │ “title”: “New title”,
> 3 │ “title”: “Second title”
^^^^^^^
4 │ }
5 │

If a key is defined multiple times, only the last definition takes effect. Previous definitions are ignored.

¥Valid

{
"title": "New title",
"secondTitle": "Second title"
}

¥Related links