Skip to content

fix(query-codemods): skip key transformation without react-query import#10830

Open
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-codemods-react-query-import-guard
Open

fix(query-codemods): skip key transformation without react-query import#10830
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-codemods-react-query-import-guard

Conversation

@raashish1601
Copy link
Copy Markdown
Contributor

@raashish1601 raashish1601 commented May 30, 2026

Summary

Avoids running the v4 key transformation codemod when a file does not import
eact-query.

  • Adds an early import check in packages/query-codemods/src/v4/key-transformation.cjs.
  • Returns original source when no
    eact-query import is found.
  • Adds a fixture/test to assert no-op behavior for non-React Query files.

Verification

px -y pnpm@11.1.0 -C tanstack-query --filter @tanstack/query-codemods test:lib

  • pnpm test:eslint (direct pnpm) is blocked in this environment by toolchain mismatch; this is unrelated to the code change.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed codemod to properly handle files without React Query imports by skipping transformation.
  • Tests

    • Added test fixtures and test cases for scenarios without React Query imports.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d51c4edf-40a8-4300-8857-f53d4ef7c1a6

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa2781 and 33f5a7d.

📒 Files selected for processing (4)
  • packages/query-codemods/src/v4/__testfixtures__/no-react-query-import.input.tsx
  • packages/query-codemods/src/v4/__testfixtures__/no-react-query-import.output.tsx
  • packages/query-codemods/src/v4/__tests__/key-transformation.test.cjs
  • packages/query-codemods/src/v4/key-transformation.cjs

📝 Walkthrough

Walkthrough

The PR adds a guard to the key-transformation codemod that detects missing React Query imports and returns the source unchanged rather than attempting transformation. Test coverage is added with a fixture pair and test case validating that files without React Query imports are not modified.

Changes

Guard for files without React Query imports

Layer / File(s) Summary
Early return guard in codemod
packages/query-codemods/src/v4/key-transformation.cjs
Codemod checks for an ImportDeclaration from react-query and exits early, returning original source if the import is absent; otherwise runs transformers normally.
Test case and fixtures for guard validation
packages/query-codemods/src/v4/__tests__/key-transformation.test.cjs, packages/query-codemods/src/v4/__testfixtures__/no-react-query-import.input.tsx, packages/query-codemods/src/v4/__testfixtures__/no-react-query-import.output.tsx
New test case no-react-query-import with TSX parser validates that a simple React component without React Query imports passes through unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A guard so wise, it checks with care,
If react-query isn't there,
It leaves the code in place, pristine,
No transformation in between—
A simple skip, a quiet pass,
With fixtures bright like morning grass! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete, missing the required 'Changes' section details and checklist items, though it does provide some context about the modifications. Fill out the 'Changes' section explaining what was changed and why, and complete the checklist items to confirm testing and changeset creation.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a guard to skip key transformation when react-query is not imported.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant