noApproximativeNumericConstant
Цей контент ще не доступний вашою мовою.
Diagnostic Category: lint/suspicious/noApproximativeNumericConstant
Since: v1.3.0
Sources:
- Same as:
approx_constant
Description
Section titled DescriptionUse standard constants instead of approximated literals.
Usually, the definition in the standard library is more precise than what people come up with or the used constant exceeds the maximum precision of the number type.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:9 lint/suspicious/noApproximativeNumericConstant FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Prefer constants from the standard library.
> 1 │ let x = 3.141;
│ ^^^^^
2 │
ℹ Unsafe fix: Use Math.PI instead.
1 │ - let·x·=·3.141;
1 │ + let·x·=·Math.PI;
2 2 │
code-block.js:1:9 lint/suspicious/noApproximativeNumericConstant FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Prefer constants from the standard library.
> 1 │ let x = 2.302;
│ ^^^^^
2 │
ℹ Unsafe fix: Use Math.LN10 instead.
1 │ - let·x·=·2.302;
1 │ + let·x·=·Math.LN10;
2 2 │