@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,1793 +1,51 @@
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);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- default: () => index_default,
24
- plugin: () => plugin
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/rules/exhaustive-deps/exhaustive-deps.rule.ts
29
- var import_utils4 = require("@typescript-eslint/utils");
30
-
31
- // src/utils/ast-utils.ts
32
- var import_utils = require("@typescript-eslint/utils");
33
-
34
- // src/utils/unique-by.ts
35
- function uniqueBy(arr, fn) {
36
- return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
37
- }
38
-
39
- // src/utils/ast-utils.ts
40
- var ASTUtils = {
41
- isNodeOfOneOf(node, types) {
42
- return types.includes(node.type);
43
- },
44
- isIdentifier(node) {
45
- return node.type === import_utils.AST_NODE_TYPES.Identifier;
46
- },
47
- isIdentifierWithName(node, name9) {
48
- return ASTUtils.isIdentifier(node) && node.name === name9;
49
- },
50
- isIdentifierWithOneOfNames(node, name9) {
51
- return ASTUtils.isIdentifier(node) && name9.includes(node.name);
52
- },
53
- isProperty(node) {
54
- return node.type === import_utils.AST_NODE_TYPES.Property;
55
- },
56
- isObjectExpression(node) {
57
- return node.type === import_utils.AST_NODE_TYPES.ObjectExpression;
58
- },
59
- isPropertyWithIdentifierKey(node, key) {
60
- return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
61
- },
62
- findPropertyWithIdentifierKey(properties, key) {
63
- return properties.find(
64
- (x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
65
- );
66
- },
67
- getNestedIdentifiers(node) {
68
- const identifiers = [];
69
- if (ASTUtils.isIdentifier(node)) {
70
- identifiers.push(node);
71
- }
72
- if ("arguments" in node) {
73
- node.arguments.forEach((x) => {
74
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
75
- });
76
- }
77
- if ("elements" in node) {
78
- node.elements.forEach((x) => {
79
- if (x !== null) {
80
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
81
- }
82
- });
83
- }
84
- if ("properties" in node) {
85
- node.properties.forEach((x) => {
86
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
87
- });
88
- }
89
- if ("expressions" in node) {
90
- node.expressions.forEach((x) => {
91
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
92
- });
93
- }
94
- if ("left" in node) {
95
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.left));
96
- }
97
- if ("right" in node) {
98
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.right));
99
- }
100
- if (node.type === import_utils.AST_NODE_TYPES.Property) {
101
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
102
- }
103
- if (node.type === import_utils.AST_NODE_TYPES.SpreadElement) {
104
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
105
- }
106
- if (node.type === import_utils.AST_NODE_TYPES.MemberExpression) {
107
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
108
- }
109
- if (node.type === import_utils.AST_NODE_TYPES.UnaryExpression) {
110
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
111
- }
112
- if (node.type === import_utils.AST_NODE_TYPES.ChainExpression) {
113
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
114
- }
115
- if (node.type === import_utils.AST_NODE_TYPES.TSNonNullExpression) {
116
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
117
- }
118
- if (node.type === import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
119
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
120
- }
121
- if (node.type === import_utils.AST_NODE_TYPES.FunctionExpression) {
122
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
123
- }
124
- if (node.type === import_utils.AST_NODE_TYPES.BlockStatement) {
125
- identifiers.push(
126
- ...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat()
127
- );
128
- }
129
- if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement && node.argument) {
130
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
131
- }
132
- return identifiers;
133
- },
134
- traverseUpOnly(identifier, allowedNodeTypes) {
135
- const parent = identifier.parent;
136
- if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
137
- return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
138
- }
139
- return identifier;
140
- },
141
- isDeclaredInNode(params) {
142
- const { functionNode, reference, scopeManager } = params;
143
- const scope = scopeManager.acquire(functionNode);
144
- if (scope === null) {
145
- return false;
146
- }
147
- return scope.set.has(reference.identifier.name);
148
- },
149
- getExternalRefs(params) {
150
- const { scopeManager, sourceCode, node } = params;
151
- const scope = scopeManager.acquire(node);
152
- if (scope === null) {
153
- return [];
154
- }
155
- const collectReferences = (currentScope) => {
156
- const references2 = [...currentScope.references];
157
- for (const childScope of currentScope.childScopes) {
158
- references2.push(...collectReferences(childScope));
159
- }
160
- return references2;
161
- };
162
- const references = collectReferences(scope).filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
163
- const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
164
- import_utils.AST_NODE_TYPES.MemberExpression,
165
- import_utils.AST_NODE_TYPES.Identifier
166
- ]);
167
- return {
168
- variable: x,
169
- node: referenceNode,
170
- text: sourceCode.getText(referenceNode)
171
- };
172
- });
173
- const localRefIds = new Set(
174
- [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
175
- );
176
- const externalRefs = references.filter(
177
- (x) => x.variable.resolved === null || !localRefIds.has(x.text)
178
- );
179
- return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
180
- },
181
- mapKeyNodeToText(node, sourceCode) {
182
- return sourceCode.getText(
183
- ASTUtils.traverseUpOnly(node, [
184
- import_utils.AST_NODE_TYPES.MemberExpression,
185
- import_utils.AST_NODE_TYPES.TSNonNullExpression,
186
- import_utils.AST_NODE_TYPES.Identifier
187
- ])
188
- );
189
- },
190
- mapKeyNodeToBaseText(node, sourceCode) {
191
- return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
192
- /(?:\?(\.)|!)/g,
193
- "$1"
194
- );
195
- },
196
- isValidReactComponentOrHookName(identifier) {
197
- return identifier !== null && identifier !== void 0 && /^(use|[A-Z])/.test(identifier.name);
198
- },
199
- getFunctionAncestor(sourceCode, node) {
200
- for (const ancestor of sourceCode.getAncestors(node)) {
201
- if (ASTUtils.isNodeOfOneOf(ancestor, [
202
- import_utils.AST_NODE_TYPES.FunctionDeclaration,
203
- import_utils.AST_NODE_TYPES.FunctionExpression,
204
- import_utils.AST_NODE_TYPES.ArrowFunctionExpression
205
- ])) {
206
- return ancestor;
207
- }
208
- if (ancestor.parent?.type === import_utils.AST_NODE_TYPES.VariableDeclarator && ancestor.parent.id.type === import_utils.AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(ancestor, [
209
- import_utils.AST_NODE_TYPES.FunctionDeclaration,
210
- import_utils.AST_NODE_TYPES.FunctionExpression,
211
- import_utils.AST_NODE_TYPES.ArrowFunctionExpression
212
- ])) {
213
- return ancestor;
214
- }
215
- }
216
- return void 0;
217
- },
218
- getReferencedExpressionByIdentifier(params) {
219
- const { node, context } = params;
220
- const sourceCode = context.sourceCode ?? context.getSourceCode();
221
- const scope = context.sourceCode.getScope(node) ? sourceCode.getScope(node) : context.getScope();
222
- const resolvedNode = scope.references.find((ref) => ref.identifier === node)?.resolved?.defs[0]?.node;
223
- if (resolvedNode?.type !== import_utils.AST_NODE_TYPES.VariableDeclarator) {
224
- return null;
225
- }
226
- return resolvedNode.init;
227
- },
228
- getClosestVariableDeclarator(node) {
229
- let currentNode = node;
230
- while (currentNode.type !== import_utils.AST_NODE_TYPES.Program) {
231
- if (currentNode.type === import_utils.AST_NODE_TYPES.VariableDeclarator) {
232
- return currentNode;
233
- }
234
- currentNode = currentNode.parent;
235
- }
236
- return void 0;
237
- },
238
- getNestedReturnStatements(node) {
239
- const returnStatements = [];
240
- if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement) {
241
- returnStatements.push(node);
242
- }
243
- if ("body" in node && node.body !== void 0 && node.body !== null) {
244
- Array.isArray(node.body) ? node.body.forEach((x) => {
245
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
246
- }) : returnStatements.push(
247
- ...ASTUtils.getNestedReturnStatements(node.body)
248
- );
249
- }
250
- if ("consequent" in node) {
251
- Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
252
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
253
- }) : returnStatements.push(
254
- ...ASTUtils.getNestedReturnStatements(node.consequent)
255
- );
256
- }
257
- if ("alternate" in node && node.alternate !== null) {
258
- Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
259
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
260
- }) : returnStatements.push(
261
- ...ASTUtils.getNestedReturnStatements(node.alternate)
262
- );
263
- }
264
- if ("cases" in node) {
265
- node.cases.forEach((x) => {
266
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
267
- });
268
- }
269
- if ("block" in node) {
270
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
271
- }
272
- if ("handler" in node && node.handler !== null) {
273
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
274
- }
275
- if ("finalizer" in node && node.finalizer !== null) {
276
- returnStatements.push(
277
- ...ASTUtils.getNestedReturnStatements(node.finalizer)
278
- );
279
- }
280
- if ("expression" in node && node.expression !== true && node.expression !== false) {
281
- returnStatements.push(
282
- ...ASTUtils.getNestedReturnStatements(node.expression)
283
- );
284
- }
285
- if ("test" in node && node.test !== null) {
286
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
287
- }
288
- return returnStatements;
289
- }
290
- };
291
-
292
- // src/utils/get-docs-url.ts
293
- var getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
294
-
295
- // src/utils/detect-react-query-imports.ts
296
- var import_utils2 = require("@typescript-eslint/utils");
297
- function detectTanstackQueryImports(create) {
298
- return (context, optionsWithDefault) => {
299
- const tanstackQueryImportSpecifiers = [];
300
- const helpers = {
301
- isSpecificTanstackQueryImport(node, source) {
302
- return !!tanstackQueryImportSpecifiers.find((specifier) => {
303
- 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) {
304
- return node.name === specifier.local.name;
305
- }
306
- return false;
307
- });
308
- },
309
- isTanstackQueryImport(node) {
310
- return !!tanstackQueryImportSpecifiers.find((specifier) => {
311
- if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
312
- return node.name === specifier.local.name;
313
- }
314
- return false;
315
- });
316
- }
317
- };
318
- const detectionInstructions = {
319
- ImportDeclaration(node) {
320
- if (node.specifiers.length > 0 && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
321
- (node.importKind === "value" || node.importKind === void 0) && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
322
- tanstackQueryImportSpecifiers.push(...node.specifiers);
323
- }
324
- }
325
- };
326
- const ruleInstructions = create(context, optionsWithDefault, helpers);
327
- const enhancedRuleInstructions = {};
328
- const allKeys = new Set(
329
- Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
330
- );
331
- allKeys.forEach((instruction) => {
332
- enhancedRuleInstructions[instruction] = (node) => {
333
- if (instruction in detectionInstructions) {
334
- detectionInstructions[instruction]?.(node);
335
- }
336
- const ruleInstruction = ruleInstructions[instruction];
337
- if (ruleInstruction) {
338
- return ruleInstruction(node);
339
- }
340
- return void 0;
341
- };
342
- });
343
- return enhancedRuleInstructions;
344
- };
345
- }
346
-
347
- // src/rules/exhaustive-deps/exhaustive-deps.utils.ts
348
- var import_utils3 = require("@typescript-eslint/utils");
349
- var ExhaustiveDepsUtils = {
350
- isRelevantReference(params) {
351
- const { sourceCode, reference, scopeManager, node, filename } = params;
352
- const component = ASTUtils.getFunctionAncestor(sourceCode, node);
353
- const queryFnScope = scopeManager.acquire(node);
354
- if (queryFnScope === null || reference.isValueReference === false) {
355
- return false;
356
- }
357
- let currentScope = reference.resolved?.scope ?? null;
358
- while (currentScope !== null) {
359
- if (currentScope === queryFnScope) {
360
- return false;
361
- }
362
- currentScope = currentScope.upper;
363
- }
364
- if (component !== void 0) {
365
- if (!ASTUtils.isDeclaredInNode({
366
- scopeManager,
367
- reference,
368
- functionNode: component
369
- })) {
370
- return false;
371
- }
372
- } else {
373
- const isVueFile = filename.endsWith(".vue");
374
- if (!isVueFile) {
375
- return false;
376
- }
377
- const definition = reference.resolved?.defs[0];
378
- const isGlobalVariable = definition === void 0;
379
- const isImport = definition?.type === "ImportBinding";
380
- if (isGlobalVariable || isImport) {
381
- return false;
382
- }
383
- }
384
- return reference.identifier.name !== "undefined" && reference.identifier.parent.type !== import_utils3.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isInstanceOfKind(reference.identifier.parent);
385
- },
386
- /**
387
- * Given required refs and existing queryKey entries, compute missing dependency paths
388
- * respecting allowlisted variables and types.
389
- */
390
- computeFilteredMissingPaths(params) {
391
- const {
392
- requiredRefs,
393
- allowlistedVariables,
394
- existingRootIdentifiers,
395
- existingFullPaths
396
- } = params;
397
- const missingPaths = /* @__PURE__ */ new Set();
398
- for (const { root, path, allowlistedByType } of requiredRefs) {
399
- if (existingRootIdentifiers.has(root)) continue;
400
- if (allowlistedVariables.has(root)) continue;
401
- if (existingFullPaths.has(path)) continue;
402
- if (allowlistedByType) continue;
403
- missingPaths.add(path);
404
- }
405
- for (const path of missingPaths) {
406
- const root = path.split(".")[0];
407
- if (root !== path && root !== void 0 && missingPaths.has(root)) {
408
- missingPaths.delete(path);
409
- }
410
- }
411
- return Array.from(missingPaths);
412
- },
413
- /**
414
- * Extract existing queryKey deps as root identifiers and full member paths.
415
- */
416
- collectQueryKeyDeps(params) {
417
- const { sourceCode, scopeManager, queryKeyNode } = params;
418
- const roots = /* @__PURE__ */ new Set();
419
- const paths = /* @__PURE__ */ new Set();
420
- const visitorKeys = sourceCode.visitorKeys;
421
- function addRoot(name9) {
422
- const cleaned = ExhaustiveDepsUtils.normalizeChain(name9);
423
- roots.add(cleaned);
424
- paths.add(cleaned);
425
- }
426
- function addFull(text) {
427
- const cleaned = ExhaustiveDepsUtils.normalizeChain(text);
428
- paths.add(cleaned);
429
- }
430
- function addRefPath(refPath) {
431
- if (!refPath) return;
432
- if (refPath.coversRootMembers) {
433
- addRoot(refPath.root);
434
- return;
435
- }
436
- addFull(refPath.path);
437
- }
438
- function visitChildren(node) {
439
- const keys = visitorKeys[node.type] ?? [];
440
- for (const key of keys) {
441
- const value = node[key];
442
- if (Array.isArray(value)) {
443
- for (const item of value) {
444
- if (ExhaustiveDepsUtils.isNode(item)) {
445
- visit(item);
446
- }
447
- }
448
- continue;
449
- }
450
- if (ExhaustiveDepsUtils.isNode(value)) {
451
- visit(value);
452
- }
453
- }
454
- }
455
- function visit(node) {
456
- if (!node) return;
457
- switch (node.type) {
458
- case import_utils3.AST_NODE_TYPES.Identifier: {
459
- addRefPath(
460
- ExhaustiveDepsUtils.computeRefPath({
461
- identifier: node,
462
- sourceCode
463
- })
464
- );
465
- return;
466
- }
467
- case import_utils3.AST_NODE_TYPES.ArrowFunctionExpression:
468
- case import_utils3.AST_NODE_TYPES.FunctionExpression:
469
- for (const reference of ExhaustiveDepsUtils.collectExternalRefsInFunction(
470
- {
471
- functionNode: node,
472
- scopeManager
473
- }
474
- )) {
475
- if (reference.identifier.type !== import_utils3.AST_NODE_TYPES.Identifier) {
476
- continue;
477
- }
478
- addRefPath(
479
- ExhaustiveDepsUtils.computeRefPath({
480
- identifier: reference.identifier,
481
- sourceCode
482
- })
483
- );
484
- }
485
- return;
486
- case import_utils3.AST_NODE_TYPES.Property:
487
- visit(node.value);
488
- return;
489
- case import_utils3.AST_NODE_TYPES.MemberExpression:
490
- if (node.parent.type === import_utils3.AST_NODE_TYPES.CallExpression && node.parent.callee === node && node.object.type === import_utils3.AST_NODE_TYPES.Identifier) {
491
- addRoot(node.object.name);
492
- } else {
493
- visit(node.object);
494
- }
495
- return;
496
- case import_utils3.AST_NODE_TYPES.CallExpression:
497
- node.arguments.forEach((argument) => visit(argument));
498
- switch (node.callee.type) {
499
- case import_utils3.AST_NODE_TYPES.Identifier:
500
- case import_utils3.AST_NODE_TYPES.MemberExpression:
501
- case import_utils3.AST_NODE_TYPES.ChainExpression:
502
- case import_utils3.AST_NODE_TYPES.TSNonNullExpression:
503
- visit(node.callee);
504
- break;
505
- }
506
- return;
507
- }
508
- visitChildren(node);
509
- }
510
- visit(queryKeyNode);
511
- return { roots, paths };
512
- },
513
- isNode(value) {
514
- return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
515
- },
516
- /**
517
- * Checks whether the resolved variable is allowlisted by its type annotation
518
- */
519
- variableIsAllowlistedByType(params) {
520
- const { allowlistedTypes, variable } = params;
521
- if (allowlistedTypes.size === 0) return false;
522
- if (!variable) return false;
523
- for (const id of variable.identifiers) {
524
- if (id.typeAnnotation) {
525
- const typeIdentifiers = /* @__PURE__ */ new Set();
526
- ExhaustiveDepsUtils.collectTypeIdentifiers(
527
- id.typeAnnotation.typeAnnotation,
528
- typeIdentifiers
529
- );
530
- for (const typeIdentifier of typeIdentifiers) {
531
- if (allowlistedTypes.has(typeIdentifier)) return true;
532
- }
533
- }
534
- }
535
- return false;
536
- },
537
- isInstanceOfKind(node) {
538
- return node.type === import_utils3.AST_NODE_TYPES.BinaryExpression && node.operator === "instanceof";
539
- },
540
- /**
541
- * Normalizes a chain by removing optional chaining operators
542
- *
543
- * Example: `a?.b.c!` -> `a.b.c`
544
- */
545
- normalizeChain(text) {
546
- return text.replace(/(?:\?(\.)|!)/g, "$1").replace(/\s+/g, "");
547
- },
548
- /**
549
- * Computes the reference path for an identifier
550
- *
551
- * Example: `a.b.c!` -> `{ path: 'a.b.c', root: 'a' }`
552
- */
553
- computeRefPath(params) {
554
- const { identifier, sourceCode } = params;
555
- const fullChainNode = ASTUtils.traverseUpOnly(identifier, [
556
- import_utils3.AST_NODE_TYPES.MemberExpression,
557
- import_utils3.AST_NODE_TYPES.TSNonNullExpression,
558
- import_utils3.AST_NODE_TYPES.Identifier
559
- ]);
560
- const fullText = ExhaustiveDepsUtils.normalizeChain(
561
- sourceCode.getText(fullChainNode)
562
- );
563
- const parent = fullChainNode.parent;
564
- let dependencyPath = fullText;
565
- let coversRootMembers = fullText === identifier.name;
566
- if (parent && parent.type === import_utils3.AST_NODE_TYPES.CallExpression && parent.callee === fullChainNode) {
567
- const segments = fullText.split(".");
568
- if (segments.length > 1) {
569
- dependencyPath = segments.slice(0, -1).join(".");
570
- }
571
- coversRootMembers = false;
572
- }
573
- dependencyPath = dependencyPath.split(".")[0] === "" ? identifier.name : dependencyPath;
574
- const root = dependencyPath.split(".")[0];
575
- return {
576
- path: dependencyPath,
577
- root: root ?? identifier.name,
578
- coversRootMembers: coversRootMembers && dependencyPath === root
579
- };
580
- },
581
- collectExternalRefsInFunction(params) {
582
- const { functionNode, scopeManager } = params;
583
- const functionScope = scopeManager.acquire(functionNode);
584
- if (functionScope === null) {
585
- return [];
586
- }
587
- const externalRefs = [];
588
- function collect(scope) {
589
- for (const reference of scope.references) {
590
- if (!reference.isRead() || reference.resolved === null) {
591
- continue;
592
- }
593
- let currentScope = reference.resolved.scope;
594
- let declaredInsideFunction = false;
595
- while (currentScope !== null) {
596
- if (currentScope === functionScope) {
597
- declaredInsideFunction = true;
598
- break;
599
- }
600
- currentScope = currentScope.upper;
601
- }
602
- if (!declaredInsideFunction) {
603
- externalRefs.push(reference);
604
- }
605
- }
606
- for (const childScope of scope.childScopes) {
607
- collect(childScope);
608
- }
609
- }
610
- collect(functionScope);
611
- return externalRefs;
612
- },
613
- /**
614
- * Recursively collects type identifiers from a type annotation
615
- */
616
- collectTypeIdentifiers(typeNode, out) {
617
- switch (typeNode.type) {
618
- case import_utils3.AST_NODE_TYPES.TSTypeReference: {
619
- if (typeNode.typeName.type === import_utils3.AST_NODE_TYPES.Identifier) {
620
- out.add(typeNode.typeName.name);
621
- }
622
- break;
623
- }
624
- case import_utils3.AST_NODE_TYPES.TSUnionType:
625
- case import_utils3.AST_NODE_TYPES.TSIntersectionType: {
626
- typeNode.types.forEach(
627
- (t) => ExhaustiveDepsUtils.collectTypeIdentifiers(t, out)
628
- );
629
- break;
630
- }
631
- case import_utils3.AST_NODE_TYPES.TSArrayType: {
632
- ExhaustiveDepsUtils.collectTypeIdentifiers(typeNode.elementType, out);
633
- break;
634
- }
635
- case import_utils3.AST_NODE_TYPES.TSTupleType: {
636
- typeNode.elementTypes.forEach(
637
- (et) => ExhaustiveDepsUtils.collectTypeIdentifiers(et, out)
638
- );
639
- break;
640
- }
641
- }
642
- },
643
- /**
644
- * Gets the function expression nodes from a queryFn property, handling conditional expressions.
645
- * When neither branch is skipToken, returns both branches so all deps are scanned.
646
- */
647
- getQueryFnNodes(queryFn) {
648
- if (queryFn.value.type !== import_utils3.AST_NODE_TYPES.ConditionalExpression) {
649
- return [queryFn.value];
650
- }
651
- if (queryFn.value.consequent.type === import_utils3.AST_NODE_TYPES.Identifier && queryFn.value.consequent.name === "skipToken") {
652
- return [queryFn.value.alternate];
653
- }
654
- if (queryFn.value.alternate.type === import_utils3.AST_NODE_TYPES.Identifier && queryFn.value.alternate.name === "skipToken") {
655
- return [queryFn.value.consequent];
656
- }
657
- return [queryFn.value.consequent, queryFn.value.alternate];
658
- }
659
- };
660
-
661
- // src/rules/exhaustive-deps/exhaustive-deps.rule.ts
662
- var QUERY_KEY = "queryKey";
663
- var QUERY_FN = "queryFn";
664
- var name = "exhaustive-deps";
665
- var createRule = import_utils4.ESLintUtils.RuleCreator(getDocsUrl);
666
- var rule = createRule({
667
- name,
668
- meta: {
669
- type: "problem",
670
- docs: {
671
- description: "Exhaustive deps rule for useQuery",
672
- recommended: "error"
673
- },
674
- messages: {
675
- missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
676
- fixTo: "Fix to {{result}}"
677
- },
678
- hasSuggestions: true,
679
- fixable: "code",
680
- schema: [
681
- {
682
- type: "object",
683
- properties: {
684
- allowlist: {
685
- type: "object",
686
- properties: {
687
- variables: { type: "array", items: { type: "string" } },
688
- types: { type: "array", items: { type: "string" } }
689
- },
690
- additionalProperties: false
691
- }
692
- },
693
- additionalProperties: false
694
- }
695
- ]
696
- },
697
- defaultOptions: [],
698
- create: detectTanstackQueryImports((context) => {
699
- return {
700
- ObjectExpression: (node) => {
701
- const scopeManager = context.sourceCode.scopeManager;
702
- const queryKey = ASTUtils.findPropertyWithIdentifierKey(
703
- node.properties,
704
- QUERY_KEY
705
- );
706
- const queryFn = ASTUtils.findPropertyWithIdentifierKey(
707
- node.properties,
708
- QUERY_FN
709
- );
710
- if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || !ASTUtils.isNodeOfOneOf(queryFn.value, [
711
- import_utils4.AST_NODE_TYPES.ArrowFunctionExpression,
712
- import_utils4.AST_NODE_TYPES.FunctionExpression,
713
- import_utils4.AST_NODE_TYPES.ConditionalExpression
714
- ])) {
715
- return;
716
- }
717
- const queryKeyNode = dereferenceVariablesAndTypeAssertions(
718
- queryKey.value,
719
- context
720
- );
721
- const queryFnNodes = ExhaustiveDepsUtils.getQueryFnNodes(queryFn);
722
- const externalRefs = queryFnNodes.flatMap(
723
- (fnNode) => ASTUtils.getExternalRefs({
724
- scopeManager,
725
- sourceCode: context.sourceCode,
726
- node: fnNode
727
- })
728
- );
729
- const relevantRefs = externalRefs.filter(
730
- (reference) => queryFnNodes.some(
731
- (fnNode) => ExhaustiveDepsUtils.isRelevantReference({
732
- sourceCode: context.sourceCode,
733
- reference,
734
- scopeManager,
735
- node: fnNode,
736
- filename: context.filename
737
- })
738
- )
739
- );
740
- const ruleOptions = context.options.at(0);
741
- const allowlistedVariables = new Set(
742
- ruleOptions?.allowlist?.variables ?? []
743
- );
744
- const allowlistedTypes = new Set(ruleOptions?.allowlist?.types ?? []);
745
- const requiredRefs = relevantRefs.flatMap((ref) => {
746
- if (ref.identifier.type !== import_utils4.AST_NODE_TYPES.Identifier) return [];
747
- const refPath = ExhaustiveDepsUtils.computeRefPath({
748
- identifier: ref.identifier,
749
- sourceCode: context.sourceCode
750
- });
751
- if (refPath === null) return [];
752
- return [
753
- {
754
- ...refPath,
755
- allowlistedByType: ExhaustiveDepsUtils.variableIsAllowlistedByType({
756
- allowlistedTypes,
757
- variable: ref.resolved ?? null
758
- })
759
- }
760
- ];
761
- });
762
- if (requiredRefs.length === 0) return;
763
- const queryKeyDeps = ExhaustiveDepsUtils.collectQueryKeyDeps({
764
- sourceCode: context.sourceCode,
765
- scopeManager,
766
- queryKeyNode
767
- });
768
- const missingPaths = ExhaustiveDepsUtils.computeFilteredMissingPaths({
769
- requiredRefs,
770
- allowlistedVariables,
771
- existingRootIdentifiers: queryKeyDeps.roots,
772
- existingFullPaths: queryKeyDeps.paths
773
- });
774
- if (missingPaths.length === 0) return;
775
- const missingAsText = missingPaths.join(", ");
776
- const suggestions = buildSuggestions({
777
- queryKeyNode,
778
- missingPaths,
779
- missingAsText,
780
- sourceCode: context.sourceCode
781
- });
782
- context.report({
783
- node,
784
- messageId: "missingDeps",
785
- data: { deps: missingAsText },
786
- suggest: suggestions
787
- });
788
- }
789
- };
790
- })
791
- });
792
- function buildSuggestions(params) {
793
- const { queryKeyNode, missingPaths, missingAsText, sourceCode } = params;
794
- if (queryKeyNode.type !== import_utils4.AST_NODE_TYPES.ArrayExpression) {
795
- return [];
796
- }
797
- const closingBracket = sourceCode.getLastToken(queryKeyNode);
798
- if (!closingBracket) return [];
799
- const existingElements = queryKeyNode.elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
800
- const resultText = `[${[...existingElements, ...missingPaths].join(", ")}]`;
801
- if (queryKeyNode.elements.length === 0) {
802
- return [
803
- {
804
- messageId: "fixTo",
805
- data: { result: resultText },
806
- fix: (fixer) => fixer.replaceText(queryKeyNode, resultText)
807
- }
808
- ];
809
- }
810
- const tokenBefore = sourceCode.getTokenBefore(closingBracket);
811
- const separator = tokenBefore?.value === "," ? " " : ", ";
812
- return [
813
- {
814
- messageId: "fixTo",
815
- data: { result: resultText },
816
- fix: (fixer) => fixer.insertTextBefore(closingBracket, `${separator}${missingAsText}`)
817
- }
818
- ];
819
- }
820
- function dereferenceVariablesAndTypeAssertions(queryKeyNode, context) {
821
- const visitedNodes = /* @__PURE__ */ new Set();
822
- for (let i = 0; i < 1 << 8; ++i) {
823
- if (visitedNodes.has(queryKeyNode)) {
824
- return queryKeyNode;
825
- }
826
- visitedNodes.add(queryKeyNode);
827
- switch (queryKeyNode.type) {
828
- case import_utils4.AST_NODE_TYPES.TSAsExpression:
829
- queryKeyNode = queryKeyNode.expression;
830
- break;
831
- case import_utils4.AST_NODE_TYPES.Identifier: {
832
- const expression = ASTUtils.getReferencedExpressionByIdentifier({
833
- context,
834
- node: queryKeyNode
835
- });
836
- if (expression == null) {
837
- return queryKeyNode;
838
- }
839
- queryKeyNode = expression;
840
- break;
841
- }
842
- default:
843
- return queryKeyNode;
844
- }
845
- }
846
- return queryKeyNode;
847
- }
848
-
849
- // src/rules/stable-query-client/stable-query-client.rule.ts
850
- var import_utils5 = require("@typescript-eslint/utils");
851
- var name2 = "stable-query-client";
852
- var createRule2 = import_utils5.ESLintUtils.RuleCreator(getDocsUrl);
853
- var rule2 = createRule2({
854
- name: name2,
855
- meta: {
856
- type: "problem",
857
- docs: {
858
- description: "Makes sure that QueryClient is stable",
859
- recommended: "error"
860
- },
861
- messages: {
862
- unstable: [
863
- "QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.",
864
- "See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable"
865
- ].join("\n"),
866
- fixTo: "Fix to {{result}}"
867
- },
868
- hasSuggestions: true,
869
- fixable: "code",
870
- schema: []
871
- },
872
- defaultOptions: [],
873
- create: detectTanstackQueryImports((context, _, helpers) => {
874
- return {
875
- NewExpression: (node) => {
876
- 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(
877
- node.callee,
878
- "@tanstack/react-query"
879
- )) {
880
- return;
881
- }
882
- const fnAncestor = ASTUtils.getFunctionAncestor(
883
- context.sourceCode,
884
- node
885
- );
886
- const isReactServerComponent = fnAncestor?.async === true;
887
- if (!ASTUtils.isValidReactComponentOrHookName(fnAncestor?.id) || isReactServerComponent) {
888
- return;
889
- }
890
- context.report({
891
- node: node.parent,
892
- messageId: "unstable",
893
- fix: (() => {
894
- const { parent } = node;
895
- if (parent.id.type !== import_utils5.AST_NODE_TYPES.Identifier) {
896
- return;
897
- }
898
- const sourceCode = context.sourceCode ?? context.getSourceCode();
899
- const nodeText = sourceCode.getText(node);
900
- const variableName = parent.id.name;
901
- return (fixer) => {
902
- return fixer.replaceTextRange(
903
- [parent.range[0], parent.range[1]],
904
- `[${variableName}] = React.useState(() => ${nodeText})`
905
- );
906
- };
907
- })()
908
- });
909
- }
910
- };
911
- })
912
- });
913
-
914
- // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
915
- var import_utils7 = require("@typescript-eslint/utils");
916
-
917
- // src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts
918
- var import_utils6 = require("@typescript-eslint/utils");
919
- var QUERY_RESULT_TYPE_NAMES = /* @__PURE__ */ new Set([
920
- "UseBaseQueryResult",
921
- "UseQueryResult",
922
- "UseSuspenseQueryResult",
923
- "DefinedUseQueryResult",
924
- "UseInfiniteQueryResult",
925
- "UseSuspenseInfiniteQueryResult",
926
- "DefinedUseInfiniteQueryResult",
927
- "QueryObserverResult",
928
- "InfiniteQueryObserverResult"
929
- ]);
930
- function isQueryResultType(type) {
931
- if (type.aliasSymbol && QUERY_RESULT_TYPE_NAMES.has(type.aliasSymbol.name)) {
932
- return true;
933
- }
934
- const symbol = type.getSymbol();
935
- if (symbol && QUERY_RESULT_TYPE_NAMES.has(symbol.name)) {
936
- return true;
937
- }
938
- return type.isUnion() && type.types.some(isQueryResultType);
939
- }
940
- var NoRestDestructuringUtils = {
941
- isObjectRestDestructuring(node) {
942
- if (node.type !== import_utils6.AST_NODE_TYPES.ObjectPattern) {
943
- return false;
944
- }
945
- return node.properties.some((p) => p.type === import_utils6.AST_NODE_TYPES.RestElement);
946
- },
947
- isQueryResultCall(node, parserServices) {
948
- if (!parserServices?.program || !parserServices.esTreeNodeToTSNodeMap) {
949
- return false;
950
- }
951
- const checker = parserServices.program.getTypeChecker();
952
- const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.callee);
953
- const signatures = checker.getTypeAtLocation(tsNode).getCallSignatures();
954
- return signatures.some((sig) => isQueryResultType(sig.getReturnType()));
955
- }
956
- };
957
-
958
- // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
959
- var name3 = "no-rest-destructuring";
960
- var queryHooks = [
961
- "useQuery",
962
- "useQueries",
963
- "useInfiniteQuery",
964
- "useSuspenseQuery",
965
- "useSuspenseQueries",
966
- "useSuspenseInfiniteQuery"
967
- ];
968
- var createRule3 = import_utils7.ESLintUtils.RuleCreator(getDocsUrl);
969
- var rule3 = createRule3({
970
- name: name3,
971
- meta: {
972
- type: "problem",
973
- docs: {
974
- description: "Disallows rest destructuring in queries",
975
- recommended: "warn"
976
- },
977
- messages: {
978
- objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
979
- },
980
- schema: []
981
- },
982
- defaultOptions: [],
983
- create: detectTanstackQueryImports((context, _, helpers) => {
984
- const queryResultVariables = /* @__PURE__ */ new Set();
985
- return {
986
- CallExpression: (node) => {
987
- if (node.parent.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator) {
988
- return;
989
- }
990
- const returnValue = node.parent.id;
991
- const isDirectHook = ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) && helpers.isTanstackQueryImport(node.callee);
992
- if (!isDirectHook) {
993
- const canReportQueryResult = returnValue.type === import_utils7.AST_NODE_TYPES.Identifier || NoRestDestructuringUtils.isObjectRestDestructuring(returnValue);
994
- if (!canReportQueryResult || !NoRestDestructuringUtils.isQueryResultCall(
995
- node,
996
- context.sourceCode.parserServices
997
- )) {
998
- return;
999
- }
1000
- }
1001
- const calleeName = ASTUtils.isIdentifier(node.callee) ? node.callee.name : null;
1002
- if (calleeName !== "useQueries" && calleeName !== "useSuspenseQueries") {
1003
- if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
1004
- return context.report({
1005
- node: node.parent,
1006
- messageId: "objectRestDestructure"
1007
- });
1008
- }
1009
- if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
1010
- queryResultVariables.add(returnValue.name);
1011
- }
1012
- return;
1013
- }
1014
- if (returnValue.type !== import_utils7.AST_NODE_TYPES.ArrayPattern) {
1015
- if (returnValue.type === import_utils7.AST_NODE_TYPES.Identifier) {
1016
- queryResultVariables.add(returnValue.name);
1017
- }
1018
- return;
1019
- }
1020
- returnValue.elements.forEach((queryResult) => {
1021
- if (queryResult === null) {
1022
- return;
1023
- }
1024
- if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
1025
- context.report({
1026
- node: queryResult,
1027
- messageId: "objectRestDestructure"
1028
- });
1029
- }
1030
- });
1031
- },
1032
- VariableDeclarator: (node) => {
1033
- if (node.init?.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.init.name) && NoRestDestructuringUtils.isObjectRestDestructuring(node.id)) {
1034
- context.report({
1035
- node,
1036
- messageId: "objectRestDestructure"
1037
- });
1038
- }
1039
- },
1040
- SpreadElement: (node) => {
1041
- if (node.argument.type === import_utils7.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.argument.name)) {
1042
- context.report({
1043
- node,
1044
- messageId: "objectRestDestructure"
1045
- });
1046
- }
1047
- }
1048
- };
1049
- })
1050
- });
1051
-
1052
- // src/rules/no-unstable-deps/no-unstable-deps.rule.ts
1053
- var import_utils8 = require("@typescript-eslint/utils");
1054
- var name4 = "no-unstable-deps";
1055
- var reactHookNames = ["useEffect", "useCallback", "useMemo"];
1056
- var useQueryHookNames = [
1057
- "useQuery",
1058
- "useSuspenseQuery",
1059
- "useQueries",
1060
- "useSuspenseQueries",
1061
- "useInfiniteQuery",
1062
- "useSuspenseInfiniteQuery"
1063
- ];
1064
- var allHookNames = ["useMutation", ...useQueryHookNames];
1065
- var createRule4 = import_utils8.ESLintUtils.RuleCreator(getDocsUrl);
1066
- var rule4 = createRule4({
1067
- name: name4,
1068
- meta: {
1069
- type: "problem",
1070
- docs: {
1071
- description: "Disallow putting the result of query hooks directly in a React hook dependency array",
1072
- recommended: "error"
1073
- },
1074
- messages: {
1075
- 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}}.`
1076
- },
1077
- schema: []
1078
- },
1079
- defaultOptions: [],
1080
- create: detectTanstackQueryImports((context, _options, helpers) => {
1081
- const trackedVariables = {};
1082
- const trackedCustomHooks = {};
1083
- const hookAliasMap = {};
1084
- const pendingVariableDeclarators = [];
1085
- const pendingDependencyChecks = [];
1086
- function getReactHook(node) {
1087
- if (node.callee.type === "Identifier") {
1088
- const calleeName = node.callee.name;
1089
- if (reactHookNames.includes(calleeName) || calleeName in hookAliasMap) {
1090
- return calleeName;
1091
- }
1092
- } 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)) {
1093
- return node.callee.property.name;
1094
- }
1095
- return void 0;
1096
- }
1097
- function collectVariableNames(pattern, queryHook) {
1098
- if (pattern.type === import_utils8.AST_NODE_TYPES.Identifier) {
1099
- trackedVariables[pattern.name] = queryHook;
1100
- } else if (pattern.type === import_utils8.AST_NODE_TYPES.ArrayPattern) {
1101
- for (const element of pattern.elements) {
1102
- if (element === null) {
1103
- continue;
1104
- }
1105
- if (element.type === import_utils8.AST_NODE_TYPES.Identifier) {
1106
- trackedVariables[element.name] = queryHook;
1107
- } else if (element.type === import_utils8.AST_NODE_TYPES.RestElement && element.argument.type === import_utils8.AST_NODE_TYPES.Identifier) {
1108
- trackedVariables[element.argument.name] = queryHook;
1109
- }
1110
- }
1111
- }
1112
- }
1113
- function isCustomHookName(hookName) {
1114
- return /^use[A-Z0-9]/.test(hookName);
1115
- }
1116
- function hasCombineProperty(callExpression) {
1117
- if (callExpression.arguments.length === 0) return false;
1118
- const firstArg = callExpression.arguments[0];
1119
- if (!firstArg || firstArg.type !== import_utils8.AST_NODE_TYPES.ObjectExpression)
1120
- return false;
1121
- return firstArg.properties.some(
1122
- (prop) => prop.type === import_utils8.AST_NODE_TYPES.Property && prop.key.type === import_utils8.AST_NODE_TYPES.Identifier && prop.key.name === "combine"
1123
- );
1124
- }
1125
- function getDirectQueryHook(callExpression) {
1126
- if (callExpression.callee.type !== import_utils8.AST_NODE_TYPES.Identifier || !allHookNames.includes(callExpression.callee.name) || !helpers.isTanstackQueryImport(callExpression.callee)) {
1127
- return void 0;
1128
- }
1129
- if ((callExpression.callee.name === "useQueries" || callExpression.callee.name === "useSuspenseQueries") && hasCombineProperty(callExpression)) {
1130
- return void 0;
1131
- }
1132
- return callExpression.callee.name;
1133
- }
1134
- function getTrackedQueryHook(callExpression) {
1135
- const directQueryHook = getDirectQueryHook(callExpression);
1136
- if (directQueryHook !== void 0) {
1137
- return directQueryHook;
1138
- }
1139
- if (callExpression.callee.type === import_utils8.AST_NODE_TYPES.Identifier) {
1140
- return trackedCustomHooks[callExpression.callee.name];
1141
- }
1142
- return void 0;
1143
- }
1144
- function getReturnedQueryHook(body) {
1145
- if (body.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1146
- return getDirectQueryHook(body);
1147
- }
1148
- if (body.type !== import_utils8.AST_NODE_TYPES.BlockStatement) {
1149
- return void 0;
1150
- }
1151
- const returnStatements = body.body.filter(
1152
- (statement) => statement.type === import_utils8.AST_NODE_TYPES.ReturnStatement
1153
- );
1154
- if (returnStatements.length !== 1) {
1155
- return void 0;
1156
- }
1157
- const returnArgument = returnStatements[0]?.argument;
1158
- if (returnArgument?.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1159
- return getDirectQueryHook(returnArgument);
1160
- }
1161
- return void 0;
1162
- }
1163
- function checkDependencyArray(reactHook, depsArray) {
1164
- depsArray.elements.forEach((dep) => {
1165
- if (dep !== null && dep.type === import_utils8.AST_NODE_TYPES.Identifier && trackedVariables[dep.name] !== void 0) {
1166
- const queryHook = trackedVariables[dep.name];
1167
- context.report({
1168
- node: dep,
1169
- messageId: "noUnstableDeps",
1170
- data: {
1171
- queryHook,
1172
- reactHook
1173
- }
1174
- });
1175
- }
1176
- });
1177
- }
1178
- return {
1179
- ImportDeclaration(node) {
1180
- if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value === "React") {
1181
- node.specifiers.forEach((specifier) => {
1182
- if (specifier.type === import_utils8.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils8.AST_NODE_TYPES.Identifier && reactHookNames.includes(specifier.imported.name)) {
1183
- hookAliasMap[specifier.local.name] = specifier.imported.name;
1184
- }
1185
- });
1186
- }
1187
- },
1188
- FunctionDeclaration(node) {
1189
- if (node.id === null || !isCustomHookName(node.id.name)) {
1190
- return;
1191
- }
1192
- const queryHook = getReturnedQueryHook(node.body);
1193
- if (queryHook !== void 0) {
1194
- trackedCustomHooks[node.id.name] = queryHook;
1195
- }
1196
- },
1197
- VariableDeclarator(node) {
1198
- 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)) {
1199
- const queryHook = getReturnedQueryHook(node.init.body);
1200
- if (queryHook !== void 0) {
1201
- trackedCustomHooks[node.id.name] = queryHook;
1202
- }
1203
- }
1204
- if (node.init !== null && node.init.type === import_utils8.AST_NODE_TYPES.CallExpression) {
1205
- pendingVariableDeclarators.push(node);
1206
- }
1207
- },
1208
- CallExpression: (node) => {
1209
- const reactHook = getReactHook(node);
1210
- if (reactHook !== void 0 && node.arguments.length > 1 && node.arguments[1]?.type === import_utils8.AST_NODE_TYPES.ArrayExpression) {
1211
- pendingDependencyChecks.push({
1212
- reactHook,
1213
- depsArray: node.arguments[1]
1214
- });
1215
- }
1216
- },
1217
- "Program:exit"() {
1218
- pendingVariableDeclarators.forEach((node) => {
1219
- if (node.init?.type !== import_utils8.AST_NODE_TYPES.CallExpression) {
1220
- return;
1221
- }
1222
- const queryHook = getTrackedQueryHook(node.init);
1223
- if (queryHook !== void 0) {
1224
- collectVariableNames(node.id, queryHook);
1225
- }
1226
- });
1227
- pendingDependencyChecks.forEach(({ reactHook, depsArray }) => {
1228
- checkDependencyArray(reactHook, depsArray);
1229
- });
1230
- }
1231
- };
1232
- })
1233
- });
1234
-
1235
- // src/utils/create-property-order-rule.ts
1236
- var import_utils9 = require("@typescript-eslint/utils");
1237
-
1238
- // src/utils/sort-data-by-order.ts
1239
- function sortDataByOrder(data, orderRules, key) {
1240
- const getSubsetIndex = (item, subsets) => {
1241
- for (let i = 0; i < subsets.length; i++) {
1242
- if (subsets[i]?.includes(item)) {
1243
- return i;
1244
- }
1245
- }
1246
- return null;
1247
- };
1248
- const orderSets = orderRules.reduce(
1249
- (sets, [A, B]) => [...sets, A, B],
1250
- []
1251
- );
1252
- const inOrderArray = data.filter(
1253
- (item) => getSubsetIndex(item[key], orderSets) !== null
1254
- );
1255
- let wasResorted = false;
1256
- const sortedArray = inOrderArray.sort((a, b) => {
1257
- const aKey = a[key], bKey = b[key];
1258
- const aSubsetIndex = getSubsetIndex(aKey, orderSets);
1259
- const bSubsetIndex = getSubsetIndex(bKey, orderSets);
1260
- if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
1261
- return aSubsetIndex - bSubsetIndex;
1262
- }
1263
- return 0;
1264
- });
1265
- const inOrderIterator = sortedArray.values();
1266
- const result = data.map((item) => {
1267
- if (getSubsetIndex(item[key], orderSets) !== null) {
1268
- const sortedItem = inOrderIterator.next().value;
1269
- if (sortedItem[key] !== item[key]) {
1270
- wasResorted = true;
1271
- }
1272
- return sortedItem;
1273
- }
1274
- return item;
1275
- });
1276
- if (!wasResorted) {
1277
- return null;
1278
- }
1279
- return result;
1280
- }
1281
-
1282
- // src/utils/create-property-order-rule.ts
1283
- var createRule5 = import_utils9.ESLintUtils.RuleCreator(getDocsUrl);
1284
- function createPropertyOrderRule(options, targetFunctions, orderRules) {
1285
- const targetFunctionSet = new Set(targetFunctions);
1286
- function isTargetFunction(node) {
1287
- return targetFunctionSet.has(node);
1288
- }
1289
- return createRule5({
1290
- ...options,
1291
- create: detectTanstackQueryImports((context) => {
1292
- return {
1293
- CallExpression(node) {
1294
- if (node.callee.type !== import_utils9.AST_NODE_TYPES.Identifier) {
1295
- return;
1296
- }
1297
- const functions = node.callee.name;
1298
- if (!isTargetFunction(functions)) {
1299
- return;
1300
- }
1301
- const argument = node.arguments[0];
1302
- if (argument === void 0 || argument.type !== "ObjectExpression") {
1303
- return;
1304
- }
1305
- const allProperties = argument.properties;
1306
- if (allProperties.length < 2) {
1307
- return;
1308
- }
1309
- const properties = allProperties.flatMap((p, index) => {
1310
- if (p.type === import_utils9.AST_NODE_TYPES.Property && p.key.type === import_utils9.AST_NODE_TYPES.Identifier) {
1311
- return { name: p.key.name, property: p };
1312
- } else return { name: `_property_${index}`, property: p };
1313
- });
1314
- const sortedProperties = sortDataByOrder(
1315
- properties,
1316
- orderRules,
1317
- "name"
1318
- );
1319
- if (sortedProperties === null) {
1320
- return;
1321
- }
1322
- context.report({
1323
- node: argument,
1324
- data: { function: node.callee.name },
1325
- messageId: "invalidOrder",
1326
- fix(fixer) {
1327
- const sourceCode = context.sourceCode;
1328
- const reorderedText = sortedProperties.reduce(
1329
- (sourceText, specifier, index) => {
1330
- let textBetweenProperties = "";
1331
- if (index < allProperties.length - 1) {
1332
- textBetweenProperties = sourceCode.getText().slice(
1333
- allProperties[index].range[1],
1334
- allProperties[index + 1].range[0]
1335
- );
1336
- }
1337
- return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
1338
- },
1339
- ""
1340
- );
1341
- return fixer.replaceTextRange(
1342
- [allProperties[0].range[0], allProperties.at(-1).range[1]],
1343
- reorderedText
1344
- );
1345
- }
1346
- });
1347
- }
1348
- };
1349
- })
1350
- });
1351
- }
1352
-
1353
- // src/rules/infinite-query-property-order/constants.ts
1354
- var infiniteQueryFunctions = [
1355
- "infiniteQueryOptions",
1356
- "useInfiniteQuery",
1357
- "useSuspenseInfiniteQuery"
1358
- ];
1359
- var sortRules = [
1360
- [["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]
1361
- ];
1362
-
1363
- // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
1364
- var name5 = "infinite-query-property-order";
1365
- var rule5 = createPropertyOrderRule(
1366
- {
1367
- name: name5,
1368
- meta: {
1369
- type: "problem",
1370
- docs: {
1371
- description: "Ensure correct order of inference sensitive properties for infinite queries",
1372
- recommended: "error"
1373
- },
1374
- messages: {
1375
- invalidOrder: "Invalid order of properties for `{{function}}`."
1376
- },
1377
- schema: [],
1378
- hasSuggestions: true,
1379
- fixable: "code"
1380
- },
1381
- defaultOptions: []
1382
- },
1383
- infiniteQueryFunctions,
1384
- sortRules
1385
- );
1386
-
1387
- // src/rules/no-void-query-fn/no-void-query-fn.rule.ts
1388
- var import_utils10 = require("@typescript-eslint/utils");
1389
- var name6 = "no-void-query-fn";
1390
- var createRule6 = import_utils10.ESLintUtils.RuleCreator(getDocsUrl);
1391
- var rule6 = createRule6({
1392
- name: name6,
1393
- meta: {
1394
- type: "problem",
1395
- docs: {
1396
- description: "Ensures queryFn returns a non-undefined value",
1397
- recommended: "error"
1398
- },
1399
- messages: {
1400
- noVoidReturn: "queryFn must return a non-undefined value"
1401
- },
1402
- schema: []
1403
- },
1404
- defaultOptions: [],
1405
- create: detectTanstackQueryImports((context) => {
1406
- return {
1407
- Property(node) {
1408
- if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, "queryFn")) {
1409
- return;
1410
- }
1411
- const parserServices = context.sourceCode.parserServices;
1412
- if (!parserServices || !parserServices.esTreeNodeToTSNodeMap || !parserServices.program) {
1413
- return;
1414
- }
1415
- const checker = parserServices.program.getTypeChecker();
1416
- const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.value);
1417
- const type = checker.getTypeAtLocation(tsNode);
1418
- if (type.getCallSignatures().length > 0) {
1419
- const returnType = type.getCallSignatures()[0]?.getReturnType();
1420
- if (!returnType) {
1421
- return;
1422
- }
1423
- if (isIllegalReturn(checker, returnType)) {
1424
- context.report({
1425
- node: node.value,
1426
- messageId: "noVoidReturn"
1427
- });
1428
- }
1429
- }
1430
- }
1431
- };
1432
- })
1433
- });
1434
- function isIllegalReturn(checker, type) {
1435
- const awaited = checker.getAwaitedType(type);
1436
- if (!awaited) return false;
1437
- if (awaited.isUnion()) {
1438
- return awaited.types.some((t) => isIllegalReturn(checker, t));
1439
- }
1440
- const typeString = checker.typeToString(awaited);
1441
- return typeString === "void" || typeString === "undefined";
1442
- }
1443
-
1444
- // src/rules/mutation-property-order/constants.ts
1445
- var mutationFunctions = ["useMutation"];
1446
- var sortRules2 = [[["onMutate"], ["onError", "onSettled"]]];
1447
-
1448
- // src/rules/mutation-property-order/mutation-property-order.rule.ts
1449
- var name7 = "mutation-property-order";
1450
- var rule7 = createPropertyOrderRule(
1451
- {
1452
- name: name7,
1453
- meta: {
1454
- type: "problem",
1455
- docs: {
1456
- description: "Ensure correct order of inference-sensitive properties in useMutation()",
1457
- recommended: "error"
1458
- },
1459
- messages: {
1460
- invalidOrder: "Invalid order of properties for `{{function}}`."
1461
- },
1462
- schema: [],
1463
- hasSuggestions: true,
1464
- fixable: "code"
1465
- },
1466
- defaultOptions: []
1467
- },
1468
- mutationFunctions,
1469
- sortRules2
1470
- );
1471
-
1472
- // src/rules/prefer-query-options/prefer-query-options.rule.ts
1473
- var import_utils11 = require("@typescript-eslint/utils");
1474
- var name8 = "prefer-query-options";
1475
- var queryHooks2 = [
1476
- "useQuery",
1477
- "useInfiniteQuery",
1478
- "useSuspenseQuery",
1479
- "useSuspenseInfiniteQuery",
1480
- "usePrefetchQuery",
1481
- "usePrefetchInfiniteQuery"
1482
- ];
1483
- var queriesHooks = ["useQueries", "useSuspenseQueries"];
1484
- var filterHooks = ["useIsFetching"];
1485
- var queryClientOptionMethods = [
1486
- "fetchQuery",
1487
- "prefetchQuery",
1488
- "fetchInfiniteQuery",
1489
- "prefetchInfiniteQuery",
1490
- "ensureQueryData",
1491
- "ensureInfiniteQueryData"
1492
- ];
1493
- var queryClientQueryKeyMethods = [
1494
- "getQueryData",
1495
- "setQueryData",
1496
- "getQueryState",
1497
- "setQueryDefaults",
1498
- "getQueryDefaults"
1499
- ];
1500
- var queryClientFilterMethods = [
1501
- "invalidateQueries",
1502
- "cancelQueries",
1503
- "refetchQueries",
1504
- "removeQueries",
1505
- "resetQueries",
1506
- "isFetching",
1507
- "getQueriesData",
1508
- "setQueriesData"
1509
- ];
1510
- var queryOptionsBuilders = ["queryOptions", "infiniteQueryOptions"];
1511
- var createRule7 = import_utils11.ESLintUtils.RuleCreator(getDocsUrl);
1512
- var rule8 = createRule7({
1513
- name: name8,
1514
- meta: {
1515
- type: "problem",
1516
- docs: {
1517
- description: "Prefer using queryOptions() to co-locate queryKey and queryFn",
1518
- recommended: "strict"
1519
- },
1520
- messages: {
1521
- preferQueryOptions: "Prefer using queryOptions() or infiniteQueryOptions() to co-locate queryKey and queryFn.",
1522
- preferQueryOptionsQueryKey: "Prefer referencing a queryKey from a queryOptions() result instead of typing it manually."
1523
- },
1524
- schema: []
1525
- },
1526
- defaultOptions: [],
1527
- create: detectTanstackQueryImports((context, _, helpers) => {
1528
- function reportInlineQueryOptions(node) {
1529
- if (ASTUtils.isObjectExpression(node) && hasInlineQueryOptions(node)) {
1530
- context.report({
1531
- node,
1532
- messageId: "preferQueryOptions"
1533
- });
1534
- }
1535
- }
1536
- function reportInlineFilterQueryKey(node) {
1537
- if (ASTUtils.isObjectExpression(node) && hasInlineFilterQueryKey(node)) {
1538
- context.report({
1539
- node,
1540
- messageId: "preferQueryOptionsQueryKey"
1541
- });
1542
- }
1543
- }
1544
- return {
1545
- CallExpression: (node) => {
1546
- if (ASTUtils.isIdentifier(node.callee)) {
1547
- const importedName = getTanstackImportName(
1548
- context,
1549
- helpers,
1550
- node.callee
1551
- );
1552
- if (importedName === null) {
1553
- return;
1554
- }
1555
- if (queryOptionsBuilders.includes(importedName)) {
1556
- return;
1557
- }
1558
- const options2 = node.arguments[0];
1559
- if (options2 === void 0) {
1560
- return;
1561
- }
1562
- if (queryHooks2.includes(importedName)) {
1563
- reportInlineQueryOptions(options2);
1564
- return;
1565
- }
1566
- if (queriesHooks.includes(importedName) && ASTUtils.isObjectExpression(options2)) {
1567
- const queries = ASTUtils.findPropertyWithIdentifierKey(
1568
- options2.properties,
1569
- "queries"
1570
- )?.value;
1571
- if (queries !== void 0) {
1572
- getQueryObjects(queries).forEach((query) => {
1573
- reportInlineQueryOptions(query);
1574
- });
1575
- }
1576
- return;
1577
- }
1578
- if (filterHooks.includes(importedName)) {
1579
- reportInlineFilterQueryKey(options2);
1580
- }
1581
- return;
1582
- }
1583
- if (node.callee.type !== import_utils11.AST_NODE_TYPES.MemberExpression || !ASTUtils.isIdentifier(node.callee.property) || !isTanstackQueryClient(node.callee.object, context, helpers)) {
1584
- return;
1585
- }
1586
- const method = node.callee.property.name;
1587
- const options = node.arguments[0];
1588
- if (options === void 0) {
1589
- return;
1590
- }
1591
- if (queryClientOptionMethods.includes(method)) {
1592
- reportInlineQueryOptions(options);
1593
- return;
1594
- }
1595
- if (queryClientQueryKeyMethods.includes(method) && isInlineArrayExpression(options)) {
1596
- context.report({
1597
- node: options,
1598
- messageId: "preferQueryOptionsQueryKey"
1599
- });
1600
- return;
1601
- }
1602
- if (queryClientFilterMethods.includes(method)) {
1603
- reportInlineFilterQueryKey(options);
1604
- }
1605
- }
1606
- };
1607
- })
1608
- });
1609
- function hasInlineQueryOptions(node) {
1610
- return ASTUtils.findPropertyWithIdentifierKey(node.properties, "queryKey") !== void 0 || ASTUtils.findPropertyWithIdentifierKey(node.properties, "queryFn") !== void 0;
1611
- }
1612
- function hasInlineFilterQueryKey(node) {
1613
- const queryKey = ASTUtils.findPropertyWithIdentifierKey(
1614
- node.properties,
1615
- "queryKey"
1616
- )?.value;
1617
- return queryKey !== void 0 && isInlineArrayExpression(queryKey);
1618
- }
1619
- function isInlineArrayExpression(node) {
1620
- return unwrapTypeAssertions(node).type === import_utils11.AST_NODE_TYPES.ArrayExpression;
1621
- }
1622
- function getReturnedObjectExpressions(node) {
1623
- if (ASTUtils.isObjectExpression(node)) {
1624
- return [node];
1625
- }
1626
- if (node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionExpression) {
1627
- return getReturnedObjectExpressions(node.body);
1628
- }
1629
- if (node.type === import_utils11.AST_NODE_TYPES.BlockStatement) {
1630
- return node.body.flatMap((statement) => {
1631
- if (statement.type === import_utils11.AST_NODE_TYPES.ReturnStatement && statement.argument !== null) {
1632
- return getReturnedObjectExpressions(statement.argument);
1633
- }
1634
- return [];
1635
- });
1636
- }
1637
- if (node.type === import_utils11.AST_NODE_TYPES.ConditionalExpression) {
1638
- return [
1639
- ...getReturnedObjectExpressions(node.consequent),
1640
- ...getReturnedObjectExpressions(node.alternate)
1641
- ];
1642
- }
1643
- if (node.type === import_utils11.AST_NODE_TYPES.LogicalExpression) {
1644
- return [
1645
- ...getReturnedObjectExpressions(node.left),
1646
- ...getReturnedObjectExpressions(node.right)
1647
- ];
1648
- }
1649
- if (node.type === import_utils11.AST_NODE_TYPES.SequenceExpression) {
1650
- return node.expressions.flatMap(
1651
- (expression) => getReturnedObjectExpressions(expression)
1652
- );
1653
- }
1654
- return [];
1655
- }
1656
- function getQueryObjects(node) {
1657
- if (node.type === import_utils11.AST_NODE_TYPES.ArrayExpression) {
1658
- return node.elements.flatMap((element) => {
1659
- if (element !== null && ASTUtils.isObjectExpression(element)) {
1660
- return [element];
1661
- }
1662
- return [];
1663
- });
1664
- }
1665
- if (node.type === import_utils11.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils11.AST_NODE_TYPES.MemberExpression && ASTUtils.isIdentifierWithName(node.callee.property, "map")) {
1666
- const mapper = node.arguments[0];
1667
- if (mapper?.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || mapper?.type === import_utils11.AST_NODE_TYPES.FunctionExpression) {
1668
- return getReturnedObjectExpressions(mapper);
1669
- }
1670
- }
1671
- return [];
1672
- }
1673
- function isTanstackQueryClient(node, context, helpers) {
1674
- const source = resolveQueryClientSource(node, context);
1675
- if (source.type === import_utils11.AST_NODE_TYPES.CallExpression && ASTUtils.isIdentifier(source.callee)) {
1676
- return getTanstackImportName(context, helpers, source.callee) === "useQueryClient";
1677
- }
1678
- if (source.type === import_utils11.AST_NODE_TYPES.NewExpression && ASTUtils.isIdentifier(source.callee)) {
1679
- return getTanstackImportName(context, helpers, source.callee) === "QueryClient";
1680
- }
1681
- return false;
1682
- }
1683
- function getTanstackImportName(context, helpers, node) {
1684
- if (!helpers.isTanstackQueryImport(node)) {
1685
- return null;
1686
- }
1687
- const definition = context.sourceCode.getScope(node).references.find((reference) => reference.identifier === node)?.resolved?.defs[0]?.node;
1688
- if (definition?.type !== import_utils11.AST_NODE_TYPES.ImportSpecifier || definition.imported.type !== import_utils11.AST_NODE_TYPES.Identifier) {
1689
- return null;
1690
- }
1691
- return definition.imported.name;
1692
- }
1693
- function resolveQueryClientSource(node, context) {
1694
- const visitedNodes = /* @__PURE__ */ new Set();
1695
- while (!visitedNodes.has(node)) {
1696
- visitedNodes.add(node);
1697
- if (node.type === import_utils11.AST_NODE_TYPES.ChainExpression) {
1698
- node = node.expression;
1699
- continue;
1700
- }
1701
- node = unwrapTypeAssertions(node);
1702
- if (node.type !== import_utils11.AST_NODE_TYPES.Identifier) {
1703
- return node;
1704
- }
1705
- const expression = ASTUtils.getReferencedExpressionByIdentifier({
1706
- context,
1707
- node
1708
- });
1709
- if (expression === null) {
1710
- return node;
1711
- }
1712
- node = expression;
1713
- }
1714
- return node;
1715
- }
1716
- function unwrapTypeAssertions(node) {
1717
- 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) {
1718
- node = node.expression;
1719
- }
1720
- return node;
1721
- }
1722
-
1723
- // src/rules.ts
1724
- var rules = {
1725
- [name]: rule,
1726
- [name2]: rule2,
1727
- [name3]: rule3,
1728
- [name4]: rule4,
1729
- [name5]: rule5,
1730
- [name6]: rule6,
1731
- [name7]: rule7,
1732
- [name8]: rule8
1733
- };
1734
-
1735
- // src/index.ts
1736
- var recommendedRules = {
1737
- "@tanstack/query/exhaustive-deps": "error",
1738
- "@tanstack/query/no-rest-destructuring": "warn",
1739
- "@tanstack/query/stable-query-client": "error",
1740
- "@tanstack/query/no-unstable-deps": "error",
1741
- "@tanstack/query/infinite-query-property-order": "error",
1742
- "@tanstack/query/no-void-query-fn": "error",
1743
- "@tanstack/query/mutation-property-order": "error"
1744
- };
1745
- var recommendedStrictRules = {
1746
- ...recommendedRules,
1747
- "@tanstack/query/prefer-query-options": "error"
1748
- };
1749
- var plugin = {
1750
- meta: {
1751
- name: "@tanstack/eslint-plugin-query"
1752
- },
1753
- configs: {
1754
- recommended: {
1755
- plugins: ["@tanstack/query"],
1756
- rules: recommendedRules
1757
- },
1758
- recommendedStrict: {
1759
- plugins: ["@tanstack/query"],
1760
- rules: recommendedStrictRules
1761
- },
1762
- "flat/recommended": [
1763
- {
1764
- name: "tanstack/query/flat/recommended",
1765
- plugins: {
1766
- "@tanstack/query": {}
1767
- // Assigned after plugin object created
1768
- },
1769
- rules: recommendedRules
1770
- }
1771
- ],
1772
- "flat/recommended-strict": [
1773
- {
1774
- name: "tanstack/query/flat/recommended-strict",
1775
- plugins: {
1776
- "@tanstack/query": {}
1777
- // Assigned after plugin object created
1778
- },
1779
- rules: recommendedStrictRules
1780
- }
1781
- ]
1782
- },
1783
- rules
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_rules = require("./rules-B1yVUvLh.cjs");
6
+ //#region src/index.ts
7
+ const recommendedRules = {
8
+ "@tanstack/query/exhaustive-deps": "error",
9
+ "@tanstack/query/no-rest-destructuring": "warn",
10
+ "@tanstack/query/stable-query-client": "error",
11
+ "@tanstack/query/no-unstable-deps": "error",
12
+ "@tanstack/query/infinite-query-property-order": "error",
13
+ "@tanstack/query/no-void-query-fn": "error",
14
+ "@tanstack/query/mutation-property-order": "error"
15
+ };
16
+ const recommendedStrictRules = {
17
+ ...recommendedRules,
18
+ "@tanstack/query/prefer-query-options": "error"
19
+ };
20
+ const plugin = {
21
+ meta: { name: "@tanstack/eslint-plugin-query" },
22
+ configs: {
23
+ recommended: {
24
+ plugins: ["@tanstack/query"],
25
+ rules: recommendedRules
26
+ },
27
+ recommendedStrict: {
28
+ plugins: ["@tanstack/query"],
29
+ rules: recommendedStrictRules
30
+ },
31
+ "flat/recommended": [{
32
+ name: "tanstack/query/flat/recommended",
33
+ plugins: { "@tanstack/query": {} },
34
+ rules: recommendedRules
35
+ }],
36
+ "flat/recommended-strict": [{
37
+ name: "tanstack/query/flat/recommended-strict",
38
+ plugins: { "@tanstack/query": {} },
39
+ rules: recommendedStrictRules
40
+ }]
41
+ },
42
+ rules: require_rules.rules
1784
43
  };
1785
44
  plugin.configs["flat/recommended"][0].plugins["@tanstack/query"] = plugin;
1786
45
  plugin.configs["flat/recommended-strict"][0].plugins["@tanstack/query"] = plugin;
1787
- var index_default = plugin;
1788
- // Annotate the CommonJS export names for ESM import in node:
1789
- 0 && (module.exports = {
1790
- plugin
1791
- });
46
+ //#endregion
47
+ exports.default = plugin;
48
+ exports.plugin = plugin;
49
+
1792
50
  module.exports = module.exports.default
1793
51
  //# sourceMappingURL=index.cjs.map