src/content/docs/linter/rules/no-duplicate-object-keys.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSON (and super languages)" icon="seti:json"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/suspicious/noDuplicateObjectKeys`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`json/no-duplicate-keys`](https://github.com/eslint/json/blob/main/docs/rules/no-duplicate-keys.md){
"linter": {
"rules": {
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
}
Disallow two keys with the same name inside objects.
{
"title": "New title",
"title": "Second title"
}
{
"title": "New title",
"secondTitle": "Second title"
}
{
"linter": {
"rules": {
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
}
Disallow two keys with the same name inside objects.
If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored, which is likely a mistake.
const obj = {
a: 1,
a: 2,
}
const obj = {
set a(v) {},
a: 2,
}
const obj = {
a: 1,
b: 2,
}
const obj = {
get a() { return 1; },
set a(v) {},
}