Duplicate Property Name in Object Literal
ID |
javascript.property_names_uniqueness |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
dead-code, reliability, suspicious-comparison |
Description
Reports object literals whose properties contain the same name twice. The later definition silently overwrites the earlier one — JavaScript does not warn — and the bug is invisible until a downstream consumer reads the property and gets the wrong value.
Getter / setter pairs (one get x() {} and one set x(v) {}) are tracked as separate slots and are not flagged against each other. Spread elements (…other) have no static name and are ignored.
Rationale
-
The duplicate is almost always a copy-paste leftover: someone duplicated a property to add a new one and forgot to rename the key.
-
The bug stays silent in code review because the eye reads two distinct keys but the runtime only honours one.
// Bad - second `name` wins
const config = {
name: "primary",
port: 8080,
name: "secondary"
};
Remediation
Rename one of the duplicates, or remove the redundant entry.
// Good
const config = {
primaryName: "primary",
port: 8080,
secondaryName: "secondary"
};