@tanstack/eslint-plugin-query 5.0.0-beta.0 → 5.0.0-beta.5
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.
- package/build/legacy/configs/index.cjs +46 -0
- package/build/legacy/configs/index.cjs.map +1 -0
- package/build/legacy/configs/index.d.cts +8 -0
- package/build/legacy/configs/index.d.ts +8 -0
- package/build/legacy/configs/index.js +21 -0
- package/build/legacy/configs/index.js.map +1 -0
- package/build/legacy/configs/index.test.cjs +21 -0
- package/build/legacy/configs/index.test.cjs.map +1 -0
- package/build/legacy/configs/index.test.d.cts +2 -0
- package/build/legacy/configs/index.test.d.ts +2 -0
- package/build/legacy/configs/index.test.js +19 -0
- package/build/legacy/configs/index.test.js.map +1 -0
- package/build/legacy/index.d.cts +3 -14
- package/build/legacy/index.d.ts +3 -14
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.cjs +141 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.cjs.map +1 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.d.cts +6 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.d.ts +6 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.js +115 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.js.map +1 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.cjs +722 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.cjs.map +1 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.d.cts +2 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.d.ts +2 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.js +720 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.js.map +1 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.cjs +52 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.cjs.map +1 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.d.cts +12 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.d.ts +12 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.js +27 -0
- package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.js.map +1 -0
- package/build/legacy/rules/index.cjs +44 -0
- package/build/legacy/rules/index.cjs.map +1 -0
- package/build/legacy/rules/index.d.cts +7 -0
- package/build/legacy/rules/index.d.ts +7 -0
- package/build/legacy/rules/index.js +9 -0
- package/build/legacy/rules/index.js.map +1 -0
- package/build/legacy/utils/ast-utils.cjs +247 -0
- package/build/legacy/utils/ast-utils.cjs.map +1 -0
- package/build/legacy/utils/ast-utils.d.cts +41 -0
- package/build/legacy/utils/ast-utils.d.ts +41 -0
- package/build/legacy/utils/ast-utils.js +222 -0
- package/build/legacy/utils/ast-utils.js.map +1 -0
- package/build/legacy/utils/create-rule.cjs +39 -0
- package/build/legacy/utils/create-rule.cjs.map +1 -0
- package/build/legacy/utils/create-rule.d.cts +10 -0
- package/build/legacy/utils/create-rule.d.ts +10 -0
- package/build/legacy/utils/create-rule.js +14 -0
- package/build/legacy/utils/create-rule.js.map +1 -0
- package/build/legacy/utils/detect-react-query-imports.cjs +70 -0
- package/build/legacy/utils/detect-react-query-imports.cjs.map +1 -0
- package/build/legacy/utils/detect-react-query-imports.d.cts +12 -0
- package/build/legacy/utils/detect-react-query-imports.d.ts +12 -0
- package/build/legacy/utils/detect-react-query-imports.js +45 -0
- package/build/legacy/utils/detect-react-query-imports.js.map +1 -0
- package/build/legacy/utils/object-utils.cjs +33 -0
- package/build/legacy/utils/object-utils.cjs.map +1 -0
- package/build/legacy/utils/object-utils.d.cts +3 -0
- package/build/legacy/utils/object-utils.d.ts +3 -0
- package/build/legacy/utils/object-utils.js +8 -0
- package/build/legacy/utils/object-utils.js.map +1 -0
- package/build/legacy/utils/test-utils.cjs +36 -0
- package/build/legacy/utils/test-utils.cjs.map +1 -0
- package/build/legacy/utils/test-utils.d.cts +3 -0
- package/build/legacy/utils/test-utils.d.ts +3 -0
- package/build/legacy/utils/test-utils.js +11 -0
- package/build/legacy/utils/test-utils.js.map +1 -0
- package/build/legacy/utils/unique-by.cjs +33 -0
- package/build/legacy/utils/unique-by.cjs.map +1 -0
- package/build/legacy/utils/unique-by.d.cts +3 -0
- package/build/legacy/utils/unique-by.d.ts +3 -0
- package/build/legacy/utils/unique-by.js +8 -0
- package/build/legacy/utils/unique-by.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// src/utils/ast-utils.ts
|
|
2
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
3
|
+
import { uniqueBy } from "./unique-by.js";
|
|
4
|
+
var ASTUtils = {
|
|
5
|
+
isNodeOfOneOf(node, types) {
|
|
6
|
+
return types.includes(node.type);
|
|
7
|
+
},
|
|
8
|
+
isIdentifier(node) {
|
|
9
|
+
return node.type === AST_NODE_TYPES.Identifier;
|
|
10
|
+
},
|
|
11
|
+
isIdentifierWithName(node, name) {
|
|
12
|
+
return ASTUtils.isIdentifier(node) && node.name === name;
|
|
13
|
+
},
|
|
14
|
+
isIdentifierWithOneOfNames(node, name) {
|
|
15
|
+
return ASTUtils.isIdentifier(node) && name.includes(node.name);
|
|
16
|
+
},
|
|
17
|
+
isProperty(node) {
|
|
18
|
+
return node.type === AST_NODE_TYPES.Property;
|
|
19
|
+
},
|
|
20
|
+
isObjectExpression(node) {
|
|
21
|
+
return node.type === AST_NODE_TYPES.ObjectExpression;
|
|
22
|
+
},
|
|
23
|
+
isPropertyWithIdentifierKey(node, key) {
|
|
24
|
+
return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
|
|
25
|
+
},
|
|
26
|
+
findPropertyWithIdentifierKey(properties, key) {
|
|
27
|
+
return properties.find(
|
|
28
|
+
(x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
getNestedIdentifiers(node) {
|
|
32
|
+
const identifiers = [];
|
|
33
|
+
if (ASTUtils.isIdentifier(node)) {
|
|
34
|
+
identifiers.push(node);
|
|
35
|
+
}
|
|
36
|
+
if ("arguments" in node) {
|
|
37
|
+
node.arguments.forEach((x) => {
|
|
38
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if ("elements" in node) {
|
|
42
|
+
node.elements.forEach((x) => {
|
|
43
|
+
if (x !== null) {
|
|
44
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if ("properties" in node) {
|
|
49
|
+
node.properties.forEach((x) => {
|
|
50
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if ("expressions" in node) {
|
|
54
|
+
node.expressions.forEach((x) => {
|
|
55
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
59
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
|
|
60
|
+
}
|
|
61
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
62
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
|
|
63
|
+
}
|
|
64
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
65
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
|
|
66
|
+
}
|
|
67
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
68
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
|
|
69
|
+
}
|
|
70
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
71
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
|
|
72
|
+
}
|
|
73
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
74
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
|
|
75
|
+
}
|
|
76
|
+
return identifiers;
|
|
77
|
+
},
|
|
78
|
+
isAncestorIsCallee(identifier) {
|
|
79
|
+
let previousNode = identifier;
|
|
80
|
+
let currentNode = identifier.parent;
|
|
81
|
+
while (currentNode !== void 0) {
|
|
82
|
+
if (currentNode.type === AST_NODE_TYPES.CallExpression && currentNode.callee === previousNode) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (currentNode.type !== AST_NODE_TYPES.MemberExpression) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
previousNode = currentNode;
|
|
89
|
+
currentNode = currentNode.parent;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
},
|
|
93
|
+
traverseUpOnly(identifier, allowedNodeTypes) {
|
|
94
|
+
const parent = identifier.parent;
|
|
95
|
+
if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
|
|
96
|
+
return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
|
|
97
|
+
}
|
|
98
|
+
return identifier;
|
|
99
|
+
},
|
|
100
|
+
isDeclaredInNode(params) {
|
|
101
|
+
const { functionNode, reference, scopeManager } = params;
|
|
102
|
+
const scope = scopeManager.acquire(functionNode);
|
|
103
|
+
if (scope === null) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return scope.set.has(reference.identifier.name);
|
|
107
|
+
},
|
|
108
|
+
getExternalRefs(params) {
|
|
109
|
+
const { scopeManager, sourceCode, node } = params;
|
|
110
|
+
const scope = scopeManager.acquire(node);
|
|
111
|
+
if (scope === null) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
const references = scope.references.filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
|
|
115
|
+
const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
|
|
116
|
+
AST_NODE_TYPES.MemberExpression,
|
|
117
|
+
AST_NODE_TYPES.Identifier
|
|
118
|
+
]);
|
|
119
|
+
return {
|
|
120
|
+
variable: x,
|
|
121
|
+
node: referenceNode,
|
|
122
|
+
text: sourceCode.getText(referenceNode)
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const localRefIds = new Set(
|
|
126
|
+
[...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
|
|
127
|
+
);
|
|
128
|
+
const externalRefs = references.filter(
|
|
129
|
+
(x) => x.variable.resolved === null || !localRefIds.has(x.text)
|
|
130
|
+
);
|
|
131
|
+
return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
|
|
132
|
+
},
|
|
133
|
+
mapKeyNodeToText(node, sourceCode) {
|
|
134
|
+
return sourceCode.getText(
|
|
135
|
+
ASTUtils.traverseUpOnly(node, [
|
|
136
|
+
AST_NODE_TYPES.MemberExpression,
|
|
137
|
+
AST_NODE_TYPES.Identifier
|
|
138
|
+
])
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
isValidReactComponentOrHookName(identifier) {
|
|
142
|
+
return identifier !== null && /^(use|[A-Z])/.test(identifier.name);
|
|
143
|
+
},
|
|
144
|
+
getFunctionAncestor(context) {
|
|
145
|
+
return context.getAncestors().find((x) => {
|
|
146
|
+
var _a;
|
|
147
|
+
if (x.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return ((_a = x.parent) == null ? void 0 : _a.type) === AST_NODE_TYPES.VariableDeclarator && x.parent.id.type === AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(x, [
|
|
151
|
+
AST_NODE_TYPES.FunctionDeclaration,
|
|
152
|
+
AST_NODE_TYPES.FunctionExpression,
|
|
153
|
+
AST_NODE_TYPES.ArrowFunctionExpression
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
getReferencedExpressionByIdentifier(params) {
|
|
158
|
+
var _a, _b, _c;
|
|
159
|
+
const { node, context } = params;
|
|
160
|
+
const resolvedNode = (_c = (_b = (_a = context.getScope().references.find((ref) => ref.identifier === node)) == null ? void 0 : _a.resolved) == null ? void 0 : _b.defs[0]) == null ? void 0 : _c.node;
|
|
161
|
+
if ((resolvedNode == null ? void 0 : resolvedNode.type) !== AST_NODE_TYPES.VariableDeclarator) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return resolvedNode.init;
|
|
165
|
+
},
|
|
166
|
+
getNestedReturnStatements(node) {
|
|
167
|
+
const returnStatements = [];
|
|
168
|
+
if (node.type === AST_NODE_TYPES.ReturnStatement) {
|
|
169
|
+
returnStatements.push(node);
|
|
170
|
+
}
|
|
171
|
+
if ("body" in node && node.body !== void 0 && node.body !== null) {
|
|
172
|
+
Array.isArray(node.body) ? node.body.forEach((x) => {
|
|
173
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
174
|
+
}) : returnStatements.push(
|
|
175
|
+
...ASTUtils.getNestedReturnStatements(node.body)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if ("consequent" in node) {
|
|
179
|
+
Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
|
|
180
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
181
|
+
}) : returnStatements.push(
|
|
182
|
+
...ASTUtils.getNestedReturnStatements(node.consequent)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if ("alternate" in node && node.alternate !== null) {
|
|
186
|
+
Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
|
|
187
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
188
|
+
}) : returnStatements.push(
|
|
189
|
+
...ASTUtils.getNestedReturnStatements(node.alternate)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
if ("cases" in node) {
|
|
193
|
+
node.cases.forEach((x) => {
|
|
194
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if ("block" in node) {
|
|
198
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
|
|
199
|
+
}
|
|
200
|
+
if ("handler" in node && node.handler !== null) {
|
|
201
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
|
|
202
|
+
}
|
|
203
|
+
if ("finalizer" in node && node.finalizer !== null) {
|
|
204
|
+
returnStatements.push(
|
|
205
|
+
...ASTUtils.getNestedReturnStatements(node.finalizer)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
209
|
+
returnStatements.push(
|
|
210
|
+
...ASTUtils.getNestedReturnStatements(node.expression)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if ("test" in node && node.test !== null) {
|
|
214
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
|
|
215
|
+
}
|
|
216
|
+
return returnStatements;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
export {
|
|
220
|
+
ASTUtils
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=ast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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'\nimport type TSESLintScopeManager from '@typescript-eslint/scope-manager'\nimport type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'\n\nexport const ASTUtils = {\n isNodeOfOneOf<T extends AST_NODE_TYPES>(\n node: TSESTree.Node,\n types: readonly 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 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: TSESTree.ObjectLiteralElement[],\n key: string,\n ): TSESTree.Property | undefined {\n return properties.find((x) =>\n ASTUtils.isPropertyWithIdentifierKey(x, key),\n ) as TSESTree.Property | undefined\n },\n getNestedIdentifiers(node: TSESTree.Node): TSESTree.Identifier[] {\n const identifiers: 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 (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 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: 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: TSESLintScopeManager.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 }): 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.Identifier,\n ]),\n )\n },\n isValidReactComponentOrHookName(identifier: TSESTree.Identifier | null) {\n return identifier !== null && /^(use|[A-Z])/.test(identifier.name)\n },\n getFunctionAncestor(\n context: Readonly<RuleContext<string, readonly unknown[]>>,\n ) {\n return context.getAncestors().find((x) => {\n if (x.type === AST_NODE_TYPES.FunctionDeclaration) {\n return true\n }\n\n return (\n x.parent?.type === AST_NODE_TYPES.VariableDeclarator &&\n x.parent.id.type === AST_NODE_TYPES.Identifier &&\n ASTUtils.isNodeOfOneOf(x, [\n AST_NODE_TYPES.FunctionDeclaration,\n AST_NODE_TYPES.FunctionExpression,\n AST_NODE_TYPES.ArrowFunctionExpression,\n ])\n )\n })\n },\n getReferencedExpressionByIdentifier(params: {\n node: TSESTree.Node\n context: Readonly<RuleContext<string, readonly unknown[]>>\n }) {\n const { node, context } = params\n\n const resolvedNode = context\n .getScope()\n .references.find((ref) => ref.identifier === node)?.resolved\n ?.defs[0]?.node\n\n if (resolvedNode?.type !== AST_NODE_TYPES.VariableDeclarator) {\n return null\n }\n\n return resolvedNode.init\n },\n getNestedReturnStatements(node: TSESTree.Node): TSESTree.ReturnStatement[] {\n const returnStatements: 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"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AAKlB,IAAM,WAAW;AAAA,EACtB,cACE,MACA,OACqC;AACrC,WAAO,MAAM,SAAS,KAAK,IAAS;AAAA,EACtC;AAAA,EACA,aAAa,MAAkD;AAC7D,WAAO,KAAK,SAAS,eAAe;AAAA,EACtC;AAAA,EACA,qBACE,MACA,MAC6B;AAC7B,WAAO,SA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getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], 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/utils/create-rule.ts
|
|
21
|
+
var create_rule_exports = {};
|
|
22
|
+
__export(create_rule_exports, {
|
|
23
|
+
createRule: () => createRule
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(create_rule_exports);
|
|
26
|
+
var import_utils = require("@typescript-eslint/utils");
|
|
27
|
+
var import_detect_react_query_imports = require("./detect-react-query-imports.cjs");
|
|
28
|
+
var getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
|
|
29
|
+
function createRule({ create, ...rest }) {
|
|
30
|
+
return import_utils.ESLintUtils.RuleCreator(getDocsUrl)({
|
|
31
|
+
...rest,
|
|
32
|
+
create: (0, import_detect_react_query_imports.detectTanstackQueryImports)(create)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
createRule
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=create-rule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/v4/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAC5B,wCAA2C;AAG3C,IAAM,aAAa,CAAC,aAClB,6CAA6C,QAAQ;AAShD,SAAS,WAAW,EAAE,QAAQ,GAAG,KAAK,GAAe;AAC1D,SAAO,yBAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,YAAQ,8DAA2B,MAAM;AAAA,EAC3C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
|
|
2
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
3
|
+
import { EnhancedCreate } from './detect-react-query-imports.cjs';
|
|
4
|
+
|
|
5
|
+
type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
|
|
6
|
+
create: EnhancedCreate;
|
|
7
|
+
};
|
|
8
|
+
declare function createRule({ create, ...rest }: EslintRule): _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
9
|
+
|
|
10
|
+
export { createRule };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
|
|
2
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
3
|
+
import { EnhancedCreate } from './detect-react-query-imports.js';
|
|
4
|
+
|
|
5
|
+
type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
|
|
6
|
+
create: EnhancedCreate;
|
|
7
|
+
};
|
|
8
|
+
declare function createRule({ create, ...rest }: EslintRule): _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
9
|
+
|
|
10
|
+
export { createRule };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/utils/create-rule.ts
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import { detectTanstackQueryImports } from "./detect-react-query-imports.js";
|
|
4
|
+
var getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
|
|
5
|
+
function createRule({ create, ...rest }) {
|
|
6
|
+
return ESLintUtils.RuleCreator(getDocsUrl)({
|
|
7
|
+
...rest,
|
|
8
|
+
create: detectTanstackQueryImports(create)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
createRule
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=create-rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/v4/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,kCAAkC;AAG3C,IAAM,aAAa,CAAC,aAClB,6CAA6C,QAAQ;AAShD,SAAS,WAAW,EAAE,QAAQ,GAAG,KAAK,GAAe;AAC1D,SAAO,YAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,QAAQ,2BAA2B,MAAM;AAAA,EAC3C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], 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/utils/detect-react-query-imports.ts
|
|
21
|
+
var detect_react_query_imports_exports = {};
|
|
22
|
+
__export(detect_react_query_imports_exports, {
|
|
23
|
+
detectTanstackQueryImports: () => detectTanstackQueryImports
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(detect_react_query_imports_exports);
|
|
26
|
+
function detectTanstackQueryImports(create) {
|
|
27
|
+
return (context, optionsWithDefault) => {
|
|
28
|
+
const tanstackQueryImportSpecifiers = [];
|
|
29
|
+
const helpers = {
|
|
30
|
+
isTanstackQueryImport(node) {
|
|
31
|
+
return !!tanstackQueryImportSpecifiers.find((specifier) => {
|
|
32
|
+
if (specifier.type === "ImportSpecifier") {
|
|
33
|
+
return node.name === specifier.local.name;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const detectionInstructions = {
|
|
40
|
+
ImportDeclaration(node) {
|
|
41
|
+
if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
|
|
42
|
+
tanstackQueryImportSpecifiers.push(...node.specifiers);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const ruleInstructions = create(context, optionsWithDefault, helpers);
|
|
47
|
+
const enhancedRuleInstructions = {};
|
|
48
|
+
const allKeys = new Set(
|
|
49
|
+
Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
|
|
50
|
+
);
|
|
51
|
+
allKeys.forEach((instruction) => {
|
|
52
|
+
enhancedRuleInstructions[instruction] = (node) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
if (instruction in detectionInstructions) {
|
|
55
|
+
(_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, node);
|
|
56
|
+
}
|
|
57
|
+
if (ruleInstructions[instruction]) {
|
|
58
|
+
return (_b = ruleInstructions[instruction]) == null ? void 0 : _b.call(ruleInstructions, node);
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return enhancedRuleInstructions;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
detectTanstackQueryImports
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=detect-react-query-imports.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/detect-react-query-imports.ts"],"sourcesContent":["import type { ESLintUtils, TSESLint, TSESTree } 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 isTanstackQueryImport: (node: TSESTree.Identifier) => boolean\n}\n\nexport type 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: TSESTree.ImportClause[] = []\n\n const helpers: Helpers = {\n isTanstackQueryImport(node) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (specifier.type === '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 node.importKind === 'value' &&\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 // TODO: canReportErrors()\n if (ruleInstructions[instruction]) {\n return ruleInstructions[instruction]?.(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,2BAA2B,QAAgC;AACzE,SAAO,CAAC,SAAS,uBAAuB;AACtC,UAAM,gCAAyD,CAAC;AAEhE,UAAM,UAAmB;AAAA,MACvB,sBAAsB,MAAM;AAC1B,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cAAI,UAAU,SAAS,mBAAmB;AACxC,mBAAO,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS,KACzB,KAAK,eAAe,WACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,QAAQ,GACnC;AACA,wCAA8B,KAAK,GAAG,KAAK,UAAU;AAAA,QACvD;AAAA,MACF;AAAA,IACF;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;AAIA,YAAQ,QAAQ,CAAC,gBAAgB;AAC/B,+BAAyB,WAAW,IAAI,CAAC,SAAS;AA1DxD;AA2DQ,YAAI,eAAe,uBAAuB;AACxC,sCAAsB,iBAAtB,+CAAqC;AAAA,QACvC;AAGA,YAAI,iBAAiB,WAAW,GAAG;AACjC,kBAAO,sBAAiB,iBAAjB,0CAAgC;AAAA,QACzC;AAEA,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
|
|
4
|
+
type Context = Parameters<Create>[0];
|
|
5
|
+
type Options = Parameters<Create>[1];
|
|
6
|
+
type Helpers = {
|
|
7
|
+
isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
|
|
8
|
+
};
|
|
9
|
+
type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
|
|
10
|
+
declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
|
|
11
|
+
|
|
12
|
+
export { EnhancedCreate, detectTanstackQueryImports };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
|
|
4
|
+
type Context = Parameters<Create>[0];
|
|
5
|
+
type Options = Parameters<Create>[1];
|
|
6
|
+
type Helpers = {
|
|
7
|
+
isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
|
|
8
|
+
};
|
|
9
|
+
type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
|
|
10
|
+
declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
|
|
11
|
+
|
|
12
|
+
export { EnhancedCreate, detectTanstackQueryImports };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/utils/detect-react-query-imports.ts
|
|
2
|
+
function detectTanstackQueryImports(create) {
|
|
3
|
+
return (context, optionsWithDefault) => {
|
|
4
|
+
const tanstackQueryImportSpecifiers = [];
|
|
5
|
+
const helpers = {
|
|
6
|
+
isTanstackQueryImport(node) {
|
|
7
|
+
return !!tanstackQueryImportSpecifiers.find((specifier) => {
|
|
8
|
+
if (specifier.type === "ImportSpecifier") {
|
|
9
|
+
return node.name === specifier.local.name;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const detectionInstructions = {
|
|
16
|
+
ImportDeclaration(node) {
|
|
17
|
+
if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
|
|
18
|
+
tanstackQueryImportSpecifiers.push(...node.specifiers);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const ruleInstructions = create(context, optionsWithDefault, helpers);
|
|
23
|
+
const enhancedRuleInstructions = {};
|
|
24
|
+
const allKeys = new Set(
|
|
25
|
+
Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
|
|
26
|
+
);
|
|
27
|
+
allKeys.forEach((instruction) => {
|
|
28
|
+
enhancedRuleInstructions[instruction] = (node) => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (instruction in detectionInstructions) {
|
|
31
|
+
(_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, node);
|
|
32
|
+
}
|
|
33
|
+
if (ruleInstructions[instruction]) {
|
|
34
|
+
return (_b = ruleInstructions[instruction]) == null ? void 0 : _b.call(ruleInstructions, node);
|
|
35
|
+
}
|
|
36
|
+
return void 0;
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
return enhancedRuleInstructions;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
detectTanstackQueryImports
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=detect-react-query-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/detect-react-query-imports.ts"],"sourcesContent":["import type { ESLintUtils, TSESLint, TSESTree } 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 isTanstackQueryImport: (node: TSESTree.Identifier) => boolean\n}\n\nexport type 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: TSESTree.ImportClause[] = []\n\n const helpers: Helpers = {\n isTanstackQueryImport(node) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (specifier.type === '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 node.importKind === 'value' &&\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 // TODO: canReportErrors()\n if (ruleInstructions[instruction]) {\n return ruleInstructions[instruction]?.(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"mappings":";AAkBO,SAAS,2BAA2B,QAAgC;AACzE,SAAO,CAAC,SAAS,uBAAuB;AACtC,UAAM,gCAAyD,CAAC;AAEhE,UAAM,UAAmB;AAAA,MACvB,sBAAsB,MAAM;AAC1B,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cAAI,UAAU,SAAS,mBAAmB;AACxC,mBAAO,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS,KACzB,KAAK,eAAe,WACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,QAAQ,GACnC;AACA,wCAA8B,KAAK,GAAG,KAAK,UAAU;AAAA,QACvD;AAAA,MACF;AAAA,IACF;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;AAIA,YAAQ,QAAQ,CAAC,gBAAgB;AAC/B,+BAAyB,WAAW,IAAI,CAAC,SAAS;AA1DxD;AA2DQ,YAAI,eAAe,uBAAuB;AACxC,sCAAsB,iBAAtB,+CAAqC;AAAA,QACvC;AAGA,YAAI,iBAAiB,WAAW,GAAG;AACjC,kBAAO,sBAAiB,iBAAjB,0CAAgC;AAAA,QACzC;AAEA,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], 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/utils/object-utils.ts
|
|
21
|
+
var object_utils_exports = {};
|
|
22
|
+
__export(object_utils_exports, {
|
|
23
|
+
objectKeys: () => objectKeys
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(object_utils_exports);
|
|
26
|
+
function objectKeys(obj) {
|
|
27
|
+
return Object.keys(obj);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
objectKeys
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=object-utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/object-utils.ts"],"sourcesContent":["export function objectKeys<T extends Record<string, unknown>>(\n obj: T,\n): Array<keyof T> {\n return Object.keys(obj) as Array<keyof T>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,WACd,KACgB;AAChB,SAAO,OAAO,KAAK,GAAG;AACxB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/object-utils.ts"],"sourcesContent":["export function objectKeys<T extends Record<string, unknown>>(\n obj: T,\n): Array<keyof T> {\n return Object.keys(obj) as Array<keyof T>\n}\n"],"mappings":";AAAO,SAAS,WACd,KACgB;AAChB,SAAO,OAAO,KAAK,GAAG;AACxB;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], 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/utils/test-utils.ts
|
|
21
|
+
var test_utils_exports = {};
|
|
22
|
+
__export(test_utils_exports, {
|
|
23
|
+
normalizeIndent: () => normalizeIndent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(test_utils_exports);
|
|
26
|
+
function normalizeIndent(template) {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const codeLines = ((_a = template[0]) == null ? void 0 : _a.split("\n")) ?? [""];
|
|
29
|
+
const leftPadding = ((_c = (_b = codeLines[1]) == null ? void 0 : _b.match(/\s+/)) == null ? void 0 : _c[0]) ?? "";
|
|
30
|
+
return codeLines.map((line) => line.slice(leftPadding.length)).join("\n");
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
normalizeIndent
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=test-utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/test-utils.ts"],"sourcesContent":["export function normalizeIndent(template: TemplateStringsArray) {\n const codeLines = template[0]?.split('\\n') ?? ['']\n const leftPadding = codeLines[1]?.match(/\\s+/)?.[0] ?? ''\n return codeLines.map((line) => line.slice(leftPadding.length)).join('\\n')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,gBAAgB,UAAgC;AAAhE;AACE,QAAM,cAAY,cAAS,CAAC,MAAV,mBAAa,MAAM,UAAS,CAAC,EAAE;AACjD,QAAM,gBAAc,qBAAU,CAAC,MAAX,mBAAc,MAAM,WAApB,mBAA6B,OAAM;AACvD,SAAO,UAAU,IAAI,CAAC,SAAS,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,KAAK,IAAI;AAC1E;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/utils/test-utils.ts
|
|
2
|
+
function normalizeIndent(template) {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
const codeLines = ((_a = template[0]) == null ? void 0 : _a.split("\n")) ?? [""];
|
|
5
|
+
const leftPadding = ((_c = (_b = codeLines[1]) == null ? void 0 : _b.match(/\s+/)) == null ? void 0 : _c[0]) ?? "";
|
|
6
|
+
return codeLines.map((line) => line.slice(leftPadding.length)).join("\n");
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
normalizeIndent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/test-utils.ts"],"sourcesContent":["export function normalizeIndent(template: TemplateStringsArray) {\n const codeLines = template[0]?.split('\\n') ?? ['']\n const leftPadding = codeLines[1]?.match(/\\s+/)?.[0] ?? ''\n return codeLines.map((line) => line.slice(leftPadding.length)).join('\\n')\n}\n"],"mappings":";AAAO,SAAS,gBAAgB,UAAgC;AAAhE;AACE,QAAM,cAAY,cAAS,CAAC,MAAV,mBAAa,MAAM,UAAS,CAAC,EAAE;AACjD,QAAM,gBAAc,qBAAU,CAAC,MAAX,mBAAc,MAAM,WAApB,mBAA6B,OAAM;AACvD,SAAO,UAAU,IAAI,CAAC,SAAS,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,KAAK,IAAI;AAC1E;","names":[]}
|