Skip to content

fix(eslint-plugin-query): use TypeFlags from typescript instead of hardcoded values#10484

Open
mvtandas wants to merge 1 commit intoTanStack:mainfrom
mvtandas:fix/eslint-no-void-query-fn-ts6
Open

fix(eslint-plugin-query): use TypeFlags from typescript instead of hardcoded values#10484
mvtandas wants to merge 1 commit intoTanStack:mainfrom
mvtandas:fix/eslint-no-void-query-fn-ts6

Conversation

@mvtandas
Copy link
Copy Markdown

@mvtandas mvtandas commented Apr 13, 2026

Summary

Fixes #10461

The no-void-query-fn rule used hardcoded values for TypeFlags.Void (16384) and TypeFlags.Undefined (32768):

const TypeFlags = {
  Void: 16384,
  Undefined: 32768,
} as const

These internal TypeScript flag values were reordered in TypeScript 6, causing the bitwise check to test for UniqueESSymbol | EnumLiteral instead of Void | Undefined. This resulted in false positives when queryFn returns an enum member.

Fix

Import TypeFlags directly from the typescript package (already listed as a peer dependency) instead of hardcoding the numeric values. This ensures correct behavior across all supported TypeScript versions (5.x and 6.x).

Test

All 34 existing no-void-query-fn tests pass.

Summary by CodeRabbit

  • Refactor
    • Updated internal implementation in eslint-plugin-query to improve code maintainability with no visible user-facing changes.

…rdcoded values

The `no-void-query-fn` rule used hardcoded values for `TypeFlags.Void`
(16384) and `TypeFlags.Undefined` (32768). These internal TypeScript
flag values were reordered in TypeScript 6 (microsoft/TypeScript#63084),
causing the rule to incorrectly flag enum returns as void/undefined.

Import `TypeFlags` from the `typescript` package (already a peer
dependency) so the correct flag values are always used regardless of
the TypeScript version.

Fixes TanStack#10461
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

Replaced locally-defined TypeFlags constant with imports from the typescript module in the no-void-query-fn ESLint rule to fix false positives when returning TypeScript enum members in TypeScript 6.

Changes

Cohort / File(s) Summary
TypeFlags Import Fix
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts
Removed hardcoded TypeFlags constants (Void: 16384, Undefined: 32768) and imported TypeFlags from the typescript module instead. Updated isIllegalReturn() to use the imported values, addressing TypeScript 6 compatibility where internal flag values changed ordering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hopped through TypeScript's land,
Where flags once stood with values grand,
But TypeScript 6 rearranged the scheme,
So we imported truth instead of dream!
No more false enums caught in the net,
The fix was simple—one line, no sweat! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers the issue, the root cause, and the fix, but lacks checklist completion indicators and changeset documentation required by the template. Complete the checklist items and confirm if a changeset was generated for this bugfix release.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: replacing hardcoded TypeFlags values with an import from the typescript package.
Linked Issues check ✅ Passed The PR successfully addresses the core requirement from #10461: importing TypeFlags directly from typescript instead of using hardcoded values, fixing false positives on enum returns.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to the no-void-query-fn rule, replacing hardcoded TypeFlags with an import, directly addressing the linked issue with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts (1)

86-86: Add a regression test for enum-member returns.

The implementation correctly handles enum members (they have different TypeFlags than Void/Undefined), but this edge case lacks explicit test coverage. Add a test case like:

{
  name: 'queryFn returns an enum member',
  code: normalizeIndent`
    import { useQuery } from '@tanstack/react-query'
    enum Status { Active }
    export default function Test() {
      const query = useQuery({
        queryKey: ['test'],
        queryFn: () => Status.Active,
      })
      return null
    }
  `,
},

This ensures enum returns continue to pass the rule and prevents silent regressions if TypeFlags handling changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts`
at line 86, Add a regression test to the no-void-query-fn rule tests to cover
enum-member returns: create a test case named "queryFn returns an enum member"
that uses the provided code snippet (import useQuery, declare enum Status {
Active }, and a useQuery whose queryFn returns Status.Active) and assert the
rule does not report an error; place it alongside the existing test cases for
the no-void-query-fn rule so the rule implementation (no-void-query-fn.rule.ts /
the logic using TypeFlags.Void | TypeFlags.Undefined) is exercised for enum
returns and prevents future regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts`:
- Line 86: Add a regression test to the no-void-query-fn rule tests to cover
enum-member returns: create a test case named "queryFn returns an enum member"
that uses the provided code snippet (import useQuery, declare enum Status {
Active }, and a useQuery whose queryFn returns Status.Active) and assert the
rule does not report an error; place it alongside the existing test cases for
the no-void-query-fn rule so the rule implementation (no-void-query-fn.rule.ts /
the logic using TypeFlags.Void | TypeFlags.Undefined) is exercised for enum
returns and prevents future regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cecf5b00-32fb-4a9d-ad2a-2dec896bb6c0

📥 Commits

Reviewing files that changed from the base of the PR and between 479b9a5 and 405410f.

📒 Files selected for processing (1)
  • packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts

@mvtandas
Copy link
Copy Markdown
Author

Friendly ping — this is a one-line fix (removes hardcoded TypeFlags values in favor of importing from typescript). All existing tests pass. Happy to address any feedback!

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.

[eslint-plugin-query] no-void-query-fn false positive on enum returns with TypeScript 6

1 participant