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
View with compliant examples side by side// 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
View with noncompliant examples side by side// Example 1
var obj = {
a: 43
};
// Example 2
var grid = {
rowNum: $('#pageSize').val()
}
// Example 3
var x = "getOther";
class A {
getValue() {}
[x]() {}
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.