fix(eslint-plugin-query): handle array-destructured useQueries result…#1
Merged
Merged
Conversation
…s in no-unstable-deps The `collectVariableNames` function in the `no-unstable-deps` rule only handled `Identifier` patterns. When users array-destructure `useQueries` or `useSuspenseQueries` results (e.g. `const [q1, q2] = useQueries(...)`), the individual variables were not tracked as unstable. This meant passing them directly to React hook dependency arrays was never flagged. Extend `collectVariableNames` to also handle `ArrayPattern` — including plain identifier elements and rest elements. Fixes TanStack#10746
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR fix?
The
no-unstable-depsrule silently ignores array-destructured resultsfrom
useQueriesanduseSuspenseQueries. Writing:const [userQuery, postsQuery] = useQueries({ queries: [...] })
causes neither variable to be tracked as unstable, so using them in
useEffectdependency arrays is never flagged — even though it should be.Root cause
collectVariableNamesinno-unstable-deps.rule.tsonly handledIdentifierpatterns. When the result is array-destructured, theidnode is an
ArrayPatternwhich was silently ignored.Evidence this is unintentional
The sibling rule
no-rest-destructuringalready handlesArrayPatterncorrectly for
useQueriesanduseSuspenseQueries(lines 69–86 ofno-rest-destructuring.rule.ts), confirming this pattern is expectedand
no-unstable-depshad a gap.Fix
Added
ArrayPatternhandling tocollectVariableNamesto iterate overelements and track each destructured variable individually, including
rest elements.
Tests added
useQueriesarray element used as dep → flaggeduseSuspenseQueriesarray element used as dep → flagged...restQueries) used as dep → flaggedRelated issue
Fixes TanStack#10746