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

rules.jshint.W075.html Maven / Gradle / Ivy

Go to download

Consume reports generated by jshint for code quality. Also consume reports for code duplication (either simian or cpd). Consumes the unit/integration tests reports (generated by Jasmin) coverage report (lcov generated by Istanbul). The information generated by reports are added in Sonar

There is a newer version: 2.1.0
Show newest version

    

History

This warning has existed in three forms in JSLint, JSHint and ESLint. It was introduced in the original version of JSLint and has remained in all three linters ever since.

  • In JSLint the warning given is the generic "Duplicate '{a}'"

  • In JSHint prior to version 1.0.0 the message used was "Duplicate member '{a}'"

  • In JSHint 1.0.0 and above and ESLint the message is "Duplicate key '{a}'"

When do I get this error?

The "Duplicate key '{a}'" error, and the alternatives "Duplicate member '{a}'" and "Duplicate '{a}'", is thrown when JSLint, JSHint or ESLint encounters an an object literal that contains more than one property with the same identifier. In the following example we attempt to assign an object containing two properties with the identifier y to a variable x:

x
 
1
var x = {
2
    y: 10,
3
    y: 20
4
};
5
JSHint found 1 errorVersion 2.9.0
Line 3:Duplicate key 'y'.

Why do I get this error?

This error is raised to highlight code that may not work as you expect and could possibly cause a fatal JavaScript syntax error. In strict mode, your code will raise a syntax error. Otherwise, it will run without error but you will most likely get unexpected results.

The specification states the following, where "previous"" is the result of calling [[GetOwnProperty]] on the object in question with the identifier we are trying to add to it (ES5 §11.1.5):

If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
    a. This production is contained in strict code...

    ...

So, when your code is running in strict mode, a syntax error will be thrown if you attempt to define multiple properties with the same identifier. When not in strict mode, no error is thrown but usually the latest definition will override any earlier definitions and you may experience some strange bugs if the naming was unintentional. Another good reason to always run your code in strict mode.

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W075. This means you can tell JSHint to not issue this warning with the /*jshint -W075 */ directive.

In ESLint the rule that generates this warning is named no-dupe-keys. You can disable it by setting it to 0, or enable it by setting it to 1.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy