@tanstack/eslint-plugin-query 5.107.1 → 5.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -100,13 +100,6 @@ const ASTUtils = {
100
100
  return resolvedNode.init;
101
101
  }
102
102
  };
103
- // src/utils/get-docs-url.ts
104
- /**
105
- * Builds the URL of a rule's documentation page.
106
- * @param ruleName - The rule's name, e.g. `exhaustive-deps`.
107
- * @returns The URL of the rule's page in the ESLint plugin docs.
108
- */
109
- const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
110
103
  // src/utils/detect-react-query-imports.ts
111
104
  /**
112
105
  * Wraps a rule's `create` function to track the identifiers imported from TanStack Query packages,
@@ -149,6 +142,13 @@ function detectTanstackQueryImports(create) {
149
142
  return enhancedRuleInstructions;
150
143
  };
151
144
  }
145
+ // src/utils/get-docs-url.ts
146
+ /**
147
+ * Builds the URL of a rule's documentation page.
148
+ * @param ruleName - The rule's name, e.g. `exhaustive-deps`.
149
+ * @returns The URL of the rule's page in the ESLint plugin docs.
150
+ */
151
+ const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
152
152
  // src/rules/exhaustive-deps/exhaustive-deps.utils.ts
153
153
  const ExhaustiveDepsUtils = {
154
154
  isRelevantReference(params) {
@@ -596,52 +596,154 @@ function dereferenceVariablesAndTypeAssertions(queryKeyNode, context) {
596
596
  }
597
597
  return queryKeyNode;
598
598
  }
599
- // src/rules/stable-query-client/stable-query-client.rule.ts
600
- const name$6 = "stable-query-client";
601
- const rule$6 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
599
+ // src/utils/sort-data-by-order.ts
600
+ /**
601
+ * Sorts the items covered by the order rules into the required order, keeping the other items in
602
+ * place.
603
+ * @param data - The items to sort.
604
+ * @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
605
+ * those in the second.
606
+ * @param key - The property of each item to compare against the groups.
607
+ * @returns The sorted items, or `null` if they were already in order.
608
+ */
609
+ function sortDataByOrder(data, orderRules, key) {
610
+ const getSubsetIndex = (item, subsets) => {
611
+ for (let i = 0; i < subsets.length; i++) {
612
+ var _subsets$i;
613
+ if ((_subsets$i = subsets[i]) === null || _subsets$i === void 0 ? void 0 : _subsets$i.includes(item)) return i;
614
+ }
615
+ return null;
616
+ };
617
+ const orderSets = orderRules.reduce((sets, [A, B]) => [
618
+ ...sets,
619
+ A,
620
+ B
621
+ ], []);
622
+ const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
623
+ let wasResorted = false;
624
+ const inOrderIterator = inOrderArray.sort((a, b) => {
625
+ const aKey = a[key], bKey = b[key];
626
+ const aSubsetIndex = getSubsetIndex(aKey, orderSets);
627
+ const bSubsetIndex = getSubsetIndex(bKey, orderSets);
628
+ if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
629
+ return 0;
630
+ }).values();
631
+ const result = data.map((item) => {
632
+ if (getSubsetIndex(item[key], orderSets) !== null) {
633
+ const sortedItem = inOrderIterator.next().value;
634
+ if (sortedItem[key] !== item[key]) wasResorted = true;
635
+ return sortedItem;
636
+ }
637
+ return item;
638
+ });
639
+ if (!wasResorted) return null;
640
+ return result;
641
+ }
642
+ // src/utils/create-property-order-rule.ts
643
+ const createRule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl);
644
+ /**
645
+ * Creates a rule that reports when the properties of the options object passed to the target
646
+ * functions are not in the required order.
647
+ * @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
648
+ * @param targetFunctions - The names of the functions whose first argument is checked.
649
+ * @param orderRules - Pairs of property groups: the properties of the first group must come before
650
+ * those of the second.
651
+ * @returns An ESLint rule that reports out-of-order properties and fixes them.
652
+ */
653
+ function createPropertyOrderRule(options, targetFunctions, orderRules) {
654
+ const targetFunctionSet = new Set(targetFunctions);
655
+ /**
656
+ * Checks whether a function name is one of the target functions.
657
+ * @param node - The function name.
658
+ * @returns `true` if the name is a target function.
659
+ */
660
+ function isTargetFunction(node) {
661
+ return targetFunctionSet.has(node);
662
+ }
663
+ return createRule$5({
664
+ ...options,
665
+ create: detectTanstackQueryImports((context) => {
666
+ return { CallExpression(node) {
667
+ if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
668
+ const functions = node.callee.name;
669
+ if (!isTargetFunction(functions)) return;
670
+ const argument = node.arguments[0];
671
+ if (argument === void 0 || argument.type !== "ObjectExpression") return;
672
+ const allProperties = argument.properties;
673
+ if (allProperties.length < 2) return;
674
+ const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
675
+ if (p.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && p.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return {
676
+ name: p.key.name,
677
+ property: p
678
+ };
679
+ else return {
680
+ name: `_property_${index}`,
681
+ property: p
682
+ };
683
+ }), orderRules, "name");
684
+ if (sortedProperties === null) return;
685
+ context.report({
686
+ node: argument,
687
+ data: { function: node.callee.name },
688
+ messageId: "invalidOrder",
689
+ fix(fixer) {
690
+ const sourceCode = context.sourceCode;
691
+ const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
692
+ let textBetweenProperties = "";
693
+ if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
694
+ return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
695
+ }, "");
696
+ return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
697
+ }
698
+ });
699
+ } };
700
+ })
701
+ });
702
+ }
703
+ // src/rules/infinite-query-property-order/constants.ts
704
+ const infiniteQueryFunctions = [
705
+ "infiniteQueryOptions",
706
+ "useInfiniteQuery",
707
+ "useSuspenseInfiniteQuery"
708
+ ];
709
+ const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
710
+ // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
711
+ const name$6 = "infinite-query-property-order";
712
+ const rule$6 = createPropertyOrderRule({
602
713
  name: name$6,
603
714
  meta: {
604
715
  type: "problem",
605
716
  docs: {
606
- description: "Makes sure that QueryClient is stable",
717
+ description: "Ensure correct order of inference sensitive properties for infinite queries",
607
718
  recommended: "error"
608
719
  },
609
- messages: {
610
- 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"),
611
- fixTo: "Fix to {{result}}"
720
+ messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
721
+ schema: [],
722
+ hasSuggestions: true,
723
+ fixable: "code"
724
+ },
725
+ defaultOptions: []
726
+ }, infiniteQueryFunctions, sortRules$1);
727
+ // src/rules/mutation-property-order/constants.ts
728
+ const mutationFunctions = ["useMutation"];
729
+ const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
730
+ // src/rules/mutation-property-order/mutation-property-order.rule.ts
731
+ const name$5 = "mutation-property-order";
732
+ const rule$5 = createPropertyOrderRule({
733
+ name: name$5,
734
+ meta: {
735
+ type: "problem",
736
+ docs: {
737
+ description: "Ensure correct order of inference-sensitive properties in useMutation()",
738
+ recommended: "error"
612
739
  },
740
+ messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
741
+ schema: [],
613
742
  hasSuggestions: true,
614
- fixable: "code",
615
- schema: []
743
+ fixable: "code"
616
744
  },
617
- defaultOptions: [],
618
- create: detectTanstackQueryImports((context, _, helpers) => {
619
- return { NewExpression: (node) => {
620
- if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
621
- const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
622
- _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration,
623
- _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression,
624
- _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression
625
- ]));
626
- const fnName = (fnAncestor === null || fnAncestor === void 0 ? void 0 : 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 === null || fnAncestor === void 0 ? void 0 : fnAncestor.id;
627
- const isReactServerComponent = (fnAncestor === null || fnAncestor === void 0 ? void 0 : fnAncestor.async) === true;
628
- if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
629
- context.report({
630
- node: node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
631
- messageId: "unstable",
632
- fix: (() => {
633
- const { parent } = node;
634
- if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
635
- const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
636
- const variableName = parent.id.name;
637
- return (fixer) => {
638
- return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
639
- };
640
- })()
641
- });
642
- } };
643
- })
644
- });
745
+ defaultOptions: []
746
+ }, mutationFunctions, sortRules);
645
747
  // src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts
646
748
  const QUERY_RESULT_TYPE_NAMES = /* @__PURE__ */ new Set([
647
749
  "UseBaseQueryResult",
@@ -678,7 +780,7 @@ const NoRestDestructuringUtils = {
678
780
  }
679
781
  };
680
782
  // src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts
681
- const name$5 = "no-rest-destructuring";
783
+ const name$4 = "no-rest-destructuring";
682
784
  const queryHooks$1 = [
683
785
  "useQuery",
684
786
  "useQueries",
@@ -687,8 +789,8 @@ const queryHooks$1 = [
687
789
  "useSuspenseQueries",
688
790
  "useSuspenseInfiniteQuery"
689
791
  ];
690
- const rule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
691
- name: name$5,
792
+ const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
793
+ name: name$4,
692
794
  meta: {
693
795
  type: "problem",
694
796
  docs: {
@@ -746,7 +848,7 @@ const rule$5 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
746
848
  })
747
849
  });
748
850
  // src/rules/no-unstable-deps/no-unstable-deps.rule.ts
749
- const name$4 = "no-unstable-deps";
851
+ const name$3 = "no-unstable-deps";
750
852
  const reactHookNames = [
751
853
  "useEffect",
752
854
  "useCallback",
@@ -760,8 +862,8 @@ const allHookNames = ["useMutation", ...[
760
862
  "useInfiniteQuery",
761
863
  "useSuspenseInfiniteQuery"
762
864
  ]];
763
- const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
764
- name: name$4,
865
+ const rule$3 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
866
+ name: name$3,
765
867
  meta: {
766
868
  type: "problem",
767
869
  docs: {
@@ -921,134 +1023,6 @@ const rule$4 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
921
1023
  };
922
1024
  })
923
1025
  });
924
- // src/utils/sort-data-by-order.ts
925
- /**
926
- * Sorts the items covered by the order rules into the required order, keeping the other items in
927
- * place.
928
- * @param data - The items to sort.
929
- * @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
930
- * those in the second.
931
- * @param key - The property of each item to compare against the groups.
932
- * @returns The sorted items, or `null` if they were already in order.
933
- */
934
- function sortDataByOrder(data, orderRules, key) {
935
- const getSubsetIndex = (item, subsets) => {
936
- for (let i = 0; i < subsets.length; i++) {
937
- var _subsets$i;
938
- if ((_subsets$i = subsets[i]) === null || _subsets$i === void 0 ? void 0 : _subsets$i.includes(item)) return i;
939
- }
940
- return null;
941
- };
942
- const orderSets = orderRules.reduce((sets, [A, B]) => [
943
- ...sets,
944
- A,
945
- B
946
- ], []);
947
- const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
948
- let wasResorted = false;
949
- const inOrderIterator = inOrderArray.sort((a, b) => {
950
- const aKey = a[key], bKey = b[key];
951
- const aSubsetIndex = getSubsetIndex(aKey, orderSets);
952
- const bSubsetIndex = getSubsetIndex(bKey, orderSets);
953
- if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
954
- return 0;
955
- }).values();
956
- const result = data.map((item) => {
957
- if (getSubsetIndex(item[key], orderSets) !== null) {
958
- const sortedItem = inOrderIterator.next().value;
959
- if (sortedItem[key] !== item[key]) wasResorted = true;
960
- return sortedItem;
961
- }
962
- return item;
963
- });
964
- if (!wasResorted) return null;
965
- return result;
966
- }
967
- // src/utils/create-property-order-rule.ts
968
- const createRule$2 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl);
969
- /**
970
- * Creates a rule that reports when the properties of the options object passed to the target
971
- * functions are not in the required order.
972
- * @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
973
- * @param targetFunctions - The names of the functions whose first argument is checked.
974
- * @param orderRules - Pairs of property groups: the properties of the first group must come before
975
- * those of the second.
976
- * @returns An ESLint rule that reports out-of-order properties and fixes them.
977
- */
978
- function createPropertyOrderRule(options, targetFunctions, orderRules) {
979
- const targetFunctionSet = new Set(targetFunctions);
980
- /**
981
- * Checks whether a function name is one of the target functions.
982
- * @param node - The function name.
983
- * @returns `true` if the name is a target function.
984
- */
985
- function isTargetFunction(node) {
986
- return targetFunctionSet.has(node);
987
- }
988
- return createRule$2({
989
- ...options,
990
- create: detectTanstackQueryImports((context) => {
991
- return { CallExpression(node) {
992
- if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
993
- const functions = node.callee.name;
994
- if (!isTargetFunction(functions)) return;
995
- const argument = node.arguments[0];
996
- if (argument === void 0 || argument.type !== "ObjectExpression") return;
997
- const allProperties = argument.properties;
998
- if (allProperties.length < 2) return;
999
- const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
1000
- if (p.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && p.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return {
1001
- name: p.key.name,
1002
- property: p
1003
- };
1004
- else return {
1005
- name: `_property_${index}`,
1006
- property: p
1007
- };
1008
- }), orderRules, "name");
1009
- if (sortedProperties === null) return;
1010
- context.report({
1011
- node: argument,
1012
- data: { function: node.callee.name },
1013
- messageId: "invalidOrder",
1014
- fix(fixer) {
1015
- const sourceCode = context.sourceCode;
1016
- const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
1017
- let textBetweenProperties = "";
1018
- if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
1019
- return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
1020
- }, "");
1021
- return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
1022
- }
1023
- });
1024
- } };
1025
- })
1026
- });
1027
- }
1028
- // src/rules/infinite-query-property-order/constants.ts
1029
- const infiniteQueryFunctions = [
1030
- "infiniteQueryOptions",
1031
- "useInfiniteQuery",
1032
- "useSuspenseInfiniteQuery"
1033
- ];
1034
- const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
1035
- // src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts
1036
- const name$3 = "infinite-query-property-order";
1037
- const rule$3 = createPropertyOrderRule({
1038
- name: name$3,
1039
- meta: {
1040
- type: "problem",
1041
- docs: {
1042
- description: "Ensure correct order of inference sensitive properties for infinite queries",
1043
- recommended: "error"
1044
- },
1045
- messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
1046
- schema: [],
1047
- hasSuggestions: true,
1048
- fixable: "code"
1049
- },
1050
- defaultOptions: []
1051
- }, infiniteQueryFunctions, sortRules$1);
1052
1026
  // src/rules/no-void-query-fn/no-void-query-fn.rule.ts
1053
1027
  const name$2 = "no-void-query-fn";
1054
1028
  const rule$2 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
@@ -1097,28 +1071,8 @@ function isIllegalReturn(checker, type) {
1097
1071
  const typeString = checker.typeToString(awaited);
1098
1072
  return typeString === "void" || typeString === "undefined";
1099
1073
  }
1100
- // src/rules/mutation-property-order/constants.ts
1101
- const mutationFunctions = ["useMutation"];
1102
- const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
1103
- // src/rules/mutation-property-order/mutation-property-order.rule.ts
1104
- const name$1 = "mutation-property-order";
1105
- const rule$1 = createPropertyOrderRule({
1106
- name: name$1,
1107
- meta: {
1108
- type: "problem",
1109
- docs: {
1110
- description: "Ensure correct order of inference-sensitive properties in useMutation()",
1111
- recommended: "error"
1112
- },
1113
- messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
1114
- schema: [],
1115
- hasSuggestions: true,
1116
- fixable: "code"
1117
- },
1118
- defaultOptions: []
1119
- }, mutationFunctions, sortRules);
1120
1074
  // src/rules/prefer-query-options/prefer-query-options.rule.ts
1121
- const name = "prefer-query-options";
1075
+ const name$1 = "prefer-query-options";
1122
1076
  const queryHooks = [
1123
1077
  "useQuery",
1124
1078
  "useInfiniteQuery",
@@ -1155,8 +1109,8 @@ const queryClientFilterMethods = [
1155
1109
  "setQueriesData"
1156
1110
  ];
1157
1111
  const queryOptionsBuilders = ["queryOptions", "infiniteQueryOptions"];
1158
- const rule = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1159
- name,
1112
+ const rule$1 = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1113
+ name: name$1,
1160
1114
  meta: {
1161
1115
  type: "problem",
1162
1116
  docs: {
@@ -1356,16 +1310,62 @@ function unwrapTypeAssertions(node) {
1356
1310
  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;
1357
1311
  return node;
1358
1312
  }
1313
+ // src/rules/stable-query-client/stable-query-client.rule.ts
1314
+ const name = "stable-query-client";
1315
+ const rule = _typescript_eslint_utils.ESLintUtils.RuleCreator(getDocsUrl)({
1316
+ name,
1317
+ meta: {
1318
+ type: "problem",
1319
+ docs: {
1320
+ description: "Makes sure that QueryClient is stable",
1321
+ recommended: "error"
1322
+ },
1323
+ messages: {
1324
+ 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"),
1325
+ fixTo: "Fix to {{result}}"
1326
+ },
1327
+ hasSuggestions: true,
1328
+ fixable: "code",
1329
+ schema: []
1330
+ },
1331
+ defaultOptions: [],
1332
+ create: detectTanstackQueryImports((context, _, helpers) => {
1333
+ return { NewExpression: (node) => {
1334
+ if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
1335
+ const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
1336
+ _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration,
1337
+ _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression,
1338
+ _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression
1339
+ ]));
1340
+ const fnName = (fnAncestor === null || fnAncestor === void 0 ? void 0 : 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 === null || fnAncestor === void 0 ? void 0 : fnAncestor.id;
1341
+ const isReactServerComponent = (fnAncestor === null || fnAncestor === void 0 ? void 0 : fnAncestor.async) === true;
1342
+ if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
1343
+ context.report({
1344
+ node: node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
1345
+ messageId: "unstable",
1346
+ fix: (() => {
1347
+ const { parent } = node;
1348
+ if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
1349
+ const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
1350
+ const variableName = parent.id.name;
1351
+ return (fixer) => {
1352
+ return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
1353
+ };
1354
+ })()
1355
+ });
1356
+ } };
1357
+ })
1358
+ });
1359
1359
  // src/rules.ts
1360
1360
  const rules = {
1361
1361
  [name$7]: rule$7,
1362
- [name$6]: rule$6,
1363
- [name$5]: rule$5,
1362
+ [name]: rule,
1364
1363
  [name$4]: rule$4,
1365
1364
  [name$3]: rule$3,
1365
+ [name$6]: rule$6,
1366
1366
  [name$2]: rule$2,
1367
- [name$1]: rule$1,
1368
- [name]: rule
1367
+ [name$5]: rule$5,
1368
+ [name$1]: rule$1
1369
1369
  };
1370
1370
  Object.defineProperty(exports, "rules", {
1371
1371
  enumerable: true,
@@ -1374,4 +1374,4 @@ Object.defineProperty(exports, "rules", {
1374
1374
  }
1375
1375
  });
1376
1376
 
1377
- //# sourceMappingURL=rules-BLyIzGVm.cjs.map
1377
+ //# sourceMappingURL=rules-pD3EQmNo.cjs.map