Skip to content

Commit 832fac3

Browse files
feat(eslint-plugin): improve type of exported plugin (#9700)
* feat(eslint-plugin): Improve type of exported plugin Use satisfies operator to verify that the shape of `plugins` matches `ESLint.Plugin` (the extended version of it) while retaining its actual shape. * add changeset --------- Co-authored-by: Lachlan Collins <[email protected]>
1 parent da9e8bc commit 832fac3

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

.changeset/red-monkeys-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/eslint-plugin-query': minor
3+
---
4+
5+
feat: improve type of exported plugin

packages/eslint-plugin-query/src/index.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,13 @@ export interface Plugin extends Omit<ESLint.Plugin, 'rules'> {
1212
}
1313
}
1414

15-
export const plugin: Plugin = {
15+
export const plugin = {
1616
meta: {
1717
name: '@tanstack/eslint-plugin-query',
1818
},
19-
configs: {} as Plugin['configs'],
20-
rules,
21-
}
22-
23-
// Assign configs here so we can reference `plugin`
24-
Object.assign(plugin.configs, {
25-
recommended: {
26-
plugins: ['@tanstack/query'],
27-
rules: {
28-
'@tanstack/query/exhaustive-deps': 'error',
29-
'@tanstack/query/no-rest-destructuring': 'warn',
30-
'@tanstack/query/stable-query-client': 'error',
31-
'@tanstack/query/no-unstable-deps': 'error',
32-
'@tanstack/query/infinite-query-property-order': 'error',
33-
'@tanstack/query/no-void-query-fn': 'error',
34-
'@tanstack/query/mutation-property-order': 'error',
35-
},
36-
},
37-
'flat/recommended': [
38-
{
39-
name: 'tanstack/query/flat/recommended',
40-
plugins: {
41-
'@tanstack/query': plugin,
42-
},
19+
configs: {
20+
recommended: {
21+
plugins: ['@tanstack/query'],
4322
rules: {
4423
'@tanstack/query/exhaustive-deps': 'error',
4524
'@tanstack/query/no-rest-destructuring': 'warn',
@@ -50,7 +29,27 @@ Object.assign(plugin.configs, {
5029
'@tanstack/query/mutation-property-order': 'error',
5130
},
5231
},
53-
],
54-
})
32+
'flat/recommended': [
33+
{
34+
name: 'tanstack/query/flat/recommended',
35+
plugins: {
36+
'@tanstack/query': {}, // Assigned after plugin object created
37+
},
38+
rules: {
39+
'@tanstack/query/exhaustive-deps': 'error',
40+
'@tanstack/query/no-rest-destructuring': 'warn',
41+
'@tanstack/query/stable-query-client': 'error',
42+
'@tanstack/query/no-unstable-deps': 'error',
43+
'@tanstack/query/infinite-query-property-order': 'error',
44+
'@tanstack/query/no-void-query-fn': 'error',
45+
'@tanstack/query/mutation-property-order': 'error',
46+
},
47+
},
48+
],
49+
},
50+
rules,
51+
} satisfies Plugin
52+
53+
plugin.configs['flat/recommended'][0]!.plugins['@tanstack/query'] = plugin
5554

5655
export default plugin

0 commit comments

Comments
 (0)