fix(eslint-plugin): avoid imports from typescript #9759
main fromrefs/pull/9759/head·merged by TkDodo View on GitHub🎯 Changes#
fixes https://github.com/TanStack/query/issues/9097
While a proper solution would be to split rules that requires type check, it's a bit too early to do it. for now, let's keep it simple.
✅ 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).
Summary by CodeRabbit#
- New Features
- None
- Bug Fixes
- Updated the “no-void-query-fn” lint rule to remove reliance on a direct TypeScript import and instead use parser-provided type information, improving compatibility and reducing incorrect reports or crashes for awaited void/undefined returns.
- Chores
- Added a changeset entry for a patch release of the ESLint plugin.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: eslint-plugin-query
Walkthrough#
Replaces direct
typescriptruntime import in the no-void-query-fn ESLint rule with type-only parser-service usage; adds a changeset entry for a patch release describing this avoidance and refactors type-checking to use local TypeFlags and parser-derived type aliases.Changes#
Cohort / File(s) Summary Release metadata /.changeset/shy-wasps-pull.mdAdds a patch changeset for @tanstack/eslint-plugin-queryexplaining the removal of a direct TypeScript import in the rule.Rule refactor (no direct TS import) /packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.tsRemoves runtime typescriptusage; adds a type-only import forParserServicesWithTypeInformation; derivesProgram,TypeChecker, andTypealiases from parser services; introduces localTypeFlagsconstants (Void, Undefined) and updates return-type checks to use parser-provided type checker and bitwise checks against local flags.Sequence Diagram(s)#
sequenceDiagram autonumber actor Dev as ESLint CLI participant ESL as ESLint participant Rule as no-void-query-fn rule participant PS as ParserServicesWithTypeInformation participant TC as TypeChecker (from PS) Dev->>ESL: Run lint ESL->>Rule: Evaluate rule for function node Rule->>PS: getParserServices() / request Program & services PS-->>Rule: Program, parser services, and typeChecker Rule->>TC: getTypeAtLocation(returnNode) TC-->>Rule: Type Note over Rule: Use local TypeFlags (Void/Undefined) to check awaited type Rule-->>ESL: Report violation if illegal void/undefined return ESL-->>Dev: Lint resultsEstimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers#
- lachlancollins
- TkDodo
Poem#
A rabbit hops through parser trees at night, I swap imports for services, tidy and light. Flags for void and undefined I spy, I nibble buggy returns as they flutter by. Patch stitched, I thump—merge takes flight. 🥕
Pre-merge checks and finishing touches#
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution Description Check ⚠️ Warning The pull request description includes the required sections and a completed checklist, but the 🎯 Changes section still contains the placeholder comment and lacks a clear summary of the actual code modifications. This omission obscures the specific updates made to the ESLint rule and the motivation behind them. Because the placeholder remains, reviewers cannot quickly verify the scope and impact of the change. The authors should remove the placeholder comment in the 🎯 Changes section and provide a concise description of the code changes, such as replacing TypeScript imports with parser services and updating type checks. Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (3 passed)
Check name Status Explanation Title Check ✅ Passed The pull request title succinctly and accurately reflects the primary change of avoiding direct TypeScript imports in the ESLint plugin rule and follows conventional commit style with an appropriate scope. It clearly conveys the intent without extraneous detail or vagueness and will be informative in the project history. This makes it easy for anyone scanning the commit log to understand the key fix at a glance. Linked Issues Check ✅ Passed The modifications remove direct imports of the TypeScript package by using type-only imports of ParserServicesWithTypeInformation and deriving type checker interfaces from parser services, which directly addresses the peer dependency resolution failures described in issue #9097. It replaces direct ts.TypeFlags usage with a local TypeFlags constant and integrates with parser-provided type information. These changes ensure ESLint can run without requiring a hoisted TypeScript dependency and align with the expected behavior outlined in the linked issue. Out of Scope Changes Check ✅ Passed All modifications are limited to the changeset entry and the no-void-query-fn ESLint rule, which are both directly related to fixing the TypeScript import issue. There are no unrelated or out-of-scope updates in this pull request. The changes do not introduce any additional features or affect other parts of the codebase. ✨ 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-avoid-importing-typescript`
📜 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 35da1a60af3ee0ad5243e0090a7b3003a9202630 and d9ad4a73696abb0bbc2e1a77364a1951d0764f6b.
📒 Files selected for processing (1)
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts(3 hunks)
⏰ 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 (2)
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts (2)
5-5: Excellent approach to eliminate the runtime typescript dependency.The type-only import and derived type aliases successfully avoid importing
typescriptat runtime while maintaining full type safety through the parser services. This directly addresses the core issue reported in #9097 where package managers without hoisting couldn't resolve thetypescriptmodule.Also applies to: 77-79
81-81: Function correctly updated to use local types and flags.The function signature and bitwise flag check properly utilize the locally defined type aliases and
TypeFlagsconstant, maintaining the original logic while eliminating thetypescriptimport dependency.Also applies to: 90-90
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.View your CI Pipeline Execution ↗ for commit d9ad4a73696abb0bbc2e1a77364a1951d0764f6b
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 1m 28s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 5s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-15 08:18:16UTCMore 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-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-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-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@9759@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9759@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9759@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9759@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@9759@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@9759@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9759@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9759@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@9759@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@9759@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9759@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9759@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@9759@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9759@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9759@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@9759@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9759@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9759@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@9759@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9759commit:
d9ad4a7Codecov Report#
:x: Patch coverage is
33.33333%with2 linesin your changes missing coverage. Please review. :white_check_mark: Project coverage is 83.36%. Comparing base (36ece87) to head (d9ad4a7). :warning: Report is 1 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #9759 +/- ## =========================================== + Coverage 45.54% 83.36% +37.81% =========================================== Files 196 19 -177 Lines 8328 559 -7769 Branches 1903 204 -1699 =========================================== - Hits 3793 466 -3327 + Misses 4093 71 -4022 + Partials 442 22 -420Components Coverage Δ @tanstack/angular-query-experimental ∅ <ø> (∅)@tanstack/eslint-plugin-query 83.36% <33.33%> (+0.32%):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: 1
🧹 Nitpick comments (1)
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts (1)
81-91: LGTM!The refactored
isIllegalReturnfunction correctly uses the localTypeFlagsconstant and maintains the same logic as before.Optional: The ternary on line 90 can be simplified:
- return awaited.flags & (TypeFlags.Void | TypeFlags.Undefined) ? true : false + return (awaited.flags & (TypeFlags.Void | TypeFlags.Undefined)) !== 0📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 36ece87d7035cb52bdd82802f0c47b1f40411fa7 and 35da1a60af3ee0ad5243e0090a7b3003a9202630.
📒 Files selected for processing (2)
.changeset/shy-wasps-pull.md(1 hunks)packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts(3 hunks)
⏰ 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)
.changeset/shy-wasps-pull.md (1)
1-5: LGTM!The changeset correctly documents this as a patch-level fix. The description accurately captures the essence of the change.
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts (2)
5-5: LGTM!The type-only import of
ParserServicesWithTypeInformationis correct and eliminates the need for direct TypeScript imports.
77-79: LGTM!The type aliases correctly derive types from
ParserServicesWithTypeInformationwithout importing TypeScript directly. This approach is actually more type-safe because it guarantees compatibility with the parser services' actual return types.packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts lines 8 to 11Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1,7 +1,11 @@11 import { ESLintUtils } from '@typescript-eslint/utils'2-import ts from 'typescript'32 import { ASTUtils } from '../../utils/ast-utils'43 import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'54 import { getDocsUrl } from '../../utils/get-docs-url'5+import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils'66 import type { ExtraRuleDocs } from '../../types'778+const TypeFlags = {9+ Void: 1 << 16, // 6553610+ Undefined: 1 << 17, // 13107211+} as const⚠️ Potential issue | 🔴 Critical
🧩 Analysis chain
Verify TypeFlags values match TypeScript's internal enum.
The hardcoded bit values eliminate the TypeScript dependency, which solves the core issue. However, if TypeScript changes these internal flag values in future versions, this code will silently produce incorrect results.
Consider adding a comment explaining these values:
const TypeFlags = { + // These values must match TypeScript's internal TypeFlags enum + // TypeScript source: https://github.com/microsoft/TypeScript/blob/main/src/compiler/types.ts Void: 1 << 16, // 65536 Undefined: 1 << 17, // 131072 } as constRun the following script to verify these values haven't changed in recent TypeScript versions:
🏁 Script executed:
#!/bin/bash # Verify TypeFlags values from TypeScript source # Fetch the TypeFlags enum definition from TypeScript's main branch curl -s https://raw.githubusercontent.com/microsoft/TypeScript/main/src/compiler/types.ts | \ grep -A 50 "export const enum TypeFlags" | \ grep -E "(Void|Undefined)\s*="Length of output: 62
Update TypeFlags to match TypeScript’s internal enum The hardcoded values for
VoidandUndefined(1<<16, 1<<17) don’t align with TS’sTypeFlags(1<<14, 1<<15). Adjust as shown:@@ packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts const TypeFlags = { - Void: 1 << 16, // 65536 - Undefined: 1 << 17, // 131072 + // Must match TS’s internal TypeFlags enum: + // https://github.com/microsoft/TypeScript/blob/main/src/compiler/types.ts + Void: 1 << 14, // 16384 + Undefined: 1 << 15, // 32768 } as const📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change8-const TypeFlags = {9- Void: 1 << 16, // 6553610- Undefined: 1 << 17, // 13107211-} as const8+const TypeFlags = {9+ // Must match TS’s internal TypeFlags enum:10+ // https://github.com/microsoft/TypeScript/blob/main/src/compiler/types.ts11+ Void: 1 << 14, // 1638412+ Undefined: 1 << 15, // 3276813+} as const🤖 Prompt for AI Agents
In packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts around lines 8 to 11, the TypeFlags constants use incorrect bit positions (1<<16, 1<<17); update them to match TypeScript’s internal TypeFlags enum by using Void = 1<<14 and Undefined = 1<<15 (keep as const) so the flags align with TS behavior.✅ Addressed in commit d9ad4a7
TkDodo merged thisb9a478d
TkDodo closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: d9ad4a73696abb0bbc2e1a77364a1951d0764f6b
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