Skip to content

Conversation

@Newbie012
Copy link
Collaborator

@Newbie012 Newbie012 commented Oct 29, 2025

fixes #9776

Summary by CodeRabbit

Bug Fixes

  • Improved accuracy of the ESLint plugin to correctly identify TanStack Query imports, preventing false positives when similarly-named hooks from other libraries are used.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

⚠️ No Changeset found

Latest commit: a64f614

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

The no-unstable-deps ESLint rule was modified to only track hooks imported from Tanstack Query, eliminating false positives when users have identically-named hooks from other sources. The rule callback now receives helpers to validate Tanstack imports before tracking dependencies.

Changes

Cohort / File(s) Summary
Rule Logic Enhancement
packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts
Updated rule creation callback signature to receive helpers parameter from detectTanstackQueryImports. Added helpers.isTanstackQueryImport() check when handling VariableDeclarator to ensure only hooks imported from Tanstack Query are tracked as unstable dependencies.
Test Coverage Expansion
packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts
Added two new valid test cases verifying that useQuery and useMutation imported from non-Tanstack sources do not trigger the rule, mirroring existing Tanstack-based test patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • The changes are focused and follow a clear pattern: narrowing scope by adding an import-source validation check
  • Helper function usage pattern is straightforward and mirrors existing code
  • Test additions are straightforward validation cases with no edge cases
  • Main consideration: verify the helpers.isTanstackQueryImport() API is correctly applied and that no legitimate Tanstack imports are inadvertently filtered

Possibly related PRs

Suggested reviewers

  • TkDodo
  • lachlancollins

Poem

🐰 A query by another name, no longer brings shame,
False alarms now silenced, the rule grows more sane,
Only TanStack hooks trigger our careful inspection,
Imports from elsewhere? They pass our reflection! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is largely incomplete compared to the required template. The author provided only a single-line reference to the issue ("fixes #9776") without completing any of the template sections. The required sections—including the "🎯 Changes" section with detailed description and motivation, the "✅ Checklist" with contributing guide and testing confirmation, and the "🚀 Release Impact" section—are all missing or empty. This minimal description does not follow the repository's template structure and lacks important information about the changes and their impact.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix(eslint-plugin): validate hook import" is concise, specific, and accurately describes the main change in the changeset. The title clearly communicates the primary objective: adding validation to check whether hooks are imported from TanStack Query. This aligns well with the code modifications that add a helpers check to verify hook imports, addressing the core issue of false positives in the no-unstable-deps rule.
Linked Issues Check ✅ Passed The code changes directly address the requirements specified in linked issue #9776. The modifications validate that hooks like useQuery are specifically imported from TanStack Query by adding a helpers.isTanstackQueryImport check to the rule logic. This distinction between TanStack and non-TanStack imports eliminates the false positives reported in the issue. Additionally, two new test cases were added to verify that non-TanStack useQuery hooks are no longer flagged as unstable, while the rule continues to function correctly for actual TanStack Query imports. All coding-related objectives from the issue are met by these changes.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly scoped to addressing the false positive issue in the no-unstable-deps eslint rule. The modifications are limited to the rule implementation file and its test file, both of which are necessary to fix and verify the specific problem. There are no unrelated changes, refactoring efforts, or modifications to other features or packages that would fall outside the scope of issue #9776.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-issue-9776

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38b4008 and a64f614.

📒 Files selected for processing (2)
  • packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts (1 hunks)
  • packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts (1)
packages/eslint-plugin-query/src/utils/detect-react-query-imports.ts (1)
  • detectTanstackQueryImports (24-97)
⏰ 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). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
🔇 Additional comments (3)
packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts (2)

37-37: LGTM! Signature correctly updated to receive helpers.

The addition of the helpers parameter enables the rule to validate hook import sources, which is essential for fixing the false positive issue.


112-113: Excellent fix! Import validation eliminates false positives.

The addition of helpers.isTanstackQueryImport(node.init.callee) ensures the rule only tracks hooks actually imported from TanStack Query packages, directly addressing issue #9776. The condition ordering is efficient, checking the name first before the more expensive import validation.

packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts (1)

66-94: Excellent test coverage for the fix!

These test cases directly validate that the rule no longer produces false positives for non-TanStack hooks with identical names, which was the core issue in #9776. The tests cover both query and mutation hook types and follow the existing test patterns well.


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.

@nx-cloud
Copy link

nx-cloud bot commented Oct 29, 2025

View your CI Pipeline Execution ↗ for commit a64f614

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-29 16:14:45 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 29, 2025

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9828

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9828

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9828

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9828

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@9828

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@9828

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9828

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9828

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@9828

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@9828

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9828

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9828

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@9828

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9828

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9828

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@9828

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9828

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9828

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@9828

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9828

commit: a64f614

@github-actions
Copy link
Contributor

Sizes for commit a64f614:

Branch Bundle Size
Main
This PR

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.59%. Comparing base (38b4008) to head (a64f614).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9828       +/-   ##
===========================================
+ Coverage   45.74%   83.59%   +37.85%     
===========================================
  Files         200       19      -181     
  Lines        8404      573     -7831     
  Branches     1919      213     -1706     
===========================================
- Hits         3844      479     -3365     
+ Misses       4112       72     -4040     
+ Partials      448       22      -426     
Components Coverage Δ
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query 83.59% <100.00%> (+0.02%) ⬆️
@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 ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TkDodo TkDodo merged commit 1986929 into main Oct 30, 2025
9 checks passed
@TkDodo TkDodo deleted the fix-issue-9776 branch October 30, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-unstable-deps eslint rule has false positives

3 participants