fix(linter): fix panic in fixer for oxc/only-used-in-recursion (#6070)

closes #6068
This commit is contained in:
camc314 2024-09-26 10:50:49 +00:00
parent 01b9c4bedc
commit c2616f7fa1
2 changed files with 14 additions and 6 deletions

View file

@ -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]
@ -401,6 +399,8 @@ fn test() {
return a(arg0);
}
",
"//¿
function writeChunks(a,callac){writeChunks(m,callac)}writeChunks(i,{})",
];
let fix = vec![

View file

@ -72,3 +72,11 @@ source: crates/oxc_linter/src/tester.rs
3 │ return 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.