@tanstack/eslint-plugin-query 5.71.5 → 5.72.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 (119) hide show
  1. package/dist/index.cjs +1001 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +24 -0
  4. package/dist/index.d.ts +24 -0
  5. package/dist/index.js +968 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/rules.cjs +966 -0
  8. package/dist/rules.cjs.map +1 -0
  9. package/dist/rules.js +929 -0
  10. package/dist/rules.js.map +1 -0
  11. package/package.json +12 -12
  12. package/dist/cjs/index.cjs +0 -38
  13. package/dist/cjs/index.cjs.map +0 -1
  14. package/dist/cjs/index.d.cts +0 -13
  15. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.rule.cjs +0 -134
  16. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.rule.cjs.map +0 -1
  17. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.rule.d.cts +0 -4
  18. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.utils.cjs +0 -26
  19. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.utils.cjs.map +0 -1
  20. package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.utils.d.cts +0 -10
  21. package/dist/cjs/rules/infinite-query-property-order/constants.cjs +0 -13
  22. package/dist/cjs/rules/infinite-query-property-order/constants.cjs.map +0 -1
  23. package/dist/cjs/rules/infinite-query-property-order/constants.d.cts +0 -4
  24. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.rule.cjs +0 -88
  25. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.rule.cjs.map +0 -1
  26. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.rule.d.cts +0 -4
  27. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.utils.cjs +0 -47
  28. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.utils.cjs.map +0 -1
  29. package/dist/cjs/rules/infinite-query-property-order/infinite-query-property-order.utils.d.cts +0 -1
  30. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.rule.cjs +0 -92
  31. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.rule.cjs.map +0 -1
  32. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.rule.d.cts +0 -4
  33. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.utils.cjs +0 -13
  34. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.utils.cjs.map +0 -1
  35. package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.utils.d.cts +0 -4
  36. package/dist/cjs/rules/no-unstable-deps/no-unstable-deps.rule.cjs +0 -93
  37. package/dist/cjs/rules/no-unstable-deps/no-unstable-deps.rule.cjs.map +0 -1
  38. package/dist/cjs/rules/no-unstable-deps/no-unstable-deps.rule.d.cts +0 -6
  39. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs +0 -71
  40. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs.map +0 -1
  41. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.d.cts +0 -4
  42. package/dist/cjs/rules.cjs +0 -16
  43. package/dist/cjs/rules.cjs.map +0 -1
  44. package/dist/cjs/rules.d.cts +0 -3
  45. package/dist/cjs/types.d.cts +0 -3
  46. package/dist/cjs/utils/ast-utils.cjs +0 -267
  47. package/dist/cjs/utils/ast-utils.cjs.map +0 -1
  48. package/dist/cjs/utils/ast-utils.d.cts +0 -38
  49. package/dist/cjs/utils/detect-react-query-imports.cjs +0 -55
  50. package/dist/cjs/utils/detect-react-query-imports.cjs.map +0 -1
  51. package/dist/cjs/utils/detect-react-query-imports.d.cts +0 -11
  52. package/dist/cjs/utils/get-docs-url.cjs +0 -5
  53. package/dist/cjs/utils/get-docs-url.cjs.map +0 -1
  54. package/dist/cjs/utils/get-docs-url.d.cts +0 -1
  55. package/dist/cjs/utils/unique-by.cjs +0 -7
  56. package/dist/cjs/utils/unique-by.cjs.map +0 -1
  57. package/dist/cjs/utils/unique-by.d.cts +0 -1
  58. package/dist/esm/index.d.ts +0 -13
  59. package/dist/esm/index.js +0 -39
  60. package/dist/esm/index.js.map +0 -1
  61. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.d.ts +0 -4
  62. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.js +0 -134
  63. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.js.map +0 -1
  64. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.utils.d.ts +0 -10
  65. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.utils.js +0 -26
  66. package/dist/esm/rules/exhaustive-deps/exhaustive-deps.utils.js.map +0 -1
  67. package/dist/esm/rules/infinite-query-property-order/constants.d.ts +0 -4
  68. package/dist/esm/rules/infinite-query-property-order/constants.js +0 -13
  69. package/dist/esm/rules/infinite-query-property-order/constants.js.map +0 -1
  70. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.rule.d.ts +0 -4
  71. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.rule.js +0 -88
  72. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.rule.js.map +0 -1
  73. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.utils.d.ts +0 -1
  74. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.utils.js +0 -47
  75. package/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.utils.js.map +0 -1
  76. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.d.ts +0 -4
  77. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.js +0 -92
  78. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.js.map +0 -1
  79. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.utils.d.ts +0 -4
  80. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.utils.js +0 -13
  81. package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.utils.js.map +0 -1
  82. package/dist/esm/rules/no-unstable-deps/no-unstable-deps.rule.d.ts +0 -6
  83. package/dist/esm/rules/no-unstable-deps/no-unstable-deps.rule.js +0 -93
  84. package/dist/esm/rules/no-unstable-deps/no-unstable-deps.rule.js.map +0 -1
  85. package/dist/esm/rules/stable-query-client/stable-query-client.rule.d.ts +0 -4
  86. package/dist/esm/rules/stable-query-client/stable-query-client.rule.js +0 -71
  87. package/dist/esm/rules/stable-query-client/stable-query-client.rule.js.map +0 -1
  88. package/dist/esm/rules.d.ts +0 -3
  89. package/dist/esm/rules.js +0 -16
  90. package/dist/esm/rules.js.map +0 -1
  91. package/dist/esm/types.d.ts +0 -3
  92. package/dist/esm/utils/ast-utils.d.ts +0 -38
  93. package/dist/esm/utils/ast-utils.js +0 -267
  94. package/dist/esm/utils/ast-utils.js.map +0 -1
  95. package/dist/esm/utils/detect-react-query-imports.d.ts +0 -11
  96. package/dist/esm/utils/detect-react-query-imports.js +0 -55
  97. package/dist/esm/utils/detect-react-query-imports.js.map +0 -1
  98. package/dist/esm/utils/get-docs-url.d.ts +0 -1
  99. package/dist/esm/utils/get-docs-url.js +0 -5
  100. package/dist/esm/utils/get-docs-url.js.map +0 -1
  101. package/dist/esm/utils/unique-by.d.ts +0 -1
  102. package/dist/esm/utils/unique-by.js +0 -7
  103. package/dist/esm/utils/unique-by.js.map +0 -1
  104. package/src/index.ts +0 -52
  105. package/src/rules/exhaustive-deps/exhaustive-deps.rule.ts +0 -184
  106. package/src/rules/exhaustive-deps/exhaustive-deps.utils.ts +0 -41
  107. package/src/rules/infinite-query-property-order/constants.ts +0 -17
  108. package/src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts +0 -107
  109. package/src/rules/infinite-query-property-order/infinite-query-property-order.utils.ts +0 -67
  110. package/src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts +0 -115
  111. package/src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts +0 -11
  112. package/src/rules/no-unstable-deps/no-unstable-deps.rule.ts +0 -129
  113. package/src/rules/stable-query-client/stable-query-client.rule.ts +0 -88
  114. package/src/rules.ts +0 -23
  115. package/src/types.ts +0 -3
  116. package/src/utils/ast-utils.ts +0 -391
  117. package/src/utils/detect-react-query-imports.ts +0 -97
  118. package/src/utils/get-docs-url.ts +0 -2
  119. package/src/utils/unique-by.ts +0 -3
@@ -1,267 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utils = require("@typescript-eslint/utils");
4
- const uniqueBy = require("./unique-by.cjs");
5
- const ASTUtils = {
6
- isNodeOfOneOf(node, types) {
7
- return types.includes(node.type);
8
- },
9
- isIdentifier(node) {
10
- return node.type === utils.AST_NODE_TYPES.Identifier;
11
- },
12
- isIdentifierWithName(node, name) {
13
- return ASTUtils.isIdentifier(node) && node.name === name;
14
- },
15
- isIdentifierWithOneOfNames(node, name) {
16
- return ASTUtils.isIdentifier(node) && name.includes(node.name);
17
- },
18
- isProperty(node) {
19
- return node.type === utils.AST_NODE_TYPES.Property;
20
- },
21
- isObjectExpression(node) {
22
- return node.type === utils.AST_NODE_TYPES.ObjectExpression;
23
- },
24
- isPropertyWithIdentifierKey(node, key) {
25
- return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
26
- },
27
- findPropertyWithIdentifierKey(properties, key) {
28
- return properties.find(
29
- (x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
30
- );
31
- },
32
- getNestedIdentifiers(node) {
33
- const identifiers = [];
34
- if (ASTUtils.isIdentifier(node)) {
35
- identifiers.push(node);
36
- }
37
- if ("arguments" in node) {
38
- node.arguments.forEach((x) => {
39
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
40
- });
41
- }
42
- if ("elements" in node) {
43
- node.elements.forEach((x) => {
44
- if (x !== null) {
45
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
46
- }
47
- });
48
- }
49
- if ("properties" in node) {
50
- node.properties.forEach((x) => {
51
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
52
- });
53
- }
54
- if ("expressions" in node) {
55
- node.expressions.forEach((x) => {
56
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
57
- });
58
- }
59
- if ("left" in node) {
60
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.left));
61
- }
62
- if ("right" in node) {
63
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.right));
64
- }
65
- if (node.type === utils.AST_NODE_TYPES.Property) {
66
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
67
- }
68
- if (node.type === utils.AST_NODE_TYPES.SpreadElement) {
69
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
70
- }
71
- if (node.type === utils.AST_NODE_TYPES.MemberExpression) {
72
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
73
- }
74
- if (node.type === utils.AST_NODE_TYPES.UnaryExpression) {
75
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
76
- }
77
- if (node.type === utils.AST_NODE_TYPES.ChainExpression) {
78
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
79
- }
80
- if (node.type === utils.AST_NODE_TYPES.TSNonNullExpression) {
81
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
82
- }
83
- if (node.type === utils.AST_NODE_TYPES.ArrowFunctionExpression) {
84
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
85
- }
86
- if (node.type === utils.AST_NODE_TYPES.FunctionExpression) {
87
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
88
- }
89
- if (node.type === utils.AST_NODE_TYPES.BlockStatement) {
90
- identifiers.push(
91
- ...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat()
92
- );
93
- }
94
- if (node.type === utils.AST_NODE_TYPES.ReturnStatement && node.argument) {
95
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
96
- }
97
- return identifiers;
98
- },
99
- isAncestorIsCallee(identifier) {
100
- let previousNode = identifier;
101
- let currentNode = identifier.parent;
102
- while (currentNode !== void 0) {
103
- if (currentNode.type === utils.AST_NODE_TYPES.CallExpression && currentNode.callee === previousNode) {
104
- return true;
105
- }
106
- if (currentNode.type !== utils.AST_NODE_TYPES.MemberExpression) {
107
- return false;
108
- }
109
- previousNode = currentNode;
110
- currentNode = currentNode.parent;
111
- }
112
- return false;
113
- },
114
- traverseUpOnly(identifier, allowedNodeTypes) {
115
- const parent = identifier.parent;
116
- if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
117
- return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
118
- }
119
- return identifier;
120
- },
121
- isDeclaredInNode(params) {
122
- const { functionNode, reference, scopeManager } = params;
123
- const scope = scopeManager.acquire(functionNode);
124
- if (scope === null) {
125
- return false;
126
- }
127
- return scope.set.has(reference.identifier.name);
128
- },
129
- getExternalRefs(params) {
130
- const { scopeManager, sourceCode, node } = params;
131
- const scope = scopeManager.acquire(node);
132
- if (scope === null) {
133
- return [];
134
- }
135
- const references = scope.references.filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
136
- const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
137
- utils.AST_NODE_TYPES.MemberExpression,
138
- utils.AST_NODE_TYPES.Identifier
139
- ]);
140
- return {
141
- variable: x,
142
- node: referenceNode,
143
- text: sourceCode.getText(referenceNode)
144
- };
145
- });
146
- const localRefIds = new Set(
147
- [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
148
- );
149
- const externalRefs = references.filter(
150
- (x) => x.variable.resolved === null || !localRefIds.has(x.text)
151
- );
152
- return uniqueBy.uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
153
- },
154
- mapKeyNodeToText(node, sourceCode) {
155
- return sourceCode.getText(
156
- ASTUtils.traverseUpOnly(node, [
157
- utils.AST_NODE_TYPES.MemberExpression,
158
- utils.AST_NODE_TYPES.TSNonNullExpression,
159
- utils.AST_NODE_TYPES.Identifier
160
- ])
161
- );
162
- },
163
- mapKeyNodeToBaseText(node, sourceCode) {
164
- return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
165
- /(?:\?(\.)|!)/g,
166
- "$1"
167
- );
168
- },
169
- isValidReactComponentOrHookName(identifier) {
170
- return identifier !== null && identifier !== void 0 && /^(use|[A-Z])/.test(identifier.name);
171
- },
172
- getFunctionAncestor(sourceCode, node) {
173
- var _a;
174
- for (const ancestor of sourceCode.getAncestors(node)) {
175
- if (ASTUtils.isNodeOfOneOf(ancestor, [
176
- utils.AST_NODE_TYPES.FunctionDeclaration,
177
- utils.AST_NODE_TYPES.FunctionExpression,
178
- utils.AST_NODE_TYPES.ArrowFunctionExpression
179
- ])) {
180
- return ancestor;
181
- }
182
- if (((_a = ancestor.parent) == null ? void 0 : _a.type) === utils.AST_NODE_TYPES.VariableDeclarator && ancestor.parent.id.type === utils.AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(ancestor, [
183
- utils.AST_NODE_TYPES.FunctionDeclaration,
184
- utils.AST_NODE_TYPES.FunctionExpression,
185
- utils.AST_NODE_TYPES.ArrowFunctionExpression
186
- ])) {
187
- return ancestor;
188
- }
189
- }
190
- return void 0;
191
- },
192
- getReferencedExpressionByIdentifier(params) {
193
- var _a, _b, _c;
194
- const { node, context } = params;
195
- const sourceCode = context.sourceCode ?? context.getSourceCode();
196
- const scope = context.sourceCode.getScope(node) ? sourceCode.getScope(node) : context.getScope();
197
- 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;
198
- if ((resolvedNode == null ? void 0 : resolvedNode.type) !== utils.AST_NODE_TYPES.VariableDeclarator) {
199
- return null;
200
- }
201
- return resolvedNode.init;
202
- },
203
- getClosestVariableDeclarator(node) {
204
- let currentNode = node;
205
- while (currentNode.type !== utils.AST_NODE_TYPES.Program) {
206
- if (currentNode.type === utils.AST_NODE_TYPES.VariableDeclarator) {
207
- return currentNode;
208
- }
209
- currentNode = currentNode.parent;
210
- }
211
- return void 0;
212
- },
213
- getNestedReturnStatements(node) {
214
- const returnStatements = [];
215
- if (node.type === utils.AST_NODE_TYPES.ReturnStatement) {
216
- returnStatements.push(node);
217
- }
218
- if ("body" in node && node.body !== void 0 && node.body !== null) {
219
- Array.isArray(node.body) ? node.body.forEach((x) => {
220
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
221
- }) : returnStatements.push(
222
- ...ASTUtils.getNestedReturnStatements(node.body)
223
- );
224
- }
225
- if ("consequent" in node) {
226
- Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
227
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
228
- }) : returnStatements.push(
229
- ...ASTUtils.getNestedReturnStatements(node.consequent)
230
- );
231
- }
232
- if ("alternate" in node && node.alternate !== null) {
233
- Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
234
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
235
- }) : returnStatements.push(
236
- ...ASTUtils.getNestedReturnStatements(node.alternate)
237
- );
238
- }
239
- if ("cases" in node) {
240
- node.cases.forEach((x) => {
241
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
242
- });
243
- }
244
- if ("block" in node) {
245
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
246
- }
247
- if ("handler" in node && node.handler !== null) {
248
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
249
- }
250
- if ("finalizer" in node && node.finalizer !== null) {
251
- returnStatements.push(
252
- ...ASTUtils.getNestedReturnStatements(node.finalizer)
253
- );
254
- }
255
- if ("expression" in node && node.expression !== true && node.expression !== false) {
256
- returnStatements.push(
257
- ...ASTUtils.getNestedReturnStatements(node.expression)
258
- );
259
- }
260
- if ("test" in node && node.test !== null) {
261
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
262
- }
263
- return returnStatements;
264
- }
265
- };
266
- exports.ASTUtils = ASTUtils;
267
- //# sourceMappingURL=ast-utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast-utils.cjs","sources":["../../../src/utils/ast-utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { uniqueBy } from './unique-by'\nimport type { TSESLint, TSESTree } from '@typescript-eslint/utils'\n\nexport const ASTUtils = {\n isNodeOfOneOf<T extends AST_NODE_TYPES>(\n node: TSESTree.Node,\n types: ReadonlyArray<T>,\n ): node is TSESTree.Node & { type: T } {\n return types.includes(node.type as T)\n },\n isIdentifier(node: TSESTree.Node): node is TSESTree.Identifier {\n return node.type === AST_NODE_TYPES.Identifier\n },\n isIdentifierWithName(\n node: TSESTree.Node,\n name: string,\n ): node is TSESTree.Identifier {\n return ASTUtils.isIdentifier(node) && node.name === name\n },\n isIdentifierWithOneOfNames<T extends Array<string>>(\n node: TSESTree.Node,\n name: T,\n ): node is TSESTree.Identifier & { name: T[number] } {\n return ASTUtils.isIdentifier(node) && name.includes(node.name)\n },\n isProperty(node: TSESTree.Node): node is TSESTree.Property {\n return node.type === AST_NODE_TYPES.Property\n },\n isObjectExpression(node: TSESTree.Node): node is TSESTree.ObjectExpression {\n return node.type === AST_NODE_TYPES.ObjectExpression\n },\n isPropertyWithIdentifierKey(\n node: TSESTree.Node,\n key: string,\n ): node is TSESTree.Property {\n return (\n ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key)\n )\n },\n findPropertyWithIdentifierKey(\n properties: Array<TSESTree.ObjectLiteralElement>,\n key: string,\n ): TSESTree.Property | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return properties.find((x) =>\n ASTUtils.isPropertyWithIdentifierKey(x, key),\n ) as TSESTree.Property | undefined\n },\n getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier> {\n const identifiers: Array<TSESTree.Identifier> = []\n\n if (ASTUtils.isIdentifier(node)) {\n identifiers.push(node)\n }\n\n if ('arguments' in node) {\n node.arguments.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('elements' in node) {\n node.elements.forEach((x) => {\n if (x !== null) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n }\n })\n }\n\n if ('properties' in node) {\n node.properties.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('expressions' in node) {\n node.expressions.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('left' in node) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.left))\n }\n\n if ('right' in node) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.right))\n }\n\n if (node.type === AST_NODE_TYPES.Property) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.value))\n }\n\n if (node.type === AST_NODE_TYPES.SpreadElement) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.MemberExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.object))\n }\n\n if (node.type === AST_NODE_TYPES.UnaryExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.ChainExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n if (node.type === AST_NODE_TYPES.TSNonNullExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.body))\n }\n\n if (node.type === AST_NODE_TYPES.FunctionExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.body))\n }\n\n if (node.type === AST_NODE_TYPES.BlockStatement) {\n identifiers.push(\n ...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat(),\n )\n }\n\n if (node.type === AST_NODE_TYPES.ReturnStatement && node.argument) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n return identifiers\n },\n isAncestorIsCallee(identifier: TSESTree.Node) {\n let previousNode = identifier\n let currentNode = identifier.parent\n\n while (currentNode !== undefined) {\n if (\n currentNode.type === AST_NODE_TYPES.CallExpression &&\n currentNode.callee === previousNode\n ) {\n return true\n }\n\n if (currentNode.type !== AST_NODE_TYPES.MemberExpression) {\n return false\n }\n\n previousNode = currentNode\n currentNode = currentNode.parent\n }\n\n return false\n },\n traverseUpOnly(\n identifier: TSESTree.Node,\n allowedNodeTypes: Array<AST_NODE_TYPES>,\n ): TSESTree.Node {\n const parent = identifier.parent\n\n if (parent !== undefined && allowedNodeTypes.includes(parent.type)) {\n return ASTUtils.traverseUpOnly(parent, allowedNodeTypes)\n }\n\n return identifier\n },\n isDeclaredInNode(params: {\n functionNode: TSESTree.Node\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { functionNode, reference, scopeManager } = params\n const scope = scopeManager.acquire(functionNode)\n\n if (scope === null) {\n return false\n }\n\n return scope.set.has(reference.identifier.name)\n },\n getExternalRefs(params: {\n scopeManager: TSESLint.Scope.ScopeManager\n sourceCode: Readonly<TSESLint.SourceCode>\n node: TSESTree.Node\n }): Array<TSESLint.Scope.Reference> {\n const { scopeManager, sourceCode, node } = params\n const scope = scopeManager.acquire(node)\n\n if (scope === null) {\n return []\n }\n\n const references = scope.references\n .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))\n .map((x) => {\n const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.Identifier,\n ])\n\n return {\n variable: x,\n node: referenceNode,\n text: sourceCode.getText(referenceNode),\n }\n })\n\n const localRefIds = new Set(\n [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])),\n )\n\n const externalRefs = references.filter(\n (x) => x.variable.resolved === null || !localRefIds.has(x.text),\n )\n\n return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable)\n },\n mapKeyNodeToText(\n node: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n ) {\n return sourceCode.getText(\n ASTUtils.traverseUpOnly(node, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.TSNonNullExpression,\n AST_NODE_TYPES.Identifier,\n ]),\n )\n },\n mapKeyNodeToBaseText(\n node: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n ) {\n return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(\n /(?:\\?(\\.)|!)/g,\n '$1',\n )\n },\n isValidReactComponentOrHookName(\n identifier: TSESTree.Identifier | null | undefined,\n ) {\n return (\n identifier !== null &&\n identifier !== undefined &&\n /^(use|[A-Z])/.test(identifier.name)\n )\n },\n getFunctionAncestor(\n sourceCode: Readonly<TSESLint.SourceCode>,\n node: TSESTree.Node,\n ) {\n for (const ancestor of sourceCode.getAncestors(node)) {\n if (\n ASTUtils.isNodeOfOneOf(ancestor, [\n AST_NODE_TYPES.FunctionDeclaration,\n AST_NODE_TYPES.FunctionExpression,\n AST_NODE_TYPES.ArrowFunctionExpression,\n ])\n ) {\n return ancestor\n }\n\n if (\n ancestor.parent?.type === AST_NODE_TYPES.VariableDeclarator &&\n ancestor.parent.id.type === AST_NODE_TYPES.Identifier &&\n ASTUtils.isNodeOfOneOf(ancestor, [\n AST_NODE_TYPES.FunctionDeclaration,\n AST_NODE_TYPES.FunctionExpression,\n AST_NODE_TYPES.ArrowFunctionExpression,\n ])\n ) {\n return ancestor\n }\n }\n\n return undefined\n },\n getReferencedExpressionByIdentifier(params: {\n node: TSESTree.Node\n context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>\n }) {\n const { node, context } = params\n\n // we need the fallbacks for backwards compat with eslint < 8.37.0\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const sourceCode = context.sourceCode ?? context.getSourceCode()\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const scope = context.sourceCode.getScope(node)\n ? sourceCode.getScope(node)\n : context.getScope()\n\n const resolvedNode = scope.references.find((ref) => ref.identifier === node)\n ?.resolved?.defs[0]?.node\n\n if (resolvedNode?.type !== AST_NODE_TYPES.VariableDeclarator) {\n return null\n }\n\n return resolvedNode.init\n },\n getClosestVariableDeclarator(node: TSESTree.Node) {\n let currentNode: TSESTree.Node | undefined = node\n\n while (currentNode.type !== AST_NODE_TYPES.Program) {\n if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {\n return currentNode\n }\n\n currentNode = currentNode.parent\n }\n\n return undefined\n },\n getNestedReturnStatements(\n node: TSESTree.Node,\n ): Array<TSESTree.ReturnStatement> {\n const returnStatements: Array<TSESTree.ReturnStatement> = []\n\n if (node.type === AST_NODE_TYPES.ReturnStatement) {\n returnStatements.push(node)\n }\n\n if ('body' in node && node.body !== undefined && node.body !== null) {\n Array.isArray(node.body)\n ? node.body.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.body),\n )\n }\n\n if ('consequent' in node) {\n Array.isArray(node.consequent)\n ? node.consequent.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.consequent),\n )\n }\n\n if ('alternate' in node && node.alternate !== null) {\n Array.isArray(node.alternate)\n ? node.alternate.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.alternate),\n )\n }\n\n if ('cases' in node) {\n node.cases.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n }\n\n if ('block' in node) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block))\n }\n\n if ('handler' in node && node.handler !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler))\n }\n\n if ('finalizer' in node && node.finalizer !== null) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.finalizer),\n )\n }\n\n if (\n 'expression' in node &&\n node.expression !== true &&\n node.expression !== false\n ) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.expression),\n )\n }\n\n if ('test' in node && node.test !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test))\n }\n\n return returnStatements\n },\n}\n"],"names":["AST_NODE_TYPES","uniqueBy"],"mappings":";;;;AAIO,MAAM,WAAW;AAAA,EACtB,cACE,MACA,OACqC;AAC9B,WAAA,MAAM,SAAS,KAAK,IAAS;AAAA,EACtC;AAAA,EACA,aAAa,MAAkD;AACtD,WAAA,KAAK,SAASA,MAAAA,eAAe;AAAA,EACtC;AAAA,EACA,qBACE,MACA,MAC6B;AAC7B,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS;AAAA,EACtD;AAAA,EACA,2BACE,MACA,MACmD;AACnD,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS,KAAK,IAAI;AAAA,EAC/D;AAAA,EACA,WAAW,MAAgD;AAClD,WAAA,KAAK,SAASA,MAAAA,eAAe;AAAA,EACtC;AAAA,EACA,mBAAmB,MAAwD;AAClE,WAAA,KAAK,SAASA,MAAAA,eAAe;AAAA,EACtC;AAAA,EACA,4BACE,MACA,KAC2B;AAEzB,WAAA,SAAS,WAAW,IAAI,KAAK,SAAS,qBAAqB,KAAK,KAAK,GAAG;AAAA,EAE5E;AAAA,EACA,8BACE,YACA,KAC+B;AAE/B,WAAO,WAAW;AAAA,MAAK,CAAC,MACtB,SAAS,4BAA4B,GAAG,GAAG;AAAA,IAC7C;AAAA,EACF;AAAA,EACA,qBAAqB,MAAiD;AACpE,UAAM,cAA0C,CAAC;AAE7C,QAAA,SAAS,aAAa,IAAI,GAAG;AAC/B,kBAAY,KAAK,IAAI;AAAA,IAAA;AAGvB,QAAI,eAAe,MAAM;AAClB,WAAA,UAAU,QAAQ,CAAC,MAAM;AAC5B,oBAAY,KAAK,GAAG,SAAS,qBAAqB,CAAC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AiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,KAAK,CAAC;AAAA,IAAA;AAGzE,QAAI,aAAa,QAAQ,KAAK,YAAY,MAAM;AAC9C,uBAAiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,OAAO,CAAC;AAAA,IAAA;AAG3E,QAAI,eAAe,QAAQ,KAAK,cAAc,MAAM;AACjC,uBAAA;AAAA,QACf,GAAG,SAAS,0BAA0B,KAAK,SAAS;AAAA,MACtD;AAAA,IAAA;AAGF,QACE,gBAAgB,QAChB,KAAK,eAAe,QACpB,KAAK,eAAe,OACpB;AACiB,uBAAA;AAAA,QACf,GAAG,SAAS,0BAA0B,KAAK,UAAU;AAAA,MACvD;AAAA,IAAA;AAGF,QAAI,UAAU,QAAQ,KAAK,SAAS,MAAM;AACxC,uBAAiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,IAAI,CAAC;AAAA,IAAA;AAGjE,WAAA;AAAA,EAAA;AAEX;;"}
@@ -1,38 +0,0 @@
1
- import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils';
2
- export declare const ASTUtils: {
3
- isNodeOfOneOf<T extends AST_NODE_TYPES>(node: TSESTree.Node, types: ReadonlyArray<T>): node is TSESTree.Node & {
4
- type: T;
5
- };
6
- isIdentifier(node: TSESTree.Node): node is TSESTree.Identifier;
7
- isIdentifierWithName(node: TSESTree.Node, name: string): node is TSESTree.Identifier;
8
- isIdentifierWithOneOfNames<T extends Array<string>>(node: TSESTree.Node, name: T): node is TSESTree.Identifier & {
9
- name: T[number];
10
- };
11
- isProperty(node: TSESTree.Node): node is TSESTree.Property;
12
- isObjectExpression(node: TSESTree.Node): node is TSESTree.ObjectExpression;
13
- isPropertyWithIdentifierKey(node: TSESTree.Node, key: string): node is TSESTree.Property;
14
- findPropertyWithIdentifierKey(properties: Array<TSESTree.ObjectLiteralElement>, key: string): TSESTree.Property | undefined;
15
- getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier>;
16
- isAncestorIsCallee(identifier: TSESTree.Node): boolean;
17
- traverseUpOnly(identifier: TSESTree.Node, allowedNodeTypes: Array<AST_NODE_TYPES>): TSESTree.Node;
18
- isDeclaredInNode(params: {
19
- functionNode: TSESTree.Node;
20
- reference: TSESLint.Scope.Reference;
21
- scopeManager: TSESLint.Scope.ScopeManager;
22
- }): boolean;
23
- getExternalRefs(params: {
24
- scopeManager: TSESLint.Scope.ScopeManager;
25
- sourceCode: Readonly<TSESLint.SourceCode>;
26
- node: TSESTree.Node;
27
- }): Array<TSESLint.Scope.Reference>;
28
- mapKeyNodeToText(node: TSESTree.Node, sourceCode: Readonly<TSESLint.SourceCode>): string;
29
- mapKeyNodeToBaseText(node: TSESTree.Node, sourceCode: Readonly<TSESLint.SourceCode>): string;
30
- isValidReactComponentOrHookName(identifier: TSESTree.Identifier | null | undefined): boolean;
31
- getFunctionAncestor(sourceCode: Readonly<TSESLint.SourceCode>, node: TSESTree.Node): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
32
- getReferencedExpressionByIdentifier(params: {
33
- node: TSESTree.Node;
34
- context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>;
35
- }): TSESTree.Expression | null;
36
- getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.VariableDeclaratorDefiniteAssignment | TSESTree.VariableDeclaratorMaybeInit | undefined;
37
- getNestedReturnStatements(node: TSESTree.Node): Array<TSESTree.ReturnStatement>;
38
- };
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utils = require("@typescript-eslint/utils");
4
- function detectTanstackQueryImports(create) {
5
- return (context, optionsWithDefault) => {
6
- const tanstackQueryImportSpecifiers = [];
7
- const helpers = {
8
- isSpecificTanstackQueryImport(node, source) {
9
- return !!tanstackQueryImportSpecifiers.find((specifier) => {
10
- if (specifier.type === utils.TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === utils.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
11
- return node.name === specifier.local.name;
12
- }
13
- return false;
14
- });
15
- },
16
- isTanstackQueryImport(node) {
17
- return !!tanstackQueryImportSpecifiers.find((specifier) => {
18
- if (specifier.type === utils.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
19
- return node.name === specifier.local.name;
20
- }
21
- return false;
22
- });
23
- }
24
- };
25
- const detectionInstructions = {
26
- ImportDeclaration(node) {
27
- if (node.specifiers.length > 0 && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
28
- (node.importKind === "value" || node.importKind === void 0) && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
29
- tanstackQueryImportSpecifiers.push(...node.specifiers);
30
- }
31
- }
32
- };
33
- const ruleInstructions = create(context, optionsWithDefault, helpers);
34
- const enhancedRuleInstructions = {};
35
- const allKeys = new Set(
36
- Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
37
- );
38
- allKeys.forEach((instruction) => {
39
- enhancedRuleInstructions[instruction] = (node) => {
40
- var _a;
41
- if (instruction in detectionInstructions) {
42
- (_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, node);
43
- }
44
- const ruleInstruction = ruleInstructions[instruction];
45
- if (ruleInstruction) {
46
- return ruleInstruction(node);
47
- }
48
- return void 0;
49
- };
50
- });
51
- return enhancedRuleInstructions;
52
- };
53
- }
54
- exports.detectTanstackQueryImports = detectTanstackQueryImports;
55
- //# sourceMappingURL=detect-react-query-imports.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"detect-react-query-imports.cjs","sources":["../../../src/utils/detect-react-query-imports.ts"],"sourcesContent":["import { TSESTree } from '@typescript-eslint/utils'\nimport type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\ntype Create = Parameters<\n ReturnType<typeof ESLintUtils.RuleCreator>\n>[0]['create']\n\ntype Context = Parameters<Create>[0]\ntype Options = Parameters<Create>[1]\ntype Helpers = {\n isSpecificTanstackQueryImport: (\n node: TSESTree.Identifier,\n source: string,\n ) => boolean\n isTanstackQueryImport: (node: TSESTree.Identifier) => boolean\n}\n\ntype EnhancedCreate = (\n context: Context,\n options: Options,\n helpers: Helpers,\n) => ReturnType<Create>\n\nexport function detectTanstackQueryImports(create: EnhancedCreate): Create {\n return (context, optionsWithDefault) => {\n const tanstackQueryImportSpecifiers: Array<TSESTree.ImportClause> = []\n\n const helpers: Helpers = {\n isSpecificTanstackQueryImport(node, source) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (\n specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&\n specifier.parent.type ===\n TSESTree.AST_NODE_TYPES.ImportDeclaration &&\n specifier.parent.source.value === source\n ) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n isTanstackQueryImport(node) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n }\n\n const detectionInstructions: TSESLint.RuleListener = {\n ImportDeclaration(node) {\n if (\n node.specifiers.length > 0 &&\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n (node.importKind === 'value' || node.importKind === undefined) &&\n node.source.value.startsWith('@tanstack/') &&\n node.source.value.endsWith('-query')\n ) {\n tanstackQueryImportSpecifiers.push(...node.specifiers)\n }\n },\n }\n\n // Call original rule definition\n const ruleInstructions = create(context, optionsWithDefault, helpers)\n const enhancedRuleInstructions: TSESLint.RuleListener = {}\n\n const allKeys = new Set(\n Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions)),\n )\n\n // Iterate over ALL instructions keys so we can override original rule instructions\n // to prevent their execution if conditions to report errors are not met.\n allKeys.forEach((instruction) => {\n enhancedRuleInstructions[instruction] = (node) => {\n if (instruction in detectionInstructions) {\n detectionInstructions[instruction]?.(node)\n }\n\n const ruleInstruction = ruleInstructions[instruction]\n\n // TODO: canReportErrors()\n if (ruleInstruction) {\n return ruleInstruction(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"names":["TSESTree"],"mappings":";;;AAuBO,SAAS,2BAA2B,QAAgC;AAClE,SAAA,CAAC,SAAS,uBAAuB;AACtC,UAAM,gCAA8D,CAAC;AAErE,UAAM,UAAmB;AAAA,MACvB,8BAA8B,MAAM,QAAQ;AAC1C,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cACE,UAAU,SAASA,MAAS,SAAA,eAAe,mBAC3C,UAAU,OAAO,SACfA,MAAAA,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,QAClC;AACO,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UAAA;AAGhC,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,MACA,sBAAsB,MAAM;AAC1B,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cAAI,UAAU,SAASA,eAAS,eAAe,iBAAiB;AACvD,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UAAA;AAGhC,iBAAA;AAAA,QAAA,CACR;AAAA,MAAA;AAAA,IAEL;AAEA,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AAEpB,YAAA,KAAK,WAAW,SAAS;AAAA,SAExB,KAAK,eAAe,WAAW,KAAK,eAAe,WACpD,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,QAAQ,GACnC;AAC8B,wCAAA,KAAK,GAAG,KAAK,UAAU;AAAA,QAAA;AAAA,MACvD;AAAA,IAEJ;AAGA,UAAM,mBAAmB,OAAO,SAAS,oBAAoB,OAAO;AACpE,UAAM,2BAAkD,CAAC;AAEzD,UAAM,UAAU,IAAI;AAAA,MAClB,OAAO,KAAK,qBAAqB,EAAE,OAAO,OAAO,KAAK,gBAAgB,CAAC;AAAA,IACzE;AAIQ,YAAA,QAAQ,CAAC,gBAAgB;AACN,+BAAA,WAAW,IAAI,CAAC,SAAS;;AAChD,YAAI,eAAe,uBAAuB;AAClB,sCAAA,iBAAA,+CAAe;AAAA,QAAI;AAGrC,cAAA,kBAAkB,iBAAiB,WAAW;AAGpD,YAAI,iBAAiB;AACnB,iBAAO,gBAAgB,IAAI;AAAA,QAAA;AAGtB,eAAA;AAAA,MACT;AAAA,IAAA,CACD;AAEM,WAAA;AAAA,EACT;AACF;;"}
@@ -1,11 +0,0 @@
1
- import { TSESTree, ESLintUtils } from '@typescript-eslint/utils';
2
- type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
3
- type Context = Parameters<Create>[0];
4
- type Options = Parameters<Create>[1];
5
- type Helpers = {
6
- isSpecificTanstackQueryImport: (node: TSESTree.Identifier, source: string) => boolean;
7
- isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
8
- };
9
- type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
10
- export declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
11
- export {};
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
4
- exports.getDocsUrl = getDocsUrl;
5
- //# sourceMappingURL=get-docs-url.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-docs-url.cjs","sources":["../../../src/utils/get-docs-url.ts"],"sourcesContent":["export const getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/latest/docs/eslint/${ruleName}`\n"],"names":[],"mappings":";;AAAO,MAAM,aAAa,CAAC,aACzB,iDAAiD,QAAQ;;"}
@@ -1 +0,0 @@
1
- export declare const getDocsUrl: (ruleName: string) => string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- function uniqueBy(arr, fn) {
4
- return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
5
- }
6
- exports.uniqueBy = uniqueBy;
7
- //# sourceMappingURL=unique-by.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unique-by.cjs","sources":["../../../src/utils/unique-by.ts"],"sourcesContent":["export function uniqueBy<T>(arr: Array<T>, fn: (x: T) => unknown): Array<T> {\n return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i)\n}\n"],"names":[],"mappings":";;AAAgB,SAAA,SAAY,KAAe,IAAiC;AAC1E,SAAO,IAAI,OAAO,CAAC,GAAG,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC1E;;"}
@@ -1 +0,0 @@
1
- export declare function uniqueBy<T>(arr: Array<T>, fn: (x: T) => unknown): Array<T>;
@@ -1,13 +0,0 @@
1
- import { rules } from './rules.js';
2
- import { ESLint, Linter } from 'eslint';
3
- import { RuleModule } from '@typescript-eslint/utils/ts-eslint';
4
- type RuleKey = keyof typeof rules;
5
- export interface Plugin extends Omit<ESLint.Plugin, 'rules'> {
6
- rules: Record<RuleKey, RuleModule<any, any, any>>;
7
- configs: {
8
- recommended: ESLint.ConfigData;
9
- 'flat/recommended': Array<Linter.Config>;
10
- };
11
- }
12
- declare const plugin: Plugin;
13
- export default plugin;
package/dist/esm/index.js DELETED
@@ -1,39 +0,0 @@
1
- import { rules } from "./rules.js";
2
- const plugin = {
3
- meta: {
4
- name: "@tanstack/eslint-plugin-query"
5
- },
6
- configs: {},
7
- rules
8
- };
9
- Object.assign(plugin.configs, {
10
- recommended: {
11
- plugins: ["@tanstack/query"],
12
- rules: {
13
- "@tanstack/query/exhaustive-deps": "error",
14
- "@tanstack/query/no-rest-destructuring": "warn",
15
- "@tanstack/query/stable-query-client": "error",
16
- "@tanstack/query/no-unstable-deps": "error",
17
- "@tanstack/query/infinite-query-property-order": "error"
18
- }
19
- },
20
- "flat/recommended": [
21
- {
22
- name: "tanstack/query/flat/recommended",
23
- plugins: {
24
- "@tanstack/query": plugin
25
- },
26
- rules: {
27
- "@tanstack/query/exhaustive-deps": "error",
28
- "@tanstack/query/no-rest-destructuring": "warn",
29
- "@tanstack/query/stable-query-client": "error",
30
- "@tanstack/query/no-unstable-deps": "error",
31
- "@tanstack/query/infinite-query-property-order": "error"
32
- }
33
- }
34
- ]
35
- });
36
- export {
37
- plugin as default
38
- };
39
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { rules } from './rules'\nimport type { ESLint, Linter } from 'eslint'\nimport type { RuleModule } from '@typescript-eslint/utils/ts-eslint'\n\ntype RuleKey = keyof typeof rules\n\nexport interface Plugin extends Omit<ESLint.Plugin, 'rules'> {\n rules: Record<RuleKey, RuleModule<any, any, any>>\n configs: {\n recommended: ESLint.ConfigData\n 'flat/recommended': Array<Linter.Config>\n }\n}\n\nconst plugin: Plugin = {\n meta: {\n name: '@tanstack/eslint-plugin-query',\n },\n configs: {} as Plugin['configs'],\n rules,\n}\n\n// Assign configs here so we can reference `plugin`\nObject.assign(plugin.configs, {\n recommended: {\n plugins: ['@tanstack/query'],\n rules: {\n '@tanstack/query/exhaustive-deps': 'error',\n '@tanstack/query/no-rest-destructuring': 'warn',\n '@tanstack/query/stable-query-client': 'error',\n '@tanstack/query/no-unstable-deps': 'error',\n '@tanstack/query/infinite-query-property-order': 'error',\n },\n },\n 'flat/recommended': [\n {\n name: 'tanstack/query/flat/recommended',\n plugins: {\n '@tanstack/query': plugin,\n },\n rules: {\n '@tanstack/query/exhaustive-deps': 'error',\n '@tanstack/query/no-rest-destructuring': 'warn',\n '@tanstack/query/stable-query-client': 'error',\n '@tanstack/query/no-unstable-deps': 'error',\n '@tanstack/query/infinite-query-property-order': 'error',\n },\n },\n ],\n})\n\nexport default plugin\n"],"names":[],"mappings":";AAcA,MAAM,SAAiB;AAAA,EACrB,MAAM;AAAA,IACJ,MAAM;AAAA,EACR;AAAA,EACA,SAAS,CAAC;AAAA,EACV;AACF;AAGA,OAAO,OAAO,OAAO,SAAS;AAAA,EAC5B,aAAa;AAAA,IACX,SAAS,CAAC,iBAAiB;AAAA,IAC3B,OAAO;AAAA,MACL,mCAAmC;AAAA,MACnC,yCAAyC;AAAA,MACzC,uCAAuC;AAAA,MACvC,oCAAoC;AAAA,MACpC,iDAAiD;AAAA,IAAA;AAAA,EAErD;AAAA,EACA,oBAAoB;AAAA,IAClB;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,QACP,mBAAmB;AAAA,MACrB;AAAA,MACA,OAAO;AAAA,QACL,mCAAmC;AAAA,QACnC,yCAAyC;AAAA,QACzC,uCAAuC;AAAA,QACvC,oCAAoC;AAAA,QACpC,iDAAiD;AAAA,MAAA;AAAA,IACnD;AAAA,EACF;AAEJ,CAAC;"}
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- import { ExtraRuleDocs } from '../../types';
3
- export declare const name = "exhaustive-deps";
4
- export declare const rule: ESLintUtils.RuleModule<string, readonly unknown[], ExtraRuleDocs, ESLintUtils.RuleListener>;
@@ -1,134 +0,0 @@
1
- import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
2
- import { ASTUtils } from "../../utils/ast-utils.js";
3
- import { getDocsUrl } from "../../utils/get-docs-url.js";
4
- import { uniqueBy } from "../../utils/unique-by.js";
5
- import { detectTanstackQueryImports } from "../../utils/detect-react-query-imports.js";
6
- import { ExhaustiveDepsUtils } from "./exhaustive-deps.utils.js";
7
- const QUERY_KEY = "queryKey";
8
- const QUERY_FN = "queryFn";
9
- const name = "exhaustive-deps";
10
- const createRule = ESLintUtils.RuleCreator(getDocsUrl);
11
- const rule = createRule({
12
- name,
13
- meta: {
14
- type: "problem",
15
- docs: {
16
- description: "Exhaustive deps rule for useQuery",
17
- recommended: "error"
18
- },
19
- messages: {
20
- missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
21
- fixTo: "Fix to {{result}}"
22
- },
23
- hasSuggestions: true,
24
- fixable: "code",
25
- schema: []
26
- },
27
- defaultOptions: [],
28
- create: detectTanstackQueryImports((context) => {
29
- return {
30
- Property: (node) => {
31
- if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
32
- return;
33
- }
34
- const scopeManager = context.sourceCode.scopeManager;
35
- const queryKey = ASTUtils.findPropertyWithIdentifierKey(
36
- node.parent.properties,
37
- QUERY_KEY
38
- );
39
- const queryFn = ASTUtils.findPropertyWithIdentifierKey(
40
- node.parent.properties,
41
- QUERY_FN
42
- );
43
- if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || !ASTUtils.isNodeOfOneOf(queryFn.value, [
44
- AST_NODE_TYPES.ArrowFunctionExpression,
45
- AST_NODE_TYPES.FunctionExpression,
46
- AST_NODE_TYPES.ConditionalExpression
47
- ])) {
48
- return;
49
- }
50
- let queryKeyNode = queryKey.value;
51
- if (queryKeyNode.type === AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression) {
52
- queryKeyNode = queryKeyNode.expression;
53
- }
54
- if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {
55
- const expression = ASTUtils.getReferencedExpressionByIdentifier({
56
- context,
57
- node: queryKeyNode
58
- });
59
- if ((expression == null ? void 0 : expression.type) === AST_NODE_TYPES.ArrayExpression) {
60
- queryKeyNode = expression;
61
- }
62
- }
63
- const externalRefs = ASTUtils.getExternalRefs({
64
- scopeManager,
65
- sourceCode: context.sourceCode,
66
- node: getQueryFnRelevantNode(queryFn)
67
- });
68
- const relevantRefs = externalRefs.filter(
69
- (reference) => ExhaustiveDepsUtils.isRelevantReference({
70
- sourceCode: context.sourceCode,
71
- reference,
72
- scopeManager,
73
- node: getQueryFnRelevantNode(queryFn)
74
- })
75
- );
76
- const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyNode).map(
77
- (identifier) => ASTUtils.mapKeyNodeToBaseText(identifier, context.sourceCode)
78
- );
79
- const missingRefs = relevantRefs.map((ref) => ({
80
- ref,
81
- text: ASTUtils.mapKeyNodeToBaseText(
82
- ref.identifier,
83
- context.sourceCode
84
- )
85
- })).filter(({ ref, text }) => {
86
- return !ref.isTypeReference && !ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(/[?.]/)[0] ?? "");
87
- }).map(({ ref, text }) => ({
88
- identifier: ref.identifier,
89
- text
90
- }));
91
- const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text);
92
- if (uniqueMissingRefs.length > 0) {
93
- const missingAsText = uniqueMissingRefs.map(
94
- (ref) => ASTUtils.mapKeyNodeToText(ref.identifier, context.sourceCode)
95
- ).join(", ");
96
- const queryKeyValue = context.sourceCode.getText(queryKeyNode);
97
- const existingWithMissing = queryKeyValue === "[]" ? `[${missingAsText}]` : queryKeyValue.replace(/\]$/, `, ${missingAsText}]`);
98
- const suggestions = [];
99
- if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {
100
- suggestions.push({
101
- messageId: "fixTo",
102
- data: { result: existingWithMissing },
103
- fix(fixer) {
104
- return fixer.replaceText(queryKeyNode, existingWithMissing);
105
- }
106
- });
107
- }
108
- context.report({
109
- node,
110
- messageId: "missingDeps",
111
- data: {
112
- deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
113
- },
114
- suggest: suggestions
115
- });
116
- }
117
- }
118
- };
119
- })
120
- });
121
- function getQueryFnRelevantNode(queryFn) {
122
- if (queryFn.value.type !== AST_NODE_TYPES.ConditionalExpression) {
123
- return queryFn.value;
124
- }
125
- if (queryFn.value.consequent.type === AST_NODE_TYPES.Identifier && queryFn.value.consequent.name === "skipToken") {
126
- return queryFn.value.alternate;
127
- }
128
- return queryFn.value.consequent;
129
- }
130
- export {
131
- name,
132
- rule
133
- };
134
- //# sourceMappingURL=exhaustive-deps.rule.js.map