Skip to content
Source
Sign inSign up
TanStack/query

fix(eslint-plugin): avoid imports from typescript #9759

MergedNewbie012(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/9759/headmerged 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. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 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
      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. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Walkthrough

      Replaces direct typescript runtime 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.md
      Adds a patch changeset for @tanstack/eslint-plugin-query explaining 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.ts
      Removes runtime typescript usage; adds a type-only import for ParserServicesWithTypeInformation; derives Program, TypeChecker, and Type aliases from parser services; introduces local TypeFlags constants (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 results

      Estimated 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 nameStatusExplanationResolution
      Description Check⚠️ WarningThe 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⚠️ WarningDocstring 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 nameStatusExplanation
      Title Check✅ PassedThe 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✅ PassedThe 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✅ PassedAll 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 typescript at 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 the typescript module.

      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 TypeFlags constant, maintaining the original logic while eliminating the typescript import 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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    4. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit d9ad4a73696abb0bbc2e1a77364a1951d0764f6b

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 28sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded5sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-10-15 08:18:16 UTC

    5. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

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

      commit: d9ad4a7

    6. github-actions[bot](GitHub profile, opens in a new tab)commented

      Sizes for commit d9ad4a73696abb0bbc2e1a77364a1951d0764f6b:

      BranchBundle Size
      Main
      This PR
    7. codecov[bot](GitHub profile, opens in a new tab)commented

      Codecov Report

      :x: Patch coverage is 33.33333% with 2 lines in 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

      Impacted file tree graph

      @@             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      -420     
      ComponentsCoverage Δ
      @tanstack/angular-query-experimental∅ <ø> (∅)
      @tanstack/eslint-plugin-query83.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 isIllegalReturn function correctly uses the local TypeFlags constant 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 ParserServicesWithTypeInformation is correct and eliminates the need for direct TypeScript imports.


    77-79: LGTM!

    The type aliases correctly derive types from ParserServicesWithTypeInformation without importing TypeScript directly. This approach is actually more type-safe because it guarantees compatibility with the parser services' actual return types.

  • TkDodo merged thisb9a478d

  • TkDodo closed this

  • Sign in to join this conversation.