fix(linter): fix useExhaustiveDependencies false positive with arrow function params#8906
fix(linter): fix useExhaustiveDependencies false positive with arrow function params#8906ddmoney420 wants to merge 1 commit intobiomejs:mainfrom
Conversation
…function params The rule incorrectly flagged hook dependencies as "unnecessary" when: 1. Arrow functions used parameters without parentheses (e.g., `props =>`) 2. Props were accessed via destructuring in function body Root cause: The self-reference check in `is_stable_expression` returned `true` for any identifier whose declaration node was an ancestor. For arrow functions, the entire expression is the declaration, so any parameter usage in the body was incorrectly marked as stable. Fix: Exclude arrow function parameters, formal parameters, and rest parameters from being considered stable self-references. Fixes biomejs#8883 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
WalkthroughThis PR fixes false positives in the Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I believe this has already been included in #8900 |
|
Thank you @ddmoney420 . We will go with #8900 fix |
Summary
Fixes false positive in
useExhaustiveDependenciesrule when props are destructured in function body or accessed directly with arrow function params without parentheses.Problem
The rule incorrectly flagged hook dependencies as "unnecessary" when:
props =>)const { msg } = props)Example that was incorrectly flagged:
Root Cause
The bug was in the
is_stable_expressionfunction. It had a "self-reference" check that returnedtrue(stable) when an identifier's ancestors included its declaration node.For arrow functions with parameters without parentheses (
props =>), the binding's declaration is the entireJsArrowFunctionExpression. Since the arrow function is an ancestor of any identifier used inside it, the check incorrectly returnedtruefor parameter usages in the body.Solution
Modified the self-reference check to exclude arrow function parameters, formal parameters, and rest parameters from being considered "stable self-references":
Test plan
useExhaustiveDependenciestests pass (53 tests)biome_js_analyzetests pass (1990 tests)AI Disclosure
This PR was written primarily by Claude Code (AI assistant).
Fixes #8883
🤖 Generated with Claude Code