@tanstack/eslint-plugin-query 5.0.0-alpha.88 → 5.0.0-beta.10

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 (86) hide show
  1. package/build/legacy/__tests__/configs.test.cjs +21 -0
  2. package/build/legacy/__tests__/configs.test.cjs.map +1 -0
  3. package/build/legacy/__tests__/configs.test.d.cts +2 -0
  4. package/build/legacy/__tests__/configs.test.d.ts +2 -0
  5. package/build/legacy/__tests__/configs.test.js +19 -0
  6. package/build/legacy/__tests__/configs.test.js.map +1 -0
  7. package/build/legacy/__tests__/exhaustive-deps.test.cjs +722 -0
  8. package/build/legacy/__tests__/exhaustive-deps.test.cjs.map +1 -0
  9. package/build/legacy/__tests__/exhaustive-deps.test.d.cts +2 -0
  10. package/build/legacy/__tests__/exhaustive-deps.test.d.ts +2 -0
  11. package/build/legacy/__tests__/exhaustive-deps.test.js +720 -0
  12. package/build/legacy/__tests__/exhaustive-deps.test.js.map +1 -0
  13. package/build/legacy/configs.cjs +46 -0
  14. package/build/legacy/configs.cjs.map +1 -0
  15. package/build/legacy/configs.d.cts +8 -0
  16. package/build/legacy/configs.d.ts +8 -0
  17. package/build/legacy/configs.js +21 -0
  18. package/build/legacy/configs.js.map +1 -0
  19. package/build/legacy/index.cjs +28 -431
  20. package/build/legacy/index.cjs.map +1 -1
  21. package/build/legacy/index.d.cts +3 -14
  22. package/build/legacy/index.d.ts +3 -14
  23. package/build/legacy/index.js +3 -432
  24. package/build/legacy/index.js.map +1 -1
  25. package/build/legacy/rules/exhaustive-deps.rule.cjs +141 -0
  26. package/build/legacy/rules/exhaustive-deps.rule.cjs.map +1 -0
  27. package/build/legacy/rules/exhaustive-deps.rule.d.cts +6 -0
  28. package/build/legacy/rules/exhaustive-deps.rule.d.ts +6 -0
  29. package/build/legacy/rules/exhaustive-deps.rule.js +115 -0
  30. package/build/legacy/rules/exhaustive-deps.rule.js.map +1 -0
  31. package/build/legacy/rules/exhaustive-deps.utils.cjs +52 -0
  32. package/build/legacy/rules/exhaustive-deps.utils.cjs.map +1 -0
  33. package/build/legacy/rules/exhaustive-deps.utils.d.cts +12 -0
  34. package/build/legacy/rules/exhaustive-deps.utils.d.ts +12 -0
  35. package/build/legacy/rules/exhaustive-deps.utils.js +27 -0
  36. package/build/legacy/rules/exhaustive-deps.utils.js.map +1 -0
  37. package/build/legacy/rules.cjs +44 -0
  38. package/build/legacy/rules.cjs.map +1 -0
  39. package/build/legacy/rules.d.cts +7 -0
  40. package/build/legacy/rules.d.ts +7 -0
  41. package/build/legacy/rules.js +9 -0
  42. package/build/legacy/rules.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
  80. package/src/{configs/index.test.ts → __tests__/configs.test.ts} +1 -1
  81. package/src/{rules/exhaustive-deps → __tests__}/exhaustive-deps.test.ts +2 -2
  82. package/src/{configs/index.ts → configs.ts} +1 -1
  83. package/src/rules/{exhaustive-deps/exhaustive-deps.rule.ts → exhaustive-deps.rule.ts} +3 -3
  84. package/src/rules/{exhaustive-deps/exhaustive-deps.utils.ts → exhaustive-deps.utils.ts} +1 -1
  85. package/src/rules.ts +5 -0
  86. package/src/rules/index.ts +0 -5
@@ -0,0 +1,141 @@
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 name2 in all)
8
+ __defProp(target, name2, { get: all[name2], 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/rules/exhaustive-deps.rule.ts
21
+ var exhaustive_deps_rule_exports = {};
22
+ __export(exhaustive_deps_rule_exports, {
23
+ name: () => name,
24
+ rule: () => rule
25
+ });
26
+ module.exports = __toCommonJS(exhaustive_deps_rule_exports);
27
+ var import_utils = require("@typescript-eslint/utils");
28
+ var import_ast_utils = require("../utils/ast-utils.cjs");
29
+ var import_create_rule = require("../utils/create-rule.cjs");
30
+ var import_unique_by = require("../utils/unique-by.cjs");
31
+ var import_exhaustive_deps = require("./exhaustive-deps.utils.cjs");
32
+ var QUERY_KEY = "queryKey";
33
+ var QUERY_FN = "queryFn";
34
+ var name = "exhaustive-deps";
35
+ var rule = (0, import_create_rule.createRule)({
36
+ name,
37
+ meta: {
38
+ type: "problem",
39
+ docs: {
40
+ description: "Exhaustive deps rule for useQuery",
41
+ recommended: "error"
42
+ },
43
+ messages: {
44
+ missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
45
+ fixTo: "Fix to {{result}}"
46
+ },
47
+ hasSuggestions: true,
48
+ fixable: "code",
49
+ schema: []
50
+ },
51
+ defaultOptions: [],
52
+ create(context) {
53
+ return {
54
+ Property(node) {
55
+ if (node.parent === void 0 || !import_ast_utils.ASTUtils.isObjectExpression(node.parent) || !import_ast_utils.ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
56
+ return;
57
+ }
58
+ const scopeManager = context.getSourceCode().scopeManager;
59
+ const queryKey = import_ast_utils.ASTUtils.findPropertyWithIdentifierKey(
60
+ node.parent.properties,
61
+ QUERY_KEY
62
+ );
63
+ const queryFn = import_ast_utils.ASTUtils.findPropertyWithIdentifierKey(
64
+ node.parent.properties,
65
+ QUERY_FN
66
+ );
67
+ if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || queryFn.value.type !== import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
68
+ return;
69
+ }
70
+ let queryKeyNode = queryKey.value;
71
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === import_utils.AST_NODE_TYPES.ArrayExpression) {
72
+ queryKeyNode = queryKeyNode.expression;
73
+ }
74
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.Identifier) {
75
+ const expression = import_ast_utils.ASTUtils.getReferencedExpressionByIdentifier({
76
+ context,
77
+ node: queryKeyNode
78
+ });
79
+ if ((expression == null ? void 0 : expression.type) === import_utils.AST_NODE_TYPES.ArrayExpression) {
80
+ queryKeyNode = expression;
81
+ }
82
+ }
83
+ const sourceCode = context.getSourceCode();
84
+ const queryKeyValue = queryKeyNode;
85
+ const externalRefs = import_ast_utils.ASTUtils.getExternalRefs({
86
+ scopeManager,
87
+ sourceCode,
88
+ node: queryFn.value
89
+ });
90
+ const relevantRefs = externalRefs.filter(
91
+ (reference) => import_exhaustive_deps.ExhaustiveDepsUtils.isRelevantReference({
92
+ context,
93
+ reference,
94
+ scopeManager
95
+ })
96
+ );
97
+ const existingKeys = import_ast_utils.ASTUtils.getNestedIdentifiers(queryKeyValue).map(
98
+ (identifier) => import_ast_utils.ASTUtils.mapKeyNodeToText(identifier, sourceCode)
99
+ );
100
+ const missingRefs = relevantRefs.map((ref) => ({
101
+ ref,
102
+ text: import_ast_utils.ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)
103
+ })).filter(({ ref, text }) => {
104
+ return !ref.isTypeReference && !import_ast_utils.ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(".")[0] ?? "");
105
+ }).map(({ ref, text }) => ({
106
+ identifier: ref.identifier,
107
+ text
108
+ }));
109
+ const uniqueMissingRefs = (0, import_unique_by.uniqueBy)(missingRefs, (x) => x.text);
110
+ if (uniqueMissingRefs.length > 0) {
111
+ const missingAsText = uniqueMissingRefs.map((ref) => import_ast_utils.ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)).join(", ");
112
+ const existingWithMissing = sourceCode.getText(queryKeyValue).replace(/\]$/, `, ${missingAsText}]`);
113
+ const suggestions = [];
114
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.ArrayExpression) {
115
+ suggestions.push({
116
+ messageId: "fixTo",
117
+ data: { result: existingWithMissing },
118
+ fix(fixer) {
119
+ return fixer.replaceText(queryKeyValue, existingWithMissing);
120
+ }
121
+ });
122
+ }
123
+ context.report({
124
+ node,
125
+ messageId: "missingDeps",
126
+ data: {
127
+ deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
128
+ },
129
+ suggest: suggestions
130
+ });
131
+ }
132
+ }
133
+ };
134
+ }
135
+ });
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ name,
139
+ rule
140
+ });
141
+ //# sourceMappingURL=exhaustive-deps.rule.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport { createRule } from '../utils/create-rule'\nimport { uniqueBy } from '../utils/unique-by'\nimport { ExhaustiveDepsUtils } from './exhaustive-deps.utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,uBAAyB;AACzB,yBAA2B;AAC3B,uBAAyB;AACzB,6BAAoC;AAGpC,IAAM,YAAY;AAClB,IAAM,WAAW;AAEV,IAAM,OAAO;AAEb,IAAM,WAAO,+BAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,IACT;AAAA,IACA,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS;AACd,WAAO;AAAA,MACL,SAAS,MAAM;AACb,YACE,KAAK,WAAW,UAChB,CAAC,0BAAS,mBAAmB,KAAK,MAAM,KACxC,CAAC,0BAAS,qBAAqB,KAAK,KAAK,SAAS,GAClD;AACA;AAAA,QACF;AAEA,cAAM,eAAe,QAAQ,cAAc,EAAE;AAC7C,cAAM,WAAW,0BAAS;AAAA,UACxB,KAAK,OAAO;AAAA,UACZ;AAAA,QACF;AACA,cAAM,UAAU,0BAAS;AA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,EAAE,KAAK,KAAK,OAAO;AAAA,UACvB,YAAY,IAAI;AAAA,UAChB;AAAA,QACF,EAAE;AAEJ,cAAM,wBAAoB,2BAAS,aAAa,CAAC,MAAM,EAAE,IAAI;AAE7D,YAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAM,gBAAgB,kBACnB,IAAI,CAAC,QAAQ,0BAAS,iBAAiB,IAAI,YAAY,UAAU,CAAC,EAClE,KAAK,IAAI;AAEZ,gBAAM,sBAAsB,WACzB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KAAK,aAAa,GAAG;AAEvC,gBAAM,cAAsD,CAAC;AAE7D,cAAI,aAAa,SAAS,4BAAe,iBAAiB;AACxD,wBAAY,KAAK;AAAA,cACf,WAAW;AAAA,cACX,MAAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACT,uBAAO,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;AAAA,YACF,CAAC;AAAA,UACH;AAEA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,YACX,MAAM;AAAA,cACJ,MAAM,kBAAkB,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,KAAK,IAAI;AAAA,YAC1D;AAAA,YACA,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const name = "exhaustive-deps";
4
+ declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
5
+
6
+ export { name, rule };
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const name = "exhaustive-deps";
4
+ declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
5
+
6
+ export { name, rule };
@@ -0,0 +1,115 @@
1
+ // src/rules/exhaustive-deps.rule.ts
2
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
+ import { ASTUtils } from "../utils/ast-utils.js";
4
+ import { createRule } from "../utils/create-rule.js";
5
+ import { uniqueBy } from "../utils/unique-by.js";
6
+ import { ExhaustiveDepsUtils } from "./exhaustive-deps.utils.js";
7
+ var QUERY_KEY = "queryKey";
8
+ var QUERY_FN = "queryFn";
9
+ var name = "exhaustive-deps";
10
+ var rule = createRule({
11
+ name,
12
+ meta: {
13
+ type: "problem",
14
+ docs: {
15
+ description: "Exhaustive deps rule for useQuery",
16
+ recommended: "error"
17
+ },
18
+ messages: {
19
+ missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
20
+ fixTo: "Fix to {{result}}"
21
+ },
22
+ hasSuggestions: true,
23
+ fixable: "code",
24
+ schema: []
25
+ },
26
+ defaultOptions: [],
27
+ create(context) {
28
+ return {
29
+ Property(node) {
30
+ if (node.parent === void 0 || !ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
31
+ return;
32
+ }
33
+ const scopeManager = context.getSourceCode().scopeManager;
34
+ const queryKey = ASTUtils.findPropertyWithIdentifierKey(
35
+ node.parent.properties,
36
+ QUERY_KEY
37
+ );
38
+ const queryFn = ASTUtils.findPropertyWithIdentifierKey(
39
+ node.parent.properties,
40
+ QUERY_FN
41
+ );
42
+ if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression) {
43
+ return;
44
+ }
45
+ let queryKeyNode = queryKey.value;
46
+ if (queryKeyNode.type === AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression) {
47
+ queryKeyNode = queryKeyNode.expression;
48
+ }
49
+ if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {
50
+ const expression = ASTUtils.getReferencedExpressionByIdentifier({
51
+ context,
52
+ node: queryKeyNode
53
+ });
54
+ if ((expression == null ? void 0 : expression.type) === AST_NODE_TYPES.ArrayExpression) {
55
+ queryKeyNode = expression;
56
+ }
57
+ }
58
+ const sourceCode = context.getSourceCode();
59
+ const queryKeyValue = queryKeyNode;
60
+ const externalRefs = ASTUtils.getExternalRefs({
61
+ scopeManager,
62
+ sourceCode,
63
+ node: queryFn.value
64
+ });
65
+ const relevantRefs = externalRefs.filter(
66
+ (reference) => ExhaustiveDepsUtils.isRelevantReference({
67
+ context,
68
+ reference,
69
+ scopeManager
70
+ })
71
+ );
72
+ const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(
73
+ (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode)
74
+ );
75
+ const missingRefs = relevantRefs.map((ref) => ({
76
+ ref,
77
+ text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)
78
+ })).filter(({ ref, text }) => {
79
+ return !ref.isTypeReference && !ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(".")[0] ?? "");
80
+ }).map(({ ref, text }) => ({
81
+ identifier: ref.identifier,
82
+ text
83
+ }));
84
+ const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text);
85
+ if (uniqueMissingRefs.length > 0) {
86
+ const missingAsText = uniqueMissingRefs.map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)).join(", ");
87
+ const existingWithMissing = sourceCode.getText(queryKeyValue).replace(/\]$/, `, ${missingAsText}]`);
88
+ const suggestions = [];
89
+ if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {
90
+ suggestions.push({
91
+ messageId: "fixTo",
92
+ data: { result: existingWithMissing },
93
+ fix(fixer) {
94
+ return fixer.replaceText(queryKeyValue, existingWithMissing);
95
+ }
96
+ });
97
+ }
98
+ context.report({
99
+ node,
100
+ messageId: "missingDeps",
101
+ data: {
102
+ deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
103
+ },
104
+ suggest: suggestions
105
+ });
106
+ }
107
+ }
108
+ };
109
+ }
110
+ });
111
+ export {
112
+ name,
113
+ rule
114
+ };
115
+ //# sourceMappingURL=exhaustive-deps.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport { createRule } from '../utils/create-rule'\nimport { uniqueBy } from '../utils/unique-by'\nimport { ExhaustiveDepsUtils } from './exhaustive-deps.utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACz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O;AACT,uBAAO,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;AAAA,YACF,CAAC;AAAA,UACH;AAEA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,YACX,MAAM;AAAA,cACJ,MAAM,kBAAkB,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,KAAK,IAAI;AAAA,YAC1D;AAAA,YACA,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,52 @@
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/rules/exhaustive-deps.utils.ts
21
+ var exhaustive_deps_utils_exports = {};
22
+ __export(exhaustive_deps_utils_exports, {
23
+ ExhaustiveDepsUtils: () => ExhaustiveDepsUtils
24
+ });
25
+ module.exports = __toCommonJS(exhaustive_deps_utils_exports);
26
+ var import_utils = require("@typescript-eslint/utils");
27
+ var import_ast_utils = require("../utils/ast-utils.cjs");
28
+ var ExhaustiveDepsUtils = {
29
+ isRelevantReference(params) {
30
+ var _a;
31
+ const { reference, scopeManager, context } = params;
32
+ const component = import_ast_utils.ASTUtils.getFunctionAncestor(context);
33
+ if (component !== void 0 && !import_ast_utils.ASTUtils.isDeclaredInNode({
34
+ scopeManager,
35
+ reference,
36
+ functionNode: component
37
+ })) {
38
+ return false;
39
+ }
40
+ return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== import_utils.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
41
+ },
42
+ isQueryClientReference(reference) {
43
+ var _a, _b, _c;
44
+ const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
45
+ return (declarator == null ? void 0 : declarator.type) === import_utils.AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === import_utils.AST_NODE_TYPES.CallExpression && declarator.init.callee.type === import_utils.AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
46
+ }
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ ExhaustiveDepsUtils
51
+ });
52
+ //# sourceMappingURL=exhaustive-deps.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const ExhaustiveDepsUtils = {\n isRelevantReference(params: {\n context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { reference, scopeManager, context } = params\n const component = ASTUtils.getFunctionAncestor(context)\n\n if (\n component !== undefined &&\n !ASTUtils.isDeclaredInNode({\n scopeManager,\n reference,\n functionNode: component,\n })\n ) {\n return false\n }\n\n return (\n reference.identifier.name !== 'undefined' &&\n reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression &&\n !ExhaustiveDepsUtils.isQueryClientReference(reference)\n )\n },\n isQueryClientReference(reference: TSESLint.Scope.Reference) {\n const declarator = reference.resolved?.defs[0]?.node\n\n return (\n declarator?.type === AST_NODE_TYPES.VariableDeclarator &&\n declarator.init?.type === AST_NODE_TYPES.CallExpression &&\n declarator.init.callee.type === AST_NODE_TYPES.Identifier &&\n declarator.init.callee.name === 'useQueryClient'\n )\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,uBAAyB;AAGlB,IAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;AATL;AAUI,UAAM,EAAE,WAAW,cAAc,QAAQ,IAAI;AAC7C,UAAM,YAAY,0BAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAAC,0BAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAChB,CAAC,GACD;AACA,aAAO;AAAA,IACT;AAEA,WACE,UAAU,WAAW,SAAS,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAAS,4BAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;AA9B9D;AA+BI,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAAS,4BAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAAS,4BAAe,kBACzC,WAAW,KAAK,OAAO,SAAS,4BAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const ExhaustiveDepsUtils: {
4
+ isRelevantReference(params: {
5
+ context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>;
6
+ reference: TSESLint.Scope.Reference;
7
+ scopeManager: TSESLint.Scope.ScopeManager;
8
+ }): boolean;
9
+ isQueryClientReference(reference: TSESLint.Scope.Reference): boolean;
10
+ };
11
+
12
+ export { ExhaustiveDepsUtils };
@@ -0,0 +1,12 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const ExhaustiveDepsUtils: {
4
+ isRelevantReference(params: {
5
+ context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>;
6
+ reference: TSESLint.Scope.Reference;
7
+ scopeManager: TSESLint.Scope.ScopeManager;
8
+ }): boolean;
9
+ isQueryClientReference(reference: TSESLint.Scope.Reference): boolean;
10
+ };
11
+
12
+ export { ExhaustiveDepsUtils };
@@ -0,0 +1,27 @@
1
+ // src/rules/exhaustive-deps.utils.ts
2
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
+ import { ASTUtils } from "../utils/ast-utils.js";
4
+ var ExhaustiveDepsUtils = {
5
+ isRelevantReference(params) {
6
+ var _a;
7
+ const { reference, scopeManager, context } = params;
8
+ const component = ASTUtils.getFunctionAncestor(context);
9
+ if (component !== void 0 && !ASTUtils.isDeclaredInNode({
10
+ scopeManager,
11
+ reference,
12
+ functionNode: component
13
+ })) {
14
+ return false;
15
+ }
16
+ return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
17
+ },
18
+ isQueryClientReference(reference) {
19
+ var _a, _b, _c;
20
+ const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
21
+ return (declarator == null ? void 0 : declarator.type) === AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === AST_NODE_TYPES.CallExpression && declarator.init.callee.type === AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
22
+ }
23
+ };
24
+ export {
25
+ ExhaustiveDepsUtils
26
+ };
27
+ //# sourceMappingURL=exhaustive-deps.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const ExhaustiveDepsUtils = {\n isRelevantReference(params: {\n context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { reference, scopeManager, context } = params\n const component = ASTUtils.getFunctionAncestor(context)\n\n if (\n component !== undefined &&\n !ASTUtils.isDeclaredInNode({\n scopeManager,\n reference,\n functionNode: component,\n })\n ) {\n return false\n }\n\n return (\n reference.identifier.name !== 'undefined' &&\n reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression &&\n !ExhaustiveDepsUtils.isQueryClientReference(reference)\n )\n },\n isQueryClientReference(reference: TSESLint.Scope.Reference) {\n const declarator = reference.resolved?.defs[0]?.node\n\n return (\n declarator?.type === AST_NODE_TYPES.VariableDeclarator &&\n declarator.init?.type === AST_NODE_TYPES.CallExpression &&\n declarator.init.callee.type === AST_NODE_TYPES.Identifier &&\n declarator.init.callee.name === 'useQueryClient'\n )\n },\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AAGlB,IAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;AATL;AAUI,UAAM,EAAE,WAAW,cAAc,QAAQ,IAAI;AAC7C,UAAM,YAAY,SAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAAC,SAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAChB,CAAC,GACD;AACA,aAAO;AAAA,IACT;AAEA,WACE,UAAU,WAAW,SAAS,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAAS,eAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;AA9B9D;AA+BI,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAAS,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAAS,eAAe,kBACzC,WAAW,KAAK,OAAO,SAAS,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;","names":[]}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/rules.ts
31
+ var rules_exports = {};
32
+ __export(rules_exports, {
33
+ rules: () => rules
34
+ });
35
+ module.exports = __toCommonJS(rules_exports);
36
+ var exhaustiveDeps = __toESM(require("./rules/exhaustive-deps.rule.cjs"), 1);
37
+ var rules = {
38
+ [exhaustiveDeps.name]: exhaustiveDeps.rule
39
+ };
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ rules
43
+ });
44
+ //# sourceMappingURL=rules.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/rules.ts"],"sourcesContent":["import * as exhaustiveDeps from './rules/exhaustive-deps.rule'\n\nexport const rules = {\n [exhaustiveDeps.name]: exhaustiveDeps.rule,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAEzB,IAAM,QAAQ;AAAA,EACnB,CAAgB,mBAAI,GAAkB;AACxC;","names":[]}
@@ -0,0 +1,7 @@
1
+ import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
2
+
3
+ declare const rules: {
4
+ "exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
5
+ };
6
+
7
+ export { rules };
@@ -0,0 +1,7 @@
1
+ import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
2
+
3
+ declare const rules: {
4
+ "exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
5
+ };
6
+
7
+ export { rules };
@@ -0,0 +1,9 @@
1
+ // src/rules.ts
2
+ import * as exhaustiveDeps from "./rules/exhaustive-deps.rule.js";
3
+ var rules = {
4
+ [exhaustiveDeps.name]: exhaustiveDeps.rule
5
+ };
6
+ export {
7
+ rules
8
+ };
9
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/rules.ts"],"sourcesContent":["import * as exhaustiveDeps from './rules/exhaustive-deps.rule'\n\nexport const rules = {\n [exhaustiveDeps.name]: exhaustiveDeps.rule,\n}\n"],"mappings":";AAAA,YAAY,oBAAoB;AAEzB,IAAM,QAAQ;AAAA,EACnB,CAAgB,mBAAI,GAAkB;AACxC;","names":[]}