noApproximativeNumericConstant
¥Summary
-
规则生效日期:
v1.3.0¥Rule available since:
v1.3.0 -
诊断类别:
lint/suspicious/noApproximativeNumericConstant¥Diagnostic Category:
lint/suspicious/noApproximativeNumericConstant -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
approx_constant相同¥Same as
approx_constant
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noApproximativeNumericConstant": "error" } } }}¥Description
使用标准常量而不是近似文字。
¥Use 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
¥Invalid
let x = 3.141;code-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 │
let x = 2.302;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 │
¥Valid
let x = Math.PI;let y = 3.14;let x = Math.LN10;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号