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

rules.jshint.W055.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 constructor name should start with an uppercase letter" error is thrown when JSLint, JSHint or ESLint encounters an identifier, preceded by the new operator, whose first character is a lowercase letter. JSHint will only raise this warning when the newcap option is set to true. In the following example we declare a constructor function myConstructor and then attempt to instantiate it:

x
 
1
/*jshint newcap: true */
2
function myConstructor() {
3
    "use strict";
4
    this.property = "Something";
5
}
6
7
var myInstance = new myConstructor();
8
JSLint found 2 errorsVersion 2015-09-23
Line 3:Unexpected 'this'.
Line 6:Unexpected 'new'.

Why do I get this error?

This error is raised to highlight a lack of convention. It is common practice for constructor function identifiers to begin with an uppercase letter. JSLint simply enforces this convention. Here's the above snippet rewritten to pass JSLint. Notice that the only difference is the uppercase "M":

8
 
1
/*jshint newcap: true */
2
function MyClass() {
3
    "use strict";
4
    this.property = "Something";
5
}
6
7
var myInstance = new MyClass();
8
JSLint found 1 errorVersion 2015-09-23
Line 3:Unexpected 'this'.

It is worth bearing in mind that this is only a convention and is not required by the language in any way. You can safely ignore this error if you prefer to name your constructor functions differently. By setting the newcap option, you can tell JSLint to allow lowercase constructors.

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 W055. This means you can tell JSHint to not issue this warning with the /*jshint -W055 */ directive.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy