javascript-style-guide
javascript-style-guide copied to clipboard
Allow leading decimal point (no-floating-decimal)
Currently, the lint doesn't allow a code like:
value = .001
then, we must rewrite to
value = 0.001
But, the number .001 is easy to note that it's a float number and not 1.
If someone forgot the operator (for example, writing x.1 instead of x+.1), Node will raise an error:
➜ ~ node
> x.1
x.1
^^
SyntaxError: Unexpected number
And, a code like:
const values = [
.10,
.05,
.42,
]
is cleaner that a code with redundant zeros:
const values = [
0.10,
0.05,
0.42,
]
I think that we need to allow leading decimal point
Concordo com a descrição que tem na docs do eslint (referência abaixo).
Acredito que perdemos legibilidade se desabilitar a regra pois, pelo menos para mim, é mais natural ver 0.xx do que .xx
https://eslint.org/docs/rules/no-floating-decimal
Although not a syntax error, this format for numbers can make it difficult to distinguish between true decimal numbers and the dot operator. For this reason, some recommend that you should always include a number before and after a decimal point to make it clear the intent is to create a decimal number.