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

rules.jshint.W008.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 two forms across the three main linters. It was introduced in the original version of JSLint and has remained in all three tools ever since.

  • In JSLint versions dated before May 2013 the warning given is "A leading decimal point can be confused with a dot: '{a}'"

  • In JSLint version dated May 2013 and later this message has been replaced with the more generic "Unexpected '{a}'"

  • In JSHint and ESLint the message has always been "A leading decimal point can be confused with a dot: '{a}'"

The situations that produce the warning have not changed despite changes to the text of the warning itself.

When do I get this error?

The "A leading decimal point can be confused with a dot" error is thrown when JSLint, JSHint and ESLint encounter a numeric literal preceded by a . token which itself is not preceded by a decimal integer literal. Here's an example in which we attempt to assign the value 0.5 to the variable x:

x
 
1
var x = .5;
2
JSLint found 1 errorVersion 2013-04-29
Line 1:A leading decimal point can be confused with a dot: '.5'.

Why do I get this error?

This error is raised to highlight a potentially confusing piece of code. Your code will run without error if you do not address this issue but it could be confusing to other developers. The ECMAScript standard states that it is syntactically valid for a numeric literal to begin with a . character ([ES5 Annex 1][es5-a1]):

DecimalLiteral ::
    DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt
    . DecimalDigits ExponentPartopt
    DecimalIntegerLiteral ExponentPartopt

The second production in the grammar quoted above shows the situation we encounter in the example at the top of this page. However, since the . character is ambiguous (it's also commonly seen in use as a "member operator", to access a property of an object), JSLint, JSHint and ESLint prefer the explicit first production from the above grammar, just to make your code easier to understand. Therefore to fix this error you can simply prepend a 0 to your number:

2
 
1
var x = 0.5;
2
JSLint found no errorsVersion 2013-04-29

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

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy