@@ -13,13 +13,18 @@ import {
1313 generateInterleavedCombinations ,
1414 generatePartialCombinations ,
1515 generatePermutations ,
16+ normalizeIndent ,
1617} from './test-utils'
1718import type { InfiniteQueryFunctions } from '../rules/infinite-query-property-order/constants'
1819
1920const ruleTester = new RuleTester ( )
2021
2122type CheckedProperties = ( typeof checkedProperties ) [ number ]
22- const orderIndependentProps = [ 'queryKey' , '...foo' ] as const
23+ const orderIndependentProps = [
24+ 'queryKey' ,
25+ '...objectExpressionSpread' ,
26+ '...callExpressionSpread' ,
27+ ] as const
2328type OrderIndependentProps = ( typeof orderIndependentProps ) [ number ]
2429
2530interface TestCase {
@@ -84,7 +89,7 @@ export function generateInvalidPermutations(
8489 Math . abs (
8590 invalid . indexOf ( 'getNextPageParam' ) -
8691 invalid . indexOf ( 'getPreviousPageParam' ) ,
87- ) !== 1 && ! invalid . includes ( 'queryFn' ) ,
92+ ) !== 1 ,
8893 ) ,
8994 )
9095 }
@@ -122,17 +127,26 @@ const invalidTestMatrix = combinate({
122127 properties : interleavedInvalidPermutations ,
123128} )
124129
130+ const callExpressionSpread = normalizeIndent `
131+ ...communitiesQuery({
132+ filters: {
133+ ...fieldValues,
134+ placementFormats: [],
135+ },
136+ })`
137+
125138function getCode ( {
126139 infiniteQueryFunction : infiniteQueryFunction ,
127140 properties,
128141} : TestCase ) {
129142 function getPropertyCode (
130143 property : CheckedProperties | OrderIndependentProps ,
131144 ) {
132- if ( property . startsWith ( '...' ) ) {
133- return property
134- }
135145 switch ( property ) {
146+ case '...objectExpressionSpread' :
147+ return `...objectExpressionSpread`
148+ case '...callExpressionSpread' :
149+ return callExpressionSpread
136150 case 'queryKey' :
137151 return `queryKey: ['projects']`
138152 case 'queryFn' :
@@ -142,8 +156,6 @@ function getCode({
142156 case 'getNextPageParam' :
143157 return 'getNextPageParam: (lastPage) => lastPage.nextId ?? undefined'
144158 }
145-
146- return `${ property } : () => null`
147159 }
148160 return `
149161 import { ${ infiniteQueryFunction } } from '@tanstack/react-query'
@@ -180,3 +192,28 @@ ruleTester.run(name, rule, {
180192 valid : validTestCases ,
181193 invalid : invalidTestCases ,
182194} )
195+
196+ // regression tests
197+
198+ const regressionTestCases = {
199+ valid : [
200+ {
201+ name : 'should pass with call expression spread' ,
202+ code : normalizeIndent `
203+ import { useInfiniteQuery } from '@tanstack/react-query'
204+ const { data, isFetching, isLoading, hasNextPage, fetchNextPage } =
205+ useInfiniteQuery({
206+ ...communitiesQuery({
207+ filters: {
208+ ...fieldValues,
209+ placementFormats: [],
210+ },
211+ }),
212+ refetchOnMount: false,
213+ })` ,
214+ } ,
215+ ] ,
216+ invalid : [ ] ,
217+ }
218+
219+ ruleTester . run ( name , rule , regressionTestCases )
0 commit comments