Skip to content

Commit 697987f

Browse files
committed
fix(noParametersOnlyUsedInRecursion): detect recursion in assignment expressions
1 parent fde87f3 commit 697987f

File tree

3 files changed

+231
-173
lines changed

3 files changed

+231
-173
lines changed

crates/biome_js_analyze/src/lint/nursery/no_parameters_only_used_in_recursion.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ fn get_function_binding(
278278
continue;
279279
}
280280

281+
// Check for variable declarator: const foo = () => ...
281282
if let Some(declarator) = JsVariableDeclarator::cast_ref(&ancestor)
282283
&& let Ok(id) = declarator.id()
283284
&& let Some(any_binding) = id.as_any_js_binding()
@@ -286,6 +287,18 @@ fn get_function_binding(
286287
return Some(model.as_binding(js_id_binding));
287288
}
288289

290+
// Check for assignment expression: foo = () => ...
291+
if let Some(assignment) = JsAssignmentExpression::cast_ref(&ancestor)
292+
&& let Ok(left) = assignment.left()
293+
&& let Some(id_assignment) = left.as_any_js_assignment()
294+
&& let Some(js_id_assignment) = id_assignment.as_js_identifier_assignment()
295+
{
296+
// For assignment expressions, resolve the assignment target to its binding.
297+
// JsIdentifierAssignment implements HasDeclarationAstNode, so model.binding()
298+
// can resolve write references to their bindings.
299+
return model.binding(js_id_assignment);
300+
}
301+
289302
if is_function_like(&ancestor) {
290303
break;
291304
}

crates/biome_js_analyze/tests/specs/nursery/noParametersOnlyUsedInRecursion/invalid.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ foo = (n, acc) => {
5656
return foo(n - 1, acc);
5757
};
5858

59+
// Separate declaration and assignment with arrow function
60+
let bar;
61+
bar = (x, unused) => {
62+
if (x === 0) return 0;
63+
return bar(x - 1, unused);
64+
};
65+
5966
// Logical AND operator
6067
function fnAnd(n, acc) {
6168
if (n === 0) return 0;

0 commit comments

Comments
 (0)