fix(eslint-plugin-query): use TypeFlags from typescript instead of hardcoded values#10484
fix(eslint-plugin-query): use TypeFlags from typescript instead of hardcoded values#10484mvtandas wants to merge 1 commit intoTanStack:mainfrom
Conversation
…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
📝 WalkthroughWalkthroughReplaced locally-defined Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (1)
packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts
|
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! |
Summary
Fixes #10461
The
no-void-query-fnrule used hardcoded values forTypeFlags.Void(16384) andTypeFlags.Undefined(32768):These internal TypeScript flag values were reordered in TypeScript 6, causing the bitwise check to test for
UniqueESSymbol | EnumLiteralinstead ofVoid | Undefined. This resulted in false positives whenqueryFnreturns an enum member.Fix
Import
TypeFlagsdirectly from thetypescriptpackage (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-fntests pass.Summary by CodeRabbit