@tanstack/eslint-plugin-query 5.94.4 → 5.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.cts +329 -0
  2. package/build/legacy/_tsup-dts-rollup.d.ts +329 -0
  3. package/build/legacy/chunk-T44AUBX4.js +1344 -0
  4. package/build/legacy/chunk-T44AUBX4.js.map +1 -0
  5. package/build/legacy/index.cjs +1413 -0
  6. package/build/legacy/index.cjs.map +1 -0
  7. package/build/legacy/index.d.cts +3 -0
  8. package/build/legacy/index.d.ts +3 -0
  9. package/build/legacy/index.js +50 -0
  10. package/build/legacy/index.js.map +1 -0
  11. package/build/legacy/rules.cjs +1370 -0
  12. package/build/legacy/rules.cjs.map +1 -0
  13. package/build/legacy/rules.d.cts +1 -0
  14. package/build/legacy/rules.d.ts +1 -0
  15. package/build/legacy/rules.js +7 -0
  16. package/build/legacy/rules.js.map +1 -0
  17. package/build/legacy/types.cjs +19 -0
  18. package/build/legacy/types.cjs.map +1 -0
  19. package/build/legacy/types.d.cts +1 -0
  20. package/build/legacy/types.d.ts +1 -0
  21. package/build/legacy/types.js +1 -0
  22. package/build/legacy/types.js.map +1 -0
  23. package/build/modern/_tsup-dts-rollup.d.cts +329 -0
  24. package/build/modern/_tsup-dts-rollup.d.ts +329 -0
  25. package/build/modern/chunk-XH4ABCYA.js +1335 -0
  26. package/build/modern/chunk-XH4ABCYA.js.map +1 -0
  27. package/build/modern/index.cjs +1405 -0
  28. package/build/modern/index.cjs.map +1 -0
  29. package/build/modern/index.d.cts +3 -0
  30. package/build/modern/index.d.ts +3 -0
  31. package/build/modern/index.js +50 -0
  32. package/build/modern/index.js.map +1 -0
  33. package/build/modern/rules.cjs +1362 -0
  34. package/build/modern/rules.cjs.map +1 -0
  35. package/build/modern/rules.d.cts +1 -0
  36. package/build/modern/rules.d.ts +1 -0
  37. package/build/modern/rules.js +7 -0
  38. package/build/modern/rules.js.map +1 -0
  39. package/build/modern/types.cjs +20 -0
  40. package/build/modern/types.cjs.map +1 -0
  41. package/build/modern/types.d.cts +1 -0
  42. package/build/modern/types.d.ts +1 -0
  43. package/build/modern/types.js +1 -0
  44. package/build/modern/types.js.map +1 -0
  45. package/package.json +1 -1
  46. package/src/rules/exhaustive-deps/exhaustive-deps.rule.ts +136 -90
  47. package/src/rules/exhaustive-deps/exhaustive-deps.utils.ts +248 -22
  48. package/src/utils/ast-utils.ts +2 -25
@@ -0,0 +1,1362 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name8 in all)
8
+ __defProp(target, name8, { get: all[name8], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/rules.ts
21
+ var rules_exports = {};
22
+ __export(rules_exports, {
23
+ rules: () => rules
24
+ });
25
+ module.exports = __toCommonJS(rules_exports);
26
+
27
+ // src/rules/exhaustive-deps/exhaustive-deps.rule.ts
28
+ var import_utils4 = require("@typescript-eslint/utils");
29
+
30
+ // src/utils/ast-utils.ts
31
+ var import_utils = require("@typescript-eslint/utils");
32
+
33
+ // src/utils/unique-by.ts
34
+ function uniqueBy(arr, fn) {
35
+ return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
36
+ }
37
+
38
+ // src/utils/ast-utils.ts
39
+ var ASTUtils = {
40
+ isNodeOfOneOf(node, types) {
41
+ return types.includes(node.type);
42
+ },
43
+ isIdentifier(node) {
44
+ return node.type === import_utils.AST_NODE_TYPES.Identifier;
45
+ },
46
+ isIdentifierWithName(node, name8) {
47
+ return ASTUtils.isIdentifier(node) && node.name === name8;
48
+ },
49
+ isIdentifierWithOneOfNames(node, name8) {
50
+ return ASTUtils.isIdentifier(node) && name8.includes(node.name);
51
+ },
52
+ isProperty(node) {
53
+ return node.type === import_utils.AST_NODE_TYPES.Property;
54
+ },
55
+ isObjectExpression(node) {
56
+ return node.type === import_utils.AST_NODE_TYPES.ObjectExpression;
57
+ },
58
+ isPropertyWithIdentifierKey(node, key) {
59
+ return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
60
+ },
61
+ findPropertyWithIdentifierKey(properties, key) {
62
+ return properties.find(
63
+ (x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
64
+ );
65
+ },
66
+ getNestedIdentifiers(node) {
67
+ const identifiers = [];
68
+ if (ASTUtils.isIdentifier(node)) {
69
+ identifiers.push(node);
70
+ }
71
+ if ("arguments" in node) {
72
+ node.arguments.forEach((x) => {
73
+ identifiers.push(...ASTUtils.getNestedIdentifiers(x));
74
+ });
75
+ }
76
+ if ("elements" in node) {
77
+ node.elements.forEach((x) => {
78
+ if (x !== null) {
79
+ identifiers.push(...ASTUtils.getNestedIdentifiers(x));
80
+ }
81
+ });
82
+ }
83
+ if ("properties" in node) {
84
+ node.properties.forEach((x) => {
85
+ identifiers.push(...ASTUtils.getNestedIdentifiers(x));
86
+ });
87
+ }
88
+ if ("expressions" in node) {
89
+ node.expressions.forEach((x) => {
90
+ identifiers.push(...ASTUtils.getNestedIdentifiers(x));
91
+ });
92
+ }
93
+ if ("left" in node) {
94
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.left));
95
+ }
96
+ if ("right" in node) {
97
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.right));
98
+ }
99
+ if (node.type === import_utils.AST_NODE_TYPES.Property) {
100
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
101
+ }
102
+ if (node.type === import_utils.AST_NODE_TYPES.SpreadElement) {
103
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
104
+ }
105
+ if (node.type === import_utils.AST_NODE_TYPES.MemberExpression) {
106
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
107
+ }
108
+ if (node.type === import_utils.AST_NODE_TYPES.UnaryExpression) {
109
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
110
+ }
111
+ if (node.type === import_utils.AST_NODE_TYPES.ChainExpression) {
112
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
113
+ }
114
+ if (node.type === import_utils.AST_NODE_TYPES.TSNonNullExpression) {
115
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
116
+ }
117
+ if (node.type === import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
118
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
119
+ }
120
+ if (node.type === import_utils.AST_NODE_TYPES.FunctionExpression) {
121
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
122
+ }
123
+ if (node.type === import_utils.AST_NODE_TYPES.BlockStatement) {
124
+ identifiers.push(
125
+ ...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat()
126
+ );
127
+ }
128
+ if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement && node.argument) {
129
+ identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
130
+ }
131
+ return identifiers;
132
+ },
133
+ traverseUpOnly(identifier, allowedNodeTypes) {
134
+ const parent = identifier.parent;
135
+ if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
136
+ return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
137
+ }
138
+ return identifier;
139
+ },
140
+ isDeclaredInNode(params) {
141
+ const { functionNode, reference, scopeManager } = params;
142
+ const scope = scopeManager.acquire(functionNode);
143
+ if (scope === null) {
144
+ return false;
145
+ }
146
+ return scope.set.has(reference.identifier.name);
147
+ },
148
+ getExternalRefs(params) {
149
+ const { scopeManager, sourceCode, node } = params;
150
+ const scope = scopeManager.acquire(node);
151
+ if (scope === null) {
152
+ return [];
153
+ }
154
+ const collectReferences = (currentScope) => {
155
+ const references2 = [...currentScope.references];
156
+ for (const childScope of currentScope.childScopes) {
157
+ references2.push(...collectReferences(childScope));
158
+ }
159
+ return references2;
160
+ };
161
+ const references = collectReferences(scope).filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
162
+ const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
163
+ import_utils.AST_NODE_TYPES.MemberExpression,
164
+ import_utils.AST_NODE_TYPES.Identifier
165
+ ]);
166
+ return {
167
+ variable: x,
168
+ node: referenceNode,
169
+ text: sourceCode.getText(referenceNode)
170
+ };
171
+ });
172
+ const localRefIds = new Set(
173
+ [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
174
+ );
175
+ const externalRefs = references.filter(
176
+ (x) => x.variable.resolved === null || !localRefIds.has(x.text)
177
+ );
178
+ return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
179
+ },
180
+ mapKeyNodeToText(node, sourceCode) {
181
+ return sourceCode.getText(
182
+ ASTUtils.traverseUpOnly(node, [
183
+ import_utils.AST_NODE_TYPES.MemberExpression,
184
+ import_utils.AST_NODE_TYPES.TSNonNullExpression,
185
+ import_utils.AST_NODE_TYPES.Identifier
186
+ ])
187
+ );
188
+ },
189
+ mapKeyNodeToBaseText(node, sourceCode) {
190
+ return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
191
+ /(?:\?(\.)|!)/g,
192
+ "$1"
193
+ );
194
+ },
195
+ isValidReactComponentOrHookName(identifier) {
196
+ return identifier !== null && identifier !== void 0 && /^(use|[A-Z])/.test(identifier.name);
197
+ },
198
+ getFunctionAncestor(sourceCode, node) {
199
+ for (const ancestor of sourceCode.getAncestors(node)) {
200
+ if (ASTUtils.isNodeOfOneOf(ancestor, [
201
+ import_utils.AST_NODE_TYPES.FunctionDeclaration,
202
+ import_utils.AST_NODE_TYPES.FunctionExpression,
203
+ import_utils.AST_NODE_TYPES.ArrowFunctionExpression
204
+ ])) {
205
+ return ancestor;
206
+ }
207
+ if (ancestor.parent?.type === import_utils.AST_NODE_TYPES.VariableDeclarator && ancestor.parent.id.type === import_utils.AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(ancestor, [
208
+ import_utils.AST_NODE_TYPES.FunctionDeclaration,
209
+ import_utils.AST_NODE_TYPES.FunctionExpression,
210
+ import_utils.AST_NODE_TYPES.ArrowFunctionExpression
211
+ ])) {
212
+ return ancestor;
213
+ }
214
+ }
215
+ return void 0;
216
+ },
217
+ getReferencedExpressionByIdentifier(params) {
218
+ const { node, context } = params;
219
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
220
+ const scope = context.sourceCode.getScope(node) ? sourceCode.getScope(node) : context.getScope();
221
+ const resolvedNode = scope.references.find((ref) => ref.identifier === node)?.resolved?.defs[0]?.node;
222
+ if (resolvedNode?.type !== import_utils.AST_NODE_TYPES.VariableDeclarator) {
223
+ return null;
224
+ }
225
+ return resolvedNode.init;
226
+ },
227
+ getClosestVariableDeclarator(node) {
228
+ let currentNode = node;
229
+ while (currentNode.type !== import_utils.AST_NODE_TYPES.Program) {
230
+ if (currentNode.type === import_utils.AST_NODE_TYPES.VariableDeclarator) {
231
+ return currentNode;
232
+ }
233
+ currentNode = currentNode.parent;
234
+ }
235
+ return void 0;
236
+ },
237
+ getNestedReturnStatements(node) {
238
+ const returnStatements = [];
239
+ if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement) {
240
+ returnStatements.push(node);
241
+ }
242
+ if ("body" in node && node.body !== void 0 && node.body !== null) {
243
+ Array.isArray(node.body) ? node.body.forEach((x) => {
244
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
245
+ }) : returnStatements.push(
246
+ ...ASTUtils.getNestedReturnStatements(node.body)
247
+ );
248
+ }
249
+ if ("consequent" in node) {
250
+ Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
251
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
252
+ }) : returnStatements.push(
253
+ ...ASTUtils.getNestedReturnStatements(node.consequent)
254
+ );
255
+ }
256
+ if ("alternate" in node && node.alternate !== null) {
257
+ Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
258
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
259
+ }) : returnStatements.push(
260
+ ...ASTUtils.getNestedReturnStatements(node.alternate)
261
+ );
262
+ }
263
+ if ("cases" in node) {
264
+ node.cases.forEach((x) => {
265
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
266
+ });
267
+ }
268
+ if ("block" in node) {
269
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
270
+ }
271
+ if ("handler" in node && node.handler !== null) {
272
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
273
+ }
274
+ if ("finalizer" in node && node.finalizer !== null) {
275
+ returnStatements.push(
276
+ ...ASTUtils.getNestedReturnStatements(node.finalizer)
277
+ );
278
+ }
279
+ if ("expression" in node && node.expression !== true && node.expression !== false) {
280
+ returnStatements.push(
281
+ ...ASTUtils.getNestedReturnStatements(node.expression)
282
+ );
283
+ }
284
+ if ("test" in node && node.test !== null) {
285
+ returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
286
+ }
287
+ return returnStatements;
288
+ }
289
+ };
290
+
291
+ // src/utils/get-docs-url.ts
292
+ var getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
293
+
294
+ // src/utils/detect-react-query-imports.ts
295
+ var import_utils2 = require("@typescript-eslint/utils");
296
+ function detectTanstackQueryImports(create) {
297
+ return (context, optionsWithDefault) => {
298
+ const tanstackQueryImportSpecifiers = [];
299
+ const helpers = {
300
+ isSpecificTanstackQueryImport(node, source) {
301
+ return !!tanstackQueryImportSpecifiers.find((specifier) => {
302
+ if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
303
+ return node.name === specifier.local.name;
304
+ }
305
+ return false;
306
+ });
307
+ },
308
+ isTanstackQueryImport(node) {
309
+ return !!tanstackQueryImportSpecifiers.find((specifier) => {
310
+ if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
311
+ return node.name === specifier.local.name;
312
+ }
313
+ return false;
314
+ });
315
+ }
316
+ };
317
+ const detectionInstructions = {
318
+ ImportDeclaration(node) {
319
+ if (node.specifiers.length > 0 && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
320
+ (node.importKind === "value" || node.importKind === void 0) && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
321
+ tanstackQueryImportSpecifiers.push(...node.specifiers);
322
+ }
323
+ }
324
+ };
325
+ const ruleInstructions = create(context, optionsWithDefault, helpers);
326
+ const enhancedRuleInstructions = {};
327
+ const allKeys = new Set(
328
+ Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
329
+ );
330
+ allKeys.forEach((instruction) => {
331
+ enhancedRuleInstructions[instruction] = (node) => {
332
+ if (instruction in detectionInstructions) {
333
+ detectionInstructions[instruction]?.(node);
334
+ }
335
+ const ruleInstruction = ruleInstructions[instruction];
336
+ if (ruleInstruction) {
337
+ return ruleInstruction(node);
338
+ }
339
+ return void 0;
340
+ };
341
+ });
342
+ return enhancedRuleInstructions;
343
+ };
344
+ }
345
+
346
+ // src/rules/exhaustive-deps/exhaustive-deps.utils.ts
347
+ var import_utils3 = require("@typescript-eslint/utils");
348
+ var ExhaustiveDepsUtils = {
349
+ isRelevantReference(params) {
350
+ const { sourceCode, reference, scopeManager, node, filename } = params;
351
+ const component = ASTUtils.getFunctionAncestor(sourceCode, node);
352
+ const queryFnScope = scopeManager.acquire(node);
353
+ if (queryFnScope === null || reference.isValueReference === false) {
354
+ return false;
355
+ }
356
+ let currentScope = reference.resolved?.scope ?? null;
357
+ while (currentScope !== null) {
358
+ if (currentScope === queryFnScope) {
359
+ return false;
360
+ }
361
+ currentScope = currentScope.upper;
362
+ }
363
+ if (component !== void 0) {
364
+ if (!ASTUtils.isDeclaredInNode({
365
+ scopeManager,
366
+ reference,
367
+ functionNode: component
368
+ })) {
369
+ return false;
370
+ }
371
+ } else {
372
+ const isVueFile = filename.endsWith(".vue");
373
+ if (!isVueFile) {
374
+ return false;
375
+ }
376
+ const definition = reference.resolved?.defs[0];
377
+ const isGlobalVariable = definition === void 0;
378
+ const isImport = definition?.type === "ImportBinding";
379
+ if (isGlobalVariable || isImport) {
380
+ return false;
381
+ }
382
+ }
383
+ return reference.identifier.name !== "undefined" && reference.identifier.parent.type !== import_utils3.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isInstanceOfKind(reference.identifier.parent);
384
+ },
385
+ /**
386
+ * Given required refs and existing queryKey entries, compute missing dependency paths
387
+ * respecting allowlisted variables and types.
388
+ */
389
+ computeFilteredMissingPaths(params) {
390
+ const {
391
+ requiredRefs,
392
+ allowlistedVariables,
393
+ existingRootIdentifiers,
394
+ existingFullPaths
395
+ } = params;
396
+ const missingPaths = /* @__PURE__ */ new Set();
397
+ for (const { root, path, allowlistedByType } of requiredRefs) {
398
+ if (existingRootIdentifiers.has(root)) continue;
399
+ if (allowlistedVariables.has(root)) continue;
400
+ if (existingFullPaths.has(path)) continue;
401
+ if (allowlistedByType) continue;
402
+ missingPaths.add(path);
403
+ }
404
+ for (const path of missingPaths) {
405
+ const root = path.split(".")[0];
406
+ if (root !== path && root !== void 0 && missingPaths.has(root)) {
407
+ missingPaths.delete(path);
408
+ }
409
+ }
410
+ return Array.from(missingPaths);
411
+ },
412
+ /**
413
+ * Extract existing queryKey deps as root identifiers and full member paths.
414
+ */
415
+ collectQueryKeyDeps(params) {
416
+ const { sourceCode, scopeManager, queryKeyNode } = params;
417
+ const roots = /* @__PURE__ */ new Set();
418
+ const paths = /* @__PURE__ */ new Set();
419
+ const visitorKeys = sourceCode.visitorKeys;
420
+ function addRoot(name8) {
421
+ const cleaned = ExhaustiveDepsUtils.normalizeChain(name8);
422
+ roots.add(cleaned);
423
+ paths.add(cleaned);
424
+ }
425
+ function addFull(text) {
426
+ const cleaned = ExhaustiveDepsUtils.normalizeChain(text);
427
+ paths.add(cleaned);
428
+ }
429
+ function addRefPath(refPath) {
430
+ if (!refPath) return;
431
+ if (refPath.coversRootMembers) {
432
+ addRoot(refPath.root);
433
+ return;
434
+ }
435
+ addFull(refPath.path);
436
+ }
437
+ function visitChildren(node) {
438
+ const keys = visitorKeys[node.type] ?? [];
439
+ for (const key of keys) {
440
+ const value = node[key];
441
+ if (Array.isArray(value)) {
442
+ for (const item of value) {
443
+ if (ExhaustiveDepsUtils.isNode(item)) {
444
+ visit(item);
445
+ }
446
+ }
447
+ continue;
448
+ }
449
+ if (ExhaustiveDepsUtils.isNode(value)) {
450
+ visit(value);
451
+ }
452
+ }
453
+ }
454
+ function visit(node) {
455
+ if (!node) return;
456
+ switch (node.type) {
457
+ case import_utils3.AST_NODE_TYPES.Identifier: {
458
+ addRefPath(
459
+ ExhaustiveDepsUtils.computeRefPath({
460
+ identifier: node,
461
+ sourceCode
462
+ })
463
+ );
464
+ return;
465
+ }
466
+ case import_utils3.AST_NODE_TYPES.ArrowFunctionExpression:
467
+ case import_utils3.AST_NODE_TYPES.FunctionExpression:
468
+ for (const reference of ExhaustiveDepsUtils.collectExternalRefsInFunction(
469
+ {
470
+ functionNode: node,
471
+ scopeManager
472
+ }
473
+ )) {
474
+ if (reference.identifier.type !== import_utils3.AST_NODE_TYPES.Identifier) {
475
+ continue;
476
+ }
477
+ addRefPath(
478
+ ExhaustiveDepsUtils.computeRefPath({
479
+ identifier: reference.identifier,
480
+ sourceCode
481
+ })
482
+ );
483
+ }
484
+ return;
485
+ case import_utils3.AST_NODE_TYPES.Property:
486
+ visit(node.value);
487
+ return;
488
+ case import_utils3.AST_NODE_TYPES.MemberExpression:
489
+ if (node.parent.type === import_utils3.AST_NODE_TYPES.CallExpression && node.parent.callee === node && node.object.type === import_utils3.AST_NODE_TYPES.Identifier) {
490
+ addRoot(node.object.name);
491
+ } else {
492
+ visit(node.object);
493
+ }
494
+ return;
495
+ case import_utils3.AST_NODE_TYPES.CallExpression:
496
+ node.arguments.forEach((argument) => visit(argument));
497
+ switch (node.callee.type) {
498
+ case import_utils3.AST_NODE_TYPES.Identifier:
499
+ case import_utils3.AST_NODE_TYPES.MemberExpression:
500
+ case import_utils3.AST_NODE_TYPES.ChainExpression:
501
+ case import_utils3.AST_NODE_TYPES.TSNonNullExpression:
502
+ visit(node.callee);
503
+ break;
504
+ }
505
+ return;
506
+ }
507
+ visitChildren(node);
508
+ }
509
+ visit(queryKeyNode);
510
+ return { roots, paths };
511
+ },
512
+ isNode(value) {
513
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
514
+ },
515
+ /**
516
+ * Checks whether the resolved variable is allowlisted by its type annotation
517
+ */
518
+ variableIsAllowlistedByType(params) {
519
+ const { allowlistedTypes, variable } = params;
520
+ if (allowlistedTypes.size === 0) return false;
521
+ if (!variable) return false;
522
+ for (const id of variable.identifiers) {
523
+ if (id.typeAnnotation) {
524
+ const typeIdentifiers = /* @__PURE__ */ new Set();
525
+ ExhaustiveDepsUtils.collectTypeIdentifiers(
526
+ id.typeAnnotation.typeAnnotation,
527
+ typeIdentifiers
528
+ );
529
+ for (const typeIdentifier of typeIdentifiers) {
530
+ if (allowlistedTypes.has(typeIdentifier)) return true;
531
+ }
532
+ }
533
+ }
534
+ return false;
535
+ },
536
+ isInstanceOfKind(node) {
537
+ return node.type === import_utils3.AST_NODE_TYPES.BinaryExpression && node.operator === "instanceof";
538
+ },
539
+ /**
540
+ * Normalizes a chain by removing optional chaining operators
541
+ *
542
+ * Example: `a?.b.c!` -> `a.b.c`
543
+ */
544
+ normalizeChain(text) {
545
+ return text.replace(/(?:\?(\.)|!)/g, "$1");
546
+ },
547
+ /**
548
+ * Computes the reference path for an identifier
549
+ *
550
+ * Example: `a.b.c!` -> `{ path: 'a.b.c', root: 'a' }`
551
+ */
552
+ computeRefPath(params) {
553
+ const { identifier, sourceCode } = params;
554
+ const fullChainNode = ASTUtils.traverseUpOnly(identifier, [
555
+ import_utils3.AST_NODE_TYPES.MemberExpression,
556
+ import_utils3.AST_NODE_TYPES.TSNonNullExpression,
557
+ import_utils3.AST_NODE_TYPES.Identifier
558
+ ]);
559
+ const fullText = ExhaustiveDepsUtils.normalizeChain(
560
+ sourceCode.getText(fullChainNode)
561
+ );
562
+ const parent = fullChainNode.parent;
563
+ let dependencyPath = fullText;
564
+ let coversRootMembers = fullText === identifier.name;
565
+ if (parent && parent.type === import_utils3.AST_NODE_TYPES.CallExpression && parent.callee === fullChainNode) {
566
+ const segments = fullText.split(".");
567
+ if (segments.length > 1) {
568
+ dependencyPath = segments.slice(0, -1).join(".");
569
+ }
570
+ coversRootMembers = false;
571
+ }
572
+ dependencyPath = dependencyPath.split(".")[0] === "" ? identifier.name : dependencyPath;
573
+ const root = dependencyPath.split(".")[0];
574
+ return {
575
+ path: dependencyPath,
576
+ root: root ?? identifier.name,
577
+ coversRootMembers: coversRootMembers && dependencyPath === root
578
+ };
579
+ },
580
+ collectExternalRefsInFunction(params) {
581
+ const { functionNode, scopeManager } = params;
582
+ const functionScope = scopeManager.acquire(functionNode);
583
+ if (functionScope === null) {
584
+ return [];
585
+ }
586
+ const externalRefs = [];
587
+ function collect(scope) {
588
+ for (const reference of scope.references) {
589
+ if (!reference.isRead() || reference.resolved === null) {
590
+ continue;
591
+ }
592
+ let currentScope = reference.resolved.scope;
593
+ let declaredInsideFunction = false;
594
+ while (currentScope !== null) {
595
+ if (currentScope === functionScope) {
596
+ declaredInsideFunction = true;
597
+ break;
598
+ }
599
+ currentScope = currentScope.upper;
600
+ }
601
+ if (!declaredInsideFunction) {
602
+ externalRefs.push(reference);
603
+ }
604
+ }
605
+ for (const childScope of scope.childScopes) {
606
+ collect(childScope);
607
+ }
608
+ }
609
+ collect(functionScope);
610
+ return externalRefs;
611
+ },
612
+ /**
613
+ * Recursively collects type identifiers from a type annotation
614
+ */
615
+ collectTypeIdentifiers(typeNode, out) {
616
+ switch (typeNode.type) {
617
+ case import_utils3.AST_NODE_TYPES.TSTypeReference: {
618
+ if (typeNode.typeName.type === import_utils3.AST_NODE_TYPES.Identifier) {
619
+ out.add(typeNode.typeName.name);
620
+ }
621
+ break;
622
+ }
623
+ case import_utils3.AST_NODE_TYPES.TSUnionType:
624
+ case import_utils3.AST_NODE_TYPES.TSIntersectionType: {
625
+ typeNode.types.forEach(
626
+ (t) => ExhaustiveDepsUtils.collectTypeIdentifiers(t, out)
627
+ );
628
+ break;
629
+ }
630
+ case import_utils3.AST_NODE_TYPES.TSArrayType: {
631
+ ExhaustiveDepsUtils.collectTypeIdentifiers(typeNode.elementType, out);
632
+ break;
633
+ }
634
+ case import_utils3.AST_NODE_TYPES.TSTupleType: {
635
+ typeNode.elementTypes.forEach(
636
+ (et) => ExhaustiveDepsUtils.collectTypeIdentifiers(et, out)
637
+ );
638
+ break;
639
+ }
640
+ }
641
+ },
642
+ /**
643
+ * Gets the function expression nodes from a queryFn property, handling conditional expressions.
644
+ * When neither branch is skipToken, returns both branches so all deps are scanned.
645
+ */
646
+ getQueryFnNodes(queryFn) {
647
+ if (queryFn.value.type !== import_utils3.AST_NODE_TYPES.ConditionalExpression) {
648
+ return [queryFn.value];
649
+ }
650
+ if (queryFn.value.consequent.type === import_utils3.AST_NODE_TYPES.Identifier && queryFn.value.consequent.name === "skipToken") {
651
+ return [queryFn.value.alternate];
652
+ }
653
+ if (queryFn.value.alternate.type === import_utils3.AST_NODE_TYPES.Identifier && queryFn.value.alternate.name === "skipToken") {
654
+ return [queryFn.value.consequent];
655
+ }
656
+ return [queryFn.value.consequent, queryFn.value.alternate];
657
+ }
658
+ };
659
+
660
+ // src/rules/exhaustive-deps/exhaustive-deps.rule.ts
661
+ var QUERY_KEY = "queryKey";
662
+ var QUERY_FN = "queryFn";
663
+ var name = "exhaustive-deps";
664
+ var createRule = import_utils4.ESLintUtils.RuleCreator(getDocsUrl);
665
+ var rule = createRule({
666
+ name,
667
+ meta: {
668
+ type: "problem",
669
+ docs: {
670
+ description: "Exhaustive deps rule for useQuery",
671
+ recommended: "error"
672
+ },
673
+ messages: {
674
+ missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
675
+ fixTo: "Fix to {{result}}"
676
+ },
677
+ hasSuggestions: true,
678
+ fixable: "code",
679
+ schema: [
680
+ {
681
+ type: "object",
682
+ properties: {
683
+ allowlist: {
684
+ type: "object",
685
+ properties: {
686
+ variables: { type: "array", items: { type: "string" } },
687
+ types: { type: "array", items: { type: "string" } }
688
+ },
689
+ additionalProperties: false
690
+ }
691
+ },
692
+ additionalProperties: false
693
+ }
694
+ ]
695
+ },
696
+ defaultOptions: [],
697
+ create: detectTanstackQueryImports((context) => {
698
+ return {
699
+ ObjectExpression: (node) => {
700
+ const scopeManager = context.sourceCode.scopeManager;
701
+ const queryKey = ASTUtils.findPropertyWithIdentifierKey(
702
+ node.properties,
703
+ QUERY_KEY
704
+ );
705
+ const queryFn = ASTUtils.findPropertyWithIdentifierKey(
706
+ node.properties,
707
+ QUERY_FN
708
+ );
709
+ if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || !ASTUtils.isNodeOfOneOf(queryFn.value, [
710
+ import_utils4.AST_NODE_TYPES.ArrowFunctionExpression,
711
+ import_utils4.AST_NODE_TYPES.FunctionExpression,
712
+ import_utils4.AST_NODE_TYPES.ConditionalExpression
713
+ ])) {
714
+ return;
715
+ }
716
+ const queryKeyNode = dereferenceVariablesAndTypeAssertions(
717
+ queryKey.value,
718
+ context
719
+ );
720
+ const queryFnNodes = ExhaustiveDepsUtils.getQueryFnNodes(queryFn);
721
+ const externalRefs = queryFnNodes.flatMap(
722
+ (fnNode) => ASTUtils.getExternalRefs({
723
+ scopeManager,
724
+ sourceCode: context.sourceCode,
725
+ node: fnNode
726
+ })
727
+ );
728
+ const relevantRefs = externalRefs.filter(
729
+ (reference) => queryFnNodes.some(
730
+ (fnNode) => ExhaustiveDepsUtils.isRelevantReference({
731
+ sourceCode: context.sourceCode,
732
+ reference,
733
+ scopeManager,
734
+ node: fnNode,
735
+ filename: context.filename
736
+ })
737
+ )
738
+ );
739
+ const ruleOptions = context.options.at(0);
740
+ const allowlistedVariables = new Set(
741
+ ruleOptions?.allowlist?.variables ?? []
742
+ );
743
+ const allowlistedTypes = new Set(ruleOptions?.allowlist?.types ?? []);
744
+ const requiredRefs = relevantRefs.flatMap((ref) => {
745
+ if (ref.identifier.type !== import_utils4.AST_NODE_TYPES.Identifier) return [];
746
+ const refPath = ExhaustiveDepsUtils.computeRefPath({
747
+ identifier: ref.identifier,
748
+ sourceCode: context.sourceCode
749
+ });
750
+ if (refPath === null) return [];
751
+ return [
752
+ {
753
+ ...refPath,
754
+ allowlistedByType: ExhaustiveDepsUtils.variableIsAllowlistedByType({
755
+ allowlistedTypes,
756
+ variable: ref.resolved ?? null
757
+ })
758
+ }
759
+ ];
760
+ });
761
+ if (requiredRefs.length === 0) return;
762
+ const queryKeyDeps = ExhaustiveDepsUtils.collectQueryKeyDeps({
763
+ sourceCode: context.sourceCode,
764
+ scopeManager,
765
+ queryKeyNode
766
+ });
767
+ const missingPaths = ExhaustiveDepsUtils.computeFilteredMissingPaths({
768
+ requiredRefs,
769
+ allowlistedVariables,
770
+ existingRootIdentifiers: queryKeyDeps.roots,
771
+ existingFullPaths: queryKeyDeps.paths
772
+ });
773
+ if (missingPaths.length === 0) return;
774
+ const missingAsText = missingPaths.join(", ");
775
+ const suggestions = buildSuggestions({
776
+ queryKeyNode,
777
+ missingPaths,
778
+ missingAsText,
779
+ sourceCode: context.sourceCode
780
+ });
781
+ context.report({
782
+ node,
783
+ messageId: "missingDeps",
784
+ data: { deps: missingAsText },
785
+ suggest: suggestions
786
+ });
787
+ }
788
+ };
789
+ })
790
+ });
791
+ function buildSuggestions(params) {
792
+ const { queryKeyNode, missingPaths, missingAsText, sourceCode } = params;
793
+ if (queryKeyNode.type !== import_utils4.AST_NODE_TYPES.ArrayExpression) {
794
+ return [];
795
+ }
796
+ const closingBracket = sourceCode.getLastToken(queryKeyNode);
797
+ if (!closingBracket) return [];
798
+ const existingElements = queryKeyNode.elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
799
+ const resultText = `[${[...existingElements, ...missingPaths].join(", ")}]`;
800
+ if (queryKeyNode.elements.length === 0) {
801
+ return [
802
+ {
803
+ messageId: "fixTo",
804
+ data: { result: resultText },
805
+ fix: (fixer) => fixer.replaceText(queryKeyNode, resultText)
806
+ }
807
+ ];
808
+ }
809
+ const tokenBefore = sourceCode.getTokenBefore(closingBracket);
810
+ const separator = tokenBefore?.value === "," ? " " : ", ";
811
+ return [
812
+ {
813
+ messageId: "fixTo",
814
+ data: { result: resultText },
815
+ fix: (fixer) => fixer.insertTextBefore(closingBracket, `${separator}${missingAsText}`)
816
+ }
817
+ ];
818
+ }
819
+ function dereferenceVariablesAndTypeAssertions(queryKeyNode, context) {
820
+ const visitedNodes = /* @__PURE__ */ new Set();
821
+ for (let i = 0; i < 1 << 8; ++i) {
822
+ if (visitedNodes.has(queryKeyNode)) {
823
+ return queryKeyNode;
824
+ }
825
+ visitedNodes.add(queryKeyNode);
826
+ switch (queryKeyNode.type) {
827
+ case import_utils4.AST_NODE_TYPES.TSAsExpression:
828
+ queryKeyNode = queryKeyNode.expression;
829
+ break;
830
+ case import_utils4.AST_NODE_TYPES.Identifier: {
831
+ const expression = ASTUtils.getReferencedExpressionByIdentifier({
832
+ context,
833
+ node: queryKeyNode
834
+ });
835
+ if (expression == null) {
836
+ return queryKeyNode;
837
+ }
838
+ queryKeyNode = expression;
839
+ break;
840
+ }
841
+ default:
842
+ return queryKeyNode;
843
+ }
844
+ }
845
+ return queryKeyNode;
846
+ }
847
+
848
+ // src/rules/stable-query-client/stable-query-client.rule.ts
849
+ var import_utils5 = require("@typescript-eslint/utils");
850
+ var name2 = "stable-query-client";
851
+ var createRule2 = import_utils5.ESLintUtils.RuleCreator(getDocsUrl);
852
+ var rule2 = createRule2({
853
+ name: name2,
854
+ meta: {
855
+ type: "problem",
856
+ docs: {
857
+ description: "Makes sure that QueryClient is stable",
858
+ recommended: "error"
859
+ },
860
+ messages: {
861
+ unstable: [
862
+ "QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.",
863
+ "See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable"
864
+ ].join("\n"),
865
+ fixTo: "Fix to {{result}}"
866
+ },
867
+ hasSuggestions: true,
868
+ fixable: "code",
869
+ schema: []
870
+ },
871
+ defaultOptions: [],
872
+ create: detectTanstackQueryImports((context, _, helpers) => {
873
+ return {
874
+ NewExpression: (node) => {
875
+ if (node.callee.type !== import_utils5.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== import_utils5.AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
876
+ node.callee,
877
+ "@tanstack/react-query"
878
+ )) {
879
+ return;
880
+ }
881
+ const fnAncestor = ASTUtils.getFunctionAncestor(
882
+ context.sourceCode,
883
+ node
884
+ );
885
+ const isReactServerComponent = fnAncestor?.async === true;
886
+ if (!ASTUtils.isValidReactComponentOrHookName(fnAncestor?.id) || isReactServerComponent) {
887
+ return;
888
+ }
889
+ context.report({
890
+ node: node.parent,
891
+ messageId: "unstable",
892
+ fix: (() => {
893
+ const { parent } = node;
894
+ if (parent.id.type !== import_utils5.AST_NODE_TYPES.Identifier) {
895
+ return;
896
+ }
897
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
898
+ const nodeText = sourceCode.getText(node);
899
+ const variableName = parent.id.name;
900
+ return (fixer) => {
901
+ return fixer.replaceTextRange(
902
+ [parent.range[0], parent.range[1]],
903
+ `[${variableName}] = React.useState(() => ${nodeText})`
904
+ );
905
+ };
906
+ })()
907
+ });
908
+ }
909
+ };
910
+ })
911
+ });
912
+
913
+ // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
914
+ var import_utils7 = require("@typescript-eslint/utils");
915
+
916
+ // src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts
917
+ var import_utils6 = require("@typescript-eslint/utils");
918
+ var NoRestDestructuringUtils = {
919
+ isObjectRestDestructuring(node) {
920
+ if (node.type !== import_utils6.AST_NODE_TYPES.ObjectPattern) {
921
+ return false;
922
+ }
923
+ return node.properties.some((p) => p.type === import_utils6.AST_NODE_TYPES.RestElement);
924
+ }
925
+ };
926
+
927
+ // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
928
+ var name3 = "no-rest-destructuring";
929
+ var queryHooks = [
930
+ "useQuery",
931
+ "useQueries",
932
+ "useInfiniteQuery",
933
+ "useSuspenseQuery",
934
+ "useSuspenseQueries",
935
+ "useSuspenseInfiniteQuery"
936
+ ];
937
+ var createRule3 = import_utils7.ESLintUtils.RuleCreator(getDocsUrl);
938
+ var rule3 = createRule3({
939
+ name: name3,
940
+ meta: {
941
+ type: "problem",
942
+ docs: {
943
+ description: "Disallows rest destructuring in queries",
944
+ recommended: "warn"
945
+ },
946
+ messages: {
947
+ objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
948
+ },
949
+ schema: []
950
+ },
951
+ defaultOptions: [],
952
+ create: detectTanstackQueryImports((context, _, helpers) => {
953
+ const queryResultVariables = /* @__PURE__ */ new Set();
954
+ return {
955
+ CallExpression: (node) => {
956
+ if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || node.parent.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator || !helpers.isTanstackQueryImport(node.callee)) {
957
+ return;
958
+ }
959
+ const returnValue = node.parent.id;
960
+ if (node.callee.name !== "useQueries" && node.callee.name !== "useSuspenseQueries") {
961
+ if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
962
+ return context.report({
963
+ node: node.parent,
964
+ messageId: "objectRestDestructure"
965
+ });
966
+ }
967
+ if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
968
+ queryResultVariables.add(returnValue.name);
969
+ }
970
+ return;
971
+ }
972
+ if (returnValue.type !== import_utils7.AST_NODE_TYPES.ArrayPattern) {
973
+ if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
974
+ queryResultVariables.add(returnValue.name);
975
+ }
976
+ return;
977
+ }
978
+ returnValue.elements.forEach((queryResult) => {
979
+ if (queryResult === null) {
980
+ return;
981
+ }
982
+ if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
983
+ context.report({
984
+ node: queryResult,
985
+ messageId: "objectRestDestructure"
986
+ });
987
+ }
988
+ });
989
+ },
990
+ VariableDeclarator: (node) => {
991
+ if (node.init?.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.init.name) && NoRestDestructuringUtils.isObjectRestDestructuring(node.id)) {
992
+ context.report({
993
+ node,
994
+ messageId: "objectRestDestructure"
995
+ });
996
+ }
997
+ },
998
+ SpreadElement: (node) => {
999
+ if (node.argument.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.argument.name)) {
1000
+ context.report({
1001
+ node,
1002
+ messageId: "objectRestDestructure"
1003
+ });
1004
+ }
1005
+ }
1006
+ };
1007
+ })
1008
+ });
1009
+
1010
+ // src/rules/no-unstable-deps/no-unstable-deps.rule.ts
1011
+ var import_utils8 = require("@typescript-eslint/utils");
1012
+ var name4 = "no-unstable-deps";
1013
+ var reactHookNames = ["useEffect", "useCallback", "useMemo"];
1014
+ var useQueryHookNames = [
1015
+ "useQuery",
1016
+ "useSuspenseQuery",
1017
+ "useQueries",
1018
+ "useSuspenseQueries",
1019
+ "useInfiniteQuery",
1020
+ "useSuspenseInfiniteQuery"
1021
+ ];
1022
+ var allHookNames = ["useMutation", ...useQueryHookNames];
1023
+ var createRule4 = import_utils8.ESLintUtils.RuleCreator(getDocsUrl);
1024
+ var rule4 = createRule4({
1025
+ name: name4,
1026
+ meta: {
1027
+ type: "problem",
1028
+ docs: {
1029
+ description: "Disallow putting the result of query hooks directly in a React hook dependency array",
1030
+ recommended: "error"
1031
+ },
1032
+ messages: {
1033
+ noUnstableDeps: `The result of {{queryHook}} is not referentially stable, so don't pass it directly into the dependencies array of {{reactHook}}. Instead, destructure the return value of {{queryHook}} and pass the destructured values into the dependency array of {{reactHook}}.`
1034
+ },
1035
+ schema: []
1036
+ },
1037
+ defaultOptions: [],
1038
+ create: detectTanstackQueryImports((context, _options, helpers) => {
1039
+ const trackedVariables = {};
1040
+ const hookAliasMap = {};
1041
+ function getReactHook(node) {
1042
+ if (node.callee.type === "Identifier") {
1043
+ const calleeName = node.callee.name;
1044
+ if (reactHookNames.includes(calleeName) || calleeName in hookAliasMap) {
1045
+ return calleeName;
1046
+ }
1047
+ } else if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "React" && node.callee.property.type === "Identifier" && reactHookNames.includes(node.callee.property.name)) {
1048
+ return node.callee.property.name;
1049
+ }
1050
+ return void 0;
1051
+ }
1052
+ function collectVariableNames(pattern, queryHook) {
1053
+ if (pattern.type === import_utils8.AST_NODE_TYPES.Identifier) {
1054
+ trackedVariables[pattern.name] = queryHook;
1055
+ }
1056
+ }
1057
+ function hasCombineProperty(callExpression) {
1058
+ if (callExpression.arguments.length === 0) return false;
1059
+ const firstArg = callExpression.arguments[0];
1060
+ if (!firstArg || firstArg.type !== import_utils8.AST_NODE_TYPES.ObjectExpression)
1061
+ return false;
1062
+ return firstArg.properties.some(
1063
+ (prop) => prop.type === import_utils8.AST_NODE_TYPES.Property && prop.key.type === import_utils8.AST_NODE_TYPES.Identifier && prop.key.name === "combine"
1064
+ );
1065
+ }
1066
+ return {
1067
+ ImportDeclaration(node) {
1068
+ if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value === "React") {
1069
+ node.specifiers.forEach((specifier) => {
1070
+ if (specifier.type === import_utils8.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils8.AST_NODE_TYPES.Identifier && reactHookNames.includes(specifier.imported.name)) {
1071
+ hookAliasMap[specifier.local.name] = specifier.imported.name;
1072
+ }
1073
+ });
1074
+ }
1075
+ },
1076
+ VariableDeclarator(node) {
1077
+ if (node.init !== null && node.init.type === import_utils8.AST_NODE_TYPES.CallExpression && node.init.callee.type === import_utils8.AST_NODE_TYPES.Identifier && allHookNames.includes(node.init.callee.name) && helpers.isTanstackQueryImport(node.init.callee)) {
1078
+ if (node.init.callee.name === "useQueries" && hasCombineProperty(node.init)) {
1079
+ return;
1080
+ }
1081
+ collectVariableNames(node.id, node.init.callee.name);
1082
+ }
1083
+ },
1084
+ CallExpression: (node) => {
1085
+ const reactHook = getReactHook(node);
1086
+ if (reactHook !== void 0 && node.arguments.length > 1 && node.arguments[1]?.type === import_utils8.AST_NODE_TYPES.ArrayExpression) {
1087
+ const depsArray = node.arguments[1].elements;
1088
+ depsArray.forEach((dep) => {
1089
+ if (dep !== null && dep.type === import_utils8.AST_NODE_TYPES.Identifier && trackedVariables[dep.name] !== void 0) {
1090
+ const queryHook = trackedVariables[dep.name];
1091
+ context.report({
1092
+ node: dep,
1093
+ messageId: "noUnstableDeps",
1094
+ data: {
1095
+ queryHook,
1096
+ reactHook
1097
+ }
1098
+ });
1099
+ }
1100
+ });
1101
+ }
1102
+ }
1103
+ };
1104
+ })
1105
+ });
1106
+
1107
+ // src/utils/create-property-order-rule.ts
1108
+ var import_utils9 = require("@typescript-eslint/utils");
1109
+
1110
+ // src/utils/sort-data-by-order.ts
1111
+ function sortDataByOrder(data, orderRules, key) {
1112
+ const getSubsetIndex = (item, subsets) => {
1113
+ for (let i = 0; i < subsets.length; i++) {
1114
+ if (subsets[i]?.includes(item)) {
1115
+ return i;
1116
+ }
1117
+ }
1118
+ return null;
1119
+ };
1120
+ const orderSets = orderRules.reduce(
1121
+ (sets, [A, B]) => [...sets, A, B],
1122
+ []
1123
+ );
1124
+ const inOrderArray = data.filter(
1125
+ (item) => getSubsetIndex(item[key], orderSets) !== null
1126
+ );
1127
+ let wasResorted = false;
1128
+ const sortedArray = inOrderArray.sort((a, b) => {
1129
+ const aKey = a[key], bKey = b[key];
1130
+ const aSubsetIndex = getSubsetIndex(aKey, orderSets);
1131
+ const bSubsetIndex = getSubsetIndex(bKey, orderSets);
1132
+ if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
1133
+ return aSubsetIndex - bSubsetIndex;
1134
+ }
1135
+ return 0;
1136
+ });
1137
+ const inOrderIterator = sortedArray.values();
1138
+ const result = data.map((item) => {
1139
+ if (getSubsetIndex(item[key], orderSets) !== null) {
1140
+ const sortedItem = inOrderIterator.next().value;
1141
+ if (sortedItem[key] !== item[key]) {
1142
+ wasResorted = true;
1143
+ }
1144
+ return sortedItem;
1145
+ }
1146
+ return item;
1147
+ });
1148
+ if (!wasResorted) {
1149
+ return null;
1150
+ }
1151
+ return result;
1152
+ }
1153
+
1154
+ // src/utils/create-property-order-rule.ts
1155
+ var createRule5 = import_utils9.ESLintUtils.RuleCreator(getDocsUrl);
1156
+ function createPropertyOrderRule(options, targetFunctions, orderRules) {
1157
+ const targetFunctionSet = new Set(targetFunctions);
1158
+ function isTargetFunction(node) {
1159
+ return targetFunctionSet.has(node);
1160
+ }
1161
+ return createRule5({
1162
+ ...options,
1163
+ create: detectTanstackQueryImports((context) => {
1164
+ return {
1165
+ CallExpression(node) {
1166
+ if (node.callee.type !== import_utils9.AST_NODE_TYPES.Identifier) {
1167
+ return;
1168
+ }
1169
+ const functions = node.callee.name;
1170
+ if (!isTargetFunction(functions)) {
1171
+ return;
1172
+ }
1173
+ const argument = node.arguments[0];
1174
+ if (argument === void 0 || argument.type !== "ObjectExpression") {
1175
+ return;
1176
+ }
1177
+ const allProperties = argument.properties;
1178
+ if (allProperties.length < 2) {
1179
+ return;
1180
+ }
1181
+ const properties = allProperties.flatMap((p, index) => {
1182
+ if (p.type === import_utils9.AST_NODE_TYPES.Property && p.key.type === import_utils9.AST_NODE_TYPES.Identifier) {
1183
+ return { name: p.key.name, property: p };
1184
+ } else return { name: `_property_${index}`, property: p };
1185
+ });
1186
+ const sortedProperties = sortDataByOrder(
1187
+ properties,
1188
+ orderRules,
1189
+ "name"
1190
+ );
1191
+ if (sortedProperties === null) {
1192
+ return;
1193
+ }
1194
+ context.report({
1195
+ node: argument,
1196
+ data: { function: node.callee.name },
1197
+ messageId: "invalidOrder",
1198
+ fix(fixer) {
1199
+ const sourceCode = context.sourceCode;
1200
+ const reorderedText = sortedProperties.reduce(
1201
+ (sourceText, specifier, index) => {
1202
+ let textBetweenProperties = "";
1203
+ if (index < allProperties.length - 1) {
1204
+ textBetweenProperties = sourceCode.getText().slice(
1205
+ allProperties[index].range[1],
1206
+ allProperties[index + 1].range[0]
1207
+ );
1208
+ }
1209
+ return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
1210
+ },
1211
+ ""
1212
+ );
1213
+ return fixer.replaceTextRange(
1214
+ [allProperties[0].range[0], allProperties.at(-1).range[1]],
1215
+ reorderedText
1216
+ );
1217
+ }
1218
+ });
1219
+ }
1220
+ };
1221
+ })
1222
+ });
1223
+ }
1224
+
1225
+ // src/rules/infinite-query-property-order/constants.ts
1226
+ var infiniteQueryFunctions = [
1227
+ "infiniteQueryOptions",
1228
+ "useInfiniteQuery",
1229
+ "useSuspenseInfiniteQuery"
1230
+ ];
1231
+ var sortRules = [
1232
+ [["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]
1233
+ ];
1234
+
1235
+ // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
1236
+ var name5 = "infinite-query-property-order";
1237
+ var rule5 = createPropertyOrderRule(
1238
+ {
1239
+ name: name5,
1240
+ meta: {
1241
+ type: "problem",
1242
+ docs: {
1243
+ description: "Ensure correct order of inference sensitive properties for infinite queries",
1244
+ recommended: "error"
1245
+ },
1246
+ messages: {
1247
+ invalidOrder: "Invalid order of properties for `{{function}}`."
1248
+ },
1249
+ schema: [],
1250
+ hasSuggestions: true,
1251
+ fixable: "code"
1252
+ },
1253
+ defaultOptions: []
1254
+ },
1255
+ infiniteQueryFunctions,
1256
+ sortRules
1257
+ );
1258
+
1259
+ // src/rules/no-void-query-fn/no-void-query-fn.rule.ts
1260
+ var import_utils10 = require("@typescript-eslint/utils");
1261
+ var TypeFlags = {
1262
+ Void: 16384,
1263
+ Undefined: 32768
1264
+ };
1265
+ var name6 = "no-void-query-fn";
1266
+ var createRule6 = import_utils10.ESLintUtils.RuleCreator(getDocsUrl);
1267
+ var rule6 = createRule6({
1268
+ name: name6,
1269
+ meta: {
1270
+ type: "problem",
1271
+ docs: {
1272
+ description: "Ensures queryFn returns a non-undefined value",
1273
+ recommended: "error"
1274
+ },
1275
+ messages: {
1276
+ noVoidReturn: "queryFn must return a non-undefined value"
1277
+ },
1278
+ schema: []
1279
+ },
1280
+ defaultOptions: [],
1281
+ create: detectTanstackQueryImports((context) => {
1282
+ return {
1283
+ Property(node) {
1284
+ if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, "queryFn")) {
1285
+ return;
1286
+ }
1287
+ const parserServices = context.sourceCode.parserServices;
1288
+ if (!parserServices || !parserServices.esTreeNodeToTSNodeMap || !parserServices.program) {
1289
+ return;
1290
+ }
1291
+ const checker = parserServices.program.getTypeChecker();
1292
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.value);
1293
+ const type = checker.getTypeAtLocation(tsNode);
1294
+ if (type.getCallSignatures().length > 0) {
1295
+ const returnType = type.getCallSignatures()[0]?.getReturnType();
1296
+ if (!returnType) {
1297
+ return;
1298
+ }
1299
+ if (isIllegalReturn(checker, returnType)) {
1300
+ context.report({
1301
+ node: node.value,
1302
+ messageId: "noVoidReturn"
1303
+ });
1304
+ }
1305
+ }
1306
+ }
1307
+ };
1308
+ })
1309
+ });
1310
+ function isIllegalReturn(checker, type) {
1311
+ const awaited = checker.getAwaitedType(type);
1312
+ if (!awaited) return false;
1313
+ if (awaited.isUnion()) {
1314
+ return awaited.types.some((t) => isIllegalReturn(checker, t));
1315
+ }
1316
+ return awaited.flags & (TypeFlags.Void | TypeFlags.Undefined) ? true : false;
1317
+ }
1318
+
1319
+ // src/rules/mutation-property-order/constants.ts
1320
+ var mutationFunctions = ["useMutation"];
1321
+ var sortRules2 = [[["onMutate"], ["onError", "onSettled"]]];
1322
+
1323
+ // src/rules/mutation-property-order/mutation-property-order.rule.ts
1324
+ var name7 = "mutation-property-order";
1325
+ var rule7 = createPropertyOrderRule(
1326
+ {
1327
+ name: name7,
1328
+ meta: {
1329
+ type: "problem",
1330
+ docs: {
1331
+ description: "Ensure correct order of inference-sensitive properties in useMutation()",
1332
+ recommended: "error"
1333
+ },
1334
+ messages: {
1335
+ invalidOrder: "Invalid order of properties for `{{function}}`."
1336
+ },
1337
+ schema: [],
1338
+ hasSuggestions: true,
1339
+ fixable: "code"
1340
+ },
1341
+ defaultOptions: []
1342
+ },
1343
+ mutationFunctions,
1344
+ sortRules2
1345
+ );
1346
+
1347
+ // src/rules.ts
1348
+ var rules = {
1349
+ [name]: rule,
1350
+ [name2]: rule2,
1351
+ [name3]: rule3,
1352
+ [name4]: rule4,
1353
+ [name5]: rule5,
1354
+ [name6]: rule6,
1355
+ [name7]: rule7
1356
+ };
1357
+ // Annotate the CommonJS export names for ESM import in node:
1358
+ 0 && (module.exports = {
1359
+ rules
1360
+ });
1361
+ module.exports = module.exports.default
1362
+ //# sourceMappingURL=rules.cjs.map