Skip to content

Commit 114c4fb

Browse files
committed
fix(linter/no-useless-spread): panic with multi byte char (#11964)
fixes #11957
1 parent 940b98f commit 114c4fb

File tree

1 file changed

+4
-2
lines changed
  • crates/oxc_linter/src/rules/unicorn/no_useless_spread

1 file changed

+4
-2
lines changed

crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ fn fix_by_removing_array_spread<'a, S: GetSpan>(
461461
///
462462
/// ## Examples
463463
/// - `{...{ a, b, }}` -> `{ a, b }`
464+
#[expect(clippy::cast_possible_truncation)]
464465
fn fix_by_removing_object_spread<'a>(
465466
fixer: RuleFixer<'_, 'a>,
466467
spread: &SpreadElement<'a>,
@@ -472,10 +473,10 @@ fn fix_by_removing_object_spread<'a>(
472473
// remove trailing commas to avoid syntax errors if this spread is followed
473474
// by another property
474475
// e.g. ` a, b, ` -> `a, b`
475-
let mut end_shrink_amount = 0;
476+
let mut end_shrink_amount: u32 = 0;
476477
for c in fixer.source_range(*replacement_span).chars().rev() {
477478
if c.is_whitespace() || c == ',' {
478-
end_shrink_amount += 1;
479+
end_shrink_amount += c.len_utf8() as u32;
479480
} else {
480481
break;
481482
}
@@ -765,6 +766,7 @@ fn test() {
765766
("setupServer(...[1, 2, 3])", "setupServer(1, 2, 3)"),
766767
("[...[1,2,,,],...[3,4,,,]]", "[1, 2, , , 3, 4, , ,]"),
767768
("[...[...foo], ...[...bar]]", "[...foo, ...bar]"),
769+
("S={...{ }}", "S={}"),
768770
];
769771
Tester::new(NoUselessSpread::NAME, NoUselessSpread::PLUGIN, pass, fail)
770772
.expect_fix(fix)

0 commit comments

Comments
 (0)