@tanstack/eslint-plugin-query 5.101.3 → 5.102.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 (68) hide show
  1. package/build/legacy/index.cjs +46 -1802
  2. package/build/legacy/index.cjs.map +1 -1
  3. package/build/legacy/index.d.cts +82 -3
  4. package/build/legacy/index.d.cts.map +1 -0
  5. package/build/legacy/index.d.ts +82 -3
  6. package/build/legacy/index.d.ts.map +1 -0
  7. package/build/legacy/index.js +39 -56
  8. package/build/legacy/index.js.map +1 -1
  9. package/build/legacy/rules-Bv1SB3jU.js +1172 -0
  10. package/build/legacy/rules-Bv1SB3jU.js.map +1 -0
  11. package/build/legacy/rules-ChMfhjqW.cjs +1177 -0
  12. package/build/legacy/rules-ChMfhjqW.cjs.map +1 -0
  13. package/build/legacy/rules.cjs +3 -1751
  14. package/build/legacy/rules.d.cts +7 -1
  15. package/build/legacy/rules.d.cts.map +1 -0
  16. package/build/legacy/rules.d.ts +7 -1
  17. package/build/legacy/rules.d.ts.map +1 -0
  18. package/build/legacy/rules.js +2 -7
  19. package/build/legacy/types.cjs +1 -19
  20. package/build/legacy/types.d.cts +7 -1
  21. package/build/legacy/types.d.cts.map +1 -0
  22. package/build/legacy/types.d.ts +7 -1
  23. package/build/legacy/types.d.ts.map +1 -0
  24. package/build/legacy/types.js +1 -1
  25. package/build/modern/index.cjs +46 -1788
  26. package/build/modern/index.cjs.map +1 -1
  27. package/build/modern/index.d.cts +83 -3
  28. package/build/modern/index.d.cts.map +1 -0
  29. package/build/modern/index.d.ts +83 -3
  30. package/build/modern/index.d.ts.map +1 -0
  31. package/build/modern/index.js +40 -56
  32. package/build/modern/index.js.map +1 -1
  33. package/build/modern/rules-B1yVUvLh.cjs +1158 -0
  34. package/build/modern/rules-B1yVUvLh.cjs.map +1 -0
  35. package/build/modern/rules-DzixDjO7.js +1153 -0
  36. package/build/modern/rules-DzixDjO7.js.map +1 -0
  37. package/build/modern/rules.cjs +3 -1737
  38. package/build/modern/rules.d.cts +8 -1
  39. package/build/modern/rules.d.cts.map +1 -0
  40. package/build/modern/rules.d.ts +8 -1
  41. package/build/modern/rules.d.ts.map +1 -0
  42. package/build/modern/rules.js +3 -7
  43. package/build/modern/types.cjs +1 -19
  44. package/build/modern/types.d.cts +8 -1
  45. package/build/modern/types.d.cts.map +1 -0
  46. package/build/modern/types.d.ts +8 -1
  47. package/build/modern/types.d.ts.map +1 -0
  48. package/build/modern/types.js +2 -1
  49. package/package.json +4 -6
  50. package/src/rules/exhaustive-deps/exhaustive-deps.utils.ts +15 -6
  51. package/src/rules/no-unstable-deps/no-unstable-deps.rule.ts +3 -3
  52. package/src/utils/ast-utils.ts +31 -198
  53. package/build/legacy/_tsup-dts-rollup.d.cts +0 -317
  54. package/build/legacy/_tsup-dts-rollup.d.ts +0 -317
  55. package/build/legacy/chunk-WVNZFPYE.js +0 -1725
  56. package/build/legacy/chunk-WVNZFPYE.js.map +0 -1
  57. package/build/legacy/rules.cjs.map +0 -1
  58. package/build/legacy/rules.js.map +0 -1
  59. package/build/legacy/types.cjs.map +0 -1
  60. package/build/legacy/types.js.map +0 -1
  61. package/build/modern/_tsup-dts-rollup.d.cts +0 -317
  62. package/build/modern/_tsup-dts-rollup.d.ts +0 -317
  63. package/build/modern/chunk-VALYN6GR.js +0 -1711
  64. package/build/modern/chunk-VALYN6GR.js.map +0 -1
  65. package/build/modern/rules.cjs.map +0 -1
  66. package/build/modern/rules.js.map +0 -1
  67. package/build/modern/types.cjs.map +0 -1
  68. package/build/modern/types.js.map +0 -1
@@ -1,1738 +1,4 @@
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 name9 in all)
8
- __defProp(target, name9, { get: all[name9], 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);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rules = require("./rules-B1yVUvLh.cjs");
3
+ exports.rules = require_rules.rules;
19
4
 
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, name9) {
47
- return ASTUtils.isIdentifier(node) && node.name === name9;
48
- },
49
- isIdentifierWithOneOfNames(node, name9) {
50
- return ASTUtils.isIdentifier(node) && name9.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(name9) {
421
- const cleaned = ExhaustiveDepsUtils.normalizeChain(name9);
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").replace(/\s+/g, "");
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 QUERY_RESULT_TYPE_NAMES = /* @__PURE__ */ new Set([
919
- "UseBaseQueryResult",
920
- "UseQueryResult",
921
- "UseSuspenseQueryResult",
922
- "DefinedUseQueryResult",
923
- "UseInfiniteQueryResult",
924
- "UseSuspenseInfiniteQueryResult",
925
- "DefinedUseInfiniteQueryResult",
926
- "QueryObserverResult",
927
- "InfiniteQueryObserverResult"
928
- ]);
929
- function isQueryResultType(type) {
930
- if (type.aliasSymbol && QUERY_RESULT_TYPE_NAMES.has(type.aliasSymbol.name)) {
931
- return true;
932
- }
933
- const symbol = type.getSymbol();
934
- if (symbol && QUERY_RESULT_TYPE_NAMES.has(symbol.name)) {
935
- return true;
936
- }
937
- return type.isUnion() && type.types.some(isQueryResultType);
938
- }
939
- var NoRestDestructuringUtils = {
940
- isObjectRestDestructuring(node) {
941
- if (node.type !== import_utils6.AST_NODE_TYPES.ObjectPattern) {
942
- return false;
943
- }
944
- return node.properties.some((p) => p.type === import_utils6.AST_NODE_TYPES.RestElement);
945
- },
946
- isQueryResultCall(node, parserServices) {
947
- if (!parserServices?.program || !parserServices.esTreeNodeToTSNodeMap) {
948
- return false;
949
- }
950
- const checker = parserServices.program.getTypeChecker();
951
- const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.callee);
952
- const signatures = checker.getTypeAtLocation(tsNode).getCallSignatures();
953
- return signatures.some((sig) => isQueryResultType(sig.getReturnType()));
954
- }
955
- };
956
-
957
- // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
958
- var name3 = "no-rest-destructuring";
959
- var queryHooks = [
960
- "useQuery",
961
- "useQueries",
962
- "useInfiniteQuery",
963
- "useSuspenseQuery",
964
- "useSuspenseQueries",
965
- "useSuspenseInfiniteQuery"
966
- ];
967
- var createRule3 = import_utils7.ESLintUtils.RuleCreator(getDocsUrl);
968
- var rule3 = createRule3({
969
- name: name3,
970
- meta: {
971
- type: "problem",
972
- docs: {
973
- description: "Disallows rest destructuring in queries",
974
- recommended: "warn"
975
- },
976
- messages: {
977
- objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
978
- },
979
- schema: []
980
- },
981
- defaultOptions: [],
982
- create: detectTanstackQueryImports((context, _, helpers) => {
983
- const queryResultVariables = /* @__PURE__ */ new Set();
984
- return {
985
- CallExpression: (node) => {
986
- if (node.parent.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator) {
987
- return;
988
- }
989
- const returnValue = node.parent.id;
990
- const isDirectHook = ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) && helpers.isTanstackQueryImport(node.callee);
991
- if (!isDirectHook) {
992
- const canReportQueryResult = returnValue.type === import_utils7.AST_NODE_TYPES.Identifier || NoRestDestructuringUtils.isObjectRestDestructuring(returnValue);
993
- if (!canReportQueryResult || !NoRestDestructuringUtils.isQueryResultCall(
994
- node,
995
- context.sourceCode.parserServices
996
- )) {
997
- return;
998
- }
999
- }
1000
- const calleeName = ASTUtils.isIdentifier(node.callee) ? node.callee.name : null;
1001
- if (calleeName !== "useQueries" && calleeName !== "useSuspenseQueries") {
1002
- if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
1003
- return context.report({
1004
- node: node.parent,
1005
- messageId: "objectRestDestructure"
1006
- });
1007
- }
1008
- if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
1009
- queryResultVariables.add(returnValue.name);
1010
- }
1011
- return;
1012
- }
1013
- if (returnValue.type !== import_utils7.AST_NODE_TYPES.ArrayPattern) {
1014
- if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
1015
- queryResultVariables.add(returnValue.name);
1016
- }
1017
- return;
1018
- }
1019
- returnValue.elements.forEach((queryResult) => {
1020
- if (queryResult === null) {
1021
- return;
1022
- }
1023
- if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
1024
- context.report({
1025
- node: queryResult,
1026
- messageId: "objectRestDestructure"
1027
- });
1028
- }
1029
- });
1030
- },
1031
- VariableDeclarator: (node) => {
1032
- if (node.init?.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.init.name) && NoRestDestructuringUtils.isObjectRestDestructuring(node.id)) {
1033
- context.report({
1034
- node,
1035
- messageId: "objectRestDestructure"
1036
- });
1037
- }
1038
- },
1039
- SpreadElement: (node) => {
1040
- if (node.argument.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.argument.name)) {
1041
- context.report({
1042
- node,
1043
- messageId: "objectRestDestructure"
1044
- });
1045
- }
1046
- }
1047
- };
1048
- })
1049
- });
1050
-
1051
- // src/rules/no-unstable-deps/no-unstable-deps.rule.ts
1052
- var import_utils8 = require("@typescript-eslint/utils");
1053
- var name4 = "no-unstable-deps";
1054
- var reactHookNames = ["useEffect", "useCallback", "useMemo"];
1055
- var useQueryHookNames = [
1056
- "useQuery",
1057
- "useSuspenseQuery",
1058
- "useQueries",
1059
- "useSuspenseQueries",
1060
- "useInfiniteQuery",
1061
- "useSuspenseInfiniteQuery"
1062
- ];
1063
- var allHookNames = ["useMutation", ...useQueryHookNames];
1064
- var createRule4 = import_utils8.ESLintUtils.RuleCreator(getDocsUrl);
1065
- var rule4 = createRule4({
1066
- name: name4,
1067
- meta: {
1068
- type: "problem",
1069
- docs: {
1070
- description: "Disallow putting the result of query hooks directly in a React hook dependency array",
1071
- recommended: "error"
1072
- },
1073
- messages: {
1074
- 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}}.`
1075
- },
1076
- schema: []
1077
- },
1078
- defaultOptions: [],
1079
- create: detectTanstackQueryImports((context, _options, helpers) => {
1080
- const trackedVariables = {};
1081
- const trackedCustomHooks = {};
1082
- const hookAliasMap = {};
1083
- const pendingVariableDeclarators = [];
1084
- const pendingDependencyChecks = [];
1085
- function getReactHook(node) {
1086
- if (node.callee.type === "Identifier") {
1087
- const calleeName = node.callee.name;
1088
- if (reactHookNames.includes(calleeName) || calleeName in hookAliasMap) {
1089
- return calleeName;
1090
- }
1091
- } 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)) {
1092
- return node.callee.property.name;
1093
- }
1094
- return void 0;
1095
- }
1096
- function collectVariableNames(pattern, queryHook) {
1097
- if (pattern.type === import_utils8.AST_NODE_TYPES.Identifier) {
1098
- trackedVariables[pattern.name] = queryHook;
1099
- } else if (pattern.type === import_utils8.AST_NODE_TYPES.ArrayPattern) {
1100
- for (const element of pattern.elements) {
1101
- if (element === null) {
1102
- continue;
1103
- }
1104
- if (element.type === import_utils8.AST_NODE_TYPES.Identifier) {
1105
- trackedVariables[element.name] = queryHook;
1106
- } else if (element.type === import_utils8.AST_NODE_TYPES.RestElement && element.argument.type === import_utils8.AST_NODE_TYPES.Identifier) {
1107
- trackedVariables[element.argument.name] = queryHook;
1108
- }
1109
- }
1110
- }
1111
- }
1112
- function isCustomHookName(hookName) {
1113
- return /^use[A-Z0-9]/.test(hookName);
1114
- }
1115
- function hasCombineProperty(callExpression) {
1116
- if (callExpression.arguments.length === 0) return false;
1117
- const firstArg = callExpression.arguments[0];
1118
- if (!firstArg || firstArg.type !== import_utils8.AST_NODE_TYPES.ObjectExpression)
1119
- return false;
1120
- return firstArg.properties.some(
1121
- (prop) => prop.type === import_utils8.AST_NODE_TYPES.Property && prop.key.type === import_utils8.AST_NODE_TYPES.Identifier && prop.key.name === "combine"
1122
- );
1123
- }
1124
- function getDirectQueryHook(callExpression) {
1125
- if (callExpression.callee.type !== import_utils8.AST_NODE_TYPES.Identifier || !allHookNames.includes(callExpression.callee.name) || !helpers.isTanstackQueryImport(callExpression.callee)) {
1126
- return void 0;
1127
- }
1128
- if ((callExpression.callee.name === "useQueries" || callExpression.callee.name === "useSuspenseQueries") && hasCombineProperty(callExpression)) {
1129
- return void 0;
1130
- }
1131
- return callExpression.callee.name;
1132
- }
1133
- function getTrackedQueryHook(callExpression) {
1134
- const directQueryHook = getDirectQueryHook(callExpression);
1135
- if (directQueryHook !== void 0) {
1136
- return directQueryHook;
1137
- }
1138
- if (callExpression.callee.type === import_utils8.AST_NODE_TYPES.Identifier) {
1139
- return trackedCustomHooks[callExpression.callee.name];
1140
- }
1141
- return void 0;
1142
- }
1143
- function getReturnedQueryHook(body) {
1144
- if (body.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1145
- return getDirectQueryHook(body);
1146
- }
1147
- if (body.type !== import_utils8.AST_NODE_TYPES.BlockStatement) {
1148
- return void 0;
1149
- }
1150
- const returnStatements = body.body.filter(
1151
- (statement) => statement.type === import_utils8.AST_NODE_TYPES.ReturnStatement
1152
- );
1153
- if (returnStatements.length !== 1) {
1154
- return void 0;
1155
- }
1156
- const returnArgument = returnStatements[0]?.argument;
1157
- if (returnArgument?.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1158
- return getDirectQueryHook(returnArgument);
1159
- }
1160
- return void 0;
1161
- }
1162
- function checkDependencyArray(reactHook, depsArray) {
1163
- depsArray.elements.forEach((dep) => {
1164
- if (dep !== null && dep.type === import_utils8.AST_NODE_TYPES.Identifier && trackedVariables[dep.name] !== void 0) {
1165
- const queryHook = trackedVariables[dep.name];
1166
- context.report({
1167
- node: dep,
1168
- messageId: "noUnstableDeps",
1169
- data: {
1170
- queryHook,
1171
- reactHook
1172
- }
1173
- });
1174
- }
1175
- });
1176
- }
1177
- return {
1178
- ImportDeclaration(node) {
1179
- if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value === "React") {
1180
- node.specifiers.forEach((specifier) => {
1181
- if (specifier.type === import_utils8.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils8.AST_NODE_TYPES.Identifier && reactHookNames.includes(specifier.imported.name)) {
1182
- hookAliasMap[specifier.local.name] = specifier.imported.name;
1183
- }
1184
- });
1185
- }
1186
- },
1187
- FunctionDeclaration(node) {
1188
- if (node.id === null || !isCustomHookName(node.id.name)) {
1189
- return;
1190
- }
1191
- const queryHook = getReturnedQueryHook(node.body);
1192
- if (queryHook !== void 0) {
1193
- trackedCustomHooks[node.id.name] = queryHook;
1194
- }
1195
- },
1196
- VariableDeclarator(node) {
1197
- if (node.id.type === import_utils8.AST_NODE_TYPES.Identifier && isCustomHookName(node.id.name) && node.init !== null && (node.init.type === import_utils8.AST_NODE_TYPES.ArrowFunctionExpression || node.init.type === import_utils8.AST_NODE_TYPES.FunctionExpression)) {
1198
- const queryHook = getReturnedQueryHook(node.init.body);
1199
- if (queryHook !== void 0) {
1200
- trackedCustomHooks[node.id.name] = queryHook;
1201
- }
1202
- }
1203
- if (node.init !== null && node.init.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1204
- pendingVariableDeclarators.push(node);
1205
- }
1206
- },
1207
- CallExpression: (node) => {
1208
- const reactHook = getReactHook(node);
1209
- if (reactHook !== void 0 && node.arguments.length > 1 && node.arguments[1]?.type === import_utils8.AST_NODE_TYPES.ArrayExpression) {
1210
- pendingDependencyChecks.push({
1211
- reactHook,
1212
- depsArray: node.arguments[1]
1213
- });
1214
- }
1215
- },
1216
- "Program:exit"() {
1217
- pendingVariableDeclarators.forEach((node) => {
1218
- if (node.init?.type !== import_utils8.AST_NODE_TYPES.CallExpression) {
1219
- return;
1220
- }
1221
- const queryHook = getTrackedQueryHook(node.init);
1222
- if (queryHook !== void 0) {
1223
- collectVariableNames(node.id, queryHook);
1224
- }
1225
- });
1226
- pendingDependencyChecks.forEach(({ reactHook, depsArray }) => {
1227
- checkDependencyArray(reactHook, depsArray);
1228
- });
1229
- }
1230
- };
1231
- })
1232
- });
1233
-
1234
- // src/utils/create-property-order-rule.ts
1235
- var import_utils9 = require("@typescript-eslint/utils");
1236
-
1237
- // src/utils/sort-data-by-order.ts
1238
- function sortDataByOrder(data, orderRules, key) {
1239
- const getSubsetIndex = (item, subsets) => {
1240
- for (let i = 0; i < subsets.length; i++) {
1241
- if (subsets[i]?.includes(item)) {
1242
- return i;
1243
- }
1244
- }
1245
- return null;
1246
- };
1247
- const orderSets = orderRules.reduce(
1248
- (sets, [A, B]) => [...sets, A, B],
1249
- []
1250
- );
1251
- const inOrderArray = data.filter(
1252
- (item) => getSubsetIndex(item[key], orderSets) !== null
1253
- );
1254
- let wasResorted = false;
1255
- const sortedArray = inOrderArray.sort((a, b) => {
1256
- const aKey = a[key], bKey = b[key];
1257
- const aSubsetIndex = getSubsetIndex(aKey, orderSets);
1258
- const bSubsetIndex = getSubsetIndex(bKey, orderSets);
1259
- if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
1260
- return aSubsetIndex - bSubsetIndex;
1261
- }
1262
- return 0;
1263
- });
1264
- const inOrderIterator = sortedArray.values();
1265
- const result = data.map((item) => {
1266
- if (getSubsetIndex(item[key], orderSets) !== null) {
1267
- const sortedItem = inOrderIterator.next().value;
1268
- if (sortedItem[key] !== item[key]) {
1269
- wasResorted = true;
1270
- }
1271
- return sortedItem;
1272
- }
1273
- return item;
1274
- });
1275
- if (!wasResorted) {
1276
- return null;
1277
- }
1278
- return result;
1279
- }
1280
-
1281
- // src/utils/create-property-order-rule.ts
1282
- var createRule5 = import_utils9.ESLintUtils.RuleCreator(getDocsUrl);
1283
- function createPropertyOrderRule(options, targetFunctions, orderRules) {
1284
- const targetFunctionSet = new Set(targetFunctions);
1285
- function isTargetFunction(node) {
1286
- return targetFunctionSet.has(node);
1287
- }
1288
- return createRule5({
1289
- ...options,
1290
- create: detectTanstackQueryImports((context) => {
1291
- return {
1292
- CallExpression(node) {
1293
- if (node.callee.type !== import_utils9.AST_NODE_TYPES.Identifier) {
1294
- return;
1295
- }
1296
- const functions = node.callee.name;
1297
- if (!isTargetFunction(functions)) {
1298
- return;
1299
- }
1300
- const argument = node.arguments[0];
1301
- if (argument === void 0 || argument.type !== "ObjectExpression") {
1302
- return;
1303
- }
1304
- const allProperties = argument.properties;
1305
- if (allProperties.length < 2) {
1306
- return;
1307
- }
1308
- const properties = allProperties.flatMap((p, index) => {
1309
- if (p.type === import_utils9.AST_NODE_TYPES.Property && p.key.type === import_utils9.AST_NODE_TYPES.Identifier) {
1310
- return { name: p.key.name, property: p };
1311
- } else return { name: `_property_${index}`, property: p };
1312
- });
1313
- const sortedProperties = sortDataByOrder(
1314
- properties,
1315
- orderRules,
1316
- "name"
1317
- );
1318
- if (sortedProperties === null) {
1319
- return;
1320
- }
1321
- context.report({
1322
- node: argument,
1323
- data: { function: node.callee.name },
1324
- messageId: "invalidOrder",
1325
- fix(fixer) {
1326
- const sourceCode = context.sourceCode;
1327
- const reorderedText = sortedProperties.reduce(
1328
- (sourceText, specifier, index) => {
1329
- let textBetweenProperties = "";
1330
- if (index < allProperties.length - 1) {
1331
- textBetweenProperties = sourceCode.getText().slice(
1332
- allProperties[index].range[1],
1333
- allProperties[index + 1].range[0]
1334
- );
1335
- }
1336
- return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
1337
- },
1338
- ""
1339
- );
1340
- return fixer.replaceTextRange(
1341
- [allProperties[0].range[0], allProperties.at(-1).range[1]],
1342
- reorderedText
1343
- );
1344
- }
1345
- });
1346
- }
1347
- };
1348
- })
1349
- });
1350
- }
1351
-
1352
- // src/rules/infinite-query-property-order/constants.ts
1353
- var infiniteQueryFunctions = [
1354
- "infiniteQueryOptions",
1355
- "useInfiniteQuery",
1356
- "useSuspenseInfiniteQuery"
1357
- ];
1358
- var sortRules = [
1359
- [["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]
1360
- ];
1361
-
1362
- // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
1363
- var name5 = "infinite-query-property-order";
1364
- var rule5 = createPropertyOrderRule(
1365
- {
1366
- name: name5,
1367
- meta: {
1368
- type: "problem",
1369
- docs: {
1370
- description: "Ensure correct order of inference sensitive properties for infinite queries",
1371
- recommended: "error"
1372
- },
1373
- messages: {
1374
- invalidOrder: "Invalid order of properties for `{{function}}`."
1375
- },
1376
- schema: [],
1377
- hasSuggestions: true,
1378
- fixable: "code"
1379
- },
1380
- defaultOptions: []
1381
- },
1382
- infiniteQueryFunctions,
1383
- sortRules
1384
- );
1385
-
1386
- // src/rules/no-void-query-fn/no-void-query-fn.rule.ts
1387
- var import_utils10 = require("@typescript-eslint/utils");
1388
- var name6 = "no-void-query-fn";
1389
- var createRule6 = import_utils10.ESLintUtils.RuleCreator(getDocsUrl);
1390
- var rule6 = createRule6({
1391
- name: name6,
1392
- meta: {
1393
- type: "problem",
1394
- docs: {
1395
- description: "Ensures queryFn returns a non-undefined value",
1396
- recommended: "error"
1397
- },
1398
- messages: {
1399
- noVoidReturn: "queryFn must return a non-undefined value"
1400
- },
1401
- schema: []
1402
- },
1403
- defaultOptions: [],
1404
- create: detectTanstackQueryImports((context) => {
1405
- return {
1406
- Property(node) {
1407
- if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, "queryFn")) {
1408
- return;
1409
- }
1410
- const parserServices = context.sourceCode.parserServices;
1411
- if (!parserServices || !parserServices.esTreeNodeToTSNodeMap || !parserServices.program) {
1412
- return;
1413
- }
1414
- const checker = parserServices.program.getTypeChecker();
1415
- const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.value);
1416
- const type = checker.getTypeAtLocation(tsNode);
1417
- if (type.getCallSignatures().length > 0) {
1418
- const returnType = type.getCallSignatures()[0]?.getReturnType();
1419
- if (!returnType) {
1420
- return;
1421
- }
1422
- if (isIllegalReturn(checker, returnType)) {
1423
- context.report({
1424
- node: node.value,
1425
- messageId: "noVoidReturn"
1426
- });
1427
- }
1428
- }
1429
- }
1430
- };
1431
- })
1432
- });
1433
- function isIllegalReturn(checker, type) {
1434
- const awaited = checker.getAwaitedType(type);
1435
- if (!awaited) return false;
1436
- if (awaited.isUnion()) {
1437
- return awaited.types.some((t) => isIllegalReturn(checker, t));
1438
- }
1439
- const typeString = checker.typeToString(awaited);
1440
- return typeString === "void" || typeString === "undefined";
1441
- }
1442
-
1443
- // src/rules/mutation-property-order/constants.ts
1444
- var mutationFunctions = ["useMutation"];
1445
- var sortRules2 = [[["onMutate"], ["onError", "onSettled"]]];
1446
-
1447
- // src/rules/mutation-property-order/mutation-property-order.rule.ts
1448
- var name7 = "mutation-property-order";
1449
- var rule7 = createPropertyOrderRule(
1450
- {
1451
- name: name7,
1452
- meta: {
1453
- type: "problem",
1454
- docs: {
1455
- description: "Ensure correct order of inference-sensitive properties in useMutation()",
1456
- recommended: "error"
1457
- },
1458
- messages: {
1459
- invalidOrder: "Invalid order of properties for `{{function}}`."
1460
- },
1461
- schema: [],
1462
- hasSuggestions: true,
1463
- fixable: "code"
1464
- },
1465
- defaultOptions: []
1466
- },
1467
- mutationFunctions,
1468
- sortRules2
1469
- );
1470
-
1471
- // src/rules/prefer-query-options/prefer-query-options.rule.ts
1472
- var import_utils11 = require("@typescript-eslint/utils");
1473
- var name8 = "prefer-query-options";
1474
- var queryHooks2 = [
1475
- "useQuery",
1476
- "useInfiniteQuery",
1477
- "useSuspenseQuery",
1478
- "useSuspenseInfiniteQuery",
1479
- "usePrefetchQuery",
1480
- "usePrefetchInfiniteQuery"
1481
- ];
1482
- var queriesHooks = ["useQueries", "useSuspenseQueries"];
1483
- var filterHooks = ["useIsFetching"];
1484
- var queryClientOptionMethods = [
1485
- "fetchQuery",
1486
- "prefetchQuery",
1487
- "fetchInfiniteQuery",
1488
- "prefetchInfiniteQuery",
1489
- "ensureQueryData",
1490
- "ensureInfiniteQueryData"
1491
- ];
1492
- var queryClientQueryKeyMethods = [
1493
- "getQueryData",
1494
- "setQueryData",
1495
- "getQueryState",
1496
- "setQueryDefaults",
1497
- "getQueryDefaults"
1498
- ];
1499
- var queryClientFilterMethods = [
1500
- "invalidateQueries",
1501
- "cancelQueries",
1502
- "refetchQueries",
1503
- "removeQueries",
1504
- "resetQueries",
1505
- "isFetching",
1506
- "getQueriesData",
1507
- "setQueriesData"
1508
- ];
1509
- var queryOptionsBuilders = ["queryOptions", "infiniteQueryOptions"];
1510
- var createRule7 = import_utils11.ESLintUtils.RuleCreator(getDocsUrl);
1511
- var rule8 = createRule7({
1512
- name: name8,
1513
- meta: {
1514
- type: "problem",
1515
- docs: {
1516
- description: "Prefer using queryOptions() to co-locate queryKey and queryFn",
1517
- recommended: "strict"
1518
- },
1519
- messages: {
1520
- preferQueryOptions: "Prefer using queryOptions() or infiniteQueryOptions() to co-locate queryKey and queryFn.",
1521
- preferQueryOptionsQueryKey: "Prefer referencing a queryKey from a queryOptions() result instead of typing it manually."
1522
- },
1523
- schema: []
1524
- },
1525
- defaultOptions: [],
1526
- create: detectTanstackQueryImports((context, _, helpers) => {
1527
- function reportInlineQueryOptions(node) {
1528
- if (ASTUtils.isObjectExpression(node) && hasInlineQueryOptions(node)) {
1529
- context.report({
1530
- node,
1531
- messageId: "preferQueryOptions"
1532
- });
1533
- }
1534
- }
1535
- function reportInlineFilterQueryKey(node) {
1536
- if (ASTUtils.isObjectExpression(node) && hasInlineFilterQueryKey(node)) {
1537
- context.report({
1538
- node,
1539
- messageId: "preferQueryOptionsQueryKey"
1540
- });
1541
- }
1542
- }
1543
- return {
1544
- CallExpression: (node) => {
1545
- if (ASTUtils.isIdentifier(node.callee)) {
1546
- const importedName = getTanstackImportName(
1547
- context,
1548
- helpers,
1549
- node.callee
1550
- );
1551
- if (importedName === null) {
1552
- return;
1553
- }
1554
- if (queryOptionsBuilders.includes(importedName)) {
1555
- return;
1556
- }
1557
- const options2 = node.arguments[0];
1558
- if (options2 === void 0) {
1559
- return;
1560
- }
1561
- if (queryHooks2.includes(importedName)) {
1562
- reportInlineQueryOptions(options2);
1563
- return;
1564
- }
1565
- if (queriesHooks.includes(importedName) && ASTUtils.isObjectExpression(options2)) {
1566
- const queries = ASTUtils.findPropertyWithIdentifierKey(
1567
- options2.properties,
1568
- "queries"
1569
- )?.value;
1570
- if (queries !== void 0) {
1571
- getQueryObjects(queries).forEach((query) => {
1572
- reportInlineQueryOptions(query);
1573
- });
1574
- }
1575
- return;
1576
- }
1577
- if (filterHooks.includes(importedName)) {
1578
- reportInlineFilterQueryKey(options2);
1579
- }
1580
- return;
1581
- }
1582
- if (node.callee.type !== import_utils11.AST_NODE_TYPES.MemberExpression || !ASTUtils.isIdentifier(node.callee.property) || !isTanstackQueryClient(node.callee.object, context, helpers)) {
1583
- return;
1584
- }
1585
- const method = node.callee.property.name;
1586
- const options = node.arguments[0];
1587
- if (options === void 0) {
1588
- return;
1589
- }
1590
- if (queryClientOptionMethods.includes(method)) {
1591
- reportInlineQueryOptions(options);
1592
- return;
1593
- }
1594
- if (queryClientQueryKeyMethods.includes(method) && isInlineArrayExpression(options)) {
1595
- context.report({
1596
- node: options,
1597
- messageId: "preferQueryOptionsQueryKey"
1598
- });
1599
- return;
1600
- }
1601
- if (queryClientFilterMethods.includes(method)) {
1602
- reportInlineFilterQueryKey(options);
1603
- }
1604
- }
1605
- };
1606
- })
1607
- });
1608
- function hasInlineQueryOptions(node) {
1609
- return ASTUtils.findPropertyWithIdentifierKey(node.properties, "queryKey") !== void 0 || ASTUtils.findPropertyWithIdentifierKey(node.properties, "queryFn") !== void 0;
1610
- }
1611
- function hasInlineFilterQueryKey(node) {
1612
- const queryKey = ASTUtils.findPropertyWithIdentifierKey(
1613
- node.properties,
1614
- "queryKey"
1615
- )?.value;
1616
- return queryKey !== void 0 && isInlineArrayExpression(queryKey);
1617
- }
1618
- function isInlineArrayExpression(node) {
1619
- return unwrapTypeAssertions(node).type === import_utils11.AST_NODE_TYPES.ArrayExpression;
1620
- }
1621
- function getReturnedObjectExpressions(node) {
1622
- if (ASTUtils.isObjectExpression(node)) {
1623
- return [node];
1624
- }
1625
- if (node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionExpression) {
1626
- return getReturnedObjectExpressions(node.body);
1627
- }
1628
- if (node.type === import_utils11.AST_NODE_TYPES.BlockStatement) {
1629
- return node.body.flatMap((statement) => {
1630
- if (statement.type === import_utils11.AST_NODE_TYPES.ReturnStatement && statement.argument !== null) {
1631
- return getReturnedObjectExpressions(statement.argument);
1632
- }
1633
- return [];
1634
- });
1635
- }
1636
- if (node.type === import_utils11.AST_NODE_TYPES.ConditionalExpression) {
1637
- return [
1638
- ...getReturnedObjectExpressions(node.consequent),
1639
- ...getReturnedObjectExpressions(node.alternate)
1640
- ];
1641
- }
1642
- if (node.type === import_utils11.AST_NODE_TYPES.LogicalExpression) {
1643
- return [
1644
- ...getReturnedObjectExpressions(node.left),
1645
- ...getReturnedObjectExpressions(node.right)
1646
- ];
1647
- }
1648
- if (node.type === import_utils11.AST_NODE_TYPES.SequenceExpression) {
1649
- return node.expressions.flatMap(
1650
- (expression) => getReturnedObjectExpressions(expression)
1651
- );
1652
- }
1653
- return [];
1654
- }
1655
- function getQueryObjects(node) {
1656
- if (node.type === import_utils11.AST_NODE_TYPES.ArrayExpression) {
1657
- return node.elements.flatMap((element) => {
1658
- if (element !== null && ASTUtils.isObjectExpression(element)) {
1659
- return [element];
1660
- }
1661
- return [];
1662
- });
1663
- }
1664
- if (node.type === import_utils11.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils11.AST_NODE_TYPES.MemberExpression && ASTUtils.isIdentifierWithName(node.callee.property, "map")) {
1665
- const mapper = node.arguments[0];
1666
- if (mapper?.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || mapper?.type === import_utils11.AST_NODE_TYPES.FunctionExpression) {
1667
- return getReturnedObjectExpressions(mapper);
1668
- }
1669
- }
1670
- return [];
1671
- }
1672
- function isTanstackQueryClient(node, context, helpers) {
1673
- const source = resolveQueryClientSource(node, context);
1674
- if (source.type === import_utils11.AST_NODE_TYPES.CallExpression && ASTUtils.isIdentifier(source.callee)) {
1675
- return getTanstackImportName(context, helpers, source.callee) === "useQueryClient";
1676
- }
1677
- if (source.type === import_utils11.AST_NODE_TYPES.NewExpression && ASTUtils.isIdentifier(source.callee)) {
1678
- return getTanstackImportName(context, helpers, source.callee) === "QueryClient";
1679
- }
1680
- return false;
1681
- }
1682
- function getTanstackImportName(context, helpers, node) {
1683
- if (!helpers.isTanstackQueryImport(node)) {
1684
- return null;
1685
- }
1686
- const definition = context.sourceCode.getScope(node).references.find((reference) => reference.identifier === node)?.resolved?.defs[0]?.node;
1687
- if (definition?.type !== import_utils11.AST_NODE_TYPES.ImportSpecifier || definition.imported.type !== import_utils11.AST_NODE_TYPES.Identifier) {
1688
- return null;
1689
- }
1690
- return definition.imported.name;
1691
- }
1692
- function resolveQueryClientSource(node, context) {
1693
- const visitedNodes = /* @__PURE__ */ new Set();
1694
- while (!visitedNodes.has(node)) {
1695
- visitedNodes.add(node);
1696
- if (node.type === import_utils11.AST_NODE_TYPES.ChainExpression) {
1697
- node = node.expression;
1698
- continue;
1699
- }
1700
- node = unwrapTypeAssertions(node);
1701
- if (node.type !== import_utils11.AST_NODE_TYPES.Identifier) {
1702
- return node;
1703
- }
1704
- const expression = ASTUtils.getReferencedExpressionByIdentifier({
1705
- context,
1706
- node
1707
- });
1708
- if (expression === null) {
1709
- return node;
1710
- }
1711
- node = expression;
1712
- }
1713
- return node;
1714
- }
1715
- function unwrapTypeAssertions(node) {
1716
- while (node.type === import_utils11.AST_NODE_TYPES.TSAsExpression || node.type === import_utils11.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils11.AST_NODE_TYPES.TSTypeAssertion) {
1717
- node = node.expression;
1718
- }
1719
- return node;
1720
- }
1721
-
1722
- // src/rules.ts
1723
- var rules = {
1724
- [name]: rule,
1725
- [name2]: rule2,
1726
- [name3]: rule3,
1727
- [name4]: rule4,
1728
- [name5]: rule5,
1729
- [name6]: rule6,
1730
- [name7]: rule7,
1731
- [name8]: rule8
1732
- };
1733
- // Annotate the CommonJS export names for ESM import in node:
1734
- 0 && (module.exports = {
1735
- rules
1736
- });
1737
- module.exports = module.exports.default
1738
- //# sourceMappingURL=rules.cjs.map