fix(eslint-plugin-query): Exhaustive deps rule not working for vue files #10011
main fromrefs/pull/10011/head·merged by TkDodo View on GitHub🎯 Changes#
Fixes: #9962
In this PR, I am identifying vue files and and fixing the exhaustive depths rule not working for them. Motivation - Thought to start my new year with some OSS contribution
In react, Similar case which works fine
Before this PR
After this PR
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: eslint-plugin-query
📝 Walkthrough
Walkthrough#
The changes fix the exhaustive-deps ESLint rule for Vue single-file components by adding filename context to dependency reference validation. When no function ancestor exists, the rule now specifically validates Vue files and treats undefined definitions and imports as globals, preventing false positives.
Changes#
Cohort / File(s) Summary Changeset
.changeset/slimy-taxes-make.mdPatch bump for @tanstack/eslint-plugin-querydocumenting the exhaustive-deps rule fix for Vue filesTest additions
packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.tsAdds Vue single-file component test scenarios covering valid cases (correct deps, imports/globals excluded) and invalid cases (missing deps with fix suggestions) Core implementation
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts,exhaustive-deps.utils.tsPasses filename context to isRelevantReference; reworks control flow to differentiate between function scope and Vue file context, treating undefined definitions and imports as non-relevant in Vue files Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested reviewers#
- TkDodo
- Newbie012
Poem#
🐰 Through Vue's component files we hop, Dependencies we'll never drop, With filenames to guide our way, Exhaustive checks will save the day! ✨
Pre-merge checks and finishing touches#
✅ Passed checks (3 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and accurately summarizes the main change: fixing the exhaustive-deps ESLint rule for Vue files, which is the core objective of this PR. Description check ✅ Passed The description includes changes explanation, all checklist items checked, and release impact documented with a changeset generated, following the template requirements. Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. ✨ Finishing touches
- 📝 Generate docstrings
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 `@coderabbitai help` to get the list of available commands and usage tips.gk9848970(GitHub profile, opens in a new tab) changed the title
View your CI Pipeline Execution ↗ for commit 4ae2db287d06e425bb3d718980c6f1eae3bbca4c
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 40s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded <1s View ↗
☁️ Nx Cloud last updated this comment at
2026-01-16 15:27:41UTCMore templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10011@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10011@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10011@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10011@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@10011@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@10011@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10011@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10011@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@10011@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@10011@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10011@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10011@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@10011@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10011@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10011@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@10011@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10011@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10011@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@10011@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10011commit:
4ae2db2Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 83.82%. Comparing base (
53fc74e) to head (4ae2db2). :warning: Report is 164 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #10011 +/- ## =========================================== + Coverage 46.00% 83.82% +37.81% =========================================== Files 200 19 -181 Lines 8534 581 -7953 Branches 1983 216 -1767 =========================================== - Hits 3926 487 -3439 + Misses 4150 72 -4078 + Partials 458 22 -436Components Coverage Δ @tanstack/angular-query-experimental ∅ <ø> (∅)@tanstack/eslint-plugin-query 83.82% <100.00%> (+0.22%):arrow_up: @tanstack/query-async-storage-persister ∅ <ø> (∅)@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)@tanstack/query-codemods ∅ <ø> (∅)@tanstack/query-core ∅ <ø> (∅)@tanstack/query-devtools ∅ <ø> (∅)@tanstack/query-persist-client-core ∅ <ø> (∅)@tanstack/query-sync-storage-persister ∅ <ø> (∅)@tanstack/query-test-utils ∅ <ø> (∅)@tanstack/react-query ∅ <ø> (∅)@tanstack/react-query-devtools ∅ <ø> (∅)@tanstack/react-query-next-experimental ∅ <ø> (∅)@tanstack/react-query-persist-client ∅ <ø> (∅)@tanstack/solid-query ∅ <ø> (∅)@tanstack/solid-query-devtools ∅ <ø> (∅)@tanstack/solid-query-persist-client ∅ <ø> (∅)@tanstack/svelte-query ∅ <ø> (∅)@tanstack/svelte-query-devtools ∅ <ø> (∅)@tanstack/svelte-query-persist-client ∅ <ø> (∅)@tanstack/vue-query ∅ <ø> (∅)@tanstack/vue-query-devtools ∅ <ø> (∅):rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts (1)
26-40: LGTM! Vue file handling logic is sound.The Vue-specific logic correctly identifies Vue single-file components and excludes global variables and imports from required dependencies, matching the expected behavior from React's exhaustive-deps rule. This properly handles Vue 3's Composition API script setup where code runs at the module level without a wrapping function.
💡 Optional: Consider adding an explanatory comment
Adding a brief comment would help future maintainers understand why Vue files are treated differently:
} else { + // Vue SFCs with script setup run at module level without a function wrapper. + // Check filename to apply Vue-specific reference resolution. const isVueFile = filename.endsWith('.vue')📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between f61647443da43639c58208d22ae8897b811d5dfc and 0e5521129a76c7d448eb8ca31a5d9446565cc59f.
📒 Files selected for processing (4)
.changeset/slimy-taxes-make.mdpackages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.tspackages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.tspackages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-02T17:57:33.184Z
Learnt from: TkDodo Repo: TanStack/query PR: 9612 File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0 Timestamp: 2025-09-02T17:57:33.184Z Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.Applied to files:
.changeset/slimy-taxes-make.md
📚 Learning: 2025-08-19T03:18:18.303Z
Learnt from: oscartbeaumont Repo: TanStack/query PR: 9564 File: packages/solid-query-devtools/src/production.tsx:2-3 Timestamp: 2025-08-19T03:18:18.303Z Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.Applied to files:
packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
📚 Learning: 2025-11-22T09:06:05.219Z
Learnt from: sukvvon Repo: TanStack/query PR: 9892 File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335 Timestamp: 2025-11-22T09:06:05.219Z Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.Applied to files:
packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
🧬 Code graph analysis (2)
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts (1)
packages/eslint-plugin-query/src/utils/ast-utils.ts (1)
ASTUtils(5-391)
packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts (1)
packages/eslint-plugin-query/src/__tests__/test-utils.ts (1)
normalizeIndent(3-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
🔇 Additional comments (8)
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts (2)
11-13: LGTM! Filename context added correctly.The filename parameter is properly added to the function signature and destructured, enabling file-context-aware relevance checks for Vue files.
16-26: LGTM! Existing React/Solid logic preserved correctly.The function ancestor check remains unchanged, maintaining the original behavior for React and Solid components where references must be declared within the component function.
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts (1)
85-85: LGTM! Filename context properly plumbed through.The filename from the ESLint rule context is correctly passed to the utility function, enabling file-based relevance checks.
packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts (5)
551-563: LGTM! Vue valid test case properly structured.This test correctly validates that the rule passes when local variables are properly included in the queryKey for Vue single-file components with script setup.
564-576: LGTM! Import exclusion test is correct.This test properly validates that imported functions (ImportBinding) are correctly excluded from required dependencies in Vue files, matching the expected behavior from React hooks.
577-589: LGTM! Global variable exclusion test is correct.This test properly validates that global variables like
fetchare correctly excluded from required dependencies while local variables likeidare still required, demonstrating the correct distinction in Vue files.
1017-1050: LGTM! Single missing dependency test is comprehensive.This test correctly validates that the rule identifies missing local variables in Vue files and provides an appropriate fix suggestion. The test structure matches existing patterns and the expected output is accurate.
1051-1086: LGTM! Multiple missing dependencies test is comprehensive.This test correctly validates that the rule can identify and suggest fixes for multiple missing dependencies in Vue files, with proper comma-separated output and correct fix suggestions.
TkDodo approved these changes
TkDodo merged this3e4f8c8
TkDodo closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 4ae2db287d06e425bb3d718980c6f1eae3bbca4c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR