
rules.jshint.W008.html Maven / Gradle / Ivy
Show all versions of sonar-web-frontend-js Show documentation
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 1var x = .5;
2
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:
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
.