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