Skip to content

Commit ef69e45

Browse files
authored
Merge branch 'main' into test/no-void-query-fn-coverage
2 parents ce694c7 + a62f695 commit ef69e45

File tree

9 files changed

+612
-498
lines changed

9 files changed

+612
-498
lines changed

packages/eslint-plugin-query/src/__tests__/stable-query-client.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ ruleTester.run('stable-query-client', rule, {
9696
`,
9797
},
9898
{
99-
name: 'QueryClient is invoked in an async (react server) component',
99+
name: 'QueryClient is not flagged when imported from a non-react-query package in an async component',
100100
code: normalizeIndent`
101101
import { QueryClient } from "@tanstack/solid-query";
102102
@@ -106,6 +106,17 @@ ruleTester.run('stable-query-client', rule, {
106106
}
107107
`,
108108
},
109+
{
110+
name: 'QueryClient is not flagged in an async react-query server component',
111+
code: normalizeIndent`
112+
import { QueryClient } from "@tanstack/react-query";
113+
114+
async function ServerComponent() {
115+
const queryClient = new QueryClient();
116+
return;
117+
}
118+
`,
119+
},
109120
],
110121
invalid: [
111122
{
@@ -188,5 +199,18 @@ ruleTester.run('stable-query-client', rule, {
188199
`,
189200
errors: [{ messageId: 'unstable' }],
190201
},
202+
{
203+
name: 'QueryClient with destructuring pattern reports error without autofix',
204+
code: normalizeIndent`
205+
import { QueryClient } from "@tanstack/react-query";
206+
207+
function Component() {
208+
const { defaultOptions } = new QueryClient();
209+
return;
210+
}
211+
`,
212+
output: null,
213+
errors: [{ messageId: 'unstable' }],
214+
},
191215
],
192216
})

packages/preact-query/src/__tests__/useMutationState.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('useMutationState', () => {
206206
function Mutate() {
207207
const { mutate, data } = useMutation({
208208
mutationKey,
209-
mutationFn: (input: number) => sleep(150).then(() => 'data' + input),
209+
mutationFn: (input: number) => sleep(150).then(() => `data${input}`),
210210
})
211211

212212
return (

packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const generateInfiniteQueryOptions = (
2525
.mockImplementation(async () => {
2626
const currentPageData = data[currentPage]
2727
if (!currentPageData) {
28-
throw new Error('No data defined for page ' + currentPage)
28+
throw new Error(`No data defined for page ${currentPage}`)
2929
}
3030

3131
await sleep(10)

packages/preact-query/src/__tests__/useQueries.test.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('useQueries', () => {
190190
queryFn: () => 'string',
191191
select: (a) => {
192192
expectTypeOf(a).toEqualTypeOf<string>()
193-
return parseInt(a)
193+
return parseInt(a, 10)
194194
},
195195
},
196196
],
@@ -219,7 +219,7 @@ describe('useQueries', () => {
219219
queryFn: () => 'string',
220220
select: (a) => {
221221
expectTypeOf(a).toEqualTypeOf<string>()
222-
return parseInt(a)
222+
return parseInt(a, 10)
223223
},
224224
placeholderData: 'string',
225225
// @ts-expect-error (initialData: string)
@@ -302,7 +302,7 @@ describe('useQueries', () => {
302302
queryFn: () => 'string',
303303
select: (a) => {
304304
expectTypeOf(a).toEqualTypeOf<string>()
305-
return parseInt(a)
305+
return parseInt(a, 10)
306306
},
307307
},
308308
],
@@ -362,7 +362,7 @@ describe('useQueries', () => {
362362
queryFn: () => 'string',
363363
select: (a) => {
364364
expectTypeOf(a).toEqualTypeOf<string>()
365-
return parseInt(a)
365+
return parseInt(a, 10)
366366
},
367367
placeholderData: 'string',
368368
// @ts-expect-error (initialData: string)
@@ -404,7 +404,7 @@ describe('useQueries', () => {
404404
queryFn: () => 'string',
405405
select: (a) => {
406406
expectTypeOf(a).toEqualTypeOf<string>()
407-
return parseInt(a)
407+
return parseInt(a, 10)
408408
},
409409
}),
410410
],
@@ -556,7 +556,7 @@ describe('useQueries', () => {
556556
{
557557
queryKey: key4,
558558
queryFn: () => 'string',
559-
select: (a: string) => parseInt(a),
559+
select: (a: string) => parseInt(a, 10),
560560
},
561561
{
562562
queryKey: key5,
@@ -596,12 +596,12 @@ describe('useQueries', () => {
596596
{
597597
queryKey: key4,
598598
queryFn: () => 'string',
599-
select: (a: string) => parseInt(a),
599+
select: (a: string) => parseInt(a, 10),
600600
},
601601
{
602602
queryKey: key5,
603603
queryFn: () => 'string',
604-
select: (a: string) => parseInt(a),
604+
select: (a: string) => parseInt(a, 10),
605605
throwOnError,
606606
},
607607
],
@@ -1138,14 +1138,14 @@ describe('useQueries', () => {
11381138
queryKey: key1,
11391139
queryFn: async () => {
11401140
await sleep(5)
1141-
return Promise.resolve('first result ' + count)
1141+
return Promise.resolve(`first result ${count}`)
11421142
},
11431143
},
11441144
{
11451145
queryKey: key2,
11461146
queryFn: async () => {
11471147
await sleep(50)
1148-
return Promise.resolve('second result ' + count)
1148+
return Promise.resolve(`second result ${count}`)
11491149
},
11501150
},
11511151
],
@@ -1330,14 +1330,14 @@ describe('useQueries', () => {
13301330
queryKey: key1,
13311331
queryFn: async () => {
13321332
await sleep(10)
1333-
return 'first result:' + value
1333+
return `first result:${value}`
13341334
},
13351335
},
13361336
{
13371337
queryKey: key2,
13381338
queryFn: async () => {
13391339
await sleep(20)
1340-
return 'second result:' + value
1340+
return `second result:${value}`
13411341
},
13421342
},
13431343
],

packages/preact-query/src/__tests__/useQuery.test.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe('useQuery', () => {
473473
queryKey: key,
474474
queryFn: async () => {
475475
await sleep(10)
476-
return 'data: ' + value
476+
return `data: ${value}`
477477
},
478478

479479
gcTime: 0,
@@ -769,7 +769,7 @@ describe('useQuery', () => {
769769
queryFn: async () => {
770770
await sleep(10)
771771
count++
772-
return 'test' + count
772+
return `test${count}`
773773
},
774774
})
775775

@@ -3686,9 +3686,8 @@ describe('useQuery', () => {
36863686
if (counter < 2) {
36873687
counter++
36883688
return Promise.reject(new Error('error'))
3689-
} else {
3690-
return Promise.resolve('data')
36913689
}
3690+
return Promise.resolve('data')
36923691
},
36933692
retryDelay: 10,
36943693
})
@@ -5062,9 +5061,8 @@ describe('useQuery', () => {
50625061
await sleep(10)
50635062
if (id % 2 === 1) {
50645063
return Promise.reject(new Error('Error'))
5065-
} else {
5066-
return 'data'
50675064
}
5065+
return 'data'
50685066
},
50695067
retry: false,
50705068
retryOnMount: false,
@@ -5300,7 +5298,7 @@ describe('useQuery', () => {
53005298
queryFn: async () => {
53015299
count++
53025300
await sleep(10)
5303-
return 'data' + count
5301+
return `data${count}`
53045302
},
53055303
})
53065304

@@ -5363,7 +5361,7 @@ describe('useQuery', () => {
53635361
queryFn: async () => {
53645362
count++
53655363
await sleep(10)
5366-
return 'data' + count
5364+
return `data${count}`
53675365
},
53685366
})
53695367

@@ -5411,7 +5409,7 @@ describe('useQuery', () => {
54115409
queryFn: async () => {
54125410
count++
54135411
await sleep(10)
5414-
return 'data' + count
5412+
return `data${count}`
54155413
},
54165414
})
54175415

@@ -5457,7 +5455,7 @@ describe('useQuery', () => {
54575455
queryFn: async () => {
54585456
count++
54595457
await sleep(10)
5460-
return 'data' + count
5458+
return `data${count}`
54615459
},
54625460
initialData: 'initial',
54635461
})
@@ -5505,7 +5503,7 @@ describe('useQuery', () => {
55055503
queryFn: async () => {
55065504
count++
55075505
await sleep(10)
5508-
return 'data' + count
5506+
return `data${count}`
55095507
},
55105508
initialData: 'initial',
55115509
})
@@ -5565,7 +5563,7 @@ describe('useQuery', () => {
55655563
queryFn: async (): Promise<unknown> => {
55665564
count++
55675565
await sleep(10)
5568-
throw new Error('failed' + count)
5566+
throw new Error(`failed${count}`)
55695567
},
55705568
retry: 2,
55715569
retryDelay: 10,
@@ -5678,7 +5676,7 @@ describe('useQuery', () => {
56785676
queryFn: async () => {
56795677
count++
56805678
await sleep(10)
5681-
return 'data' + count
5679+
return `data${count}`
56825680
},
56835681
})
56845682

@@ -5735,7 +5733,7 @@ describe('useQuery', () => {
57355733
queryFn: async () => {
57365734
count++
57375735
await sleep(10)
5738-
return 'data' + count
5736+
return `data${count}`
57395737
},
57405738
refetchOnReconnect: false,
57415739
})
@@ -5787,7 +5785,7 @@ describe('useQuery', () => {
57875785
function Component() {
57885786
const state = useQuery({
57895787
queryKey: key,
5790-
queryFn: async () => {
5788+
queryFn: () => {
57915789
count++
57925790
return `data${count}`
57935791
},
@@ -5862,7 +5860,7 @@ describe('useQuery', () => {
58625860
queryFn: async () => {
58635861
count++
58645862
await sleep(10)
5865-
return 'data ' + count
5863+
return `data ${count}`
58665864
},
58675865
networkMode: 'always',
58685866
})
@@ -5898,7 +5896,7 @@ describe('useQuery', () => {
58985896
queryFn: async (): Promise<unknown> => {
58995897
count++
59005898
await sleep(10)
5901-
throw new Error('error ' + count)
5899+
throw new Error(`error ${count}`)
59025900
},
59035901
networkMode: 'always',
59045902
retry: 1,
@@ -5942,7 +5940,7 @@ describe('useQuery', () => {
59425940
queryFn: async (): Promise<unknown> => {
59435941
count++
59445942
await sleep(10)
5945-
throw new Error('failed' + count)
5943+
throw new Error(`failed${count}`)
59465944
},
59475945
retry: 2,
59485946
retryDelay: 1,
@@ -6067,7 +6065,7 @@ describe('useQuery', () => {
60676065
renders++
60686066
return (
60696067
<div>
6070-
<span>{data ? 'has data' + data : 'no data'}</span>
6068+
<span>{data ? `has data${data}` : 'no data'}</span>
60716069
<button
60726070
onClick={() => queryClient.setQueryData<string>(key, 'new data')}
60736071
>
@@ -6697,7 +6695,7 @@ describe('useQuery', () => {
66976695
expect(results[3]).toMatchObject({
66986696
status: 'error',
66996697
fetchStatus: 'idle',
6700-
error: error,
6698+
error,
67016699
errorUpdateCount: 2,
67026700
isLoading: false,
67036701
failureCount: 1,

0 commit comments

Comments
 (0)