Skip to content
Source
Sign inSign up
TanStack/query

fix(eslint-plugin-query): Exhaustive deps rule not working for vue files #10011

Mergedgk9848970(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/10011/headmerged 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

  • Screenshot 2026-01-01 at 12 54 38 AM

Before this PR

  • Screenshot 2026-01-01 at 12 58 34 AM

After this PR

  • Screenshot 2026-01-01 at 12 57 02 AM

✅ 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. 🦋 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
      NameType
      @tanstack/eslint-plugin-queryPatch

      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

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: eslint-plugin-query

    3. 📝 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.md
      Patch bump for @tanstack/eslint-plugin-query documenting the exhaustive-deps rule fix for Vue files
      Test additions
      packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
      Adds 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.ts
      Passes 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 nameStatusExplanation
      Title check✅ PassedThe 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✅ PassedThe description includes changes explanation, all checklist items checked, and release impact documented with a changeset generated, following the template requirements.
      Docstring Coverage✅ PassedNo 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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    4. gk9848970(GitHub profile, opens in a new tab) changed the title

    5. View your CI Pipeline Execution ↗ for commit 4ae2db287d06e425bb3d718980c6f1eae3bbca4c

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded40sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded<1sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-01-16 15:27:41 UTC

    6. More templates

      @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@10011

      commit: 4ae2db2

    7. Codecov 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

      Impacted file tree graph

      @@             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      -436     
      ComponentsCoverage Δ
      @tanstack/angular-query-experimental∅ <ø> (∅)
      @tanstack/eslint-plugin-query83.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.md
    • packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
    • packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts
    • packages/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 fetch are correctly excluded from required dependencies while local variables like id are 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

  • 🎉 This PR has been released!

    Thank you for your contribution!

  • Sign in to join this conversation.