Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JAVASCRIPT-1.2
-
Component/s: JavaScript
-
Labels:None
-
Number of attachments :
Description
title
Duplicate property names not allowed in object literals
description
Even if JavaScript allows to have duplicate property names in object literals, this is a vector for bugs as only the last instance of a duplicated property determines the actual value that will be used for it. Therefore, changing values of other occurences of a duplicated property will have no effect and may cause misunderstandings and bugs.
What's more, using duplicate property names will generate an error in JavaScript strict mode code.
The following code snippet illustrates this rule :
var data = {
"key": "value",
"key": "value", // Non-Compliant - duplicate of "key"
" key": "value,
key: "value", // Non-Compliant - duplicate of "key"
\u006bey: "value", // Non-Compliant - duplicate of "key"
"\u006bey": "value", // Non-Compliant - duplicate of "key"
"\x6bey": "value", // Non-Compliant - duplicate of "key"
"1": "value",
1: "value" // Non-Compliant - duplicate of "1"
}
message
Rename or remove duplicate property name '
{0}'.
severity
Critical
in Sonar way?
Yes
Issue Links
- is related to
-
SONARPLUGINS-2515
Update the SQALE mapping for new rules
-
- relates to
-
SONARPLUGINS-2508
Rule : Source should comply with the javascript strict mode
-
Manually tested.