@r_masseater/oxlint-typed-rules 0.4.3 → 0.6.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.
- package/README.md +9 -1
- package/dist/config-rules-Buk48gLL.mjs +6 -0
- package/dist/config-rules-Buk48gLL.mjs.map +1 -0
- package/dist/drizzle.mjs +2 -2
- package/dist/{eslint-utils-ujGlgEMD.mjs → eslint-utils-BF_HFO08.mjs} +14 -14
- package/dist/{eslint-utils-ujGlgEMD.mjs.map → eslint-utils-BF_HFO08.mjs.map} +1 -1
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +1 -1
- package/dist/react.mjs +311 -322
- package/dist/react.mjs.map +1 -1
- package/dist/remotion.mjs +3 -3
- package/dist/remotion.mjs.map +1 -1
- package/dist/tanstack-query.mjs +199 -199
- package/dist/tanstack-query.mjs.map +1 -1
- package/dist/tanstack-router.mjs +11 -11
- package/dist/tanstack-router.mjs.map +1 -1
- package/dist/tanstack-start.mjs +35 -34
- package/dist/tanstack-start.mjs.map +1 -1
- package/dist/{typed-rule-DFpV2XgE.mjs → typed-rule-FCRt1nKZ.mjs} +25 -52
- package/dist/typed-rule-FCRt1nKZ.mjs.map +1 -0
- package/dist/{typescript-eslint-utils-C6OO2FjX.mjs → typescript-eslint-utils-C7ew0-XM.mjs} +2 -2
- package/dist/{typescript-eslint-utils-C6OO2FjX.mjs.map → typescript-eslint-utils-C7ew0-XM.mjs.map} +1 -1
- package/dist/{upstream-plugin-D4Lz9A1H.mjs → upstream-plugin-eT7t_K7e.mjs} +3 -4
- package/dist/upstream-plugin-eT7t_K7e.mjs.map +1 -0
- package/dist/version-BMMFrB-m.mjs +83 -0
- package/dist/version-BMMFrB-m.mjs.map +1 -0
- package/package.json +28 -27
- package/skills/run-typed-eslint-rules/SKILL.md +30 -2
- package/dist/ts-compat-CFDky9Ie.mjs +0 -132
- package/dist/ts-compat-CFDky9Ie.mjs.map +0 -1
- package/dist/typed-rule-DFpV2XgE.mjs.map +0 -1
- package/dist/upstream-plugin-D4Lz9A1H.mjs.map +0 -1
package/dist/tanstack-query.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as import_eslint_utils, r as init_typescript_eslint_utils, t as import_dist } from "./typescript-eslint-utils-
|
|
2
|
-
import { n as optionallyTypedRules } from "./typed-rule-
|
|
3
|
-
import { n as upstreamPlugin } from "./upstream-plugin-
|
|
4
|
-
// ../../node_modules/.pnpm/@tanstack+eslint-plugin-query@5.
|
|
1
|
+
import { n as import_eslint_utils, r as init_typescript_eslint_utils, t as import_dist } from "./typescript-eslint-utils-C7ew0-XM.mjs";
|
|
2
|
+
import { n as optionallyTypedRules } from "./typed-rule-FCRt1nKZ.mjs";
|
|
3
|
+
import { n as upstreamPlugin } from "./upstream-plugin-eT7t_K7e.mjs";
|
|
4
|
+
// ../../node_modules/.pnpm/@tanstack+eslint-plugin-query@5.108.4_eslint@10.15.0_jiti@2.7.0_supports-color@10.2.2___341d9f768158d706a68580de4a313aaa/node_modules/@tanstack/eslint-plugin-query/build/modern/rules-B-srrCS9.js
|
|
5
5
|
init_typescript_eslint_utils();
|
|
6
6
|
/**
|
|
7
7
|
* Removes duplicate items, keeping the first item for each key.
|
|
@@ -101,12 +101,6 @@ const ASTUtils = {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
/**
|
|
104
|
-
* Builds the URL of a rule's documentation page.
|
|
105
|
-
* @param ruleName - The rule's name, e.g. `exhaustive-deps`.
|
|
106
|
-
* @returns The URL of the rule's page in the ESLint plugin docs.
|
|
107
|
-
*/
|
|
108
|
-
const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
|
|
109
|
-
/**
|
|
110
104
|
* Wraps a rule's `create` function to track the identifiers imported from TanStack Query packages,
|
|
111
105
|
* and passes helpers that check them.
|
|
112
106
|
* @param create - The rule's `create` function, which also receives the helpers.
|
|
@@ -144,6 +138,12 @@ function detectTanstackQueryImports(create) {
|
|
|
144
138
|
return enhancedRuleInstructions;
|
|
145
139
|
};
|
|
146
140
|
}
|
|
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
|
const ExhaustiveDepsUtils = {
|
|
148
148
|
isRelevantReference(params) {
|
|
149
149
|
const { sourceCode, reference, scopeManager, node, filename } = params;
|
|
@@ -585,51 +585,145 @@ function dereferenceVariablesAndTypeAssertions(queryKeyNode, context) {
|
|
|
585
585
|
}
|
|
586
586
|
return queryKeyNode;
|
|
587
587
|
}
|
|
588
|
-
|
|
589
|
-
|
|
588
|
+
/**
|
|
589
|
+
* Sorts the items covered by the order rules into the required order, keeping the other items in
|
|
590
|
+
* place.
|
|
591
|
+
* @param data - The items to sort.
|
|
592
|
+
* @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
|
|
593
|
+
* those in the second.
|
|
594
|
+
* @param key - The property of each item to compare against the groups.
|
|
595
|
+
* @returns The sorted items, or `null` if they were already in order.
|
|
596
|
+
*/
|
|
597
|
+
function sortDataByOrder(data, orderRules, key) {
|
|
598
|
+
const getSubsetIndex = (item, subsets) => {
|
|
599
|
+
for (let i = 0; i < subsets.length; i++) if (subsets[i]?.includes(item)) return i;
|
|
600
|
+
return null;
|
|
601
|
+
};
|
|
602
|
+
const orderSets = orderRules.reduce((sets, [A, B]) => [
|
|
603
|
+
...sets,
|
|
604
|
+
A,
|
|
605
|
+
B
|
|
606
|
+
], []);
|
|
607
|
+
const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
|
|
608
|
+
let wasResorted = false;
|
|
609
|
+
const inOrderIterator = inOrderArray.sort((a, b) => {
|
|
610
|
+
const aKey = a[key], bKey = b[key];
|
|
611
|
+
const aSubsetIndex = getSubsetIndex(aKey, orderSets);
|
|
612
|
+
const bSubsetIndex = getSubsetIndex(bKey, orderSets);
|
|
613
|
+
if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
|
|
614
|
+
return 0;
|
|
615
|
+
}).values();
|
|
616
|
+
const result = data.map((item) => {
|
|
617
|
+
if (getSubsetIndex(item[key], orderSets) !== null) {
|
|
618
|
+
const sortedItem = inOrderIterator.next().value;
|
|
619
|
+
if (sortedItem[key] !== item[key]) wasResorted = true;
|
|
620
|
+
return sortedItem;
|
|
621
|
+
}
|
|
622
|
+
return item;
|
|
623
|
+
});
|
|
624
|
+
if (!wasResorted) return null;
|
|
625
|
+
return result;
|
|
626
|
+
}
|
|
627
|
+
const createRule$5 = import_eslint_utils.RuleCreator(getDocsUrl);
|
|
628
|
+
/**
|
|
629
|
+
* Creates a rule that reports when the properties of the options object passed to the target
|
|
630
|
+
* functions are not in the required order.
|
|
631
|
+
* @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
|
|
632
|
+
* @param targetFunctions - The names of the functions whose first argument is checked.
|
|
633
|
+
* @param orderRules - Pairs of property groups: the properties of the first group must come before
|
|
634
|
+
* those of the second.
|
|
635
|
+
* @returns An ESLint rule that reports out-of-order properties and fixes them.
|
|
636
|
+
*/
|
|
637
|
+
function createPropertyOrderRule(options, targetFunctions, orderRules) {
|
|
638
|
+
const targetFunctionSet = new Set(targetFunctions);
|
|
639
|
+
/**
|
|
640
|
+
* Checks whether a function name is one of the target functions.
|
|
641
|
+
* @param node - The function name.
|
|
642
|
+
* @returns `true` if the name is a target function.
|
|
643
|
+
*/
|
|
644
|
+
function isTargetFunction(node) {
|
|
645
|
+
return targetFunctionSet.has(node);
|
|
646
|
+
}
|
|
647
|
+
return createRule$5({
|
|
648
|
+
...options,
|
|
649
|
+
create: detectTanstackQueryImports((context) => {
|
|
650
|
+
return { CallExpression(node) {
|
|
651
|
+
if (node.callee.type !== import_dist.AST_NODE_TYPES.Identifier) return;
|
|
652
|
+
const functions = node.callee.name;
|
|
653
|
+
if (!isTargetFunction(functions)) return;
|
|
654
|
+
const argument = node.arguments[0];
|
|
655
|
+
if (argument === void 0 || argument.type !== "ObjectExpression") return;
|
|
656
|
+
const allProperties = argument.properties;
|
|
657
|
+
if (allProperties.length < 2) return;
|
|
658
|
+
const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
|
|
659
|
+
if (p.type === import_dist.AST_NODE_TYPES.Property && p.key.type === import_dist.AST_NODE_TYPES.Identifier) return {
|
|
660
|
+
name: p.key.name,
|
|
661
|
+
property: p
|
|
662
|
+
};
|
|
663
|
+
else return {
|
|
664
|
+
name: `_property_${index}`,
|
|
665
|
+
property: p
|
|
666
|
+
};
|
|
667
|
+
}), orderRules, "name");
|
|
668
|
+
if (sortedProperties === null) return;
|
|
669
|
+
context.report({
|
|
670
|
+
node: argument,
|
|
671
|
+
data: { function: node.callee.name },
|
|
672
|
+
messageId: "invalidOrder",
|
|
673
|
+
fix(fixer) {
|
|
674
|
+
const sourceCode = context.sourceCode;
|
|
675
|
+
const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
|
|
676
|
+
let textBetweenProperties = "";
|
|
677
|
+
if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
|
|
678
|
+
return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
|
|
679
|
+
}, "");
|
|
680
|
+
return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
} };
|
|
684
|
+
})
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
const infiniteQueryFunctions = [
|
|
688
|
+
"infiniteQueryOptions",
|
|
689
|
+
"useInfiniteQuery",
|
|
690
|
+
"useSuspenseInfiniteQuery"
|
|
691
|
+
];
|
|
692
|
+
const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
|
|
693
|
+
const name$6 = "infinite-query-property-order";
|
|
694
|
+
const rule$6 = createPropertyOrderRule({
|
|
590
695
|
name: name$6,
|
|
591
696
|
meta: {
|
|
592
697
|
type: "problem",
|
|
593
698
|
docs: {
|
|
594
|
-
description: "
|
|
699
|
+
description: "Ensure correct order of inference sensitive properties for infinite queries",
|
|
595
700
|
recommended: "error"
|
|
596
701
|
},
|
|
597
|
-
messages: {
|
|
598
|
-
|
|
599
|
-
|
|
702
|
+
messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
|
|
703
|
+
schema: [],
|
|
704
|
+
hasSuggestions: true,
|
|
705
|
+
fixable: "code"
|
|
706
|
+
},
|
|
707
|
+
defaultOptions: []
|
|
708
|
+
}, infiniteQueryFunctions, sortRules$1);
|
|
709
|
+
const mutationFunctions = ["useMutation"];
|
|
710
|
+
const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
|
|
711
|
+
const name$5 = "mutation-property-order";
|
|
712
|
+
const rule$5 = createPropertyOrderRule({
|
|
713
|
+
name: name$5,
|
|
714
|
+
meta: {
|
|
715
|
+
type: "problem",
|
|
716
|
+
docs: {
|
|
717
|
+
description: "Ensure correct order of inference-sensitive properties in useMutation()",
|
|
718
|
+
recommended: "error"
|
|
600
719
|
},
|
|
720
|
+
messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
|
|
721
|
+
schema: [],
|
|
601
722
|
hasSuggestions: true,
|
|
602
|
-
fixable: "code"
|
|
603
|
-
schema: []
|
|
723
|
+
fixable: "code"
|
|
604
724
|
},
|
|
605
|
-
defaultOptions: []
|
|
606
|
-
|
|
607
|
-
return { NewExpression: (node) => {
|
|
608
|
-
if (node.callee.type !== import_dist.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
|
|
609
|
-
const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
|
|
610
|
-
import_dist.AST_NODE_TYPES.FunctionDeclaration,
|
|
611
|
-
import_dist.AST_NODE_TYPES.FunctionExpression,
|
|
612
|
-
import_dist.AST_NODE_TYPES.ArrowFunctionExpression
|
|
613
|
-
]));
|
|
614
|
-
const fnName = fnAncestor?.parent.type === import_dist.AST_NODE_TYPES.VariableDeclarator && fnAncestor.parent.id.type === import_dist.AST_NODE_TYPES.Identifier ? fnAncestor.parent.id : fnAncestor?.id;
|
|
615
|
-
const isReactServerComponent = fnAncestor?.async === true;
|
|
616
|
-
if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
|
|
617
|
-
context.report({
|
|
618
|
-
node: node.parent.type === import_dist.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
|
|
619
|
-
messageId: "unstable",
|
|
620
|
-
fix: (() => {
|
|
621
|
-
const { parent } = node;
|
|
622
|
-
if (parent.type !== import_dist.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== import_dist.AST_NODE_TYPES.Identifier) return;
|
|
623
|
-
const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
|
|
624
|
-
const variableName = parent.id.name;
|
|
625
|
-
return (fixer) => {
|
|
626
|
-
return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
|
|
627
|
-
};
|
|
628
|
-
})()
|
|
629
|
-
});
|
|
630
|
-
} };
|
|
631
|
-
})
|
|
632
|
-
});
|
|
725
|
+
defaultOptions: []
|
|
726
|
+
}, mutationFunctions, sortRules);
|
|
633
727
|
const QUERY_RESULT_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
634
728
|
"UseBaseQueryResult",
|
|
635
729
|
"UseQueryResult",
|
|
@@ -664,7 +758,7 @@ const NoRestDestructuringUtils = {
|
|
|
664
758
|
return checker.getTypeAtLocation(tsNode).getCallSignatures().some((sig) => isQueryResultType(sig.getReturnType()));
|
|
665
759
|
}
|
|
666
760
|
};
|
|
667
|
-
const name$
|
|
761
|
+
const name$4 = "no-rest-destructuring";
|
|
668
762
|
const queryHooks$1 = [
|
|
669
763
|
"useQuery",
|
|
670
764
|
"useQueries",
|
|
@@ -673,8 +767,8 @@ const queryHooks$1 = [
|
|
|
673
767
|
"useSuspenseQueries",
|
|
674
768
|
"useSuspenseInfiniteQuery"
|
|
675
769
|
];
|
|
676
|
-
const rule$
|
|
677
|
-
name: name$
|
|
770
|
+
const rule$4 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
771
|
+
name: name$4,
|
|
678
772
|
meta: {
|
|
679
773
|
type: "problem",
|
|
680
774
|
docs: {
|
|
@@ -730,7 +824,7 @@ const rule$5 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
|
730
824
|
};
|
|
731
825
|
})
|
|
732
826
|
});
|
|
733
|
-
const name$
|
|
827
|
+
const name$3 = "no-unstable-deps";
|
|
734
828
|
const reactHookNames = [
|
|
735
829
|
"useEffect",
|
|
736
830
|
"useCallback",
|
|
@@ -744,8 +838,8 @@ const allHookNames = ["useMutation", ...[
|
|
|
744
838
|
"useInfiniteQuery",
|
|
745
839
|
"useSuspenseInfiniteQuery"
|
|
746
840
|
]];
|
|
747
|
-
const rule$
|
|
748
|
-
name: name$
|
|
841
|
+
const rule$3 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
842
|
+
name: name$3,
|
|
749
843
|
meta: {
|
|
750
844
|
type: "problem",
|
|
751
845
|
docs: {
|
|
@@ -902,127 +996,6 @@ const rule$4 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
|
902
996
|
};
|
|
903
997
|
})
|
|
904
998
|
});
|
|
905
|
-
/**
|
|
906
|
-
* Sorts the items covered by the order rules into the required order, keeping the other items in
|
|
907
|
-
* place.
|
|
908
|
-
* @param data - The items to sort.
|
|
909
|
-
* @param orderRules - Pairs of groups: items whose `key` is in the first group must come before
|
|
910
|
-
* those in the second.
|
|
911
|
-
* @param key - The property of each item to compare against the groups.
|
|
912
|
-
* @returns The sorted items, or `null` if they were already in order.
|
|
913
|
-
*/
|
|
914
|
-
function sortDataByOrder(data, orderRules, key) {
|
|
915
|
-
const getSubsetIndex = (item, subsets) => {
|
|
916
|
-
for (let i = 0; i < subsets.length; i++) if (subsets[i]?.includes(item)) return i;
|
|
917
|
-
return null;
|
|
918
|
-
};
|
|
919
|
-
const orderSets = orderRules.reduce((sets, [A, B]) => [
|
|
920
|
-
...sets,
|
|
921
|
-
A,
|
|
922
|
-
B
|
|
923
|
-
], []);
|
|
924
|
-
const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
|
|
925
|
-
let wasResorted = false;
|
|
926
|
-
const inOrderIterator = inOrderArray.sort((a, b) => {
|
|
927
|
-
const aKey = a[key], bKey = b[key];
|
|
928
|
-
const aSubsetIndex = getSubsetIndex(aKey, orderSets);
|
|
929
|
-
const bSubsetIndex = getSubsetIndex(bKey, orderSets);
|
|
930
|
-
if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
|
|
931
|
-
return 0;
|
|
932
|
-
}).values();
|
|
933
|
-
const result = data.map((item) => {
|
|
934
|
-
if (getSubsetIndex(item[key], orderSets) !== null) {
|
|
935
|
-
const sortedItem = inOrderIterator.next().value;
|
|
936
|
-
if (sortedItem[key] !== item[key]) wasResorted = true;
|
|
937
|
-
return sortedItem;
|
|
938
|
-
}
|
|
939
|
-
return item;
|
|
940
|
-
});
|
|
941
|
-
if (!wasResorted) return null;
|
|
942
|
-
return result;
|
|
943
|
-
}
|
|
944
|
-
const createRule$2 = import_eslint_utils.RuleCreator(getDocsUrl);
|
|
945
|
-
/**
|
|
946
|
-
* Creates a rule that reports when the properties of the options object passed to the target
|
|
947
|
-
* functions are not in the required order.
|
|
948
|
-
* @param options - The rule's metadata, such as `name`, `meta`, and `defaultOptions`.
|
|
949
|
-
* @param targetFunctions - The names of the functions whose first argument is checked.
|
|
950
|
-
* @param orderRules - Pairs of property groups: the properties of the first group must come before
|
|
951
|
-
* those of the second.
|
|
952
|
-
* @returns An ESLint rule that reports out-of-order properties and fixes them.
|
|
953
|
-
*/
|
|
954
|
-
function createPropertyOrderRule(options, targetFunctions, orderRules) {
|
|
955
|
-
const targetFunctionSet = new Set(targetFunctions);
|
|
956
|
-
/**
|
|
957
|
-
* Checks whether a function name is one of the target functions.
|
|
958
|
-
* @param node - The function name.
|
|
959
|
-
* @returns `true` if the name is a target function.
|
|
960
|
-
*/
|
|
961
|
-
function isTargetFunction(node) {
|
|
962
|
-
return targetFunctionSet.has(node);
|
|
963
|
-
}
|
|
964
|
-
return createRule$2({
|
|
965
|
-
...options,
|
|
966
|
-
create: detectTanstackQueryImports((context) => {
|
|
967
|
-
return { CallExpression(node) {
|
|
968
|
-
if (node.callee.type !== import_dist.AST_NODE_TYPES.Identifier) return;
|
|
969
|
-
const functions = node.callee.name;
|
|
970
|
-
if (!isTargetFunction(functions)) return;
|
|
971
|
-
const argument = node.arguments[0];
|
|
972
|
-
if (argument === void 0 || argument.type !== "ObjectExpression") return;
|
|
973
|
-
const allProperties = argument.properties;
|
|
974
|
-
if (allProperties.length < 2) return;
|
|
975
|
-
const sortedProperties = sortDataByOrder(allProperties.flatMap((p, index) => {
|
|
976
|
-
if (p.type === import_dist.AST_NODE_TYPES.Property && p.key.type === import_dist.AST_NODE_TYPES.Identifier) return {
|
|
977
|
-
name: p.key.name,
|
|
978
|
-
property: p
|
|
979
|
-
};
|
|
980
|
-
else return {
|
|
981
|
-
name: `_property_${index}`,
|
|
982
|
-
property: p
|
|
983
|
-
};
|
|
984
|
-
}), orderRules, "name");
|
|
985
|
-
if (sortedProperties === null) return;
|
|
986
|
-
context.report({
|
|
987
|
-
node: argument,
|
|
988
|
-
data: { function: node.callee.name },
|
|
989
|
-
messageId: "invalidOrder",
|
|
990
|
-
fix(fixer) {
|
|
991
|
-
const sourceCode = context.sourceCode;
|
|
992
|
-
const reorderedText = sortedProperties.reduce((sourceText, specifier, index) => {
|
|
993
|
-
let textBetweenProperties = "";
|
|
994
|
-
if (index < allProperties.length - 1) textBetweenProperties = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
|
|
995
|
-
return sourceText + sourceCode.getText(specifier.property) + textBetweenProperties;
|
|
996
|
-
}, "");
|
|
997
|
-
return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], reorderedText);
|
|
998
|
-
}
|
|
999
|
-
});
|
|
1000
|
-
} };
|
|
1001
|
-
})
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
const infiniteQueryFunctions = [
|
|
1005
|
-
"infiniteQueryOptions",
|
|
1006
|
-
"useInfiniteQuery",
|
|
1007
|
-
"useSuspenseInfiniteQuery"
|
|
1008
|
-
];
|
|
1009
|
-
const sortRules$1 = [[["queryFn"], ["getPreviousPageParam", "getNextPageParam"]]];
|
|
1010
|
-
const name$3 = "infinite-query-property-order";
|
|
1011
|
-
const rule$3 = createPropertyOrderRule({
|
|
1012
|
-
name: name$3,
|
|
1013
|
-
meta: {
|
|
1014
|
-
type: "problem",
|
|
1015
|
-
docs: {
|
|
1016
|
-
description: "Ensure correct order of inference sensitive properties for infinite queries",
|
|
1017
|
-
recommended: "error"
|
|
1018
|
-
},
|
|
1019
|
-
messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
|
|
1020
|
-
schema: [],
|
|
1021
|
-
hasSuggestions: true,
|
|
1022
|
-
fixable: "code"
|
|
1023
|
-
},
|
|
1024
|
-
defaultOptions: []
|
|
1025
|
-
}, infiniteQueryFunctions, sortRules$1);
|
|
1026
999
|
const name$2 = "no-void-query-fn";
|
|
1027
1000
|
const rule$2 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
1028
1001
|
name: name$2,
|
|
@@ -1069,25 +1042,7 @@ function isIllegalReturn(checker, type) {
|
|
|
1069
1042
|
const typeString = checker.typeToString(awaited);
|
|
1070
1043
|
return typeString === "void" || typeString === "undefined";
|
|
1071
1044
|
}
|
|
1072
|
-
const
|
|
1073
|
-
const sortRules = [[["onMutate"], ["onError", "onSettled"]]];
|
|
1074
|
-
const name$1 = "mutation-property-order";
|
|
1075
|
-
const rule$1 = createPropertyOrderRule({
|
|
1076
|
-
name: name$1,
|
|
1077
|
-
meta: {
|
|
1078
|
-
type: "problem",
|
|
1079
|
-
docs: {
|
|
1080
|
-
description: "Ensure correct order of inference-sensitive properties in useMutation()",
|
|
1081
|
-
recommended: "error"
|
|
1082
|
-
},
|
|
1083
|
-
messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
|
|
1084
|
-
schema: [],
|
|
1085
|
-
hasSuggestions: true,
|
|
1086
|
-
fixable: "code"
|
|
1087
|
-
},
|
|
1088
|
-
defaultOptions: []
|
|
1089
|
-
}, mutationFunctions, sortRules);
|
|
1090
|
-
const name = "prefer-query-options";
|
|
1045
|
+
const name$1 = "prefer-query-options";
|
|
1091
1046
|
const queryHooks = [
|
|
1092
1047
|
"useQuery",
|
|
1093
1048
|
"useInfiniteQuery",
|
|
@@ -1124,8 +1079,8 @@ const queryClientFilterMethods = [
|
|
|
1124
1079
|
"setQueriesData"
|
|
1125
1080
|
];
|
|
1126
1081
|
const queryOptionsBuilders = ["queryOptions", "infiniteQueryOptions"];
|
|
1127
|
-
const rule = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
1128
|
-
name,
|
|
1082
|
+
const rule$1 = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
1083
|
+
name: name$1,
|
|
1129
1084
|
meta: {
|
|
1130
1085
|
type: "problem",
|
|
1131
1086
|
docs: {
|
|
@@ -1322,17 +1277,62 @@ function unwrapTypeAssertions(node) {
|
|
|
1322
1277
|
while (node.type === import_dist.AST_NODE_TYPES.TSAsExpression || node.type === import_dist.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_dist.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
|
|
1323
1278
|
return node;
|
|
1324
1279
|
}
|
|
1280
|
+
const name = "stable-query-client";
|
|
1281
|
+
const rule = import_eslint_utils.RuleCreator(getDocsUrl)({
|
|
1282
|
+
name,
|
|
1283
|
+
meta: {
|
|
1284
|
+
type: "problem",
|
|
1285
|
+
docs: {
|
|
1286
|
+
description: "Makes sure that QueryClient is stable",
|
|
1287
|
+
recommended: "error"
|
|
1288
|
+
},
|
|
1289
|
+
messages: {
|
|
1290
|
+
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"),
|
|
1291
|
+
fixTo: "Fix to {{result}}"
|
|
1292
|
+
},
|
|
1293
|
+
hasSuggestions: true,
|
|
1294
|
+
fixable: "code",
|
|
1295
|
+
schema: []
|
|
1296
|
+
},
|
|
1297
|
+
defaultOptions: [],
|
|
1298
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
1299
|
+
return { NewExpression: (node) => {
|
|
1300
|
+
if (node.callee.type !== import_dist.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || !helpers.isSpecificTanstackQueryImport(node.callee, "@tanstack/react-query")) return;
|
|
1301
|
+
const fnAncestor = context.sourceCode.getAncestors(node).reverse().find((ancestor) => ASTUtils.isNodeOfOneOf(ancestor, [
|
|
1302
|
+
import_dist.AST_NODE_TYPES.FunctionDeclaration,
|
|
1303
|
+
import_dist.AST_NODE_TYPES.FunctionExpression,
|
|
1304
|
+
import_dist.AST_NODE_TYPES.ArrowFunctionExpression
|
|
1305
|
+
]));
|
|
1306
|
+
const fnName = fnAncestor?.parent.type === import_dist.AST_NODE_TYPES.VariableDeclarator && fnAncestor.parent.id.type === import_dist.AST_NODE_TYPES.Identifier ? fnAncestor.parent.id : fnAncestor?.id;
|
|
1307
|
+
const isReactServerComponent = fnAncestor?.async === true;
|
|
1308
|
+
if (!ASTUtils.isValidReactComponentOrHookName(fnName) || isReactServerComponent) return;
|
|
1309
|
+
context.report({
|
|
1310
|
+
node: node.parent.type === import_dist.AST_NODE_TYPES.VariableDeclarator ? node.parent : node,
|
|
1311
|
+
messageId: "unstable",
|
|
1312
|
+
fix: (() => {
|
|
1313
|
+
const { parent } = node;
|
|
1314
|
+
if (parent.type !== import_dist.AST_NODE_TYPES.VariableDeclarator || parent.id.type !== import_dist.AST_NODE_TYPES.Identifier) return;
|
|
1315
|
+
const nodeText = (context.sourceCode ?? context.getSourceCode()).getText(node);
|
|
1316
|
+
const variableName = parent.id.name;
|
|
1317
|
+
return (fixer) => {
|
|
1318
|
+
return fixer.replaceTextRange([parent.range[0], parent.range[1]], `[${variableName}] = React.useState(() => ${nodeText})`);
|
|
1319
|
+
};
|
|
1320
|
+
})()
|
|
1321
|
+
});
|
|
1322
|
+
} };
|
|
1323
|
+
})
|
|
1324
|
+
});
|
|
1325
1325
|
const rules = {
|
|
1326
1326
|
[name$7]: rule$7,
|
|
1327
|
-
[name
|
|
1328
|
-
[name$5]: rule$5,
|
|
1327
|
+
[name]: rule,
|
|
1329
1328
|
[name$4]: rule$4,
|
|
1330
1329
|
[name$3]: rule$3,
|
|
1330
|
+
[name$6]: rule$6,
|
|
1331
1331
|
[name$2]: rule$2,
|
|
1332
|
-
[name$
|
|
1333
|
-
[name]: rule
|
|
1332
|
+
[name$5]: rule$5,
|
|
1333
|
+
[name$1]: rule$1
|
|
1334
1334
|
};
|
|
1335
|
-
// ../../node_modules/.pnpm/@tanstack+eslint-plugin-query@5.
|
|
1335
|
+
// ../../node_modules/.pnpm/@tanstack+eslint-plugin-query@5.108.4_eslint@10.15.0_jiti@2.7.0_supports-color@10.2.2___341d9f768158d706a68580de4a313aaa/node_modules/@tanstack/eslint-plugin-query/build/modern/index.js
|
|
1336
1336
|
const recommendedRules = {
|
|
1337
1337
|
"@tanstack/query/exhaustive-deps": "error",
|
|
1338
1338
|
"@tanstack/query/no-rest-destructuring": "warn",
|