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

rules.jshint.W069.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

    

When do I get this error?

The "['{a}'] is better written in dot notation" error is thrown when JSLint, JSHint or ESLint encounters an attempt to access a property using a string literal within a pair of square brackets when the property name is not a reserved word. In the following example we attempt to access the prop property of the x object:

x
 
1
var x = {
2
        prop: 10
3
    },
4
    y = x["prop"];
5
JSLint found 1 errorVersion 2015-09-23
Line 3:['prop'] is better written in dot notation.

Why do I get this error?

This error is raised to highlight a unnecessarily verbose and potentially confusing piece of code. It is very common in many programming languages to use dot notation when referring to properties of an object. There is no problem with either syntax, and both will work in all environments. However, by using dot notation where possible, you can save three characters every time. Here's the above snippet, this time with dot notation:

5
 
1
var x = {
2
        prop: 10
3
    },
4
    y = x.prop;
5
JSLint found no errorsVersion 2015-09-23

However, it's important to remember that you have to use the square bracket notation if you want to access a property whose identifier is a reserved word. JSLint and JSHint will not raise this error in that situation. In the following example, x has a property with the identifier class. Notice that JSLint does not throw an error, even though we are using square bracket notation:

5
 
1
var x = {
2
        "class": 10
3
    },
4
    y = x["class"];
5
JSLint found 2 errorsVersion 2015-09-23
Line 1:Quotes are not needed around 'class'.
Line 3:['class'] is better written in dot notation.

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 W069. This means you can tell JSHint to not issue this warning with the /*jshint -W069 */ directive. You can also set the sub option to true.

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy