Skip to content

Commit 0943575

Browse files
authored
ci(*): init ESLint configurations to include 'vitest/expect-expect' rule as error across multiple packages gradually (#9104)
* chore(*): init ESLint configurations to include 'vitest/expect-expect' rule as error across multiple packages gradually * chore(query-core): remove unused import from ESLint configuration * chore(angular-query-experimental): update eslint rule * chore: integrate vitest ESLint plugin and apply recommended rules across multiple packages * chore(react-query-devtools): add vitest ESLint plugin to configuration
1 parent 127bd01 commit 0943575

File tree

27 files changed

+212
-35
lines changed

27 files changed

+212
-35
lines changed

eslint.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export default [
4545
{
4646
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
4747
plugins: { vitest },
48-
rules: {
49-
...vitest.configs.recommended.rules,
50-
'vitest/expect-expect': 'warn',
51-
},
48+
rules: vitest.configs.recommended.rules,
5249
settings: { vitest: { typecheck: true } },
5350
},
5451
]

packages/angular-query-experimental/eslint.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22

33
import pluginJsdoc from 'eslint-plugin-jsdoc'
4+
import vitest from '@vitest/eslint-plugin'
45
import rootConfig from './root.eslint.config.js'
56

67
export default [
@@ -28,4 +29,13 @@ export default [
2829
],
2930
},
3031
},
32+
{
33+
plugins: { vitest },
34+
rules: {
35+
'vitest/expect-expect': [
36+
'error',
37+
{ assertFunctionNames: ['expect', 'expectSignals'] },
38+
],
39+
},
40+
},
3141
]

packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ describe('initialData', () => {
108108
})
109109

110110
describe('structuralSharing', () => {
111-
it('should restrict to same types', () => {
111+
it('should be able to use structuralSharing with unknown types', () => {
112+
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
112113
injectQuery(() => ({
113114
queryKey: ['key'],
114115
queryFn: () => 5,
115-
structuralSharing: (_oldData, newData) => {
116+
structuralSharing: (oldData, newData) => {
117+
expectTypeOf(oldData).toBeUnknown()
118+
expectTypeOf(newData).toBeUnknown()
116119
return newData
117120
},
118121
}))

packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { mutationOptions } from '../mutation-options'
22

33
describe('mutationOptions', () => {
44
test('should not allow excess properties', () => {
5-
return mutationOptions({
6-
mutationFn: () => Promise.resolve(5),
7-
mutationKey: ['key'],
8-
// @ts-expect-error this is a good error, because onMutates does not exist!
9-
onMutates: 1000,
10-
})
5+
expectTypeOf(mutationOptions).parameter(0).not.toHaveProperty('onMutates')
116
})
127

138
test('should infer types for callbacks', () => {

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import type { Signal } from '@angular/core'
44

55
describe('queryOptions', () => {
66
test('should not allow excess properties', () => {
7-
return queryOptions({
8-
queryKey: ['key'],
9-
queryFn: () => Promise.resolve(5),
10-
// @ts-expect-error this is a good error, because stallTime does not exist!
11-
stallTime: 1000,
12-
})
7+
expectTypeOf(queryOptions).parameter(0).not.toHaveProperty('stallTime')
138
})
149

1510
test('should infer types for callbacks', () => {
16-
return queryOptions({
11+
queryOptions({
1712
queryKey: ['key'],
1813
queryFn: () => Promise.resolve(5),
1914
staleTime: 1000,
@@ -24,7 +19,7 @@ describe('queryOptions', () => {
2419
})
2520

2621
test('should allow undefined response in initialData', () => {
27-
return (id: string | null) =>
22+
const options = (id: string | null) =>
2823
queryOptions({
2924
queryKey: ['todo', id],
3025
queryFn: () =>
@@ -40,6 +35,10 @@ describe('queryOptions', () => {
4035
title: 'Initial Data',
4136
},
4237
})
38+
39+
expectTypeOf(options(null).initialData).returns.toEqualTypeOf<
40+
{ id: string; title: string } | undefined
41+
>()
4342
})
4443
})
4544

packages/eslint-plugin-query/eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default [
88
{
99
plugins: { vitest },
1010
rules: {
11+
...vitest.configs.recommended.rules,
1112
'vitest/expect-expect': [
1213
'warn',
1314
{
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/query-codemods/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

56
export default [
@@ -15,4 +16,11 @@ export default [
1516
'sort-imports': 'off',
1617
},
1718
},
19+
{
20+
plugins: { vitest },
21+
rules: {
22+
...vitest.configs.recommended.rules,
23+
'vitest/expect-expect': 'warn',
24+
},
25+
},
1826
]

packages/query-core/eslint.config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/query-core/src/__tests__/query.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ describe('query', () => {
10031003
const key = queryKey()
10041004

10051005
const queryFn = vi
1006-
.fn()
1006+
.fn<() => Promise<string>>()
10071007
.mockImplementation(() => sleep(10).then(() => 'data'))
10081008

10091009
queryClient.prefetchQuery({
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/react-query-devtools/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import pluginReact from '@eslint-react/eslint-plugin'
45
import pluginReactHooks from 'eslint-plugin-react-hooks'
56
import rootConfig from './root.eslint.config.js'
@@ -19,4 +20,11 @@ export default [
1920
'react-hooks/rules-of-hooks': 'error',
2021
},
2122
},
23+
{
24+
plugins: { vitest },
25+
rules: {
26+
...vitest.configs.recommended.rules,
27+
'vitest/expect-expect': 'warn',
28+
},
29+
},
2230
]

packages/react-query-next-experimental/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import pluginReact from '@eslint-react/eslint-plugin'
45
import pluginReactHooks from 'eslint-plugin-react-hooks'
56
import rootConfig from './root.eslint.config.js'
@@ -20,4 +21,11 @@ export default [
2021
'react-hooks/rules-of-hooks': 'error',
2122
},
2223
},
24+
{
25+
plugins: { vitest },
26+
rules: {
27+
...vitest.configs.recommended.rules,
28+
'vitest/expect-expect': 'warn',
29+
},
30+
},
2331
]

packages/react-query-persist-client/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import pluginReact from '@eslint-react/eslint-plugin'
45
import pluginReactHooks from 'eslint-plugin-react-hooks'
56
import rootConfig from './root.eslint.config.js'
@@ -19,4 +20,11 @@ export default [
1920
'react-hooks/rules-of-hooks': 'error',
2021
},
2122
},
23+
{
24+
plugins: { vitest },
25+
rules: {
26+
...vitest.configs.recommended.rules,
27+
'vitest/expect-expect': 'warn',
28+
},
29+
},
2230
]

packages/react-query/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import pluginReact from '@eslint-react/eslint-plugin'
45
// @ts-expect-error
56
import pluginReactCompiler from 'eslint-plugin-react-compiler'
@@ -31,4 +32,11 @@ export default [
3132
'react-compiler/react-compiler': 'off',
3233
},
3334
},
35+
{
36+
plugins: { vitest },
37+
rules: {
38+
...vitest.configs.recommended.rules,
39+
'vitest/expect-expect': 'warn',
40+
},
41+
},
3442
]

packages/react-query/src/__tests__/useQuery.test-d.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,14 @@ describe('useQuery', () => {
308308
})
309309

310310
describe('structuralSharing', () => {
311-
it('should restrict to same types', () => {
311+
it('should be able to use structuralSharing with unknown types', () => {
312+
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
312313
useQuery({
313314
queryKey: ['key'],
314315
queryFn: () => 5,
315-
structuralSharing: (_oldData, newData) => {
316+
structuralSharing: (oldData, newData) => {
317+
expectTypeOf(oldData).toBeUnknown()
318+
expectTypeOf(newData).toBeUnknown()
316319
return newData
317320
},
318321
})
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/solid-query/eslint.config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/svelte-query-devtools/eslint.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import pluginSvelte from 'eslint-plugin-svelte'
45
import rootConfig from './root.eslint.config.js'
56

@@ -13,4 +14,11 @@ export default [
1314
'svelte/valid-compile': 'off',
1415
},
1516
},
17+
{
18+
plugins: { vitest },
19+
rules: {
20+
...vitest.configs.recommended.rules,
21+
'vitest/expect-expect': 'warn',
22+
},
23+
},
1624
]

0 commit comments

Comments
 (0)