Skip to content

Commit

Permalink
fix(linter): fix panic in fixer for oxc/only-used-in-recursion (#6070)
Browse files Browse the repository at this point in the history
closes #6068
  • Loading branch information
camc314 committed Sep 26, 2024
1 parent 01b9c4b commit c2616f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/oxc/only_used_in_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ fn is_function_maybe_reassigned<'a>(
// skipping whitespace, commas, finds the next character (exclusive)
#[allow(clippy::cast_possible_truncation)]
fn skip_to_next_char(s: &str, start: u32) -> u32 {
let mut i = start as usize;
while i < s.len() {
let c = s.chars().nth(i).unwrap();
for (i, c) in s.char_indices().skip(start as usize) {
if !c.is_whitespace() && c != ',' {
break;
return i as u32;
}
i += 1;
}
i as u32

s.len() as u32
}

#[test]
Expand Down Expand Up @@ -401,6 +399,8 @@ fn test() {
return a(arg0);
}
",
"//¿
function writeChunks(a,callac){writeChunks(m,callac)}writeChunks(i,{})",
];

let fix = vec![
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_linter/src/snapshots/only_used_in_recursion.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ source: crates/oxc_linter/src/tester.rs
3return a(arg0);
╰────
help: Remove the argument and its usage. Alternatively, use the argument in the function body.

⚠ oxc(only-used-in-recursion): Parameter `callac` is only used in recursive calls
╭─[only_used_in_recursion.tsx:2:24]
1 │ //¿
2 │ function writeChunks(a,callac){writeChunks(m,callac)}writeChunks(i,{})
· ──────
╰────
help: Remove the argument and its usage. Alternatively, use the argument in the function body.

0 comments on commit c2616f7

Please sign in to comment.