@tanstack/eslint-plugin-query 5.0.0-alpha.88 → 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.
Files changed (79) hide show
  1. package/build/legacy/configs/index.cjs +46 -0
  2. package/build/legacy/configs/index.cjs.map +1 -0
  3. package/build/legacy/configs/index.d.cts +8 -0
  4. package/build/legacy/configs/index.d.ts +8 -0
  5. package/build/legacy/configs/index.js +21 -0
  6. package/build/legacy/configs/index.js.map +1 -0
  7. package/build/legacy/configs/index.test.cjs +21 -0
  8. package/build/legacy/configs/index.test.cjs.map +1 -0
  9. package/build/legacy/configs/index.test.d.cts +2 -0
  10. package/build/legacy/configs/index.test.d.ts +2 -0
  11. package/build/legacy/configs/index.test.js +19 -0
  12. package/build/legacy/configs/index.test.js.map +1 -0
  13. package/build/legacy/index.cjs +28 -431
  14. package/build/legacy/index.cjs.map +1 -1
  15. package/build/legacy/index.d.cts +3 -14
  16. package/build/legacy/index.d.ts +3 -14
  17. package/build/legacy/index.js +3 -432
  18. package/build/legacy/index.js.map +1 -1
  19. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.cjs +141 -0
  20. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.cjs.map +1 -0
  21. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.d.cts +6 -0
  22. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.d.ts +6 -0
  23. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.js +115 -0
  24. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.rule.js.map +1 -0
  25. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.cjs +722 -0
  26. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.cjs.map +1 -0
  27. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.d.cts +2 -0
  28. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.d.ts +2 -0
  29. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.js +720 -0
  30. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.test.js.map +1 -0
  31. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.cjs +52 -0
  32. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.cjs.map +1 -0
  33. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.d.cts +12 -0
  34. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.d.ts +12 -0
  35. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.js +27 -0
  36. package/build/legacy/rules/exhaustive-deps/exhaustive-deps.utils.js.map +1 -0
  37. package/build/legacy/rules/index.cjs +44 -0
  38. package/build/legacy/rules/index.cjs.map +1 -0
  39. package/build/legacy/rules/index.d.cts +7 -0
  40. package/build/legacy/rules/index.d.ts +7 -0
  41. package/build/legacy/rules/index.js +9 -0
  42. package/build/legacy/rules/index.js.map +1 -0
  43. package/build/legacy/utils/ast-utils.cjs +247 -0
  44. package/build/legacy/utils/ast-utils.cjs.map +1 -0
  45. package/build/legacy/utils/ast-utils.d.cts +41 -0
  46. package/build/legacy/utils/ast-utils.d.ts +41 -0
  47. package/build/legacy/utils/ast-utils.js +222 -0
  48. package/build/legacy/utils/ast-utils.js.map +1 -0
  49. package/build/legacy/utils/create-rule.cjs +39 -0
  50. package/build/legacy/utils/create-rule.cjs.map +1 -0
  51. package/build/legacy/utils/create-rule.d.cts +10 -0
  52. package/build/legacy/utils/create-rule.d.ts +10 -0
  53. package/build/legacy/utils/create-rule.js +14 -0
  54. package/build/legacy/utils/create-rule.js.map +1 -0
  55. package/build/legacy/utils/detect-react-query-imports.cjs +70 -0
  56. package/build/legacy/utils/detect-react-query-imports.cjs.map +1 -0
  57. package/build/legacy/utils/detect-react-query-imports.d.cts +12 -0
  58. package/build/legacy/utils/detect-react-query-imports.d.ts +12 -0
  59. package/build/legacy/utils/detect-react-query-imports.js +45 -0
  60. package/build/legacy/utils/detect-react-query-imports.js.map +1 -0
  61. package/build/legacy/utils/object-utils.cjs +33 -0
  62. package/build/legacy/utils/object-utils.cjs.map +1 -0
  63. package/build/legacy/utils/object-utils.d.cts +3 -0
  64. package/build/legacy/utils/object-utils.d.ts +3 -0
  65. package/build/legacy/utils/object-utils.js +8 -0
  66. package/build/legacy/utils/object-utils.js.map +1 -0
  67. package/build/legacy/utils/test-utils.cjs +36 -0
  68. package/build/legacy/utils/test-utils.cjs.map +1 -0
  69. package/build/legacy/utils/test-utils.d.cts +3 -0
  70. package/build/legacy/utils/test-utils.d.ts +3 -0
  71. package/build/legacy/utils/test-utils.js +11 -0
  72. package/build/legacy/utils/test-utils.js.map +1 -0
  73. package/build/legacy/utils/unique-by.cjs +33 -0
  74. package/build/legacy/utils/unique-by.cjs.map +1 -0
  75. package/build/legacy/utils/unique-by.d.cts +3 -0
  76. package/build/legacy/utils/unique-by.d.ts +3 -0
  77. package/build/legacy/utils/unique-by.js +8 -0
  78. package/build/legacy/utils/unique-by.js.map +1 -0
  79. package/package.json +2 -2
@@ -0,0 +1,46 @@
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/configs/index.ts
21
+ var configs_exports = {};
22
+ __export(configs_exports, {
23
+ configs: () => configs
24
+ });
25
+ module.exports = __toCommonJS(configs_exports);
26
+ var import_rules = require("../rules.cjs");
27
+ function generateRecommendedConfig(allRules) {
28
+ return Object.entries(allRules).reduce((memo, [name, rule]) => {
29
+ const { recommended } = rule.meta.docs || {};
30
+ return {
31
+ ...memo,
32
+ ...recommended ? { [`@tanstack/query/${name}`]: recommended } : {}
33
+ };
34
+ }, {});
35
+ }
36
+ var configs = {
37
+ recommended: {
38
+ plugins: ["@tanstack/eslint-plugin-query"],
39
+ rules: generateRecommendedConfig(import_rules.rules)
40
+ }
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ configs
45
+ });
46
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/configs/index.ts"],"sourcesContent":["import { rules } from '../rules'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<string, TSESLint.RuleModule<any, any>>,\n) {\n return Object.entries(allRules).reduce((memo, [name, rule]) => {\n const { recommended } = rule.meta.docs || {}\n\n return {\n ...memo,\n ...(recommended ? { [`@tanstack/query/${name}`]: recommended } : {}),\n }\n }, {} as Record<string, 'strict' | 'error' | 'warn'>)\n}\n\nexport const configs = {\n recommended: {\n plugins: ['@tanstack/eslint-plugin-query'],\n rules: generateRecommendedConfig(rules),\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAGtB,SAAS,0BACP,UACA;AACA,SAAO,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM;AAC7D,UAAM,EAAE,YAAY,IAAI,KAAK,KAAK,QAAQ,CAAC;AAE3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,cAAc,EAAE,CAAC,mBAAmB,IAAI,EAAE,GAAG,YAAY,IAAI,CAAC;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,CAAgD;AACtD;AAEO,IAAM,UAAU;AAAA,EACrB,aAAa;AAAA,IACX,SAAS,CAAC,+BAA+B;AAAA,IACzC,OAAO,0BAA0B,kBAAK;AAAA,EACxC;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ declare const configs: {
2
+ recommended: {
3
+ plugins: string[];
4
+ rules: Record<string, "error" | "strict" | "warn">;
5
+ };
6
+ };
7
+
8
+ export { configs };
@@ -0,0 +1,8 @@
1
+ declare const configs: {
2
+ recommended: {
3
+ plugins: string[];
4
+ rules: Record<string, "error" | "strict" | "warn">;
5
+ };
6
+ };
7
+
8
+ export { configs };
@@ -0,0 +1,21 @@
1
+ // src/configs/index.ts
2
+ import { rules } from "../rules.js";
3
+ function generateRecommendedConfig(allRules) {
4
+ return Object.entries(allRules).reduce((memo, [name, rule]) => {
5
+ const { recommended } = rule.meta.docs || {};
6
+ return {
7
+ ...memo,
8
+ ...recommended ? { [`@tanstack/query/${name}`]: recommended } : {}
9
+ };
10
+ }, {});
11
+ }
12
+ var configs = {
13
+ recommended: {
14
+ plugins: ["@tanstack/eslint-plugin-query"],
15
+ rules: generateRecommendedConfig(rules)
16
+ }
17
+ };
18
+ export {
19
+ configs
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/configs/index.ts"],"sourcesContent":["import { rules } from '../rules'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<string, TSESLint.RuleModule<any, any>>,\n) {\n return Object.entries(allRules).reduce((memo, [name, rule]) => {\n const { recommended } = rule.meta.docs || {}\n\n return {\n ...memo,\n ...(recommended ? { [`@tanstack/query/${name}`]: recommended } : {}),\n }\n }, {} as Record<string, 'strict' | 'error' | 'warn'>)\n}\n\nexport const configs = {\n recommended: {\n plugins: ['@tanstack/eslint-plugin-query'],\n rules: generateRecommendedConfig(rules),\n },\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAGtB,SAAS,0BACP,UACA;AACA,SAAO,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM;AAC7D,UAAM,EAAE,YAAY,IAAI,KAAK,KAAK,QAAQ,CAAC;AAE3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,cAAc,EAAE,CAAC,mBAAmB,IAAI,EAAE,GAAG,YAAY,IAAI,CAAC;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,CAAgD;AACtD;AAEO,IAAM,UAAU;AAAA,EACrB,aAAa;AAAA,IACX,SAAS,CAAC,+BAA+B;AAAA,IACzC,OAAO,0BAA0B,KAAK;AAAA,EACxC;AACF;","names":[]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ // src/configs/index.test.ts
4
+ var import_index = require("./index.cjs");
5
+ describe("configs", () => {
6
+ it("should match snapshot", () => {
7
+ expect(import_index.configs).toMatchInlineSnapshot(`
8
+ {
9
+ "recommended": {
10
+ "plugins": [
11
+ "@tanstack/eslint-plugin-query",
12
+ ],
13
+ "rules": {
14
+ "@tanstack/query/exhaustive-deps": "error",
15
+ },
16
+ },
17
+ }
18
+ `);
19
+ });
20
+ });
21
+ //# sourceMappingURL=index.test.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/configs/index.test.ts"],"sourcesContent":["import { configs } from './index'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";;;AAAA,mBAAwB;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,yBAAyB,MAAM;AAChC,WAAO,oBAAO,EAAE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAWrC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,19 @@
1
+ // src/configs/index.test.ts
2
+ import { configs } from "./index.js";
3
+ describe("configs", () => {
4
+ it("should match snapshot", () => {
5
+ expect(configs).toMatchInlineSnapshot(`
6
+ {
7
+ "recommended": {
8
+ "plugins": [
9
+ "@tanstack/eslint-plugin-query",
10
+ ],
11
+ "rules": {
12
+ "@tanstack/query/exhaustive-deps": "error",
13
+ },
14
+ },
15
+ }
16
+ `);
17
+ });
18
+ });
19
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/configs/index.test.ts"],"sourcesContent":["import { configs } from './index'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,yBAAyB,MAAM;AAChC,WAAO,OAAO,EAAE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAWrC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
@@ -1,437 +1,34 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/rules/exhaustive-deps/exhaustive-deps.rule.ts
2
- var _utils = require('@typescript-eslint/utils');
3
-
4
- // src/utils/ast-utils.ts
5
-
6
-
7
- // src/utils/unique-by.ts
8
- function uniqueBy(arr, fn) {
9
- return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
10
- }
11
-
12
- // src/utils/ast-utils.ts
13
- var ASTUtils = {
14
- isNodeOfOneOf(node, types) {
15
- return types.includes(node.type);
16
- },
17
- isIdentifier(node) {
18
- return node.type === _utils.AST_NODE_TYPES.Identifier;
19
- },
20
- isIdentifierWithName(node, name2) {
21
- return ASTUtils.isIdentifier(node) && node.name === name2;
22
- },
23
- isIdentifierWithOneOfNames(node, name2) {
24
- return ASTUtils.isIdentifier(node) && name2.includes(node.name);
25
- },
26
- isProperty(node) {
27
- return node.type === _utils.AST_NODE_TYPES.Property;
28
- },
29
- isObjectExpression(node) {
30
- return node.type === _utils.AST_NODE_TYPES.ObjectExpression;
31
- },
32
- isPropertyWithIdentifierKey(node, key) {
33
- return ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key);
34
- },
35
- findPropertyWithIdentifierKey(properties, key) {
36
- return properties.find(
37
- (x) => ASTUtils.isPropertyWithIdentifierKey(x, key)
38
- );
39
- },
40
- getNestedIdentifiers(node) {
41
- const identifiers = [];
42
- if (ASTUtils.isIdentifier(node)) {
43
- identifiers.push(node);
44
- }
45
- if ("arguments" in node) {
46
- node.arguments.forEach((x) => {
47
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
48
- });
49
- }
50
- if ("elements" in node) {
51
- node.elements.forEach((x) => {
52
- if (x !== null) {
53
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
54
- }
55
- });
56
- }
57
- if ("properties" in node) {
58
- node.properties.forEach((x) => {
59
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
60
- });
61
- }
62
- if ("expressions" in node) {
63
- node.expressions.forEach((x) => {
64
- identifiers.push(...ASTUtils.getNestedIdentifiers(x));
65
- });
66
- }
67
- if (node.type === _utils.AST_NODE_TYPES.Property) {
68
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.value));
69
- }
70
- if (node.type === _utils.AST_NODE_TYPES.SpreadElement) {
71
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
72
- }
73
- if (node.type === _utils.AST_NODE_TYPES.MemberExpression) {
74
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.object));
75
- }
76
- if (node.type === _utils.AST_NODE_TYPES.UnaryExpression) {
77
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument));
78
- }
79
- if (node.type === _utils.AST_NODE_TYPES.ChainExpression) {
80
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
81
- }
82
- if (node.type === _utils.AST_NODE_TYPES.TSNonNullExpression) {
83
- identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression));
84
- }
85
- return identifiers;
86
- },
87
- isAncestorIsCallee(identifier) {
88
- let previousNode = identifier;
89
- let currentNode = identifier.parent;
90
- while (currentNode !== void 0) {
91
- if (currentNode.type === _utils.AST_NODE_TYPES.CallExpression && currentNode.callee === previousNode) {
92
- return true;
93
- }
94
- if (currentNode.type !== _utils.AST_NODE_TYPES.MemberExpression) {
95
- return false;
96
- }
97
- previousNode = currentNode;
98
- currentNode = currentNode.parent;
99
- }
100
- return false;
101
- },
102
- traverseUpOnly(identifier, allowedNodeTypes) {
103
- const parent = identifier.parent;
104
- if (parent !== void 0 && allowedNodeTypes.includes(parent.type)) {
105
- return ASTUtils.traverseUpOnly(parent, allowedNodeTypes);
106
- }
107
- return identifier;
108
- },
109
- isDeclaredInNode(params) {
110
- const { functionNode, reference, scopeManager } = params;
111
- const scope = scopeManager.acquire(functionNode);
112
- if (scope === null) {
113
- return false;
114
- }
115
- return scope.set.has(reference.identifier.name);
116
- },
117
- getExternalRefs(params) {
118
- const { scopeManager, sourceCode, node } = params;
119
- const scope = scopeManager.acquire(node);
120
- if (scope === null) {
121
- return [];
122
- }
123
- const references = scope.references.filter((x) => x.isRead() && !scope.set.has(x.identifier.name)).map((x) => {
124
- const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
125
- _utils.AST_NODE_TYPES.MemberExpression,
126
- _utils.AST_NODE_TYPES.Identifier
127
- ]);
128
- return {
129
- variable: x,
130
- node: referenceNode,
131
- text: sourceCode.getText(referenceNode)
132
- };
133
- });
134
- const localRefIds = new Set(
135
- [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0]))
136
- );
137
- const externalRefs = references.filter(
138
- (x) => x.variable.resolved === null || !localRefIds.has(x.text)
139
- );
140
- return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable);
141
- },
142
- mapKeyNodeToText(node, sourceCode) {
143
- return sourceCode.getText(
144
- ASTUtils.traverseUpOnly(node, [
145
- _utils.AST_NODE_TYPES.MemberExpression,
146
- _utils.AST_NODE_TYPES.Identifier
147
- ])
148
- );
149
- },
150
- isValidReactComponentOrHookName(identifier) {
151
- return identifier !== null && /^(use|[A-Z])/.test(identifier.name);
152
- },
153
- getFunctionAncestor(context) {
154
- return context.getAncestors().find((x) => {
155
- var _a;
156
- if (x.type === _utils.AST_NODE_TYPES.FunctionDeclaration) {
157
- return true;
158
- }
159
- return ((_a = x.parent) == null ? void 0 : _a.type) === _utils.AST_NODE_TYPES.VariableDeclarator && x.parent.id.type === _utils.AST_NODE_TYPES.Identifier && ASTUtils.isNodeOfOneOf(x, [
160
- _utils.AST_NODE_TYPES.FunctionDeclaration,
161
- _utils.AST_NODE_TYPES.FunctionExpression,
162
- _utils.AST_NODE_TYPES.ArrowFunctionExpression
163
- ]);
164
- });
165
- },
166
- getReferencedExpressionByIdentifier(params) {
167
- var _a, _b, _c;
168
- const { node, context } = params;
169
- 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;
170
- if ((resolvedNode == null ? void 0 : resolvedNode.type) !== _utils.AST_NODE_TYPES.VariableDeclarator) {
171
- return null;
172
- }
173
- return resolvedNode.init;
174
- },
175
- getNestedReturnStatements(node) {
176
- const returnStatements = [];
177
- if (node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
178
- returnStatements.push(node);
179
- }
180
- if ("body" in node && node.body !== void 0 && node.body !== null) {
181
- Array.isArray(node.body) ? node.body.forEach((x) => {
182
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
183
- }) : returnStatements.push(
184
- ...ASTUtils.getNestedReturnStatements(node.body)
185
- );
186
- }
187
- if ("consequent" in node) {
188
- Array.isArray(node.consequent) ? node.consequent.forEach((x) => {
189
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
190
- }) : returnStatements.push(
191
- ...ASTUtils.getNestedReturnStatements(node.consequent)
192
- );
193
- }
194
- if ("alternate" in node && node.alternate !== null) {
195
- Array.isArray(node.alternate) ? node.alternate.forEach((x) => {
196
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
197
- }) : returnStatements.push(
198
- ...ASTUtils.getNestedReturnStatements(node.alternate)
199
- );
200
- }
201
- if ("cases" in node) {
202
- node.cases.forEach((x) => {
203
- returnStatements.push(...ASTUtils.getNestedReturnStatements(x));
204
- });
205
- }
206
- if ("block" in node) {
207
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block));
208
- }
209
- if ("handler" in node && node.handler !== null) {
210
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler));
211
- }
212
- if ("finalizer" in node && node.finalizer !== null) {
213
- returnStatements.push(
214
- ...ASTUtils.getNestedReturnStatements(node.finalizer)
215
- );
216
- }
217
- if ("expression" in node && node.expression !== true && node.expression !== false) {
218
- returnStatements.push(
219
- ...ASTUtils.getNestedReturnStatements(node.expression)
220
- );
221
- }
222
- if ("test" in node && node.test !== null) {
223
- returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test));
224
- }
225
- return returnStatements;
226
- }
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 });
227
9
  };
228
-
229
- // src/utils/create-rule.ts
230
-
231
-
232
- // src/utils/detect-react-query-imports.ts
233
- function detectTanstackQueryImports(create) {
234
- return (context, optionsWithDefault) => {
235
- const tanstackQueryImportSpecifiers = [];
236
- const helpers = {
237
- isTanstackQueryImport(node) {
238
- return !!tanstackQueryImportSpecifiers.find((specifier) => {
239
- if (specifier.type === "ImportSpecifier") {
240
- return node.name === specifier.local.name;
241
- }
242
- return false;
243
- });
244
- }
245
- };
246
- const detectionInstructions = {
247
- ImportDeclaration(node) {
248
- if (node.specifiers.length > 0 && node.importKind === "value" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-query")) {
249
- tanstackQueryImportSpecifiers.push(...node.specifiers);
250
- }
251
- }
252
- };
253
- const ruleInstructions = create(context, optionsWithDefault, helpers);
254
- const enhancedRuleInstructions = {};
255
- const allKeys = new Set(
256
- Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
257
- );
258
- allKeys.forEach((instruction) => {
259
- enhancedRuleInstructions[instruction] = (node) => {
260
- var _a, _b;
261
- if (instruction in detectionInstructions) {
262
- (_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, node);
263
- }
264
- if (ruleInstructions[instruction]) {
265
- return (_b = ruleInstructions[instruction]) == null ? void 0 : _b.call(ruleInstructions, node);
266
- }
267
- return void 0;
268
- };
269
- });
270
- return enhancedRuleInstructions;
271
- };
272
- }
273
-
274
- // src/utils/create-rule.ts
275
- var getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
276
- function createRule({ create, ...rest }) {
277
- return _utils.ESLintUtils.RuleCreator(getDocsUrl)({
278
- ...rest,
279
- create: detectTanstackQueryImports(create)
280
- });
281
- }
282
-
283
- // src/rules/exhaustive-deps/exhaustive-deps.utils.ts
284
-
285
- var ExhaustiveDepsUtils = {
286
- isRelevantReference(params) {
287
- var _a;
288
- const { reference, scopeManager, context } = params;
289
- const component = ASTUtils.getFunctionAncestor(context);
290
- if (component !== void 0 && !ASTUtils.isDeclaredInNode({
291
- scopeManager,
292
- reference,
293
- functionNode: component
294
- })) {
295
- return false;
296
- }
297
- return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== _utils.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
298
- },
299
- isQueryClientReference(reference) {
300
- var _a, _b, _c;
301
- const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
302
- return (declarator == null ? void 0 : declarator.type) === _utils.AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === _utils.AST_NODE_TYPES.CallExpression && declarator.init.callee.type === _utils.AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
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 });
303
15
  }
16
+ return to;
304
17
  };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
305
19
 
306
- // src/rules/exhaustive-deps/exhaustive-deps.rule.ts
307
- var QUERY_KEY = "queryKey";
308
- var QUERY_FN = "queryFn";
309
- var name = "exhaustive-deps";
310
- var rule = createRule({
311
- name,
312
- meta: {
313
- type: "problem",
314
- docs: {
315
- description: "Exhaustive deps rule for useQuery",
316
- recommended: "error"
317
- },
318
- messages: {
319
- missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
320
- fixTo: "Fix to {{result}}"
321
- },
322
- hasSuggestions: true,
323
- fixable: "code",
324
- schema: []
325
- },
326
- defaultOptions: [],
327
- create(context) {
328
- return {
329
- Property(node) {
330
- if (node.parent === void 0 || !ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
331
- return;
332
- }
333
- const scopeManager = context.getSourceCode().scopeManager;
334
- const queryKey = ASTUtils.findPropertyWithIdentifierKey(
335
- node.parent.properties,
336
- QUERY_KEY
337
- );
338
- const queryFn = ASTUtils.findPropertyWithIdentifierKey(
339
- node.parent.properties,
340
- QUERY_FN
341
- );
342
- if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || queryFn.value.type !== _utils.AST_NODE_TYPES.ArrowFunctionExpression) {
343
- return;
344
- }
345
- let queryKeyNode = queryKey.value;
346
- if (queryKeyNode.type === _utils.AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === _utils.AST_NODE_TYPES.ArrayExpression) {
347
- queryKeyNode = queryKeyNode.expression;
348
- }
349
- if (queryKeyNode.type === _utils.AST_NODE_TYPES.Identifier) {
350
- const expression = ASTUtils.getReferencedExpressionByIdentifier({
351
- context,
352
- node: queryKeyNode
353
- });
354
- if ((expression == null ? void 0 : expression.type) === _utils.AST_NODE_TYPES.ArrayExpression) {
355
- queryKeyNode = expression;
356
- }
357
- }
358
- const sourceCode = context.getSourceCode();
359
- const queryKeyValue = queryKeyNode;
360
- const externalRefs = ASTUtils.getExternalRefs({
361
- scopeManager,
362
- sourceCode,
363
- node: queryFn.value
364
- });
365
- const relevantRefs = externalRefs.filter(
366
- (reference) => ExhaustiveDepsUtils.isRelevantReference({
367
- context,
368
- reference,
369
- scopeManager
370
- })
371
- );
372
- const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(
373
- (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode)
374
- );
375
- const missingRefs = relevantRefs.map((ref) => ({
376
- ref,
377
- text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)
378
- })).filter(({ ref, text }) => {
379
- return !ref.isTypeReference && !ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(_nullishCoalesce(text.split(".")[0], () => ( "")));
380
- }).map(({ ref, text }) => ({
381
- identifier: ref.identifier,
382
- text
383
- }));
384
- const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text);
385
- if (uniqueMissingRefs.length > 0) {
386
- const missingAsText = uniqueMissingRefs.map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)).join(", ");
387
- const existingWithMissing = sourceCode.getText(queryKeyValue).replace(/\]$/, `, ${missingAsText}]`);
388
- const suggestions = [];
389
- if (queryKeyNode.type === _utils.AST_NODE_TYPES.ArrayExpression) {
390
- suggestions.push({
391
- messageId: "fixTo",
392
- data: { result: existingWithMissing },
393
- fix(fixer) {
394
- return fixer.replaceText(queryKeyValue, existingWithMissing);
395
- }
396
- });
397
- }
398
- context.report({
399
- node,
400
- messageId: "missingDeps",
401
- data: {
402
- deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
403
- },
404
- suggest: suggestions
405
- });
406
- }
407
- }
408
- };
409
- }
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ configs: () => import_configs.configs,
24
+ rules: () => import_rules.rules
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+ var import_configs = require("./configs.cjs");
28
+ var import_rules = require("./rules.cjs");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ configs,
32
+ rules
410
33
  });
411
-
412
- // src/rules/index.ts
413
- var rules = {
414
- [name]: rule
415
- };
416
-
417
- // src/configs/index.ts
418
- function generateRecommendedConfig(allRules) {
419
- return Object.entries(allRules).reduce((memo, [name2, rule2]) => {
420
- const { recommended } = rule2.meta.docs || {};
421
- return {
422
- ...memo,
423
- ...recommended ? { [`@tanstack/query/${name2}`]: recommended } : {}
424
- };
425
- }, {});
426
- }
427
- var configs = {
428
- recommended: {
429
- plugins: ["@tanstack/eslint-plugin-query"],
430
- rules: generateRecommendedConfig(rules)
431
- }
432
- };
433
-
434
-
435
-
436
- exports.configs = configs; exports.rules = rules;
437
34
  //# sourceMappingURL=index.cjs.map