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

rules.jshint.W005.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 dot following a number can be confused with a decimal point" error is thrown when JSHint encounters a numeric literal containing a decimal point as the left-hand-side of a member expression. In the following example we attempt to assign the string representation of a number to a variable:

x
 
1
var a = 5.4.toString();
2
JSHint found 1 errorVersion 2.9.0
Line 1:A dot following a number can be confused with a decimal point.

Note that this is slightly different to closely related "A trailing decimal point can be consued with a dot" error, although JSLint will use that message in this situation too.

Why do I get this error?

This error is raised to highlight a potentially confusing piece of code. Your script will run without error if you do not change it, but it could be confusing to other developers, especially at first glance.

Since a number can only contain a single decimal point the parser is able to determine that any subsequent occurences of the character after a numeric literal can only be intended as a member operator. In other words the ambiguity of the . character is removed. However the construct can appear confusing at first glance.

The best solution in this case is to wrap the number in parentheses:

2
 
1
var a = (5.4).toString();
2
JSHint found no errorsVersion 2.9.0

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy