noDuplicateObjectKeys
Ta treść nie jest jeszcze dostępna w Twoim języku.
Summary
Section titled “Summary”- Rule available since: v1.0.0
- Diagnostic Category: lint/suspicious/noDuplicateObjectKeys
- This rule is recommended, which means is enabled by default.
- 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": {      "suspicious": {        "noDuplicateObjectKeys": "error"      }    }  }}Description
Section titled “Description”Disallow two keys with the same name inside objects.
Examples
Section titled “Examples”Invalid
Section titled “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.
  
{  "title": "New title",  "secondTitle": "Second title"}Related links
Section titled “Related links”Summary
Section titled “Summary”- Rule available since: v1.0.0
- Diagnostic Category: lint/suspicious/noDuplicateObjectKeys
- This rule is recommended, which means is enabled by default.
- This rule has an unsafe fix.
- The default severity of this rule is error.
- Sources:
- Same as no-dupe-keys
 
- Same as 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "suspicious": {        "noDuplicateObjectKeys": "error"      }    }  }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const obj = {     a: 1,     a: 2,}code-block.js:2:5 lint/suspicious/noDuplicateObjectKeys  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ This property is later overwritten by an object member with the same name.
  
    1 │ const obj = {
  > 2 │    	a: 1,
      │    	^^^^
    3 │    	a: 2,
    4 │ }
  
  ℹ Overwritten with this property.
  
    1 │ const obj = {
    2 │    	a: 1,
  > 3 │    	a: 2,
      │    	^^^^
    4 │ }
    5 │ 
  
  ℹ 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.
  
  ℹ Unsafe fix: Remove this property.
  
    1 1 │   const obj = {
    2   │ - ···→ a:·1,
    3 2 │      	a: 2,
    4 3 │   }
  
const obj = {     set a(v) {},     a: 2,}code-block.js:2:5 lint/suspicious/noDuplicateObjectKeys  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ This setter is later overwritten by an object member with the same name.
  
    1 │ const obj = {
  > 2 │    	set a(v) {},
      │    	^^^^^^^^^^^
    3 │    	a: 2,
    4 │ }
  
  ℹ Overwritten with this property.
  
    1 │ const obj = {
    2 │    	set a(v) {},
  > 3 │    	a: 2,
      │    	^^^^
    4 │ }
    5 │ 
  
  ℹ 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.
  
  ℹ Unsafe fix: Remove this setter.
  
    1 1 │   const obj = {
    2   │ - ···→ set·a(v)·{},
    3 2 │      	a: 2,
    4 3 │   }
  
const obj = {     a: 1,     b: 2,}const obj = {     get a() { return 1; },     set a(v) {},}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.