-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(eslint-plugin): improve type of exported plugin #9700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(eslint-plugin): improve type of exported plugin #9700
Conversation
Use satisfies operator to verify that the shape of `plugins` matches `ESLint.Plugin` (the extended version of it) while retaining its actual shape.
π¦ Changeset detectedLatest commit: f35e108 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 |
WalkthroughIntroduces a new changeset entry and refactors the ESLint plugin export by inlining configs, adding a flat/recommended preset, removing the explicit Plugin type annotation, and performing a post-creation assignment to reference the plugin within its flat config. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant ESLint as ESLint
participant Plugin as @tanstack/eslint-plugin-query
Dev->>ESLint: import { defineConfig }
Dev->>Plugin: import plugin
Note over Plugin: plugin object created with inlined configs
Plugin->>Plugin: set configs['flat/recommended'][0].plugins['@tanstack/query'] = plugin
Dev->>ESLint: defineConfig([...plugin.configs['flat/recommended']])
ESLint->>ESLint: Load rules from plugin and apply recommended sets
Estimated code review effortπ― 2 (Simple) | β±οΈ ~10 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touchesβ Passed checks (5 passed)
β¨ Finishing touches
π§ͺ Generate 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (4)
.changeset/red-monkeys-attack.md (1)
2-5
: Minor bump is appropriate; clarify the user-facing change.The version bump to minor makes sense (new flat config + type improvements). Consider making the summary explicitly mention the new
flat/recommended
preset and the compatibility fix foreslint/config
βsdefineConfig()
, and link the issue to auto-close.Apply this diff to tighten the message:
-feat: improve type of exported plugin +feat: add `flat/recommended` preset and improve exported plugin types + +This makes `@tanstack/eslint-plugin-query` configs compatible with `eslint/config`βs `defineConfig()` and fixes the type mismatch reported in #9689.packages/eslint-plugin-query/src/index.ts (3)
32-49
: Avoid post-creation mutation; build the flat config without placeholders.The placeholder
{}
plus the follow-up assignment works but is brittle and makes the object temporarily invalid. Consider constructing via a small factory/IIFE so the plugin self-reference is wired at creation time.Example refactor (keeps your
satisfies
pattern, removes the mutation):// above: import/types stay the same const recommendedRules: Linter.RulesRecord = { '@tanstack/query/exhaustive-deps': 'error', '@tanstack/query/no-rest-destructuring': 'warn', '@tanstack/query/stable-query-client': 'error', '@tanstack/query/no-unstable-deps': 'error', '@tanstack/query/infinite-query-property-order': 'error', '@tanstack/query/no-void-query-fn': 'error', '@tanstack/query/mutation-property-order': 'error', }; export const plugin = (() => { const core = { meta: { name: '@tanstack/eslint-plugin-query' }, rules, } satisfies ESLint.Plugin & { rules: Record<RuleKey, RuleModule<any, any, any>> }; return { ...core, configs: { recommended: { plugins: ['@tanstack/query'], rules: recommendedRules, }, 'flat/recommended': [ { name: '@tanstack/query/flat/recommended', plugins: { '@tanstack/query': core }, rules: recommendedRules, }, ], }, } satisfies Plugin; })();Minimal alternative (if you prefer to keep structure): assign
core
instead ofplugin
in the flat configβsplugins
map;ESLint.Plugin
doesnβt requireconfigs
, socore
suffices.
34-34
: Nit: include scope in the flat configname
.For clarity in tooling/debug output, prefer
@tanstack/query/flat/recommended
.Apply this diff:
- name: 'tanstack/query/flat/recommended', + name: '@tanstack/query/flat/recommended',
53-53
: Remove non-null assertion and guard the mutation (or drop it per refactor).If you keep the current pattern, avoid
!
and add a small guard to prevent future refactors from throwing.-plugin.configs['flat/recommended'][0]!.plugins['@tanstack/query'] = plugin +const firstFlat = plugin.configs['flat/recommended'][0] +if (firstFlat?.plugins) { + firstFlat.plugins['@tanstack/query'] = plugin +}Alternatively, adopt the factory approach above and delete this line entirely.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
.changeset/red-monkeys-attack.md
(1 hunks)packages/eslint-plugin-query/src/index.ts
(2 hunks)
π§° Additional context used
π§ Learnings (1)
π Learning: 2025-08-19T03:18:18.303Z
Learnt from: oscartbeaumont
PR: TanStack/query#9564
File: packages/solid-query-devtools/src/production.tsx:2-3
Timestamp: 2025-08-19T03:18:18.303Z
Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.
Applied to files:
packages/eslint-plugin-query/src/index.ts
π Additional comments (2)
packages/eslint-plugin-query/src/index.ts (2)
15-51
: Good use ofsatisfies
to keep runtime shape and strengthen types.Inlining
configs
and validating the object withsatisfies Plugin
is clean and addresses the compatibility goal.
19-21
: Legacy (eslintrc)recommended
config looks correct.
plugins: ['@tanstack/query']
and the rules set align with the classic config expectations.If you have examples/docs that import
plugin.configs.recommended
, verify a quick smoke run with ESLint 9.x using eslintrc to ensure no regressions in legacy users.
View your CI Pipeline Execution β for commit f35e108
βοΈ Nx Cloud last updated this comment at |
Codecov Reportβ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #9700 +/- ##
===========================================
+ Coverage 46.41% 83.03% +36.61%
===========================================
Files 214 19 -195
Lines 8499 560 -7939
Branches 1930 206 -1724
===========================================
- Hits 3945 465 -3480
+ Misses 4111 73 -4038
+ Partials 443 22 -421 π New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks @mdmower-csnw !
π― Changes
Use TypeScript's
satisfies
operator to verify that the shape ofplugins
matchesESLint.Plugin
(the extended version of it) while retaining its actual shape.Fixes #9689
β Checklist
pnpm test:pr
.π Release Impact
Summary by CodeRabbit