useNumberNamespace
¥Summary
-
规则生效日期:
v1.5.0¥Rule available since:
v1.5.0 -
诊断类别:
lint/style/useNumberNamespace¥Diagnostic Category:
lint/style/useNumberNamespace -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "style": { "useNumberNamespace": "error" } } }}¥Description
使用 Number 属性而不是全局属性。
¥Use the Number properties instead of global ones.
ES2015 将一些全局变量移入 Number 属性以保持一致性。
¥ES2015 moved some globals into the Number properties for consistency.
该规则不报告全局变量 isFinite 和 isNaN,因为它们的行为与相应的 Number 的属性 Number.isFinite 和 Number.isNaN 略有不同。你可以使用专用规则 noGlobalIsFinite 和 noGlobalIsNan 强制使用 Number.isFinite 和 Number.isNaN。
¥The rule doesn’t report the globals isFinite and isNaN because they have a slightly different behavior to their corresponding Number’s properties Number.isFinite and Number.isNaN.
You can use the dedicated rules noGlobalIsFinite and noGlobalIsNan to enforce the use of Number.isFinite and Number.isNaN.
¥Examples
¥Invalid
parseInt("1"); // truecode-block.js:1:1 lint/style/useNumberNamespace FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use Number.parseInt instead of the equivalent global.
> 1 │ parseInt(“1”); // true
│ ^^^^^^^^
2 │
ℹ ES2015 moved some globals into the Number namespace for consistency.
ℹ Safe fix: Use Number.parseInt instead.
1 │ - parseInt(“1”);·//·true
1 │ + Number.parseInt(“1”);·//·true
2 2 │
parseFloat("1.1"); // truecode-block.js:1:1 lint/style/useNumberNamespace FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use Number.parseFloat instead of the equivalent global.
> 1 │ parseFloat(“1.1”); // true
│ ^^^^^^^^^^
2 │
ℹ ES2015 moved some globals into the Number namespace for consistency.
ℹ Safe fix: Use Number.parseFloat instead.
1 │ - parseFloat(“1.1”);·//·true
1 │ + Number.parseFloat(“1.1”);·//·true
2 2 │
NaN; // truecode-block.js:1:1 lint/style/useNumberNamespace FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use Number.NaN instead of the equivalent global.
> 1 │ NaN; // true
│ ^^^
2 │
ℹ ES2015 moved some globals into the Number namespace for consistency.
ℹ Safe fix: Use Number.NaN instead.
1 │ - NaN;·//·true
1 │ + Number.NaN;·//·true
2 2 │
Infinity; // truecode-block.js:1:1 lint/style/useNumberNamespace FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use Number.POSITIVE_INFINITY instead of the equivalent global.
> 1 │ Infinity; // true
│ ^^^^^^^^
2 │
ℹ ES2015 moved some globals into the Number namespace for consistency.
ℹ Safe fix: Use Number.POSITIVE_INFINITY instead.
1 │ - Infinity;·//·true
1 │ + Number.POSITIVE_INFINITY;·//·true
2 2 │
-Infinity; // truecode-block.js:1:2 lint/style/useNumberNamespace FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use Number.NEGATIVE_INFINITY instead of the equivalent global.
> 1 │ -Infinity; // true
│ ^^^^^^^^
2 │
ℹ ES2015 moved some globals into the Number namespace for consistency.
ℹ Safe fix: Use Number.NEGATIVE_INFINITY instead.
1 │ - -Infinity;·//·true
1 │ + Number.NEGATIVE_INFINITY;·//·true
2 2 │
¥Valid
Number.parseInt("1"); // falseNumber.parseFloat("1.1"); // falseNumber.NaN; // falseNumber.POSITIVE_INFINITY; // falseNumber.NEGATIVE_INFINITY; // false¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号