fix(eslint-plugin-query): detect rest destructuring on custom query hooks#10775
fix(eslint-plugin-query): detect rest destructuring on custom query hooks#10775Newbie012 wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
ae64db4 to
bded2a5
Compare
…ooks Adds an opportunistic type-aware path to no-rest-destructuring. When TypeScript parser services are available, the rule resolves the call expression's return type and reports rest destructuring on custom hooks that return a TanStack Query result. Untyped projects keep the existing AST-only behavior unchanged. Closes TanStack#8951
bded2a5 to
fc06643
Compare
| > | ||
| type Type = ReturnType<TypeChecker['getTypeAtLocation']> | ||
|
|
||
| const QUERY_RESULT_TYPE_NAMES = new Set([ |
There was a problem hiding this comment.
Not a fan of this arbitrary list. I'm open to suggestions
Closes #8951
🎯 Changes
The lint rule
no-rest-destructuringnow also flags rest destructuring on custom hooks that return a TanStack Query result. Detection uses the TypeScript type checker and runs opportunistically, only when parser services are available, so untyped projects see no change.Direct calls to
useQuery/useInfiniteQuery/useSuspenseQuery/useSuspenseInfiniteQuerykeep reporting via the existing AST path. The type-aware path handles wrappers by checking whether the call result resolves to known TanStack Query result type names.Matched return types:
UseQueryResult,UseSuspenseQueryResult,UseInfiniteQueryResult,UseSuspenseInfiniteQueryResult, theirDefined*variants, and the underlyingQueryObserverResult/InfiniteQueryObserverResultnames.A note on the
recommendedTypeCheckedpreset from #8966: I would still like to land that preset and graduate type-aware rules into it, but the conversation has been stalled and I did not want to block this user-facing bug. Happy to follow up by moving this rule (and other type-aware rules) behind a dedicated preset whenever the maintainers want to take that direction.✅ Checklist
pnpm run test:pr.🚀 Release Impact