@tanstack/eslint-plugin-query 5.101.3 → 5.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/build/legacy/index.cjs +46 -1802
  2. package/build/legacy/index.cjs.map +1 -1
  3. package/build/legacy/index.d.cts +82 -3
  4. package/build/legacy/index.d.cts.map +1 -0
  5. package/build/legacy/index.d.ts +82 -3
  6. package/build/legacy/index.d.ts.map +1 -0
  7. package/build/legacy/index.js +39 -56
  8. package/build/legacy/index.js.map +1 -1
  9. package/build/legacy/rules-Bv1SB3jU.js +1172 -0
  10. package/build/legacy/rules-Bv1SB3jU.js.map +1 -0
  11. package/build/legacy/rules-ChMfhjqW.cjs +1177 -0
  12. package/build/legacy/rules-ChMfhjqW.cjs.map +1 -0
  13. package/build/legacy/rules.cjs +3 -1751
  14. package/build/legacy/rules.d.cts +7 -1
  15. package/build/legacy/rules.d.cts.map +1 -0
  16. package/build/legacy/rules.d.ts +7 -1
  17. package/build/legacy/rules.d.ts.map +1 -0
  18. package/build/legacy/rules.js +2 -7
  19. package/build/legacy/types.cjs +1 -19
  20. package/build/legacy/types.d.cts +7 -1
  21. package/build/legacy/types.d.cts.map +1 -0
  22. package/build/legacy/types.d.ts +7 -1
  23. package/build/legacy/types.d.ts.map +1 -0
  24. package/build/legacy/types.js +1 -1
  25. package/build/modern/index.cjs +46 -1788
  26. package/build/modern/index.cjs.map +1 -1
  27. package/build/modern/index.d.cts +83 -3
  28. package/build/modern/index.d.cts.map +1 -0
  29. package/build/modern/index.d.ts +83 -3
  30. package/build/modern/index.d.ts.map +1 -0
  31. package/build/modern/index.js +40 -56
  32. package/build/modern/index.js.map +1 -1
  33. package/build/modern/rules-B1yVUvLh.cjs +1158 -0
  34. package/build/modern/rules-B1yVUvLh.cjs.map +1 -0
  35. package/build/modern/rules-DzixDjO7.js +1153 -0
  36. package/build/modern/rules-DzixDjO7.js.map +1 -0
  37. package/build/modern/rules.cjs +3 -1737
  38. package/build/modern/rules.d.cts +8 -1
  39. package/build/modern/rules.d.cts.map +1 -0
  40. package/build/modern/rules.d.ts +8 -1
  41. package/build/modern/rules.d.ts.map +1 -0
  42. package/build/modern/rules.js +3 -7
  43. package/build/modern/types.cjs +1 -19
  44. package/build/modern/types.d.cts +8 -1
  45. package/build/modern/types.d.cts.map +1 -0
  46. package/build/modern/types.d.ts +8 -1
  47. package/build/modern/types.d.ts.map +1 -0
  48. package/build/modern/types.js +2 -1
  49. package/package.json +4 -6
  50. package/src/rules/exhaustive-deps/exhaustive-deps.utils.ts +15 -6
  51. package/src/rules/no-unstable-deps/no-unstable-deps.rule.ts +3 -3
  52. package/src/utils/ast-utils.ts +31 -198
  53. package/build/legacy/_tsup-dts-rollup.d.cts +0 -317
  54. package/build/legacy/_tsup-dts-rollup.d.ts +0 -317
  55. package/build/legacy/chunk-WVNZFPYE.js +0 -1725
  56. package/build/legacy/chunk-WVNZFPYE.js.map +0 -1
  57. package/build/legacy/rules.cjs.map +0 -1
  58. package/build/legacy/rules.js.map +0 -1
  59. package/build/legacy/types.cjs.map +0 -1
  60. package/build/legacy/types.js.map +0 -1
  61. package/build/modern/_tsup-dts-rollup.d.cts +0 -317
  62. package/build/modern/_tsup-dts-rollup.d.ts +0 -317
  63. package/build/modern/chunk-VALYN6GR.js +0 -1711
  64. package/build/modern/chunk-VALYN6GR.js.map +0 -1
  65. package/build/modern/rules.cjs.map +0 -1
  66. package/build/modern/rules.js.map +0 -1
  67. package/build/modern/types.cjs.map +0 -1
  68. package/build/modern/types.js.map +0 -1
@@ -1 +1,8 @@
1
- export { rules } from './_tsup-dts-rollup.cjs';
1
+ import { ExtraRuleDocs } from "./types.cjs";
2
+ import { ESLintUtils } from "@typescript-eslint/utils";
3
+ //#region src/rules.d.ts
4
+ declare const rules: Record<string, ESLintUtils.RuleModule<string, ReadonlyArray<unknown>, ExtraRuleDocs, ESLintUtils.RuleListener>>;
5
+ //#endregion
6
+ export { rules };
7
+
8
+ //# sourceMappingURL=rules.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.cts","names":[],"sources":["../../src/rules.ts"],"mappings":";;;cAWa,OAAO,eAElB,YAAY,mBAEV,wBACA,eACA,YAAY"}
@@ -1 +1,8 @@
1
- export { rules } from './_tsup-dts-rollup.js';
1
+ import { ExtraRuleDocs } from "./types.js";
2
+ import { ESLintUtils } from "@typescript-eslint/utils";
3
+ //#region src/rules.d.ts
4
+ declare const rules: Record<string, ESLintUtils.RuleModule<string, ReadonlyArray<unknown>, ExtraRuleDocs, ESLintUtils.RuleListener>>;
5
+ //#endregion
6
+ export { rules };
7
+
8
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","names":[],"sources":["../../src/rules.ts"],"mappings":";;;cAWa,OAAO,eAElB,YAAY,mBAEV,wBACA,eACA,YAAY"}
@@ -1,7 +1,3 @@
1
- import {
2
- rules
3
- } from "./chunk-VALYN6GR.js";
4
- export {
5
- rules
6
- };
7
- //# sourceMappingURL=rules.js.map
1
+ import { t as rules } from "./rules-DzixDjO7.js";
2
+ export { rules };
3
+
@@ -1,20 +1,2 @@
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
15
2
 
16
- // src/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
19
- module.exports = module.exports.default
20
- //# sourceMappingURL=types.cjs.map
@@ -1 +1,8 @@
1
- export { ExtraRuleDocs } from './_tsup-dts-rollup.cjs';
1
+ //#region src/types.d.ts
2
+ type ExtraRuleDocs = {
3
+ recommended: 'strict' | 'error' | 'warn';
4
+ };
5
+ //#endregion
6
+ export { ExtraRuleDocs };
7
+
8
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/types.ts"],"mappings":";KAAY;EACV"}
@@ -1 +1,8 @@
1
- export { ExtraRuleDocs } from './_tsup-dts-rollup.js';
1
+ //#region src/types.d.ts
2
+ type ExtraRuleDocs = {
3
+ recommended: 'strict' | 'error' | 'warn';
4
+ };
5
+ //#endregion
6
+ export { ExtraRuleDocs };
7
+
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";KAAY;EACV"}
@@ -1 +1,2 @@
1
- //# sourceMappingURL=types.js.map
1
+ export {};
2
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/eslint-plugin-query",
3
- "version": "5.101.3",
3
+ "version": "5.102.0",
4
4
  "description": "ESLint plugin for TanStack Query",
5
5
  "author": "Eliya Cohen",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "peerDependencies": {
53
53
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
54
- "typescript": "^5.4.0 || ^6.0.0"
54
+ "typescript": "^5.6.0 || ^6.0.0 || ^7.0.0"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
57
  "typescript": {
@@ -63,17 +63,15 @@
63
63
  "compile": "tsc --build",
64
64
  "test:eslint": "eslint --concurrency=auto ./src",
65
65
  "test:types": "npm-run-all --serial test:types:*",
66
- "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build",
67
- "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build",
68
66
  "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build",
69
67
  "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build",
70
68
  "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --build",
71
69
  "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --build",
72
70
  "test:types:tscurrent": "tsc --build",
73
- "test:types:ts60": "node ../../node_modules/typescript60/lib/tsc.js --build",
71
+ "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --build",
74
72
  "test:lib": "vitest",
75
73
  "test:lib:dev": "pnpm run test:lib --watch",
76
74
  "test:build": "publint --strict && attw --pack",
77
- "build": "tsup --tsconfig tsconfig.prod.json"
75
+ "build": "tsdown --tsconfig tsconfig.prod.json"
78
76
  }
79
77
  }
@@ -55,11 +55,24 @@ export const ExhaustiveDepsUtils = {
55
55
 
56
56
  return (
57
57
  reference.identifier.name !== 'undefined' &&
58
+ !ExhaustiveDepsUtils.isFunctionCallTarget(reference.identifier) &&
58
59
  reference.identifier.parent.type !== AST_NODE_TYPES.NewExpression &&
59
60
  !ExhaustiveDepsUtils.isInstanceOfKind(reference.identifier.parent)
60
61
  )
61
62
  },
62
63
 
64
+ isFunctionCallTarget(
65
+ identifier: TSESTree.Identifier | TSESTree.JSXIdentifier,
66
+ ): boolean {
67
+ const callee = ASTUtils.traverseUpMemberExpression(identifier)
68
+
69
+ return (
70
+ callee.parent !== undefined &&
71
+ callee.parent.type === AST_NODE_TYPES.CallExpression &&
72
+ callee.parent.callee === callee
73
+ )
74
+ },
75
+
63
76
  /**
64
77
  * Given required refs and existing queryKey entries, compute missing dependency paths
65
78
  * respecting allowlisted variables and types.
@@ -272,7 +285,7 @@ export const ExhaustiveDepsUtils = {
272
285
  isInstanceOfKind(node: TSESTree.Node) {
273
286
  return (
274
287
  node.type === AST_NODE_TYPES.BinaryExpression &&
275
- node.operator === 'instanceof'
288
+ (node as TSESTree.SymmetricBinaryExpression).operator === 'instanceof'
276
289
  )
277
290
  },
278
291
 
@@ -296,11 +309,7 @@ export const ExhaustiveDepsUtils = {
296
309
  }): { path: string; root: string; coversRootMembers: boolean } | null {
297
310
  const { identifier, sourceCode } = params
298
311
 
299
- const fullChainNode = ASTUtils.traverseUpOnly(identifier, [
300
- AST_NODE_TYPES.MemberExpression,
301
- AST_NODE_TYPES.TSNonNullExpression,
302
- AST_NODE_TYPES.Identifier,
303
- ])
312
+ const fullChainNode = ASTUtils.traverseUpMemberExpression(identifier)
304
313
 
305
314
  const fullText = ExhaustiveDepsUtils.normalizeChain(
306
315
  sourceCode.getText(fullChainNode),
@@ -35,9 +35,9 @@ export const rule = createRule({
35
35
  defaultOptions: [],
36
36
 
37
37
  create: detectTanstackQueryImports((context, _options, helpers) => {
38
- const trackedVariables: Record<string, string> = {}
39
- const trackedCustomHooks: Record<string, string> = {}
40
- const hookAliasMap: Record<string, string> = {}
38
+ const trackedVariables: Record<string, string> = Object.create(null)
39
+ const trackedCustomHooks: Record<string, string> = Object.create(null)
40
+ const hookAliasMap: Record<string, string> = Object.create(null)
41
41
  const pendingVariableDeclarators: Array<TSESTree.VariableDeclarator> = []
42
42
  const pendingDependencyChecks: Array<{
43
43
  reactHook: string
@@ -46,91 +46,6 @@ export const ASTUtils = {
46
46
  ASTUtils.isPropertyWithIdentifierKey(x, key),
47
47
  )
48
48
  },
49
- getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier> {
50
- const identifiers: Array<TSESTree.Identifier> = []
51
-
52
- if (ASTUtils.isIdentifier(node)) {
53
- identifiers.push(node)
54
- }
55
-
56
- if ('arguments' in node) {
57
- node.arguments.forEach((x) => {
58
- identifiers.push(...ASTUtils.getNestedIdentifiers(x))
59
- })
60
- }
61
-
62
- if ('elements' in node) {
63
- node.elements.forEach((x) => {
64
- if (x !== null) {
65
- identifiers.push(...ASTUtils.getNestedIdentifiers(x))
66
- }
67
- })
68
- }
69
-
70
- if ('properties' in node) {
71
- node.properties.forEach((x) => {
72
- identifiers.push(...ASTUtils.getNestedIdentifiers(x))
73
- })
74
- }
75
-
76
- if ('expressions' in node) {
77
- node.expressions.forEach((x) => {
78
- identifiers.push(...ASTUtils.getNestedIdentifiers(x))
79
- })
80
- }
81
-
82
- if ('left' in node) {
83
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.left))
84
- }
85
-
86
- if ('right' in node) {
87
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.right))
88
- }
89
-
90
- if (node.type === AST_NODE_TYPES.Property) {
91
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.value))
92
- }
93
-
94
- if (node.type === AST_NODE_TYPES.SpreadElement) {
95
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))
96
- }
97
-
98
- if (node.type === AST_NODE_TYPES.MemberExpression) {
99
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.object))
100
- }
101
-
102
- if (node.type === AST_NODE_TYPES.UnaryExpression) {
103
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))
104
- }
105
-
106
- if (node.type === AST_NODE_TYPES.ChainExpression) {
107
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))
108
- }
109
-
110
- if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
111
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))
112
- }
113
-
114
- if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
115
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body))
116
- }
117
-
118
- if (node.type === AST_NODE_TYPES.FunctionExpression) {
119
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.body))
120
- }
121
-
122
- if (node.type === AST_NODE_TYPES.BlockStatement) {
123
- identifiers.push(
124
- ...node.body.map((body) => ASTUtils.getNestedIdentifiers(body)).flat(),
125
- )
126
- }
127
-
128
- if (node.type === AST_NODE_TYPES.ReturnStatement && node.argument) {
129
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))
130
- }
131
-
132
- return identifiers
133
- },
134
49
  traverseUpOnly(
135
50
  identifier: TSESTree.Node,
136
51
  allowedNodeTypes: Array<AST_NODE_TYPES>,
@@ -143,6 +58,21 @@ export const ASTUtils = {
143
58
 
144
59
  return identifier
145
60
  },
61
+ traverseUpMemberExpression(node: TSESTree.Node): TSESTree.Node {
62
+ const parent = node.parent
63
+
64
+ if (
65
+ parent !== undefined &&
66
+ ((parent.type === AST_NODE_TYPES.MemberExpression &&
67
+ parent.object === node) ||
68
+ parent.type === AST_NODE_TYPES.ChainExpression ||
69
+ parent.type === AST_NODE_TYPES.TSNonNullExpression)
70
+ ) {
71
+ return ASTUtils.traverseUpMemberExpression(parent)
72
+ }
73
+
74
+ return node
75
+ },
146
76
  isDeclaredInNode(params: {
147
77
  functionNode: TSESTree.Node
148
78
  reference: TSESLint.Scope.Reference
@@ -184,10 +114,22 @@ export const ASTUtils = {
184
114
  const references = collectReferences(scope)
185
115
  .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))
186
116
  .map((x) => {
187
- const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
188
- AST_NODE_TYPES.MemberExpression,
189
- AST_NODE_TYPES.Identifier,
190
- ])
117
+ const memberPath = ASTUtils.traverseUpMemberExpression(x.identifier)
118
+ const memberExpression = memberPath.parent
119
+ const isComputedCallProperty =
120
+ memberExpression !== undefined &&
121
+ memberExpression.type === AST_NODE_TYPES.MemberExpression &&
122
+ memberExpression.computed &&
123
+ memberExpression.property === memberPath &&
124
+ memberExpression.parent.type === AST_NODE_TYPES.CallExpression &&
125
+ memberExpression.parent.callee === memberExpression
126
+
127
+ const referenceNode = isComputedCallProperty
128
+ ? memberPath
129
+ : ASTUtils.traverseUpOnly(x.identifier, [
130
+ AST_NODE_TYPES.MemberExpression,
131
+ AST_NODE_TYPES.Identifier,
132
+ ])
191
133
 
192
134
  return {
193
135
  variable: x,
@@ -206,27 +148,6 @@ export const ASTUtils = {
206
148
 
207
149
  return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable)
208
150
  },
209
- mapKeyNodeToText(
210
- node: TSESTree.Node,
211
- sourceCode: Readonly<TSESLint.SourceCode>,
212
- ) {
213
- return sourceCode.getText(
214
- ASTUtils.traverseUpOnly(node, [
215
- AST_NODE_TYPES.MemberExpression,
216
- AST_NODE_TYPES.TSNonNullExpression,
217
- AST_NODE_TYPES.Identifier,
218
- ]),
219
- )
220
- },
221
- mapKeyNodeToBaseText(
222
- node: TSESTree.Node,
223
- sourceCode: Readonly<TSESLint.SourceCode>,
224
- ) {
225
- return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
226
- /(?:\?(\.)|!)/g,
227
- '$1',
228
- )
229
- },
230
151
  isValidReactComponentOrHookName(
231
152
  identifier: TSESTree.Identifier | null | undefined,
232
153
  ) {
@@ -289,92 +210,4 @@ export const ASTUtils = {
289
210
 
290
211
  return resolvedNode.init
291
212
  },
292
- getClosestVariableDeclarator(node: TSESTree.Node) {
293
- let currentNode: TSESTree.Node | undefined = node
294
-
295
- while (currentNode.type !== AST_NODE_TYPES.Program) {
296
- if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {
297
- return currentNode
298
- }
299
-
300
- currentNode = currentNode.parent
301
- }
302
-
303
- return undefined
304
- },
305
- getNestedReturnStatements(
306
- node: TSESTree.Node,
307
- ): Array<TSESTree.ReturnStatement> {
308
- const returnStatements: Array<TSESTree.ReturnStatement> = []
309
-
310
- if (node.type === AST_NODE_TYPES.ReturnStatement) {
311
- returnStatements.push(node)
312
- }
313
-
314
- if ('body' in node && node.body !== undefined && node.body !== null) {
315
- Array.isArray(node.body)
316
- ? node.body.forEach((x) => {
317
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x))
318
- })
319
- : returnStatements.push(
320
- ...ASTUtils.getNestedReturnStatements(node.body),
321
- )
322
- }
323
-
324
- if ('consequent' in node) {
325
- Array.isArray(node.consequent)
326
- ? node.consequent.forEach((x) => {
327
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x))
328
- })
329
- : returnStatements.push(
330
- ...ASTUtils.getNestedReturnStatements(node.consequent),
331
- )
332
- }
333
-
334
- if ('alternate' in node && node.alternate !== null) {
335
- Array.isArray(node.alternate)
336
- ? node.alternate.forEach((x) => {
337
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x))
338
- })
339
- : returnStatements.push(
340
- ...ASTUtils.getNestedReturnStatements(node.alternate),
341
- )
342
- }
343
-
344
- if ('cases' in node) {
345
- node.cases.forEach((x) => {
346
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x))
347
- })
348
- }
349
-
350
- if ('block' in node) {
351
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block))
352
- }
353
-
354
- if ('handler' in node && node.handler !== null) {
355
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler))
356
- }
357
-
358
- if ('finalizer' in node && node.finalizer !== null) {
359
- returnStatements.push(
360
- ...ASTUtils.getNestedReturnStatements(node.finalizer),
361
- )
362
- }
363
-
364
- if (
365
- 'expression' in node &&
366
- node.expression !== true &&
367
- node.expression !== false
368
- ) {
369
- returnStatements.push(
370
- ...ASTUtils.getNestedReturnStatements(node.expression),
371
- )
372
- }
373
-
374
- if ('test' in node && node.test !== null) {
375
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test))
376
- }
377
-
378
- return returnStatements
379
- },
380
213
  }