useNumberToFixedDigitsArgument
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/suspicious/useNumberToFixedDigitsArgument
Since: v1.8.0
Sources:
Enforce using the digits argument with Number#toFixed()
.
When using Number#toFixed()
explicitly specify the number of digits you want to appear after the decimal point,
to avoid unexpected results, rather than relying on its default value of 0.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:30 lint/suspicious/useNumberToFixedDigitsArgument FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Specify the number of digits you want to appear after the decimal point.
> 1 │ const string = number.toFixed();
│ ^^
2 │
ℹ Unsafe fix: Add explicit digits argument to toFixed method.
1 │ const·string·=·number.toFixed(0);
│ +
Valid
Section titled ValidCaveats
Section titled CaveatsThis rule always assumes that toFixed
is called on a number.
It does not check the type of the callee.