Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.