Lint Rules

noDupeKeys (since v11.0.0)

Prevents object literals having more than one property declaration for the same name. 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

Invalid

const obj = {
   	a: 1,
   	a: 2,
}
nursery/noDupeKeys.js:2:5 lint/nursery/noDupeKeys  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This property value named a is later overwritten by an object member with the same name.
  
    1 │ const obj = {
  > 2 │    	a: 1,
      	^^^^
    3 │    	a: 2,
    4 │ }
  
   Overwritten with this value.
  
    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.
  
   Suggested fix: Remove this property value named a
  
    1 1  const obj = {
    2  - ···a:·1,
    3  - ···a:·2,
      2+ ···a:·2,
    4 3  }
    5 4  
  
const obj = {
   	set a(v) {},
   	a: 2,
}
nursery/noDupeKeys.js:2:5 lint/nursery/noDupeKeys  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This setter named a 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 value.
  
    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.
  
   Suggested fix: Remove this setter named a
  
    1 1  const obj = {
    2  - ···set·a(v)·{},
    3  - ···a:·2,
      2+ ···a:·2,
    4 3  }
    5 4  
  

Valid

const obj = {
   	a: 1,
   	b: 2,
}
const obj = {
   	get a() { return 1; },
   	set a(v) {},
}