Property should not be redeclared in object literals or classes

  • DUPLICATE_PROPERTY
  • Error
  • Medium
  • No tags

This rule applies when an object literal or a class has multiple properties with the same name.

Because only the last property is used, a programmer needs to check whether expected value is set.

Noncompliant Code Example

// Example 1
var obj = {
    a: 42,
    get a() { // DUPLICATE_PROPERTY alarm
        return 43;
    }
};

// Example 2
var grid = {
    rowNum: $('#pageSize').val(),
    rowNum: 15 // DUPLICATE_PROPERTY alarm
}

// Example 3
var x = "getValue";
class A {
    getValue() {}
    [x]() {}  // DUPLICATE_PROPERTY alarm
}

Compliant Code Example

// Choose the property which you intend to apply. And delete others.

var obj = {
    a: 43
};

var grid = {
    rowNum: $('#pageSize').val()
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.