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