@oncoursesystems/eslint-config 1.0.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.
- package/LICENSE +21 -0
- package/README.md +193 -0
- package/dist/build-MNP2VQ2J.js +130 -0
- package/dist/chunk-3DH23OWQ.js +98399 -0
- package/dist/chunk-UVR5GK7I.js +65 -0
- package/dist/index.cjs +132276 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1095 -0
- package/dist/jiti-AGHD3IJV.js +31362 -0
- package/dist/lib-DX5OAELA.js +158 -0
- package/dist/src-LTC4MYI6.js +1127 -0
- package/package.json +80 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1095 @@
|
|
|
1
|
+
import {
|
|
2
|
+
require_dist
|
|
3
|
+
} from "./chunk-3DH23OWQ.js";
|
|
4
|
+
import {
|
|
5
|
+
__toESM,
|
|
6
|
+
init_esm_shims
|
|
7
|
+
} from "./chunk-UVR5GK7I.js";
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
init_esm_shims();
|
|
11
|
+
import { antfu } from "@antfu/eslint-config";
|
|
12
|
+
|
|
13
|
+
// src/config.ts
|
|
14
|
+
init_esm_shims();
|
|
15
|
+
|
|
16
|
+
// src/configs/expo.ts
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
import { ensurePackages, interopDefault } from "@antfu/eslint-config";
|
|
19
|
+
async function expo() {
|
|
20
|
+
await ensurePackages(["eslint-plugin-expo"]);
|
|
21
|
+
const pluginExpo = await interopDefault(import("./build-MNP2VQ2J.js"));
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
name: "oncourse/expo/setup",
|
|
25
|
+
plugins: {
|
|
26
|
+
expo: pluginExpo
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "oncourse/expo/rules",
|
|
31
|
+
rules: {
|
|
32
|
+
"expo/no-dynamic-env-var": ["error"],
|
|
33
|
+
"expo/no-env-var-destructuring": ["error"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/configs/javascript.ts
|
|
40
|
+
init_esm_shims();
|
|
41
|
+
var sortOptions = Object.freeze({
|
|
42
|
+
ignoreCase: false,
|
|
43
|
+
partitionByNewLine: true,
|
|
44
|
+
type: "natural"
|
|
45
|
+
});
|
|
46
|
+
function javascript() {
|
|
47
|
+
return {
|
|
48
|
+
files: ["**/*.{cjs,js,mjs,ts}"],
|
|
49
|
+
rules: {
|
|
50
|
+
"perfectionist/sort-array-includes": ["error", sortOptions],
|
|
51
|
+
"perfectionist/sort-enums": ["error", sortOptions],
|
|
52
|
+
"perfectionist/sort-imports": [
|
|
53
|
+
"error",
|
|
54
|
+
{
|
|
55
|
+
environment: "node",
|
|
56
|
+
groups: [["builtin", "external"], "internal", "parent", "sibling"],
|
|
57
|
+
ignoreCase: false,
|
|
58
|
+
internalPattern: ["@/**", "~/**"],
|
|
59
|
+
type: "natural"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"perfectionist/sort-interfaces": ["error", sortOptions],
|
|
63
|
+
"perfectionist/sort-intersection-types": ["error", sortOptions],
|
|
64
|
+
"perfectionist/sort-object-types": ["error", sortOptions],
|
|
65
|
+
"perfectionist/sort-objects": ["error", sortOptions],
|
|
66
|
+
"perfectionist/sort-sets": ["error", sortOptions],
|
|
67
|
+
"perfectionist/sort-union-types": ["error", sortOptions],
|
|
68
|
+
"perfectionist/sort-variable-declarations": ["error", sortOptions]
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/configs/sencha.ts
|
|
74
|
+
init_esm_shims();
|
|
75
|
+
import { ensurePackages as ensurePackages2, interopDefault as interopDefault2 } from "@antfu/eslint-config";
|
|
76
|
+
async function sencha() {
|
|
77
|
+
await ensurePackages2(["@sencha/eslint-plugin-extjs"]);
|
|
78
|
+
const pluginSencha = await interopDefault2(import("./lib-DX5OAELA.js"));
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
name: "oncourse/sencha/setup",
|
|
82
|
+
plugins: {
|
|
83
|
+
"@sencha/extjs": pluginSencha
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "oncourse/sencha/rules",
|
|
88
|
+
rules: {
|
|
89
|
+
...pluginSencha.configs.recommended.rules
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/config.ts
|
|
96
|
+
function oncourseConfigs(options) {
|
|
97
|
+
return [
|
|
98
|
+
options?.expo ? expo() : {},
|
|
99
|
+
javascript(),
|
|
100
|
+
options?.sencha ? sencha() : {},
|
|
101
|
+
{
|
|
102
|
+
files: ["**/.vscode/*.json"],
|
|
103
|
+
rules: {
|
|
104
|
+
"jsonc/sort-array-values": [
|
|
105
|
+
"error",
|
|
106
|
+
{ order: { natural: true, type: "asc" }, pathPattern: "^.*$" }
|
|
107
|
+
],
|
|
108
|
+
"jsonc/sort-keys": [
|
|
109
|
+
"error",
|
|
110
|
+
"asc",
|
|
111
|
+
{ caseSensitive: true, natural: true }
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/options.ts
|
|
119
|
+
init_esm_shims();
|
|
120
|
+
|
|
121
|
+
// src/configs/react.ts
|
|
122
|
+
init_esm_shims();
|
|
123
|
+
|
|
124
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/index.js
|
|
125
|
+
init_esm_shims();
|
|
126
|
+
|
|
127
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules.js
|
|
128
|
+
init_esm_shims();
|
|
129
|
+
|
|
130
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.js
|
|
131
|
+
init_esm_shims();
|
|
132
|
+
var import_utils4 = __toESM(require_dist(), 1);
|
|
133
|
+
|
|
134
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/utils/ast-utils.js
|
|
135
|
+
init_esm_shims();
|
|
136
|
+
var import_utils = __toESM(require_dist(), 1);
|
|
137
|
+
|
|
138
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/utils/unique-by.js
|
|
139
|
+
init_esm_shims();
|
|
140
|
+
function uniqueBy(arr, fn) {
|
|
141
|
+
return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/utils/ast-utils.js
|
|
145
|
+
var ASTUtils = {
|
|
146
|
+
isNodeOfOneOf(node, types) {
|
|
147
|
+
return types.includes(node.type);
|
|
148
|
+
},
|
|
149
|
+
isIdentifier(node) {
|
|
150
|
+
return node.type === import_utils.AST_NODE_TYPES.Identifier;
|
|
151
|
+
},
|
|
152
|
+
isIdentifierWithName(node, name6) {
|
|
153
|
+
return ASTUtils.isIdentifier(node) && node.name === name6;
|
|
154
|
+
},
|
|
155
|
+
isIdentifierWithOneOfNames(node, name6) {
|
|
156
|
+
return ASTUtils.isIdentifier(node) && name6.includes(node.name);
|
|
157
|
+
},
|
|
158
|
+
isProperty(node) {
|
|
159
|
+
return node.type === import_utils.AST_NODE_TYPES.Property;
|
|
160
|
+
},
|
|
161
|
+
isObjectExpression(node) {
|
|
162
|
+
return node.type === import_utils.AST_NODE_TYPES.ObjectExpression;
|
|
163
|
+
},
|
|
164
|
+
isPropertyWithIdentifierKey(node, key) {
|
|
165
|
+
return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
|
|
166
|
+
},
|
|
167
|
+
findPropertyWithIdentifierKey(properties, key) {
|
|
168
|
+
return properties.find(
|
|
169
|
+
(x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
getNestedIdentifiers(node) {
|
|
173
|
+
const identifiers = [];
|
|
174
|
+
if (ASTUtils.isIdentifier(node)) {
|
|
175
|
+
identifiers.push(node);
|
|
176
|
+
}
|
|
177
|
+
if ("arguments" in node) {
|
|
178
|
+
node.arguments.forEach((x) => {
|
|
179
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if ("elements" in node) {
|
|
183
|
+
node.elements.forEach((x) => {
|
|
184
|
+
if (x !== null) {
|
|
185
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if ("properties" in node) {
|
|
190
|
+
node.properties.forEach((x) => {
|
|
191
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if ("expressions" in node) {
|
|
195
|
+
node.expressions.forEach((x) => {
|
|
196
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(x));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if ("left" in node) {
|
|
200
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.left));
|
|
201
|
+
}
|
|
202
|
+
if ("right" in node) {
|
|
203
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.right));
|
|
204
|
+
}
|
|
205
|
+
if (node.type === import_utils.AST_NODE_TYPES.Property) {
|
|
206
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
|
|
207
|
+
}
|
|
208
|
+
if (node.type === import_utils.AST_NODE_TYPES.SpreadElement) {
|
|
209
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
|
|
210
|
+
}
|
|
211
|
+
if (node.type === import_utils.AST_NODE_TYPES.MemberExpression) {
|
|
212
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
|
|
213
|
+
}
|
|
214
|
+
if (node.type === import_utils.AST_NODE_TYPES.UnaryExpression) {
|
|
215
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
|
|
216
|
+
}
|
|
217
|
+
if (node.type === import_utils.AST_NODE_TYPES.ChainExpression) {
|
|
218
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
|
|
219
|
+
}
|
|
220
|
+
if (node.type === import_utils.AST_NODE_TYPES.TSNonNullExpression) {
|
|
221
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
|
|
222
|
+
}
|
|
223
|
+
if (node.type === import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
224
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
|
|
225
|
+
}
|
|
226
|
+
if (node.type === import_utils.AST_NODE_TYPES.FunctionExpression) {
|
|
227
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.body));
|
|
228
|
+
}
|
|
229
|
+
if (node.type === import_utils.AST_NODE_TYPES.BlockStatement) {
|
|
230
|
+
identifiers.push(
|
|
231
|
+
...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat()
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement && node.argument) {
|
|
235
|
+
identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
|
|
236
|
+
}
|
|
237
|
+
return identifiers;
|
|
238
|
+
},
|
|
239
|
+
isAncestorIsCallee(identifier) {
|
|
240
|
+
let previousNode = identifier;
|
|
241
|
+
let currentNode = identifier.parent;
|
|
242
|
+
while (currentNode !== void 0) {
|
|
243
|
+
if (currentNode.type === import_utils.AST_NODE_TYPES.CallExpression && currentNode.callee === previousNode) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
if (currentNode.type !== import_utils.AST_NODE_TYPES.MemberExpression) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
previousNode = currentNode;
|
|
250
|
+
currentNode = currentNode.parent;
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
},
|
|
254
|
+
traverseUpOnly(identifier, allowedNodeTypes) {
|
|
255
|
+
const parent = identifier.parent;
|
|
256
|
+
if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
|
|
257
|
+
return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
|
|
258
|
+
}
|
|
259
|
+
return identifier;
|
|
260
|
+
},
|
|
261
|
+
isDeclaredInNode(params) {
|
|
262
|
+
const { functionNode, reference, scopeManager } = params;
|
|
263
|
+
const scope = scopeManager.acquire(functionNode);
|
|
264
|
+
if (scope === null) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return scope.set.has(reference.identifier.name);
|
|
268
|
+
},
|
|
269
|
+
getExternalRefs(params) {
|
|
270
|
+
const { scopeManager, sourceCode, node } = params;
|
|
271
|
+
const scope = scopeManager.acquire(node);
|
|
272
|
+
if (scope === null) {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
const references = scope.references.filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
|
|
276
|
+
const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
|
|
277
|
+
import_utils.AST_NODE_TYPES.MemberExpression,
|
|
278
|
+
import_utils.AST_NODE_TYPES.Identifier
|
|
279
|
+
]);
|
|
280
|
+
return {
|
|
281
|
+
variable: x,
|
|
282
|
+
node: referenceNode,
|
|
283
|
+
text: sourceCode.getText(referenceNode)
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
const localRefIds = new Set(
|
|
287
|
+
[...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
|
|
288
|
+
);
|
|
289
|
+
const externalRefs = references.filter(
|
|
290
|
+
(x) => x.variable.resolved === null || !localRefIds.has(x.text)
|
|
291
|
+
);
|
|
292
|
+
return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
|
|
293
|
+
},
|
|
294
|
+
mapKeyNodeToText(node, sourceCode) {
|
|
295
|
+
return sourceCode.getText(
|
|
296
|
+
ASTUtils.traverseUpOnly(node, [
|
|
297
|
+
import_utils.AST_NODE_TYPES.MemberExpression,
|
|
298
|
+
import_utils.AST_NODE_TYPES.Identifier
|
|
299
|
+
])
|
|
300
|
+
);
|
|
301
|
+
},
|
|
302
|
+
isValidReactComponentOrHookName(identifier) {
|
|
303
|
+
return identifier !== null && identifier !== void 0 && /^(use|[A-Z])/.test(identifier.name);
|
|
304
|
+
},
|
|
305
|
+
getFunctionAncestor(sourceCode, node) {
|
|
306
|
+
var _a;
|
|
307
|
+
for (const ancestor of sourceCode.getAncestors(node)) {
|
|
308
|
+
if (ASTUtils.isNodeOfOneOf(ancestor, [
|
|
309
|
+
import_utils.AST_NODE_TYPES.FunctionDeclaration,
|
|
310
|
+
import_utils.AST_NODE_TYPES.FunctionExpression,
|
|
311
|
+
import_utils.AST_NODE_TYPES.ArrowFunctionExpression
|
|
312
|
+
])) {
|
|
313
|
+
return ancestor;
|
|
314
|
+
}
|
|
315
|
+
if (((_a = ancestor.parent) == null ? void 0 : _a.type) === import_utils.AST_NODE_TYPES.VariableDeclarator && ancestor.parent.id.type === import_utils.AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(ancestor, [
|
|
316
|
+
import_utils.AST_NODE_TYPES.FunctionDeclaration,
|
|
317
|
+
import_utils.AST_NODE_TYPES.FunctionExpression,
|
|
318
|
+
import_utils.AST_NODE_TYPES.ArrowFunctionExpression
|
|
319
|
+
])) {
|
|
320
|
+
return ancestor;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return void 0;
|
|
324
|
+
},
|
|
325
|
+
getReferencedExpressionByIdentifier(params) {
|
|
326
|
+
var _a, _b, _c;
|
|
327
|
+
const { node, context } = params;
|
|
328
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
329
|
+
const scope = context.sourceCode.getScope(node) ? sourceCode.getScope(node) : context.getScope();
|
|
330
|
+
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;
|
|
331
|
+
if ((resolvedNode == null ? void 0 : resolvedNode.type) !== import_utils.AST_NODE_TYPES.VariableDeclarator) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
return resolvedNode.init;
|
|
335
|
+
},
|
|
336
|
+
getClosestVariableDeclarator(node) {
|
|
337
|
+
let currentNode = node;
|
|
338
|
+
while (currentNode.type !== import_utils.AST_NODE_TYPES.Program) {
|
|
339
|
+
if (currentNode.type === import_utils.AST_NODE_TYPES.VariableDeclarator) {
|
|
340
|
+
return currentNode;
|
|
341
|
+
}
|
|
342
|
+
currentNode = currentNode.parent;
|
|
343
|
+
}
|
|
344
|
+
return void 0;
|
|
345
|
+
},
|
|
346
|
+
getNestedReturnStatements(node) {
|
|
347
|
+
const returnStatements = [];
|
|
348
|
+
if (node.type === import_utils.AST_NODE_TYPES.ReturnStatement) {
|
|
349
|
+
returnStatements.push(node);
|
|
350
|
+
}
|
|
351
|
+
if ("body" in node && node.body !== void 0 && node.body !== null) {
|
|
352
|
+
Array.isArray(node.body) ? node.body.forEach((x) => {
|
|
353
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
354
|
+
}) : returnStatements.push(
|
|
355
|
+
...ASTUtils.getNestedReturnStatements(node.body)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if ("consequent" in node) {
|
|
359
|
+
Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
|
|
360
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
361
|
+
}) : returnStatements.push(
|
|
362
|
+
...ASTUtils.getNestedReturnStatements(node.consequent)
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
if ("alternate" in node && node.alternate !== null) {
|
|
366
|
+
Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
|
|
367
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
368
|
+
}) : returnStatements.push(
|
|
369
|
+
...ASTUtils.getNestedReturnStatements(node.alternate)
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
if ("cases" in node) {
|
|
373
|
+
node.cases.forEach((x) => {
|
|
374
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if ("block" in node) {
|
|
378
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
|
|
379
|
+
}
|
|
380
|
+
if ("handler" in node && node.handler !== null) {
|
|
381
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
|
|
382
|
+
}
|
|
383
|
+
if ("finalizer" in node && node.finalizer !== null) {
|
|
384
|
+
returnStatements.push(
|
|
385
|
+
...ASTUtils.getNestedReturnStatements(node.finalizer)
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
389
|
+
returnStatements.push(
|
|
390
|
+
...ASTUtils.getNestedReturnStatements(node.expression)
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
if ("test" in node && node.test !== null) {
|
|
394
|
+
returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
|
|
395
|
+
}
|
|
396
|
+
return returnStatements;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/utils/get-docs-url.js
|
|
401
|
+
init_esm_shims();
|
|
402
|
+
var getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
|
|
403
|
+
|
|
404
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/utils/detect-react-query-imports.js
|
|
405
|
+
init_esm_shims();
|
|
406
|
+
var import_utils2 = __toESM(require_dist(), 1);
|
|
407
|
+
function detectTanstackQueryImports(create) {
|
|
408
|
+
return (context, optionsWithDefault) => {
|
|
409
|
+
const tanstackQueryImportSpecifiers = [];
|
|
410
|
+
const helpers = {
|
|
411
|
+
isSpecificTanstackQueryImport(node, source) {
|
|
412
|
+
return !!tanstackQueryImportSpecifiers.find((specifier) => {
|
|
413
|
+
if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
|
|
414
|
+
return node.name === specifier.local.name;
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
isTanstackQueryImport(node) {
|
|
420
|
+
return !!tanstackQueryImportSpecifiers.find((specifier) => {
|
|
421
|
+
if (specifier.type === import_utils2.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
|
|
422
|
+
return node.name === specifier.local.name;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const detectionInstructions = {
|
|
429
|
+
ImportDeclaration(node) {
|
|
430
|
+
if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
|
|
431
|
+
tanstackQueryImportSpecifiers.push(...node.specifiers);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const ruleInstructions = create(context, optionsWithDefault, helpers);
|
|
436
|
+
const enhancedRuleInstructions = {};
|
|
437
|
+
const allKeys = new Set(
|
|
438
|
+
Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
|
|
439
|
+
);
|
|
440
|
+
allKeys.forEach((instruction) => {
|
|
441
|
+
enhancedRuleInstructions[instruction] = (node) => {
|
|
442
|
+
var _a, _b;
|
|
443
|
+
if (instruction in detectionInstructions) {
|
|
444
|
+
(_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, node);
|
|
445
|
+
}
|
|
446
|
+
if (ruleInstructions[instruction]) {
|
|
447
|
+
return (_b = ruleInstructions[instruction]) == null ? void 0 : _b.call(ruleInstructions, node);
|
|
448
|
+
}
|
|
449
|
+
return void 0;
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
return enhancedRuleInstructions;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/exhaustive-deps/exhaustive-deps.utils.js
|
|
457
|
+
init_esm_shims();
|
|
458
|
+
var import_utils3 = __toESM(require_dist(), 1);
|
|
459
|
+
var ExhaustiveDepsUtils = {
|
|
460
|
+
isRelevantReference(params) {
|
|
461
|
+
const { sourceCode, reference, scopeManager, node } = params;
|
|
462
|
+
const component = ASTUtils.getFunctionAncestor(sourceCode, node);
|
|
463
|
+
if (component === void 0) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
if (!ASTUtils.isDeclaredInNode({
|
|
467
|
+
scopeManager,
|
|
468
|
+
reference,
|
|
469
|
+
functionNode: component
|
|
470
|
+
})) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
return reference.identifier.name !== "undefined" && reference.identifier.parent.type !== import_utils3.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isInstanceOfKind(reference.identifier.parent) && !ExhaustiveDepsUtils.isQueryClientReference(reference);
|
|
474
|
+
},
|
|
475
|
+
isInstanceOfKind(node) {
|
|
476
|
+
return node.type === import_utils3.AST_NODE_TYPES.BinaryExpression && node.operator === "instanceof";
|
|
477
|
+
},
|
|
478
|
+
isQueryClientReference(reference) {
|
|
479
|
+
var _a, _b, _c;
|
|
480
|
+
const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
|
|
481
|
+
return (declarator == null ? void 0 : declarator.type) === import_utils3.AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === import_utils3.AST_NODE_TYPES.CallExpression && declarator.init.callee.type === import_utils3.AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.js
|
|
486
|
+
var QUERY_KEY = "queryKey";
|
|
487
|
+
var QUERY_FN = "queryFn";
|
|
488
|
+
var name = "exhaustive-deps";
|
|
489
|
+
var createRule = import_utils4.ESLintUtils.RuleCreator(getDocsUrl);
|
|
490
|
+
var rule = createRule({
|
|
491
|
+
name,
|
|
492
|
+
meta: {
|
|
493
|
+
type: "problem",
|
|
494
|
+
docs: {
|
|
495
|
+
description: "Exhaustive deps rule for useQuery",
|
|
496
|
+
recommended: "error"
|
|
497
|
+
},
|
|
498
|
+
messages: {
|
|
499
|
+
missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
|
|
500
|
+
fixTo: "Fix to {{result}}"
|
|
501
|
+
},
|
|
502
|
+
hasSuggestions: true,
|
|
503
|
+
fixable: "code",
|
|
504
|
+
schema: []
|
|
505
|
+
},
|
|
506
|
+
defaultOptions: [],
|
|
507
|
+
create: detectTanstackQueryImports((context) => {
|
|
508
|
+
return {
|
|
509
|
+
Property: (node) => {
|
|
510
|
+
if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const scopeManager = context.sourceCode.scopeManager;
|
|
514
|
+
const queryKey = ASTUtils.findPropertyWithIdentifierKey(
|
|
515
|
+
node.parent.properties,
|
|
516
|
+
QUERY_KEY
|
|
517
|
+
);
|
|
518
|
+
const queryFn = ASTUtils.findPropertyWithIdentifierKey(
|
|
519
|
+
node.parent.properties,
|
|
520
|
+
QUERY_FN
|
|
521
|
+
);
|
|
522
|
+
if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || !ASTUtils.isNodeOfOneOf(queryFn.value, [
|
|
523
|
+
import_utils4.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
524
|
+
import_utils4.AST_NODE_TYPES.FunctionExpression,
|
|
525
|
+
import_utils4.AST_NODE_TYPES.ConditionalExpression
|
|
526
|
+
])) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
let queryKeyNode = queryKey.value;
|
|
530
|
+
if (queryKeyNode.type === import_utils4.AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === import_utils4.AST_NODE_TYPES.ArrayExpression) {
|
|
531
|
+
queryKeyNode = queryKeyNode.expression;
|
|
532
|
+
}
|
|
533
|
+
if (queryKeyNode.type === import_utils4.AST_NODE_TYPES.Identifier) {
|
|
534
|
+
const expression = ASTUtils.getReferencedExpressionByIdentifier({
|
|
535
|
+
context,
|
|
536
|
+
node: queryKeyNode
|
|
537
|
+
});
|
|
538
|
+
if ((expression == null ? void 0 : expression.type) === import_utils4.AST_NODE_TYPES.ArrayExpression) {
|
|
539
|
+
queryKeyNode = expression;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const externalRefs = ASTUtils.getExternalRefs({
|
|
543
|
+
scopeManager,
|
|
544
|
+
sourceCode: context.sourceCode,
|
|
545
|
+
node: getQueryFnRelevantNode(queryFn)
|
|
546
|
+
});
|
|
547
|
+
const relevantRefs = externalRefs.filter(
|
|
548
|
+
(reference) => ExhaustiveDepsUtils.isRelevantReference({
|
|
549
|
+
sourceCode: context.sourceCode,
|
|
550
|
+
reference,
|
|
551
|
+
scopeManager,
|
|
552
|
+
node: getQueryFnRelevantNode(queryFn)
|
|
553
|
+
})
|
|
554
|
+
);
|
|
555
|
+
const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyNode).map(
|
|
556
|
+
(identifier) => ASTUtils.mapKeyNodeToText(identifier, context.sourceCode)
|
|
557
|
+
);
|
|
558
|
+
const missingRefs = relevantRefs.map((ref) => ({
|
|
559
|
+
ref,
|
|
560
|
+
text: ASTUtils.mapKeyNodeToText(ref.identifier, context.sourceCode)
|
|
561
|
+
})).filter(({ ref, text }) => {
|
|
562
|
+
return !ref.isTypeReference && !ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(/[?.]/)[0] ?? "");
|
|
563
|
+
}).map(({ ref, text }) => ({
|
|
564
|
+
identifier: ref.identifier,
|
|
565
|
+
text
|
|
566
|
+
}));
|
|
567
|
+
const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text);
|
|
568
|
+
if (uniqueMissingRefs.length > 0) {
|
|
569
|
+
const missingAsText = uniqueMissingRefs.map(
|
|
570
|
+
(ref) => ASTUtils.mapKeyNodeToText(ref.identifier, context.sourceCode)
|
|
571
|
+
).join(", ");
|
|
572
|
+
const queryKeyValue = context.sourceCode.getText(queryKeyNode);
|
|
573
|
+
const existingWithMissing = queryKeyValue === "[]" ? `[${missingAsText}]` : queryKeyValue.replace(/\]$/, `, ${missingAsText}]`);
|
|
574
|
+
const suggestions = [];
|
|
575
|
+
if (queryKeyNode.type === import_utils4.AST_NODE_TYPES.ArrayExpression) {
|
|
576
|
+
suggestions.push({
|
|
577
|
+
messageId: "fixTo",
|
|
578
|
+
data: { result: existingWithMissing },
|
|
579
|
+
fix(fixer) {
|
|
580
|
+
return fixer.replaceText(queryKeyNode, existingWithMissing);
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
context.report({
|
|
585
|
+
node,
|
|
586
|
+
messageId: "missingDeps",
|
|
587
|
+
data: {
|
|
588
|
+
deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
|
|
589
|
+
},
|
|
590
|
+
suggest: suggestions
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
})
|
|
596
|
+
});
|
|
597
|
+
function getQueryFnRelevantNode(queryFn) {
|
|
598
|
+
if (queryFn.value.type !== import_utils4.AST_NODE_TYPES.ConditionalExpression) {
|
|
599
|
+
return queryFn.value;
|
|
600
|
+
}
|
|
601
|
+
if (queryFn.value.consequent.type === import_utils4.AST_NODE_TYPES.Identifier && queryFn.value.consequent.name === "skipToken") {
|
|
602
|
+
return queryFn.value.alternate;
|
|
603
|
+
}
|
|
604
|
+
return queryFn.value.consequent;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/stable-query-client/stable-query-client.rule.js
|
|
608
|
+
init_esm_shims();
|
|
609
|
+
var import_utils5 = __toESM(require_dist(), 1);
|
|
610
|
+
var name2 = "stable-query-client";
|
|
611
|
+
var createRule2 = import_utils5.ESLintUtils.RuleCreator(getDocsUrl);
|
|
612
|
+
var rule2 = createRule2({
|
|
613
|
+
name: name2,
|
|
614
|
+
meta: {
|
|
615
|
+
type: "problem",
|
|
616
|
+
docs: {
|
|
617
|
+
description: "Makes sure that QueryClient is stable",
|
|
618
|
+
recommended: "error"
|
|
619
|
+
},
|
|
620
|
+
messages: {
|
|
621
|
+
unstable: [
|
|
622
|
+
"QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.",
|
|
623
|
+
"See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable"
|
|
624
|
+
].join("\n"),
|
|
625
|
+
fixTo: "Fix to {{result}}"
|
|
626
|
+
},
|
|
627
|
+
hasSuggestions: true,
|
|
628
|
+
fixable: "code",
|
|
629
|
+
schema: []
|
|
630
|
+
},
|
|
631
|
+
defaultOptions: [],
|
|
632
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
633
|
+
return {
|
|
634
|
+
NewExpression: (node) => {
|
|
635
|
+
if (node.callee.type !== import_utils5.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== import_utils5.AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
|
|
636
|
+
node.callee,
|
|
637
|
+
"@tanstack/react-query"
|
|
638
|
+
)) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
const fnAncestor = ASTUtils.getFunctionAncestor(
|
|
642
|
+
context.sourceCode,
|
|
643
|
+
node
|
|
644
|
+
);
|
|
645
|
+
const isReactServerComponent = (fnAncestor == null ? void 0 : fnAncestor.async) === true;
|
|
646
|
+
if (!ASTUtils.isValidReactComponentOrHookName(fnAncestor == null ? void 0 : fnAncestor.id) || isReactServerComponent) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
context.report({
|
|
650
|
+
node: node.parent,
|
|
651
|
+
messageId: "unstable",
|
|
652
|
+
fix: (() => {
|
|
653
|
+
const { parent } = node;
|
|
654
|
+
if (parent.id.type !== import_utils5.AST_NODE_TYPES.Identifier) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
658
|
+
const nodeText = sourceCode.getText(node);
|
|
659
|
+
const variableName = parent.id.name;
|
|
660
|
+
return (fixer) => {
|
|
661
|
+
return fixer.replaceTextRange(
|
|
662
|
+
[parent.range[0], parent.range[1]],
|
|
663
|
+
`[${variableName}] = React.useState(() => ${nodeText})`
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
})()
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
})
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.js
|
|
674
|
+
init_esm_shims();
|
|
675
|
+
var import_utils7 = __toESM(require_dist(), 1);
|
|
676
|
+
|
|
677
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.utils.js
|
|
678
|
+
init_esm_shims();
|
|
679
|
+
var import_utils6 = __toESM(require_dist(), 1);
|
|
680
|
+
var NoRestDestructuringUtils = {
|
|
681
|
+
isObjectRestDestructuring(node) {
|
|
682
|
+
if (node.type !== import_utils6.AST_NODE_TYPES.ObjectPattern) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
return node.properties.some((p) => p.type === import_utils6.AST_NODE_TYPES.RestElement);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.js
|
|
690
|
+
var name3 = "no-rest-destructuring";
|
|
691
|
+
var queryHooks = [
|
|
692
|
+
"useQuery",
|
|
693
|
+
"useQueries",
|
|
694
|
+
"useInfiniteQuery",
|
|
695
|
+
"useSuspenseQuery",
|
|
696
|
+
"useSuspenseQueries",
|
|
697
|
+
"useSuspenseInfiniteQuery"
|
|
698
|
+
];
|
|
699
|
+
var createRule3 = import_utils7.ESLintUtils.RuleCreator(getDocsUrl);
|
|
700
|
+
var rule3 = createRule3({
|
|
701
|
+
name: name3,
|
|
702
|
+
meta: {
|
|
703
|
+
type: "problem",
|
|
704
|
+
docs: {
|
|
705
|
+
description: "Disallows rest destructuring in queries",
|
|
706
|
+
recommended: "warn"
|
|
707
|
+
},
|
|
708
|
+
messages: {
|
|
709
|
+
objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
|
|
710
|
+
},
|
|
711
|
+
schema: []
|
|
712
|
+
},
|
|
713
|
+
defaultOptions: [],
|
|
714
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
715
|
+
return {
|
|
716
|
+
CallExpression: (node) => {
|
|
717
|
+
if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const returnValue = node.parent.id;
|
|
721
|
+
if (node.callee.name !== "useQueries" && node.callee.name !== "useSuspenseQueries") {
|
|
722
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
|
|
723
|
+
context.report({
|
|
724
|
+
node: node.parent,
|
|
725
|
+
messageId: "objectRestDestructure"
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (returnValue.type !== import_utils7.AST_NODE_TYPES.ArrayPattern) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
returnValue.elements.forEach((queryResult) => {
|
|
734
|
+
if (queryResult === null) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
|
|
738
|
+
context.report({
|
|
739
|
+
node: queryResult,
|
|
740
|
+
messageId: "objectRestDestructure"
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
})
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/no-unstable-deps/no-unstable-deps.rule.js
|
|
750
|
+
init_esm_shims();
|
|
751
|
+
var import_utils8 = __toESM(require_dist(), 1);
|
|
752
|
+
var name4 = "no-unstable-deps";
|
|
753
|
+
var reactHookNames = ["useEffect", "useCallback", "useMemo"];
|
|
754
|
+
var useQueryHookNames = [
|
|
755
|
+
"useQuery",
|
|
756
|
+
"useSuspenseQuery",
|
|
757
|
+
"useQueries",
|
|
758
|
+
"useSuspenseQueries",
|
|
759
|
+
"useInfiniteQuery",
|
|
760
|
+
"useSuspenseInfiniteQuery"
|
|
761
|
+
];
|
|
762
|
+
var allHookNames = ["useMutation", ...useQueryHookNames];
|
|
763
|
+
var createRule4 = import_utils8.ESLintUtils.RuleCreator(getDocsUrl);
|
|
764
|
+
var rule4 = createRule4({
|
|
765
|
+
name: name4,
|
|
766
|
+
meta: {
|
|
767
|
+
type: "problem",
|
|
768
|
+
docs: {
|
|
769
|
+
description: "Disallow putting the result of query hooks directly in a React hook dependency array",
|
|
770
|
+
recommended: "error"
|
|
771
|
+
},
|
|
772
|
+
messages: {
|
|
773
|
+
noUnstableDeps: `The result of {{queryHook}} is not referentially stable, so don't pass it directly into the dependencies array of {{reactHook}}. Instead, destructure the return value of {{queryHook}} and pass the destructured values into the dependency array of {{reactHook}}.`
|
|
774
|
+
},
|
|
775
|
+
schema: []
|
|
776
|
+
},
|
|
777
|
+
defaultOptions: [],
|
|
778
|
+
create: detectTanstackQueryImports((context) => {
|
|
779
|
+
const trackedVariables = {};
|
|
780
|
+
const hookAliasMap = {};
|
|
781
|
+
function getReactHook(node) {
|
|
782
|
+
if (node.callee.type === "Identifier") {
|
|
783
|
+
const calleeName = node.callee.name;
|
|
784
|
+
if (reactHookNames.includes(calleeName) || calleeName in hookAliasMap) {
|
|
785
|
+
return calleeName;
|
|
786
|
+
}
|
|
787
|
+
} else if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "React" && node.callee.property.type === "Identifier" && reactHookNames.includes(node.callee.property.name)) {
|
|
788
|
+
return node.callee.property.name;
|
|
789
|
+
}
|
|
790
|
+
return void 0;
|
|
791
|
+
}
|
|
792
|
+
function collectVariableNames(pattern, queryHook) {
|
|
793
|
+
if (pattern.type === import_utils8.AST_NODE_TYPES.Identifier) {
|
|
794
|
+
trackedVariables[pattern.name] = queryHook;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
ImportDeclaration(node) {
|
|
799
|
+
if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value === "React") {
|
|
800
|
+
node.specifiers.forEach((specifier) => {
|
|
801
|
+
if (specifier.type === import_utils8.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils8.AST_NODE_TYPES.Identifier && reactHookNames.includes(specifier.imported.name)) {
|
|
802
|
+
hookAliasMap[specifier.local.name] = specifier.imported.name;
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
VariableDeclarator(node) {
|
|
808
|
+
if (node.init !== null && node.init.type === import_utils8.AST_NODE_TYPES.CallExpression && node.init.callee.type === import_utils8.AST_NODE_TYPES.Identifier && allHookNames.includes(node.init.callee.name)) {
|
|
809
|
+
collectVariableNames(node.id, node.init.callee.name);
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
CallExpression: (node) => {
|
|
813
|
+
var _a;
|
|
814
|
+
const reactHook = getReactHook(node);
|
|
815
|
+
if (reactHook !== void 0 && node.arguments.length > 1 && ((_a = node.arguments[1]) == null ? void 0 : _a.type) === import_utils8.AST_NODE_TYPES.ArrayExpression) {
|
|
816
|
+
const depsArray = node.arguments[1].elements;
|
|
817
|
+
depsArray.forEach((dep) => {
|
|
818
|
+
if (dep !== null && dep.type === import_utils8.AST_NODE_TYPES.Identifier && trackedVariables[dep.name] !== void 0) {
|
|
819
|
+
const queryHook = trackedVariables[dep.name];
|
|
820
|
+
context.report({
|
|
821
|
+
node: dep,
|
|
822
|
+
messageId: "noUnstableDeps",
|
|
823
|
+
data: {
|
|
824
|
+
queryHook,
|
|
825
|
+
reactHook
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
})
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.rule.js
|
|
837
|
+
init_esm_shims();
|
|
838
|
+
var import_utils9 = __toESM(require_dist(), 1);
|
|
839
|
+
|
|
840
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.utils.js
|
|
841
|
+
init_esm_shims();
|
|
842
|
+
function sortDataByOrder(data, orderRules, key) {
|
|
843
|
+
const getSubsetIndex = (item, subsets) => {
|
|
844
|
+
var _a;
|
|
845
|
+
for (let i = 0; i < subsets.length; i++) {
|
|
846
|
+
if ((_a = subsets[i]) == null ? void 0 : _a.includes(item)) {
|
|
847
|
+
return i;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return null;
|
|
851
|
+
};
|
|
852
|
+
const orderSets = orderRules.reduce(
|
|
853
|
+
(sets, [A, B]) => [...sets, A, B],
|
|
854
|
+
[]
|
|
855
|
+
);
|
|
856
|
+
const inOrderArray = data.filter(
|
|
857
|
+
(item) => getSubsetIndex(item[key], orderSets) !== null
|
|
858
|
+
);
|
|
859
|
+
let wasResorted = false;
|
|
860
|
+
const sortedArray = inOrderArray.sort((a, b) => {
|
|
861
|
+
const aKey = a[key], bKey = b[key];
|
|
862
|
+
const aSubsetIndex = getSubsetIndex(aKey, orderSets);
|
|
863
|
+
const bSubsetIndex = getSubsetIndex(bKey, orderSets);
|
|
864
|
+
if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
|
|
865
|
+
return aSubsetIndex - bSubsetIndex;
|
|
866
|
+
}
|
|
867
|
+
return 0;
|
|
868
|
+
});
|
|
869
|
+
const inOrderIterator = sortedArray.values();
|
|
870
|
+
const result = data.map((item) => {
|
|
871
|
+
if (getSubsetIndex(item[key], orderSets) !== null) {
|
|
872
|
+
const sortedItem = inOrderIterator.next().value;
|
|
873
|
+
if (sortedItem[key] !== item[key]) {
|
|
874
|
+
wasResorted = true;
|
|
875
|
+
}
|
|
876
|
+
return sortedItem;
|
|
877
|
+
}
|
|
878
|
+
return item;
|
|
879
|
+
});
|
|
880
|
+
if (!wasResorted) {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
return result;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/infinite-query-property-order/constants.js
|
|
887
|
+
init_esm_shims();
|
|
888
|
+
var infiniteQueryFunctions = [
|
|
889
|
+
"infiniteQueryOptions",
|
|
890
|
+
"useInfiniteQuery",
|
|
891
|
+
"useSuspenseInfiniteQuery"
|
|
892
|
+
];
|
|
893
|
+
var sortRules = [
|
|
894
|
+
[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]
|
|
895
|
+
];
|
|
896
|
+
|
|
897
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules/infinite-query-property-order/infinite-query-property-order.rule.js
|
|
898
|
+
var createRule5 = import_utils9.ESLintUtils.RuleCreator(getDocsUrl);
|
|
899
|
+
var infiniteQueryFunctionsSet = new Set(infiniteQueryFunctions);
|
|
900
|
+
function isInfiniteQueryFunction(node) {
|
|
901
|
+
return infiniteQueryFunctionsSet.has(node);
|
|
902
|
+
}
|
|
903
|
+
var name5 = "infinite-query-property-order";
|
|
904
|
+
var rule5 = createRule5({
|
|
905
|
+
name: name5,
|
|
906
|
+
meta: {
|
|
907
|
+
type: "problem",
|
|
908
|
+
docs: {
|
|
909
|
+
description: "Ensure correct order of inference sensitive properties for infinite queries",
|
|
910
|
+
recommended: "error"
|
|
911
|
+
},
|
|
912
|
+
messages: {
|
|
913
|
+
invalidOrder: "Invalid order of properties for `{{function}}`."
|
|
914
|
+
},
|
|
915
|
+
schema: [],
|
|
916
|
+
hasSuggestions: true,
|
|
917
|
+
fixable: "code"
|
|
918
|
+
},
|
|
919
|
+
defaultOptions: [],
|
|
920
|
+
create: detectTanstackQueryImports((context) => {
|
|
921
|
+
return {
|
|
922
|
+
CallExpression(node) {
|
|
923
|
+
if (node.callee.type !== import_utils9.AST_NODE_TYPES.Identifier) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const infiniteQueryFunction = node.callee.name;
|
|
927
|
+
if (!isInfiniteQueryFunction(infiniteQueryFunction)) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const argument = node.arguments[0];
|
|
931
|
+
if (argument === void 0 || argument.type !== "ObjectExpression") {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
const allProperties = argument.properties;
|
|
935
|
+
if (allProperties.length < 2) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const properties = allProperties.flatMap((p, index) => {
|
|
939
|
+
if (p.type === import_utils9.AST_NODE_TYPES.Property && p.key.type === import_utils9.AST_NODE_TYPES.Identifier) {
|
|
940
|
+
return { name: p.key.name, property: p };
|
|
941
|
+
} else return { name: `_property_${index}`, property: p };
|
|
942
|
+
});
|
|
943
|
+
const sortedProperties = sortDataByOrder(properties, sortRules, "name");
|
|
944
|
+
if (sortedProperties === null) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
context.report({
|
|
948
|
+
node: argument,
|
|
949
|
+
data: { function: node.callee.name },
|
|
950
|
+
messageId: "invalidOrder",
|
|
951
|
+
fix(fixer) {
|
|
952
|
+
const sourceCode = context.sourceCode;
|
|
953
|
+
const reorderedText = sortedProperties.reduce(
|
|
954
|
+
(sourceText, specifier, index) => {
|
|
955
|
+
let textBetweenProperties = "";
|
|
956
|
+
if (index < allProperties.length - 1) {
|
|
957
|
+
textBetweenProperties = sourceCode.getText().slice(
|
|
958
|
+
allProperties[index].range[1],
|
|
959
|
+
allProperties[index + 1].range[0]
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
|
|
963
|
+
},
|
|
964
|
+
""
|
|
965
|
+
);
|
|
966
|
+
return fixer.replaceTextRange(
|
|
967
|
+
[allProperties[0].range[0], allProperties.at(-1).range[1]],
|
|
968
|
+
reorderedText
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
})
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/rules.js
|
|
978
|
+
var rules = {
|
|
979
|
+
[name]: rule,
|
|
980
|
+
[name2]: rule2,
|
|
981
|
+
[name3]: rule3,
|
|
982
|
+
[name4]: rule4,
|
|
983
|
+
[name5]: rule5
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// node_modules/.pnpm/@tanstack+eslint-plugin-query@5.61.3_eslint@9.15.0_jiti@2.4.0__typescript@5.7.2/node_modules/@tanstack/eslint-plugin-query/dist/esm/index.js
|
|
987
|
+
var plugin = {
|
|
988
|
+
meta: {
|
|
989
|
+
name: "@tanstack/eslint-plugin-query"
|
|
990
|
+
},
|
|
991
|
+
configs: {},
|
|
992
|
+
rules
|
|
993
|
+
};
|
|
994
|
+
Object.assign(plugin.configs, {
|
|
995
|
+
recommended: {
|
|
996
|
+
plugins: ["@tanstack/query"],
|
|
997
|
+
rules: {
|
|
998
|
+
"@tanstack/query/exhaustive-deps": "error",
|
|
999
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
1000
|
+
"@tanstack/query/stable-query-client": "error",
|
|
1001
|
+
"@tanstack/query/no-unstable-deps": "error",
|
|
1002
|
+
"@tanstack/query/infinite-query-property-order": "error"
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
"flat/recommended": [
|
|
1006
|
+
{
|
|
1007
|
+
plugins: {
|
|
1008
|
+
"@tanstack/query": plugin
|
|
1009
|
+
},
|
|
1010
|
+
rules: {
|
|
1011
|
+
"@tanstack/query/exhaustive-deps": "error",
|
|
1012
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
1013
|
+
"@tanstack/query/stable-query-client": "error",
|
|
1014
|
+
"@tanstack/query/no-unstable-deps": "error",
|
|
1015
|
+
"@tanstack/query/infinite-query-property-order": "error"
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
]
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
// src/configs/react.ts
|
|
1022
|
+
function reactOverrides() {
|
|
1023
|
+
return {
|
|
1024
|
+
overrides: {}
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
function reactPlugins(options) {
|
|
1028
|
+
return options?.react ? [
|
|
1029
|
+
...plugin.configs["flat/recommended"]
|
|
1030
|
+
] : [];
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// src/configs/typescript.ts
|
|
1034
|
+
init_esm_shims();
|
|
1035
|
+
function typescript(options = {}) {
|
|
1036
|
+
const { overrides = {} } = options;
|
|
1037
|
+
return {
|
|
1038
|
+
...options,
|
|
1039
|
+
overrides: {
|
|
1040
|
+
"ts/array-type": [
|
|
1041
|
+
"error",
|
|
1042
|
+
{
|
|
1043
|
+
default: "generic"
|
|
1044
|
+
}
|
|
1045
|
+
],
|
|
1046
|
+
"ts/explicit-member-accessibility": [
|
|
1047
|
+
"error",
|
|
1048
|
+
{
|
|
1049
|
+
accessibility: "explicit"
|
|
1050
|
+
}
|
|
1051
|
+
],
|
|
1052
|
+
"ts/no-redeclare": "off",
|
|
1053
|
+
"ts/no-use-before-define": "off",
|
|
1054
|
+
...overrides
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// src/options.ts
|
|
1060
|
+
function oncourseOptions(options) {
|
|
1061
|
+
return {
|
|
1062
|
+
formatters: {
|
|
1063
|
+
css: true,
|
|
1064
|
+
html: true,
|
|
1065
|
+
markdown: true
|
|
1066
|
+
},
|
|
1067
|
+
lessOpinionated: true,
|
|
1068
|
+
name: "oncourse",
|
|
1069
|
+
react: options?.react ? reactOverrides() : false,
|
|
1070
|
+
...reactPlugins(options),
|
|
1071
|
+
stylistic: {
|
|
1072
|
+
indent: 2,
|
|
1073
|
+
quotes: "single",
|
|
1074
|
+
semi: true
|
|
1075
|
+
},
|
|
1076
|
+
typescript: typescript()
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/index.ts
|
|
1081
|
+
export * from "@antfu/eslint-config";
|
|
1082
|
+
function oncourse(options, ...configs) {
|
|
1083
|
+
return antfu(
|
|
1084
|
+
{
|
|
1085
|
+
...oncourseOptions(options),
|
|
1086
|
+
...options
|
|
1087
|
+
},
|
|
1088
|
+
...oncourseConfigs(options),
|
|
1089
|
+
...configs
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
var src_default = oncourse;
|
|
1093
|
+
export {
|
|
1094
|
+
src_default as default
|
|
1095
|
+
};
|