@tanstack/eslint-plugin-query 5.107.1 → 5.107.2

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 (36) hide show
  1. package/build/legacy/index.cjs +1 -1
  2. package/build/legacy/index.cjs.map +1 -1
  3. package/build/legacy/index.d.cts +1 -1
  4. package/build/legacy/index.d.ts +1 -1
  5. package/build/legacy/index.js +1 -1
  6. package/build/legacy/index.js.map +1 -1
  7. package/build/legacy/{rules-CPKYJdWR.js → rules-Cqo5K2Zp.js} +206 -206
  8. package/build/legacy/rules-Cqo5K2Zp.js.map +1 -0
  9. package/build/legacy/{rules-BLyIzGVm.cjs → rules-pD3EQmNo.cjs} +206 -206
  10. package/build/legacy/rules-pD3EQmNo.cjs.map +1 -0
  11. package/build/legacy/rules.cjs +1 -1
  12. package/build/legacy/rules.js +1 -1
  13. package/build/modern/index.cjs +1 -1
  14. package/build/modern/index.cjs.map +1 -1
  15. package/build/modern/index.d.cts +1 -1
  16. package/build/modern/index.d.ts +1 -1
  17. package/build/modern/index.js +1 -1
  18. package/build/modern/index.js.map +1 -1
  19. package/build/modern/{rules-D9GziSYo.js → rules-B-srrCS9.js} +203 -203
  20. package/build/modern/rules-B-srrCS9.js.map +1 -0
  21. package/build/modern/{rules-37gxMz0U.cjs → rules-ss1ZR5cp.cjs} +203 -203
  22. package/build/modern/rules-ss1ZR5cp.cjs.map +1 -0
  23. package/build/modern/rules.cjs +1 -1
  24. package/build/modern/rules.js +1 -1
  25. package/package.json +3 -3
  26. package/src/index.ts +1 -1
  27. package/src/rules/exhaustive-deps/exhaustive-deps.rule.ts +1 -1
  28. package/src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts +1 -1
  29. package/src/rules/no-unstable-deps/no-unstable-deps.rule.ts +1 -1
  30. package/src/rules/stable-query-client/stable-query-client.rule.ts +1 -1
  31. package/src/rules.ts +3 -3
  32. package/src/utils/create-property-order-rule.ts +1 -2
  33. package/build/legacy/rules-BLyIzGVm.cjs.map +0 -1
  34. package/build/legacy/rules-CPKYJdWR.js.map +0 -1
  35. package/build/modern/rules-37gxMz0U.cjs.map +0 -1
  36. package/build/modern/rules-D9GziSYo.js.map +0 -1
@@ -98,13 +98,6 @@ const ASTUtils = {
98
98
  return resolvedNode.init;
99
99
  }
100
100
  };
101
- // src/utils/get-docs-url.ts
102
- /**
103
- * Builds the URL of a rule's documentation page.
104
- * @param ruleName - The rule's name, e.g. `exhaustive-deps`.
105
- * @returns The URL of the rule's page in the ESLint plugin docs.
106
- */
107
- const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
108
101
  // src/utils/detect-react-query-imports.ts
109
102
  /**
110
103
  * Wraps a rule's `create` function to track the identifiers imported from TanStack Query packages,
@@ -144,6 +137,13 @@ function detectTanstackQueryImports(create) {
144
137
  return enhancedRuleInstructions;
145
138
  };
146
139
  }
140
+ // src/utils/get-docs-url.ts
141
+ /**
142
+ * Builds the URL of a rule's documentation page.
143
+ * @param ruleName - The rule's name, e.g. `exhaustive-deps`.
144
+ * @returns The URL of the rule's page in the ESLint plugin docs.
145
+ */
146
+ const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
147
147
  // src/rules/exhaustive-deps/exhaustive-deps.utils.ts
148
148
  const ExhaustiveDepsUtils = {
149
149
  isRelevantReference(params) {
@@ -587,52 +587,151 @@ function dereferenceVariablesAndTypeAssertions(queryKeyNode, context) {
587
587
  }
588
588
  return queryKeyNode;
589
589
  }
590
- // src/rules/stable-query-client/stable-query-client.rule.ts
591
- const name$6 = "stable-query-client";
592
- const rule$6 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
590
+ // src/utils/sort-data-by-order.ts
591
+ /**
592
+ * Sorts the items covered by the order rules into the required order, keeping the other items in
593
+ * place.
594
+ * @param data - The items to sort.
595
+ * @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
596
+ * those in the second.
597
+ * @param key - The property of each item to compare against the groups.
598
+ * @returns The sorted items, or `null` if they were already in order.
599
+ */
600
+ function sortDataByOrder(data, orderRules, key) {
601
+ const getSubsetIndex = (item, subsets) => {
602
+ for (let i = 0; i < subsets.length; i++) if (subsets[i]?.includes(item)) return i;
603
+ return null;
604
+ };
605
+ const orderSets = orderRules.reduce((sets, [A, B]) => [
606
+ ...sets,
607
+ A,
608
+ B
609
+ ], []);
610
+ const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
611
+ let wasResorted = false;
612
+ const inOrderIterator = inOrderArray.sort((a, b) => {
613
+ const aKey = a[key], bKey = b[key];
614
+ const aSubsetIndex = getSubsetIndex(aKey, orderSets);
615
+ const bSubsetIndex = getSubsetIndex(bKey, orderSets);
616
+ if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
617
+ return 0;
618
+ }).values();
619
+ const result = data.map((item) => {
620
+ if (getSubsetIndex(item[key], orderSets) !== null) {
621
+ const sortedItem = inOrderIterator.next().value;
622
+ if (sortedItem[key] !== item[key]) wasResorted = true;
623
+ return sortedItem;
624
+ }
625
+ return item;
626
+ });
627
+ if (!wasResorted) return null;
628
+ return result;
629
+ }
630
+ // src/utils/create-property-order-rule.ts
631
+ const createRule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl);
632
+ /**
633
+ * Creates a rule that reports when the properties of the options object passed to the target
634
+ * functions are not in the required order.
635
+ * @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
636
+ * @param targetFunctions - The names of the functions whose first argument is checked.
637
+ * @param orderRules - Pairs of property groups: the properties of the first group must come before
638
+ * those of the second.
639
+ * @returns An ESLint rule that reports out-of-order properties and fixes them.
640
+ */
641
+ function createPropertyOrderRule(options, targetFunctions, orderRules) {
642
+ const targetFunctionSet = new Set(targetFunctions);
643
+ /**
644
+ * Checks whether a function name is one of the target functions.
645
+ * @param node - The function name.
646
+ * @returns `true` if the name is a target function.
647
+ */
648
+ function isTargetFunction(node) {
649
+ return targetFunctionSet.has(node);
650
+ }
651
+ return createRule$5({
652
+ ...options,
653
+ create: detectTanstackQueryImports((context) => {
654
+ return { CallExpression(node) {
655
+ if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
656
+ const functions = node.callee.name;
657
+ if (!isTargetFunction(functions)) return;
658
+ const argument = node.arguments[0];
659
+ if (argument === void 0 || argument.type !== "ObjectExpression") return;
660
+ const allProperties = argument.properties;
661
+ if (allProperties.length < 2) return;
662
+ const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
663
+ if (p.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && p.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return {
664
+ name: p.key.name,
665
+ property: p
666
+ };
667
+ else return {
668
+ name: `_property_${index}`,
669
+ property: p
670
+ };
671
+ }), orderRules, "name");
672
+ if (sortedProperties === null) return;
673
+ context.report({
674
+ node: argument,
675
+ data: { function: node.callee.name },
676
+ messageId: "invalidOrder",
677
+ fix(fixer) {
678
+ const sourceCode = context.sourceCode;
679
+ const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
680
+ let textBetweenProperties = "";
681
+ if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
682
+ return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
683
+ }, "");
684
+ return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
685
+ }
686
+ });
687
+ } };
688
+ })
689
+ });
690
+ }
691
+ // src/rules/infinite-query-property-order/constants.ts
692
+ const infiniteQueryFunctions = [
693
+ "infiniteQueryOptions",
694
+ "useInfiniteQuery",
695
+ "useSuspenseInfiniteQuery"
696
+ ];
697
+ const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
698
+ // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
699
+ const name$6 = "infinite-query-property-order";
700
+ const rule$6 = createPropertyOrderRule({
593
701
  name: name$6,
594
702
  meta: {
595
703
  type: "problem",
596
704
  docs: {
597
- description: "Makes sure that QueryClient is stable",
705
+ description: "Ensure correct order of inference sensitive properties for infinite queries",
598
706
  recommended: "error"
599
707
  },
600
- messages: {
601
- unstable: ["QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.", "See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable"].join("\n"),
602
- fixTo: "Fix to {{result}}"
708
+ messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
709
+ schema: [],
710
+ hasSuggestions: true,
711
+ fixable: "code"
712
+ },
713
+ defaultOptions: []
714
+ }, infiniteQueryFunctions, sortRules$1);
715
+ // src/rules/mutation-property-order/constants.ts
716
+ const mutationFunctions = ["useMutation"];
717
+ const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
718
+ // src/rules/mutation-property-order/mutation-property-order.rule.ts
719
+ const name$5 = "mutation-property-order";
720
+ const rule$5 = createPropertyOrderRule({
721
+ name: name$5,
722
+ meta: {
723
+ type: "problem",
724
+ docs: {
725
+ description: "Ensure correct order of inference-sensitive properties in useMutation()",
726
+ recommended: "error"
603
727
  },
728
+ messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
729
+ schema: [],
604
730
  hasSuggestions: true,
605
- fixable: "code",
606
- schema: []
731
+ fixable: "code"
607
732
  },
608
- defaultOptions: [],
609
- create: detectTanstackQueryImports((context, _, helpers) => {
610
- return { NewExpression: (node) => {
611
- if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
612
- const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
613
- _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration,
614
- _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression,
615
- _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression
616
- ]));
617
- const fnName = fnAncestor?.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator && fnAncestor.parent.id.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? fnAncestor.parent.id : fnAncestor?.id;
618
- const isReactServerComponent = fnAncestor?.async === true;
619
- if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
620
- context.report({
621
- node: node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
622
- messageId: "unstable",
623
- fix: (() => {
624
- const { parent } = node;
625
- if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
626
- const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
627
- const variableName = parent.id.name;
628
- return (fixer) => {
629
- return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
630
- };
631
- })()
632
- });
633
- } };
634
- })
635
- });
733
+ defaultOptions: []
734
+ }, mutationFunctions, sortRules);
636
735
  // src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts
637
736
  const QUERY_RESULT_TYPE_NAMES = /* @__PURE__ */ new Set([
638
737
  "UseBaseQueryResult",
@@ -669,7 +768,7 @@ const NoRestDestructuringUtils = {
669
768
  }
670
769
  };
671
770
  // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
672
- const name$5 = "no-rest-destructuring";
771
+ const name$4 = "no-rest-destructuring";
673
772
  const queryHooks$1 = [
674
773
  "useQuery",
675
774
  "useQueries",
@@ -678,8 +777,8 @@ const queryHooks$1 = [
678
777
  "useSuspenseQueries",
679
778
  "useSuspenseInfiniteQuery"
680
779
  ];
681
- const rule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
682
- name: name$5,
780
+ const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
781
+ name: name$4,
683
782
  meta: {
684
783
  type: "problem",
685
784
  docs: {
@@ -736,7 +835,7 @@ const rule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
736
835
  })
737
836
  });
738
837
  // src/rules/no-unstable-deps/no-unstable-deps.rule.ts
739
- const name$4 = "no-unstable-deps";
838
+ const name$3 = "no-unstable-deps";
740
839
  const reactHookNames = [
741
840
  "useEffect",
742
841
  "useCallback",
@@ -750,8 +849,8 @@ const allHookNames = ["useMutation", ...[
750
849
  "useInfiniteQuery",
751
850
  "useSuspenseInfiniteQuery"
752
851
  ]];
753
- const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
754
- name: name$4,
852
+ const rule$3 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
853
+ name: name$3,
755
854
  meta: {
756
855
  type: "problem",
757
856
  docs: {
@@ -908,131 +1007,6 @@ const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
908
1007
  };
909
1008
  })
910
1009
  });
911
- // src/utils/sort-data-by-order.ts
912
- /**
913
- * Sorts the items covered by the order rules into the required order, keeping the other items in
914
- * place.
915
- * @param data - The items to sort.
916
- * @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
917
- * those in the second.
918
- * @param key - The property of each item to compare against the groups.
919
- * @returns The sorted items, or `null` if they were already in order.
920
- */
921
- function sortDataByOrder(data, orderRules, key) {
922
- const getSubsetIndex = (item, subsets) => {
923
- for (let i = 0; i < subsets.length; i++) if (subsets[i]?.includes(item)) return i;
924
- return null;
925
- };
926
- const orderSets = orderRules.reduce((sets, [A, B]) => [
927
- ...sets,
928
- A,
929
- B
930
- ], []);
931
- const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
932
- let wasResorted = false;
933
- const inOrderIterator = inOrderArray.sort((a, b) => {
934
- const aKey = a[key], bKey = b[key];
935
- const aSubsetIndex = getSubsetIndex(aKey, orderSets);
936
- const bSubsetIndex = getSubsetIndex(bKey, orderSets);
937
- if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
938
- return 0;
939
- }).values();
940
- const result = data.map((item) => {
941
- if (getSubsetIndex(item[key], orderSets) !== null) {
942
- const sortedItem = inOrderIterator.next().value;
943
- if (sortedItem[key] !== item[key]) wasResorted = true;
944
- return sortedItem;
945
- }
946
- return item;
947
- });
948
- if (!wasResorted) return null;
949
- return result;
950
- }
951
- // src/utils/create-property-order-rule.ts
952
- const createRule$2 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl);
953
- /**
954
- * Creates a rule that reports when the properties of the options object passed to the target
955
- * functions are not in the required order.
956
- * @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
957
- * @param targetFunctions - The names of the functions whose first argument is checked.
958
- * @param orderRules - Pairs of property groups: the properties of the first group must come before
959
- * those of the second.
960
- * @returns An ESLint rule that reports out-of-order properties and fixes them.
961
- */
962
- function createPropertyOrderRule(options, targetFunctions, orderRules) {
963
- const targetFunctionSet = new Set(targetFunctions);
964
- /**
965
- * Checks whether a function name is one of the target functions.
966
- * @param node - The function name.
967
- * @returns `true` if the name is a target function.
968
- */
969
- function isTargetFunction(node) {
970
- return targetFunctionSet.has(node);
971
- }
972
- return createRule$2({
973
- ...options,
974
- create: detectTanstackQueryImports((context) => {
975
- return { CallExpression(node) {
976
- if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
977
- const functions = node.callee.name;
978
- if (!isTargetFunction(functions)) return;
979
- const argument = node.arguments[0];
980
- if (argument === void 0 || argument.type !== "ObjectExpression") return;
981
- const allProperties = argument.properties;
982
- if (allProperties.length < 2) return;
983
- const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
984
- if (p.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && p.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return {
985
- name: p.key.name,
986
- property: p
987
- };
988
- else return {
989
- name: `_property_${index}`,
990
- property: p
991
- };
992
- }), orderRules, "name");
993
- if (sortedProperties === null) return;
994
- context.report({
995
- node: argument,
996
- data: { function: node.callee.name },
997
- messageId: "invalidOrder",
998
- fix(fixer) {
999
- const sourceCode = context.sourceCode;
1000
- const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
1001
- let textBetweenProperties = "";
1002
- if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
1003
- return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
1004
- }, "");
1005
- return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
1006
- }
1007
- });
1008
- } };
1009
- })
1010
- });
1011
- }
1012
- // src/rules/infinite-query-property-order/constants.ts
1013
- const infiniteQueryFunctions = [
1014
- "infiniteQueryOptions",
1015
- "useInfiniteQuery",
1016
- "useSuspenseInfiniteQuery"
1017
- ];
1018
- const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
1019
- // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
1020
- const name$3 = "infinite-query-property-order";
1021
- const rule$3 = createPropertyOrderRule({
1022
- name: name$3,
1023
- meta: {
1024
- type: "problem",
1025
- docs: {
1026
- description: "Ensure correct order of inference sensitive properties for infinite queries",
1027
- recommended: "error"
1028
- },
1029
- messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
1030
- schema: [],
1031
- hasSuggestions: true,
1032
- fixable: "code"
1033
- },
1034
- defaultOptions: []
1035
- }, infiniteQueryFunctions, sortRules$1);
1036
1010
  // src/rules/no-void-query-fn/no-void-query-fn.rule.ts
1037
1011
  const name$2 = "no-void-query-fn";
1038
1012
  const rule$2 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
@@ -1080,28 +1054,8 @@ function isIllegalReturn(checker, type) {
1080
1054
  const typeString = checker.typeToString(awaited);
1081
1055
  return typeString === "void" || typeString === "undefined";
1082
1056
  }
1083
- // src/rules/mutation-property-order/constants.ts
1084
- const mutationFunctions = ["useMutation"];
1085
- const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
1086
- // src/rules/mutation-property-order/mutation-property-order.rule.ts
1087
- const name$1 = "mutation-property-order";
1088
- const rule$1 = createPropertyOrderRule({
1089
- name: name$1,
1090
- meta: {
1091
- type: "problem",
1092
- docs: {
1093
- description: "Ensure correct order of inference-sensitive properties in useMutation()",
1094
- recommended: "error"
1095
- },
1096
- messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
1097
- schema: [],
1098
- hasSuggestions: true,
1099
- fixable: "code"
1100
- },
1101
- defaultOptions: []
1102
- }, mutationFunctions, sortRules);
1103
1057
  // src/rules/prefer-query-options/prefer-query-options.rule.ts
1104
- const name = "prefer-query-options";
1058
+ const name$1 = "prefer-query-options";
1105
1059
  const queryHooks = [
1106
1060
  "useQuery",
1107
1061
  "useInfiniteQuery",
@@ -1138,8 +1092,8 @@ const queryClientFilterMethods = [
1138
1092
  "setQueriesData"
1139
1093
  ];
1140
1094
  const queryOptionsBuilders = ["queryOptions", "infiniteQueryOptions"];
1141
- const rule = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1142
- name,
1095
+ const rule$1 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1096
+ name: name$1,
1143
1097
  meta: {
1144
1098
  type: "problem",
1145
1099
  docs: {
@@ -1336,16 +1290,62 @@ function unwrapTypeAssertions(node) {
1336
1290
  while (node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSAsExpression || node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSSatisfiesExpression || node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
1337
1291
  return node;
1338
1292
  }
1293
+ // src/rules/stable-query-client/stable-query-client.rule.ts
1294
+ const name = "stable-query-client";
1295
+ const rule = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1296
+ name,
1297
+ meta: {
1298
+ type: "problem",
1299
+ docs: {
1300
+ description: "Makes sure that QueryClient is stable",
1301
+ recommended: "error"
1302
+ },
1303
+ messages: {
1304
+ unstable: ["QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.", "See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable"].join("\n"),
1305
+ fixTo: "Fix to {{result}}"
1306
+ },
1307
+ hasSuggestions: true,
1308
+ fixable: "code",
1309
+ schema: []
1310
+ },
1311
+ defaultOptions: [],
1312
+ create: detectTanstackQueryImports((context, _, helpers) => {
1313
+ return { NewExpression: (node) => {
1314
+ if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
1315
+ const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
1316
+ _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration,
1317
+ _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression,
1318
+ _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression
1319
+ ]));
1320
+ const fnName = fnAncestor?.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator && fnAncestor.parent.id.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? fnAncestor.parent.id : fnAncestor?.id;
1321
+ const isReactServerComponent = fnAncestor?.async === true;
1322
+ if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
1323
+ context.report({
1324
+ node: node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
1325
+ messageId: "unstable",
1326
+ fix: (() => {
1327
+ const { parent } = node;
1328
+ if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
1329
+ const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
1330
+ const variableName = parent.id.name;
1331
+ return (fixer) => {
1332
+ return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
1333
+ };
1334
+ })()
1335
+ });
1336
+ } };
1337
+ })
1338
+ });
1339
1339
  // src/rules.ts
1340
1340
  const rules = {
1341
1341
  [name$7]: rule$7,
1342
- [name$6]: rule$6,
1343
- [name$5]: rule$5,
1342
+ [name]: rule,
1344
1343
  [name$4]: rule$4,
1345
1344
  [name$3]: rule$3,
1345
+ [name$6]: rule$6,
1346
1346
  [name$2]: rule$2,
1347
- [name$1]: rule$1,
1348
- [name]: rule
1347
+ [name$5]: rule$5,
1348
+ [name$1]: rule$1
1349
1349
  };
1350
1350
  Object.defineProperty(exports, "rules", {
1351
1351
  enumerable: true,
@@ -1355,4 +1355,4 @@ Object.defineProperty(exports, "rules", {
1355
1355
  });
1356
1356
 
1357
1357
 
1358
- //# sourceMappingURL=rules-37gxMz0U.cjs.map
1358
+ //# sourceMappingURL=rules-ss1ZR5cp.cjs.map