mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(linter/unicorn/numeric-separators-style): report misgrouped BigInt literals (#27207)
### Bug `unicorn/numeric-separators-style` checks number literals with `formatted != raw`, but for BigInt literals it only compares lengths: `formatted.len() != number.span.size()`. A BigInt with the same number of separators in the wrong places has the same length as the correct form, so it is never reported: ```js const a = 12_34_567; // reported, fixed to 1_234_567 const b = 12_34_567n; // not reported (should become 1_234_567n) const c = 0xA_BCDn; // not reported (should become 0xAB_CDn) ``` Co-authored-by: breken-ai <312387581+breken-ai@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+19
-1
No files matched your search
@@ -265,7 +265,7 @@ impl Rule for NumericSeparatorsStyle {
|
||||
|
||||
let formatted = self.format_bigint(number, raw);
|
||||
|
||||
if formatted.len() != number.span.size() as usize {
|
||||
if formatted != raw {
|
||||
ctx.diagnostic_with_fix(
|
||||
numeric_separators_style_diagnostic(number.span),
|
||||
|fixer| fixer.replace(number.span, formatted),
|
||||
@@ -737,6 +737,8 @@ fn test() {
|
||||
("const foo = 1_9_223n", None),
|
||||
("const foo = 80_7n", None),
|
||||
("const foo = 123456789_100n", None),
|
||||
("const foo = 12_34_567n", None),
|
||||
("const foo = 0xA_BCDn", None),
|
||||
("const foo = 1_2_345_678", None),
|
||||
("const foo = 12_3", None),
|
||||
("const foo = 1234567890", None),
|
||||
@@ -828,6 +830,8 @@ fn test() {
|
||||
("const foo = 1_9_223n", "const foo = 19_223n", None),
|
||||
("const foo = 80_7n", "const foo = 807n", None),
|
||||
("const foo = 123456789_100n", "const foo = 123_456_789_100n", None),
|
||||
("const foo = 12_34_567n", "const foo = 1_234_567n", None),
|
||||
("const foo = 0xA_BCDn", "const foo = 0xAB_CDn", None),
|
||||
("const foo = 1_2_345_678", "const foo = 12_345_678", None),
|
||||
("const foo = 12_3", "const foo = 123", None),
|
||||
("const foo = 1234567890", "const foo = 1_234_567_890", None),
|
||||
|
||||
@@ -107,6 +107,20 @@ source: crates/oxc_linter/src/tester.rs
|
||||
╰────
|
||||
help: Group digits with numeric separators (_) so longer numbers are easier to read.
|
||||
|
||||
⚠ unicorn(numeric-separators-style): Invalid group length in numeric value.
|
||||
╭─[numeric_separators_style.tsx:1:13]
|
||||
1 │ const foo = 12_34_567n
|
||||
· ──────────
|
||||
╰────
|
||||
help: Group digits with numeric separators (_) so longer numbers are easier to read.
|
||||
|
||||
⚠ unicorn(numeric-separators-style): Invalid group length in numeric value.
|
||||
╭─[numeric_separators_style.tsx:1:13]
|
||||
1 │ const foo = 0xA_BCDn
|
||||
· ────────
|
||||
╰────
|
||||
help: Group digits with numeric separators (_) so longer numbers are easier to read.
|
||||
|
||||
⚠ unicorn(numeric-separators-style): Invalid group length in numeric value.
|
||||
╭─[numeric_separators_style.tsx:1:13]
|
||||
1 │ const foo = 1_2_345_678
|
||||
|
||||
Reference in new issue
Block a user