useNumericSeparators
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/style/useNumericSeparators¥Diagnostic Category:
lint/style/useNumericSeparators -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
unicorn/numeric-separators-style相同¥Same as
unicorn/numeric-separators-style -
与
unreadable_literal相同¥Same as
unreadable_literal
-
¥How to configure
{ "linter": { "rules": { "style": { "useNumericSeparators": "error" } } }}¥Description
强制在数值字面量中使用数字分隔符。
¥Enforce the use of numeric separators in numeric literals.
强制使用 数字分隔符 对数字进行分组。过长的数字难以阅读,因此使用下划线 (_) 分隔数字组可以提高代码清晰度。此规则还通过检查数字组的大小是否正确来强制执行数字分隔符的正确使用。
¥Enforces a convention of grouping digits using numeric separators.
Long numbers can become difficult to read, so separating groups of digits with an underscore (_) improves code clarity. This rule also enforces proper usage of the numeric separator, by checking if the groups of digits are of the correct size.
¥Examples
¥Invalid
var a = 1234567890;code-block.js:1:9 lint/style/useNumericSeparators FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Long numeric literal lacks separators.
> 1 │ var a = 1234567890;
│ ^^^^^^^^^^
2 │
ℹ Adding separators helps improve readability and clarity for long numbers.
ℹ Safe fix: Add numeric separators.
1 │ - var·a·=·1234567890;
1 │ + var·a·=·1_234_567_890;
2 2 │
var a = -999_99;code-block.js:1:10 lint/style/useNumericSeparators FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Inconsistent grouping of digits in numeric literal.
> 1 │ var a = -999_99;
│ ^^^^^^
2 │
ℹ Numbers with inconsistently placed separators can be misleading or confusing.
ℹ Safe fix: Use consistent numeric separator grouping.
1 │ - var·a·=·-999_99;
1 │ + var·a·=·-99_999;
2 2 │
var a = 0.1234567;code-block.js:1:9 lint/style/useNumericSeparators FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Long numeric literal lacks separators.
> 1 │ var a = 0.1234567;
│ ^^^^^^^^^
2 │
ℹ Adding separators helps improve readability and clarity for long numbers.
ℹ Safe fix: Add numeric separators.
1 │ - var·a·=·0.1234567;
1 │ + var·a·=·0.123_456_7;
2 2 │
var a = 0b11001100;code-block.js:1:9 lint/style/useNumericSeparators FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Long numeric literal lacks separators.
> 1 │ var a = 0b11001100;
│ ^^^^^^^^^^
2 │
ℹ Adding separators helps improve readability and clarity for long numbers.
ℹ Safe fix: Add numeric separators.
1 │ - var·a·=·0b11001100;
1 │ + var·a·=·0b1100_1100;
2 2 │
¥Valid
var a = 1_234_567_890;var a = -99_999;var a = 0.123_456_7;var a = 0b1100_1100;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号