feat(tanstack-query): add query-destructure-result rule#688
feat(tanstack-query): add query-destructure-result rule#688devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Aiden Bai <aiden.bai05@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
commit: |
|
No React Doctor issues found. 🎉 Reviewed by React Doctor for commit |
| title: "Destructure TanStack Query result", | ||
| tags: ["test-noise"], | ||
| requires: ["tanstack-query"], | ||
| severity: "error", |
There was a problem hiding this comment.
🟡 Severity "error" inconsistent with all other tanstack-query rules which use "warn"
The new query-destructure-result rule uses severity: "error" while every other tanstack-query rule in the codebase uses severity: "warn" — including query-no-rest-destructuring (query-no-rest-destructuring.ts:14), which addresses the exact same tracked-property optimization concern and even gives a near-identical recommendation ("Destructure only the fields you need…subscribes to every field and adds re-renders"). Since the default rule severity flows through to the oxlint config (packages/core/src/runners/oxlint/config.ts:137), this rule will fire as an error (potentially failing CI) for a performance hint that its sibling rule treats as a warning.
| severity: "error", | |
| severity: "warn", |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Keeping severity: "error" — this matches the spec provided by the requester (screenshot shows severity: error). Assigning the whole query object completely defeats TanStack Query's tracked-property optimization, which is a stronger signal than rest-destructuring (which at least destructures some fields).
|
/rde parity |
|
❌ Parity failed — trace |
Co-Authored-By: Aiden Bai <aiden.bai05@gmail.com>
|
RDE parity results:
False positives: 0 — manually inspected all 31 hits from Typical hit: Added changeset ( |
Why
Catches
const result = useQuery(...)— assigning the whole TanStack Query object to a variable bypasses tracked-property optimization, subscribing the component to every field and re-rendering on any change.Before:
After:
What changed
query-destructure-result.VariableDeclaratorwhereinitis aCallExpressionforuseQuery/useSuspenseQuery/useInfiniteQuery/useSuspenseInfiniteQueryandidis anIdentifier(not destructured).error, frameworktanstack-query, taggedtest-noise.const { data } = ...) and rest-destructuring (caught separately byquery-no-rest-destructuring).Eval results
TanStack/query,cal.com,create-t3-app,TanStack/router)query-destructure-resultTest plan
cd packages/oxlint-plugin-react-doctor && nr test— passes (pre-existing failures in unrelatedjsx-no-new-*rules only)npx tsc --noEmit— passesnr lint— pre-existing Node.js version issue (needs >=22.18.0), unrelatedLink to Devin session: https://app.devin.ai/sessions/26bb7313d5254e48aa4832c0ccc25691
Requested by: @aidenybai
Note
Low Risk
Additive lint rule and registry entry only; no runtime or security behavior changes.
Overview
Adds
query-destructure-result, a TanStack Query lint that errors when a query hook return value is bound to a single identifier (e.g.const query = useQuery(...)) instead of destructuring fields like{ data, isLoading }.The rule visits
VariableDeclaratornodes, matches direct calls touseQuery/useSuspenseQuery/useInfiniteQuery/useSuspenseInfiniteQueryviaTANSTACK_QUERY_HOOKS, and only fires whenidis anIdentifier—object destructuring is allowed; rest patterns remain covered byquery-no-rest-destructuring. It is registered under frameworktanstack-query, category Bugs, severity error, with a patch changeset foroxlint-plugin-react-doctor.Reviewed by Cursor Bugbot for commit 766583f. Bugbot is set up for automated code reviews on this repo. Configure here.