All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.DuplicatePropertyName.html Maven / Gradle / Ivy

JavaScript allows duplicate property names in object literals, but only the last instance of a duplicated property determines the actual value that will be used for it. Therefore, changing values of other occurrences 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 :

Noncompliant Code Example

var data = {
  "key": "value",
  "1": "value",
  "key": "value", // Noncompliant - duplicate of "key"
  'key': "value", // Noncompliant - duplicate of "key"
  key: "value", // Noncompliant - duplicate of "key"
  \u006bey: "value", // Noncompliant - duplicate of "key"
  "\u006bey": "value", // Noncompliant - duplicate of "key"
  "\x6bey": "value", // Noncompliant - duplicate of "key"
  1: "value" // Noncompliant - duplicate of "1"
}

Compliant Solution

var data = {
  "key": "value",
  "1": "value",
  "key2": "value",
  'key3': "value",
  key4: "value",
  \u006bey5: "value",
  "\u006bey6": "value",
  "\x6bey7": "value",
  1b: "value"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy