eslint-plugin-react-x 5.30.0-beta.13 → 5.30.0-beta.15
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/dist/index.js +62 -1066
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -112,8 +112,7 @@ const rules$7 = {
|
|
|
112
112
|
"react-x/no-unused-state": "off",
|
|
113
113
|
"react-x/refs": "off",
|
|
114
114
|
"react-x/set-state-in-render": "off",
|
|
115
|
-
"react-x/static-components": "off"
|
|
116
|
-
"react-x/unstable-exhaustive-deps": "off"
|
|
115
|
+
"react-x/static-components": "off"
|
|
117
116
|
};
|
|
118
117
|
// src/configs/disable-type-checked.ts
|
|
119
118
|
var disable_type_checked_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -130,7 +129,7 @@ const rules$6 = {
|
|
|
130
129
|
};
|
|
131
130
|
// package.json
|
|
132
131
|
var name$6 = "eslint-plugin-react-x";
|
|
133
|
-
var version = "5.30.0-beta.
|
|
132
|
+
var version = "5.30.0-beta.15";
|
|
134
133
|
// src/utils/create-rule.ts
|
|
135
134
|
function getDocsUrl(ruleName) {
|
|
136
135
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
@@ -192,7 +191,7 @@ function create$50(context) {
|
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
193
|
// src/rules/exhaustive-deps/exhaustive-deps.ts
|
|
195
|
-
const rule$
|
|
194
|
+
const rule$1 = {
|
|
196
195
|
meta: {
|
|
197
196
|
type: "suggestion",
|
|
198
197
|
docs: {
|
|
@@ -288,7 +287,7 @@ const rule$2 = {
|
|
|
288
287
|
while (init.type === "TSAsExpression" || init.type === "AsExpression") init = init.expression;
|
|
289
288
|
let declaration = defNode.parent;
|
|
290
289
|
if (declaration == null && componentScope != null) {
|
|
291
|
-
fastFindReferenceWithParent
|
|
290
|
+
fastFindReferenceWithParent(componentScope.block, def.node.id);
|
|
292
291
|
declaration = def.node.parent;
|
|
293
292
|
if (declaration == null) return false;
|
|
294
293
|
}
|
|
@@ -300,7 +299,7 @@ const rule$2 = {
|
|
|
300
299
|
const id = def.node.id;
|
|
301
300
|
const { name } = callee;
|
|
302
301
|
if (name === "useRef" && id.type === "Identifier") return true;
|
|
303
|
-
else if (isUseEffectEventIdentifier$
|
|
302
|
+
else if (isUseEffectEventIdentifier$1(callee) && id.type === "Identifier") {
|
|
304
303
|
for (const ref of resolved.references) if (ref !== id) useEffectEventVariables.add(ref.identifier);
|
|
305
304
|
return true;
|
|
306
305
|
} else if (name === "useState" || name === "useReducer" || name === "useActionState") {
|
|
@@ -372,10 +371,10 @@ const rule$2 = {
|
|
|
372
371
|
for (const reference of currentScope.references) {
|
|
373
372
|
if (!reference.resolved) continue;
|
|
374
373
|
if (!pureScopes.has(reference.resolved.scope)) continue;
|
|
375
|
-
const referenceNode = fastFindReferenceWithParent
|
|
374
|
+
const referenceNode = fastFindReferenceWithParent(node, reference.identifier);
|
|
376
375
|
if (referenceNode == null) continue;
|
|
377
|
-
const dependencyNode = getDependency
|
|
378
|
-
const dependency = analyzePropertyChain
|
|
376
|
+
const dependencyNode = getDependency(referenceNode);
|
|
377
|
+
const dependency = analyzePropertyChain(dependencyNode, optionalChains);
|
|
379
378
|
if (isEffect && dependencyNode.type === "Identifier" && (dependencyNode.parent?.type === "MemberExpression" || dependencyNode.parent?.type === "OptionalMemberExpression") && !dependencyNode.parent.computed && dependencyNode.parent.property.type === "Identifier" && dependencyNode.parent.property.name === "current" && isInsideEffectCleanup(reference)) currentRefsInEffectCleanup.set(dependency, {
|
|
380
379
|
reference,
|
|
381
380
|
dependencyNode
|
|
@@ -445,7 +444,7 @@ const rule$2 = {
|
|
|
445
444
|
});
|
|
446
445
|
});
|
|
447
446
|
if (setStateInsideEffectWithoutDeps) {
|
|
448
|
-
const { suggestedDependencies } = collectRecommendations
|
|
447
|
+
const { suggestedDependencies } = collectRecommendations({
|
|
449
448
|
dependencies,
|
|
450
449
|
declaredDependencies: [],
|
|
451
450
|
stableDependencies,
|
|
@@ -495,7 +494,7 @@ const rule$2 = {
|
|
|
495
494
|
});
|
|
496
495
|
let declaredDependency;
|
|
497
496
|
try {
|
|
498
|
-
declaredDependency = analyzePropertyChain
|
|
497
|
+
declaredDependency = analyzePropertyChain(declaredDependencyNode, null);
|
|
499
498
|
} catch (error) {
|
|
500
499
|
if (error instanceof Error && /Unsupported node type/.test(error.message)) {
|
|
501
500
|
if (declaredDependencyNode.type === "Literal") {
|
|
@@ -523,7 +522,7 @@ const rule$2 = {
|
|
|
523
522
|
});
|
|
524
523
|
if (!isDeclaredInComponent) externalDependencies.add(declaredDependency);
|
|
525
524
|
});
|
|
526
|
-
const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies } = collectRecommendations
|
|
525
|
+
const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies } = collectRecommendations({
|
|
527
526
|
dependencies,
|
|
528
527
|
declaredDependencies,
|
|
529
528
|
stableDependencies,
|
|
@@ -532,7 +531,7 @@ const rule$2 = {
|
|
|
532
531
|
});
|
|
533
532
|
let suggestedDeps = suggestedDependencies;
|
|
534
533
|
if (duplicateDependencies.size + missingDependencies.size + unnecessaryDependencies.size === 0) {
|
|
535
|
-
scanForConstructions
|
|
534
|
+
scanForConstructions({
|
|
536
535
|
declaredDependencies,
|
|
537
536
|
declaredDependenciesNode,
|
|
538
537
|
componentScope,
|
|
@@ -560,7 +559,7 @@ const rule$2 = {
|
|
|
560
559
|
});
|
|
561
560
|
return;
|
|
562
561
|
}
|
|
563
|
-
if (!isEffect && missingDependencies.size > 0) suggestedDeps = collectRecommendations
|
|
562
|
+
if (!isEffect && missingDependencies.size > 0) suggestedDeps = collectRecommendations({
|
|
564
563
|
dependencies,
|
|
565
564
|
declaredDependencies: [],
|
|
566
565
|
stableDependencies,
|
|
@@ -589,7 +588,7 @@ const rule$2 = {
|
|
|
589
588
|
}
|
|
590
589
|
function getWarningMessage(deps, singlePrefix, label, fixVerb) {
|
|
591
590
|
if (deps.size === 0) return null;
|
|
592
|
-
return (deps.size > 1 ? "" : singlePrefix + " ") + label + " " + (deps.size > 1 ? "dependencies" : "dependency") + ": " + joinEnglish
|
|
591
|
+
return (deps.size > 1 ? "" : singlePrefix + " ") + label + " " + (deps.size > 1 ? "dependencies" : "dependency") + ": " + joinEnglish(Array.from(deps).sort().map((name) => "'" + formatDependency(name) + "'")) + `. Either ${fixVerb} ${deps.size > 1 ? "them" : "it"} or remove the dependency array.`;
|
|
593
592
|
}
|
|
594
593
|
let extraWarning = "";
|
|
595
594
|
if (unnecessaryDependencies.size > 0) {
|
|
@@ -611,7 +610,7 @@ const rule$2 = {
|
|
|
611
610
|
if (!Array.isArray(refs)) return;
|
|
612
611
|
let isPropsOnlyUsedInMembers = true;
|
|
613
612
|
for (const ref of refs) {
|
|
614
|
-
const id = fastFindReferenceWithParent
|
|
613
|
+
const id = fastFindReferenceWithParent(componentScope.block, ref.identifier);
|
|
615
614
|
if (!id) {
|
|
616
615
|
isPropsOnlyUsedInMembers = false;
|
|
617
616
|
break;
|
|
@@ -719,11 +718,11 @@ const rule$2 = {
|
|
|
719
718
|
});
|
|
720
719
|
}
|
|
721
720
|
function visitCallExpression(node) {
|
|
722
|
-
const callbackIndex = getReactiveHookCallbackIndex
|
|
721
|
+
const callbackIndex = getReactiveHookCallbackIndex(node.callee, options);
|
|
723
722
|
if (callbackIndex === -1) return;
|
|
724
723
|
let callback = node.arguments[callbackIndex];
|
|
725
724
|
const reactiveHook = node.callee;
|
|
726
|
-
const nodeWithoutNamespace = getNodeWithoutReactNamespace$
|
|
725
|
+
const nodeWithoutNamespace = getNodeWithoutReactNamespace$1(reactiveHook);
|
|
727
726
|
const reactiveHookName = "name" in nodeWithoutNamespace ? nodeWithoutNamespace.name : "";
|
|
728
727
|
const maybeNode = node.arguments[callbackIndex + 1];
|
|
729
728
|
const declaredDependenciesNode = maybeNode && !(maybeNode.type === "Identifier" && maybeNode.name === "undefined") ? maybeNode : void 0;
|
|
@@ -763,7 +762,7 @@ const rule$2 = {
|
|
|
763
762
|
if (def.type === "Parameter") {
|
|
764
763
|
reportProblem({
|
|
765
764
|
node: reactiveHook,
|
|
766
|
-
message: getUnknownDependenciesMessage
|
|
765
|
+
message: getUnknownDependenciesMessage(reactiveHookName)
|
|
767
766
|
});
|
|
768
767
|
return;
|
|
769
768
|
}
|
|
@@ -786,7 +785,7 @@ const rule$2 = {
|
|
|
786
785
|
default:
|
|
787
786
|
reportProblem({
|
|
788
787
|
node: reactiveHook,
|
|
789
|
-
message: getUnknownDependenciesMessage
|
|
788
|
+
message: getUnknownDependenciesMessage(reactiveHookName)
|
|
790
789
|
});
|
|
791
790
|
return;
|
|
792
791
|
}
|
|
@@ -804,7 +803,7 @@ const rule$2 = {
|
|
|
804
803
|
return { CallExpression: visitCallExpression };
|
|
805
804
|
}
|
|
806
805
|
};
|
|
807
|
-
function collectRecommendations
|
|
806
|
+
function collectRecommendations({ dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect }) {
|
|
808
807
|
const depTree = createDepTree();
|
|
809
808
|
function createDepTree() {
|
|
810
809
|
return {
|
|
@@ -890,7 +889,7 @@ function collectRecommendations$1({ dependencies, declaredDependencies, stableDe
|
|
|
890
889
|
missingDependencies
|
|
891
890
|
};
|
|
892
891
|
}
|
|
893
|
-
function getConstructionExpressionType
|
|
892
|
+
function getConstructionExpressionType(node) {
|
|
894
893
|
switch (node.type) {
|
|
895
894
|
case "ObjectExpression": return "object";
|
|
896
895
|
case "ArrayExpression": return "array";
|
|
@@ -898,15 +897,15 @@ function getConstructionExpressionType$1(node) {
|
|
|
898
897
|
case "FunctionExpression": return "function";
|
|
899
898
|
case "ClassExpression": return "class";
|
|
900
899
|
case "ConditionalExpression":
|
|
901
|
-
if (getConstructionExpressionType
|
|
900
|
+
if (getConstructionExpressionType(node.consequent) != null || getConstructionExpressionType(node.alternate) != null) return "conditional";
|
|
902
901
|
return null;
|
|
903
902
|
case "LogicalExpression":
|
|
904
|
-
if (getConstructionExpressionType
|
|
903
|
+
if (getConstructionExpressionType(node.left) != null || getConstructionExpressionType(node.right) != null) return "logical expression";
|
|
905
904
|
return null;
|
|
906
905
|
case "JSXFragment": return "JSX fragment";
|
|
907
906
|
case "JSXElement": return "JSX element";
|
|
908
907
|
case "AssignmentExpression":
|
|
909
|
-
if (getConstructionExpressionType
|
|
908
|
+
if (getConstructionExpressionType(node.right) != null) return "assignment expression";
|
|
910
909
|
return null;
|
|
911
910
|
case "NewExpression": return "object construction";
|
|
912
911
|
case "Literal":
|
|
@@ -914,18 +913,18 @@ function getConstructionExpressionType$1(node) {
|
|
|
914
913
|
return null;
|
|
915
914
|
case "TypeCastExpression":
|
|
916
915
|
case "AsExpression":
|
|
917
|
-
case "TSAsExpression": return getConstructionExpressionType
|
|
916
|
+
case "TSAsExpression": return getConstructionExpressionType(node.expression);
|
|
918
917
|
}
|
|
919
918
|
return null;
|
|
920
919
|
}
|
|
921
|
-
function scanForConstructions
|
|
920
|
+
function scanForConstructions({ declaredDependencies, declaredDependenciesNode, componentScope, scope }) {
|
|
922
921
|
const constructions = declaredDependencies.map(({ key }) => {
|
|
923
922
|
const ref = componentScope.variables.find((v) => v.name === key);
|
|
924
923
|
if (ref == null) return null;
|
|
925
924
|
const node = ref.defs[0];
|
|
926
925
|
if (node == null) return null;
|
|
927
926
|
if (node.type === "Variable" && node.node.type === "VariableDeclarator" && node.node.id.type === "Identifier" && node.node.init != null) {
|
|
928
|
-
const constantExpressionType = getConstructionExpressionType
|
|
927
|
+
const constantExpressionType = getConstructionExpressionType(node.node.init);
|
|
929
928
|
if (constantExpressionType) return [ref, constantExpressionType];
|
|
930
929
|
}
|
|
931
930
|
if (node.type === "FunctionName" && node.node.type === "FunctionDeclaration") return [ref, "function"];
|
|
@@ -945,7 +944,7 @@ function scanForConstructions$1({ declaredDependencies, declaredDependenciesNode
|
|
|
945
944
|
let currentScope = reference.from;
|
|
946
945
|
while (currentScope !== scope && currentScope != null) currentScope = currentScope.upper;
|
|
947
946
|
if (currentScope !== scope) {
|
|
948
|
-
if (!isAncestorNodeOf
|
|
947
|
+
if (!isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) return true;
|
|
949
948
|
}
|
|
950
949
|
}
|
|
951
950
|
return false;
|
|
@@ -956,45 +955,45 @@ function scanForConstructions$1({ declaredDependencies, declaredDependenciesNode
|
|
|
956
955
|
isUsedOutsideOfHook: isUsedOutsideOfHook(ref)
|
|
957
956
|
}));
|
|
958
957
|
}
|
|
959
|
-
function getDependency
|
|
960
|
-
if (node.parent && (node.parent.type === "MemberExpression" || node.parent.type === "OptionalMemberExpression") && node.parent.object === node && "name" in node.parent.property && node.parent.property.name !== "current" && !node.parent.computed && !(node.parent.parent != null && (node.parent.parent.type === "CallExpression" || node.parent.parent.type === "OptionalCallExpression") && node.parent.parent.callee === node.parent)) return getDependency
|
|
958
|
+
function getDependency(node) {
|
|
959
|
+
if (node.parent && (node.parent.type === "MemberExpression" || node.parent.type === "OptionalMemberExpression") && node.parent.object === node && "name" in node.parent.property && node.parent.property.name !== "current" && !node.parent.computed && !(node.parent.parent != null && (node.parent.parent.type === "CallExpression" || node.parent.parent.type === "OptionalCallExpression") && node.parent.parent.callee === node.parent)) return getDependency(node.parent);
|
|
961
960
|
else if (node.type === "MemberExpression" && node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node) return node.object;
|
|
962
961
|
else return node;
|
|
963
962
|
}
|
|
964
|
-
function markNode
|
|
963
|
+
function markNode(node, optionalChains, result) {
|
|
965
964
|
if (optionalChains) {
|
|
966
965
|
if ("optional" in node && node.optional) {
|
|
967
966
|
if (!optionalChains.has(result)) optionalChains.set(result, true);
|
|
968
967
|
} else optionalChains.set(result, false);
|
|
969
968
|
}
|
|
970
969
|
}
|
|
971
|
-
function analyzePropertyChain
|
|
970
|
+
function analyzePropertyChain(node, optionalChains) {
|
|
972
971
|
if (node.type === "Identifier" || node.type === "JSXIdentifier") {
|
|
973
972
|
const result = node.name;
|
|
974
973
|
if (optionalChains) optionalChains.set(result, false);
|
|
975
974
|
return result;
|
|
976
975
|
} else if (node.type === "MemberExpression" && !node.computed) {
|
|
977
|
-
const result = `${analyzePropertyChain
|
|
978
|
-
markNode
|
|
976
|
+
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
977
|
+
markNode(node, optionalChains, result);
|
|
979
978
|
return result;
|
|
980
979
|
} else if (node.type === "OptionalMemberExpression" && !node.computed) {
|
|
981
|
-
const result = `${analyzePropertyChain
|
|
982
|
-
markNode
|
|
980
|
+
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
981
|
+
markNode(node, optionalChains, result);
|
|
983
982
|
return result;
|
|
984
983
|
} else if (node.type === "ChainExpression" && (!("computed" in node) || !node.computed)) {
|
|
985
984
|
const expression = node.expression;
|
|
986
985
|
if (expression.type === "CallExpression") throw new Error(`Unsupported node type: ${expression.type}`);
|
|
987
|
-
const result = `${analyzePropertyChain
|
|
988
|
-
markNode
|
|
986
|
+
const result = `${analyzePropertyChain(expression.object, optionalChains)}.${analyzePropertyChain(expression.property, null)}`;
|
|
987
|
+
markNode(expression, optionalChains, result);
|
|
989
988
|
return result;
|
|
990
989
|
} else throw new Error(`Unsupported node type: ${node.type}`);
|
|
991
990
|
}
|
|
992
|
-
function getNodeWithoutReactNamespace$
|
|
991
|
+
function getNodeWithoutReactNamespace$1(node) {
|
|
993
992
|
if (node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "React" && node.property.type === "Identifier" && !node.computed) return node.property;
|
|
994
993
|
return node;
|
|
995
994
|
}
|
|
996
|
-
function getReactiveHookCallbackIndex
|
|
997
|
-
const node = getNodeWithoutReactNamespace$
|
|
995
|
+
function getReactiveHookCallbackIndex(calleeNode, options) {
|
|
996
|
+
const node = getNodeWithoutReactNamespace$1(calleeNode);
|
|
998
997
|
if (node.type !== "Identifier") return -1;
|
|
999
998
|
switch (node.name) {
|
|
1000
999
|
case "useEffect":
|
|
@@ -1005,7 +1004,7 @@ function getReactiveHookCallbackIndex$1(calleeNode, options) {
|
|
|
1005
1004
|
default: if (node === calleeNode && options && options.additionalHooks) {
|
|
1006
1005
|
let name;
|
|
1007
1006
|
try {
|
|
1008
|
-
name = analyzePropertyChain
|
|
1007
|
+
name = analyzePropertyChain(node, null);
|
|
1009
1008
|
} catch (error) {
|
|
1010
1009
|
if (error instanceof Error && /Unsupported node type/.test(error.message)) return 0;
|
|
1011
1010
|
else throw error;
|
|
@@ -1014,20 +1013,20 @@ function getReactiveHookCallbackIndex$1(calleeNode, options) {
|
|
|
1014
1013
|
} else return -1;
|
|
1015
1014
|
}
|
|
1016
1015
|
}
|
|
1017
|
-
function fastFindReferenceWithParent
|
|
1016
|
+
function fastFindReferenceWithParent(start, target) {
|
|
1018
1017
|
const queue = [start];
|
|
1019
1018
|
let item;
|
|
1020
1019
|
while (queue.length) {
|
|
1021
1020
|
item = queue.shift();
|
|
1022
|
-
if (isSameIdentifier
|
|
1023
|
-
if (!isAncestorNodeOf
|
|
1021
|
+
if (isSameIdentifier(item, target)) return item;
|
|
1022
|
+
if (!isAncestorNodeOf(item, target)) continue;
|
|
1024
1023
|
for (const [key, value] of Object.entries(item)) {
|
|
1025
1024
|
if (key === "parent") continue;
|
|
1026
|
-
if (isNodeLike
|
|
1025
|
+
if (isNodeLike(value)) {
|
|
1027
1026
|
value.parent = item;
|
|
1028
1027
|
queue.push(value);
|
|
1029
1028
|
} else if (Array.isArray(value)) value.forEach((val) => {
|
|
1030
|
-
if (isNodeLike
|
|
1029
|
+
if (isNodeLike(val)) {
|
|
1031
1030
|
val.parent = item;
|
|
1032
1031
|
queue.push(val);
|
|
1033
1032
|
}
|
|
@@ -1036,7 +1035,7 @@ function fastFindReferenceWithParent$1(start, target) {
|
|
|
1036
1035
|
}
|
|
1037
1036
|
return null;
|
|
1038
1037
|
}
|
|
1039
|
-
function joinEnglish
|
|
1038
|
+
function joinEnglish(arr) {
|
|
1040
1039
|
let s = "";
|
|
1041
1040
|
for (let i = 0; i < arr.length; i++) {
|
|
1042
1041
|
s += arr[i];
|
|
@@ -1046,19 +1045,19 @@ function joinEnglish$1(arr) {
|
|
|
1046
1045
|
}
|
|
1047
1046
|
return s;
|
|
1048
1047
|
}
|
|
1049
|
-
function isNodeLike
|
|
1048
|
+
function isNodeLike(val) {
|
|
1050
1049
|
return typeof val === "object" && val !== null && !Array.isArray(val) && "type" in val && typeof val.type === "string";
|
|
1051
1050
|
}
|
|
1052
|
-
function isSameIdentifier
|
|
1051
|
+
function isSameIdentifier(a, b) {
|
|
1053
1052
|
return (a.type === "Identifier" || a.type === "JSXIdentifier") && a.type === b.type && a.name === b.name && !!a.range && !!b.range && a.range[0] === b.range[0] && a.range[1] === b.range[1];
|
|
1054
1053
|
}
|
|
1055
|
-
function isAncestorNodeOf
|
|
1054
|
+
function isAncestorNodeOf(a, b) {
|
|
1056
1055
|
return !!a.range && !!b.range && a.range[0] <= b.range[0] && a.range[1] >= b.range[1];
|
|
1057
1056
|
}
|
|
1058
|
-
function isUseEffectEventIdentifier$
|
|
1057
|
+
function isUseEffectEventIdentifier$1(node) {
|
|
1059
1058
|
return node.type === "Identifier" && node.name === "useEffectEvent";
|
|
1060
1059
|
}
|
|
1061
|
-
function getUnknownDependenciesMessage
|
|
1060
|
+
function getUnknownDependenciesMessage(reactiveHookName) {
|
|
1062
1061
|
return `React Hook ${reactiveHookName} received a function whose dependencies are unknown. Pass an inline function instead.`;
|
|
1063
1062
|
}
|
|
1064
1063
|
// src/rules/globals/helpers.ts
|
|
@@ -6092,7 +6091,7 @@ function isInsideTryCatch(node) {
|
|
|
6092
6091
|
}
|
|
6093
6092
|
return false;
|
|
6094
6093
|
}
|
|
6095
|
-
function getNodeWithoutReactNamespace
|
|
6094
|
+
function getNodeWithoutReactNamespace(node) {
|
|
6096
6095
|
if (node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "React" && node.property.type === "Identifier" && !node.computed) return node.property;
|
|
6097
6096
|
return node;
|
|
6098
6097
|
}
|
|
@@ -6101,7 +6100,7 @@ function isEffectIdentifier(node, additionalHooks) {
|
|
|
6101
6100
|
if (additionalHooks && node.type === "Identifier") return additionalHooks.test(node.name);
|
|
6102
6101
|
return false;
|
|
6103
6102
|
}
|
|
6104
|
-
function isUseEffectEventIdentifier
|
|
6103
|
+
function isUseEffectEventIdentifier(node) {
|
|
6105
6104
|
return node.type === "Identifier" && node.name === "useEffectEvent";
|
|
6106
6105
|
}
|
|
6107
6106
|
function useEffectEventError(fn, called) {
|
|
@@ -6111,7 +6110,7 @@ function useEffectEventError(fn, called) {
|
|
|
6111
6110
|
function isUseIdentifier(node) {
|
|
6112
6111
|
return isReactFunction(node, "use");
|
|
6113
6112
|
}
|
|
6114
|
-
const rule
|
|
6113
|
+
const rule = {
|
|
6115
6114
|
meta: {
|
|
6116
6115
|
type: "problem",
|
|
6117
6116
|
docs: {
|
|
@@ -6136,7 +6135,7 @@ const rule$1 = {
|
|
|
6136
6135
|
function recordAllUseEffectEventFunctions(scope) {
|
|
6137
6136
|
for (const reference of scope.references) {
|
|
6138
6137
|
const parent = reference.identifier.parent;
|
|
6139
|
-
if (parent?.type === "VariableDeclarator" && parent.init && parent.init.type === "CallExpression" && parent.init.callee && isUseEffectEventIdentifier
|
|
6138
|
+
if (parent?.type === "VariableDeclarator" && parent.init && parent.init.type === "CallExpression" && parent.init.callee && isUseEffectEventIdentifier(parent.init.callee)) {
|
|
6140
6139
|
if (reference.resolved === null) throw new Error("Unexpected null reference.resolved");
|
|
6141
6140
|
for (const ref of reference.resolved.references) if (ref !== reference) useEffectEventFunctions.add(ref.identifier);
|
|
6142
6141
|
}
|
|
@@ -6315,9 +6314,9 @@ const rule$1 = {
|
|
|
6315
6314
|
}
|
|
6316
6315
|
reactHooks.push(callee);
|
|
6317
6316
|
}
|
|
6318
|
-
const nodeWithoutNamespace = getNodeWithoutReactNamespace
|
|
6319
|
-
if ((isEffectIdentifier(nodeWithoutNamespace, additionalEffectHooks) || isUseEffectEventIdentifier
|
|
6320
|
-
if (isUseEffectEventIdentifier
|
|
6317
|
+
const nodeWithoutNamespace = getNodeWithoutReactNamespace(node.callee);
|
|
6318
|
+
if ((isEffectIdentifier(nodeWithoutNamespace, additionalEffectHooks) || isUseEffectEventIdentifier(nodeWithoutNamespace)) && node.arguments.length > 0) lastEffect = node;
|
|
6319
|
+
if (isUseEffectEventIdentifier(nodeWithoutNamespace) && node.parent?.type !== "VariableDeclarator" && node.parent?.type !== "ExpressionStatement") {
|
|
6321
6320
|
const message = useEffectEventError(null, false);
|
|
6322
6321
|
context.report({
|
|
6323
6322
|
node,
|
|
@@ -7180,1008 +7179,6 @@ function create$3(context) {
|
|
|
7180
7179
|
}
|
|
7181
7180
|
} });
|
|
7182
7181
|
}
|
|
7183
|
-
// src/rules/unstable-exhaustive-deps/lib.ts
|
|
7184
|
-
function getHookConfigs(hooks = []) {
|
|
7185
|
-
const reactive = /* @__PURE__ */ new Map();
|
|
7186
|
-
const stable = /* @__PURE__ */ new Map();
|
|
7187
|
-
for (const { name, closureIndex, dependenciesIndex, stableResult } of hooks) {
|
|
7188
|
-
if (closureIndex != null && dependenciesIndex != null && closureIndex !== dependenciesIndex) reactive.set(name, {
|
|
7189
|
-
closureIndex,
|
|
7190
|
-
dependenciesIndex
|
|
7191
|
-
});
|
|
7192
|
-
if (stableResult === true) stable.set(name, true);
|
|
7193
|
-
else if (typeof stableResult === "number") stable.set(name, /* @__PURE__ */ new Set([stableResult]));
|
|
7194
|
-
else if (Array.isArray(stableResult)) stable.set(name, new Set(stableResult));
|
|
7195
|
-
}
|
|
7196
|
-
return {
|
|
7197
|
-
reactive,
|
|
7198
|
-
stable
|
|
7199
|
-
};
|
|
7200
|
-
}
|
|
7201
|
-
function getReactiveHookConfig(node, configs) {
|
|
7202
|
-
if (configs.reactive.size === 0) return null;
|
|
7203
|
-
const name = Extract.getCalleeName(node);
|
|
7204
|
-
if (name == null) return null;
|
|
7205
|
-
const config = configs.reactive.get(name);
|
|
7206
|
-
if (config == null) return null;
|
|
7207
|
-
return {
|
|
7208
|
-
name,
|
|
7209
|
-
...config
|
|
7210
|
-
};
|
|
7211
|
-
}
|
|
7212
|
-
function isConfiguredStableHookValue(variable, configs) {
|
|
7213
|
-
if (configs.stable.size === 0) return false;
|
|
7214
|
-
let matchedNode = null;
|
|
7215
|
-
let stableResult = null;
|
|
7216
|
-
let initializerCount = 0;
|
|
7217
|
-
for (const def of variable.defs) {
|
|
7218
|
-
if (def.type !== DefinitionType.Variable || def.node.init == null) continue;
|
|
7219
|
-
initializerCount++;
|
|
7220
|
-
const init = Extract.unwrap(def.node.init);
|
|
7221
|
-
if (init.type !== AST_NODE_TYPES.CallExpression) continue;
|
|
7222
|
-
const name = Extract.getCalleeName(init);
|
|
7223
|
-
if (name == null) continue;
|
|
7224
|
-
const config = configs.stable.get(name);
|
|
7225
|
-
if (config == null) continue;
|
|
7226
|
-
if (matchedNode != null) return false;
|
|
7227
|
-
matchedNode = def.node;
|
|
7228
|
-
stableResult = config;
|
|
7229
|
-
}
|
|
7230
|
-
if (initializerCount !== 1) return false;
|
|
7231
|
-
if (matchedNode == null || stableResult == null) return false;
|
|
7232
|
-
if (variable.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
7233
|
-
const { id } = matchedNode;
|
|
7234
|
-
if (stableResult === true) return id.type === AST_NODE_TYPES.Identifier;
|
|
7235
|
-
if (id.type !== AST_NODE_TYPES.ArrayPattern) return false;
|
|
7236
|
-
const index = id.elements.findIndex((element) => {
|
|
7237
|
-
if (element == null) return false;
|
|
7238
|
-
const binding = element.type === AST_NODE_TYPES.AssignmentPattern ? element.left : element;
|
|
7239
|
-
return variable.identifiers.some((identifier) => identifier === binding);
|
|
7240
|
-
});
|
|
7241
|
-
return index !== -1 && stableResult.has(index);
|
|
7242
|
-
}
|
|
7243
|
-
// src/rules/unstable-exhaustive-deps/unstable-exhaustive-deps.ts
|
|
7244
|
-
const rule = {
|
|
7245
|
-
meta: {
|
|
7246
|
-
type: "suggestion",
|
|
7247
|
-
docs: {
|
|
7248
|
-
description: "Verifies the list of dependencies for Hooks like 'useEffect' and similar, with support for custom Hooks and stable Hook results.",
|
|
7249
|
-
url: "https://eslint-react.xyz/docs/rules/unstable-exhaustive-deps"
|
|
7250
|
-
},
|
|
7251
|
-
fixable: "code",
|
|
7252
|
-
hasSuggestions: true,
|
|
7253
|
-
schema: [{
|
|
7254
|
-
type: "object",
|
|
7255
|
-
additionalProperties: false,
|
|
7256
|
-
enableDangerousAutofixThisMayCauseInfiniteLoops: false,
|
|
7257
|
-
properties: {
|
|
7258
|
-
additionalHooks: { type: "string" },
|
|
7259
|
-
enableDangerousAutofixThisMayCauseInfiniteLoops: { type: "boolean" },
|
|
7260
|
-
experimental_autoDependenciesHooks: {
|
|
7261
|
-
type: "array",
|
|
7262
|
-
items: { type: "string" }
|
|
7263
|
-
},
|
|
7264
|
-
hooks: {
|
|
7265
|
-
type: "array",
|
|
7266
|
-
items: {
|
|
7267
|
-
type: "object",
|
|
7268
|
-
additionalProperties: false,
|
|
7269
|
-
dependencies: {
|
|
7270
|
-
closureIndex: ["dependenciesIndex"],
|
|
7271
|
-
dependenciesIndex: ["closureIndex"]
|
|
7272
|
-
},
|
|
7273
|
-
properties: {
|
|
7274
|
-
name: {
|
|
7275
|
-
type: "string",
|
|
7276
|
-
minLength: 1
|
|
7277
|
-
},
|
|
7278
|
-
closureIndex: {
|
|
7279
|
-
type: "integer",
|
|
7280
|
-
minimum: 0
|
|
7281
|
-
},
|
|
7282
|
-
dependenciesIndex: {
|
|
7283
|
-
type: "integer",
|
|
7284
|
-
minimum: 0
|
|
7285
|
-
},
|
|
7286
|
-
stableResult: { oneOf: [
|
|
7287
|
-
{ type: "boolean" },
|
|
7288
|
-
{
|
|
7289
|
-
type: "integer",
|
|
7290
|
-
minimum: 0
|
|
7291
|
-
},
|
|
7292
|
-
{
|
|
7293
|
-
type: "array",
|
|
7294
|
-
items: {
|
|
7295
|
-
type: "integer",
|
|
7296
|
-
minimum: 0
|
|
7297
|
-
},
|
|
7298
|
-
minItems: 1
|
|
7299
|
-
}
|
|
7300
|
-
] }
|
|
7301
|
-
},
|
|
7302
|
-
required: ["name"]
|
|
7303
|
-
}
|
|
7304
|
-
},
|
|
7305
|
-
requireExplicitEffectDeps: { type: "boolean" }
|
|
7306
|
-
}
|
|
7307
|
-
}]
|
|
7308
|
-
},
|
|
7309
|
-
create(context) {
|
|
7310
|
-
const rawOptions = context.options && context.options[0];
|
|
7311
|
-
const additionalHooks = rawOptions && rawOptions.additionalHooks ? new RegExp(rawOptions.additionalHooks) : getSettingsFromContext(context).additionalEffectHooks;
|
|
7312
|
-
const enableDangerousAutofixThisMayCauseInfiniteLoops = rawOptions && rawOptions.enableDangerousAutofixThisMayCauseInfiniteLoops || false;
|
|
7313
|
-
const experimental_autoDependenciesHooks = rawOptions && Array.isArray(rawOptions.experimental_autoDependenciesHooks) ? rawOptions.experimental_autoDependenciesHooks : [];
|
|
7314
|
-
const requireExplicitEffectDeps = rawOptions && rawOptions.requireExplicitEffectDeps || false;
|
|
7315
|
-
const options = {
|
|
7316
|
-
additionalHooks,
|
|
7317
|
-
experimental_autoDependenciesHooks,
|
|
7318
|
-
enableDangerousAutofixThisMayCauseInfiniteLoops,
|
|
7319
|
-
hooks: getHookConfigs(rawOptions && rawOptions.hooks),
|
|
7320
|
-
requireExplicitEffectDeps
|
|
7321
|
-
};
|
|
7322
|
-
function reportProblem(problem) {
|
|
7323
|
-
if (enableDangerousAutofixThisMayCauseInfiniteLoops) {
|
|
7324
|
-
if (Array.isArray(problem.suggest) && problem.suggest.length > 0 && problem.suggest[0]) problem.fix = problem.suggest[0].fix;
|
|
7325
|
-
}
|
|
7326
|
-
context.report(problem);
|
|
7327
|
-
}
|
|
7328
|
-
const getSourceCode = typeof context.getSourceCode === "function" ? () => {
|
|
7329
|
-
return context.getSourceCode();
|
|
7330
|
-
} : () => {
|
|
7331
|
-
return context.sourceCode;
|
|
7332
|
-
};
|
|
7333
|
-
const getScope = typeof context.getScope === "function" ? () => {
|
|
7334
|
-
return context.getScope();
|
|
7335
|
-
} : (node) => {
|
|
7336
|
-
return context.sourceCode.getScope(node);
|
|
7337
|
-
};
|
|
7338
|
-
const scopeManager = getSourceCode().scopeManager;
|
|
7339
|
-
const setStateCallSites = /* @__PURE__ */ new WeakMap();
|
|
7340
|
-
const stateVariables = /* @__PURE__ */ new WeakSet();
|
|
7341
|
-
const stableKnownValueCache = /* @__PURE__ */ new WeakMap();
|
|
7342
|
-
const functionWithoutCapturedValueCache = /* @__PURE__ */ new WeakMap();
|
|
7343
|
-
const useEffectEventVariables = /* @__PURE__ */ new WeakSet();
|
|
7344
|
-
function memoizeWithWeakMap(fn, map) {
|
|
7345
|
-
return function(arg) {
|
|
7346
|
-
if (map.has(arg)) return map.get(arg);
|
|
7347
|
-
const result = fn(arg);
|
|
7348
|
-
map.set(arg, result);
|
|
7349
|
-
return result;
|
|
7350
|
-
};
|
|
7351
|
-
}
|
|
7352
|
-
function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect, isAutoDepsHook, callExpression, dependenciesIndex) {
|
|
7353
|
-
if (isEffect && node.async) reportProblem({
|
|
7354
|
-
node,
|
|
7355
|
-
message: "Effect callbacks are synchronous to prevent race conditions. Put the async function inside:\n\nuseEffect(() => {\n async function fetchData() {\n // You can await here\n const response = await MyAPI.getData(someId);\n // ...\n }\n fetchData();\n}, [someId]); // Or [] if effect doesn't need props or state\n\nLearn more about data fetching with Hooks: https://react.dev/link/hooks-data-fetching"
|
|
7356
|
-
});
|
|
7357
|
-
const scope = scopeManager.acquire(node);
|
|
7358
|
-
if (!scope) throw new Error("Unable to acquire scope for the current node. This is a bug in eslint-plugin-react-hooks, please file an issue.");
|
|
7359
|
-
const pureScopes = /* @__PURE__ */ new Set();
|
|
7360
|
-
let componentScope = null;
|
|
7361
|
-
{
|
|
7362
|
-
let currentScope = scope.upper;
|
|
7363
|
-
while (currentScope) {
|
|
7364
|
-
pureScopes.add(currentScope);
|
|
7365
|
-
if (currentScope.type === "function" || currentScope.type === "hook" || currentScope.type === "component") break;
|
|
7366
|
-
currentScope = currentScope.upper;
|
|
7367
|
-
}
|
|
7368
|
-
if (!currentScope) return;
|
|
7369
|
-
componentScope = currentScope;
|
|
7370
|
-
}
|
|
7371
|
-
const isArray = Array.isArray;
|
|
7372
|
-
function isStableKnownHookValue(resolved) {
|
|
7373
|
-
if (!isArray(resolved.defs)) return false;
|
|
7374
|
-
const initializers = resolved.defs.filter((definition) => definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.init != null);
|
|
7375
|
-
if (initializers.length !== 1) return false;
|
|
7376
|
-
const def = initializers[0];
|
|
7377
|
-
const defNode = def.node;
|
|
7378
|
-
if (defNode.type !== "VariableDeclarator") return false;
|
|
7379
|
-
let init = defNode.init;
|
|
7380
|
-
if (init == null) return false;
|
|
7381
|
-
while (init.type === "TSAsExpression" || init.type === "AsExpression") init = init.expression;
|
|
7382
|
-
let declaration = defNode.parent;
|
|
7383
|
-
if (declaration == null && componentScope != null) {
|
|
7384
|
-
fastFindReferenceWithParent(componentScope.block, def.node.id);
|
|
7385
|
-
declaration = def.node.parent;
|
|
7386
|
-
if (declaration == null) return false;
|
|
7387
|
-
}
|
|
7388
|
-
if (declaration != null && "kind" in declaration && declaration.kind === "const" && init.type === "Literal" && (typeof init.value === "string" || typeof init.value === "number" || init.value === null)) return true;
|
|
7389
|
-
if (init.type !== "CallExpression") return false;
|
|
7390
|
-
let callee = init.callee;
|
|
7391
|
-
if (callee.type === "MemberExpression" && "name" in callee.object && callee.object.name === "React" && callee.property != null && !callee.computed) callee = callee.property;
|
|
7392
|
-
if (callee.type !== "Identifier") return false;
|
|
7393
|
-
const id = def.node.id;
|
|
7394
|
-
const { name } = callee;
|
|
7395
|
-
if (name === "useRef" && id.type === "Identifier") return true;
|
|
7396
|
-
else if (isUseEffectEventIdentifier(callee) && id.type === "Identifier") {
|
|
7397
|
-
for (const ref of resolved.references) if (ref !== id) useEffectEventVariables.add(ref.identifier);
|
|
7398
|
-
return true;
|
|
7399
|
-
} else if (name === "useState" || name === "useReducer" || name === "useActionState") {
|
|
7400
|
-
const isActionState = name === "useActionState";
|
|
7401
|
-
if (id.type === "ArrayPattern" && (isActionState ? id.elements.length >= 2 : id.elements.length === 2) && isArray(resolved.identifiers)) {
|
|
7402
|
-
const firstNode = id.elements[0] ?? null;
|
|
7403
|
-
const secondNode = id.elements[1] ?? null;
|
|
7404
|
-
const firstElement = firstNode?.type === "AssignmentPattern" ? firstNode.left : firstNode;
|
|
7405
|
-
const secondElement = secondNode?.type === "AssignmentPattern" ? secondNode.left : secondNode;
|
|
7406
|
-
if (resolved.identifiers.some((identifier) => identifier === secondElement)) {
|
|
7407
|
-
if (name === "useState") {
|
|
7408
|
-
const references = resolved.references;
|
|
7409
|
-
for (const reference of references) {
|
|
7410
|
-
if (reference.isWrite() && reference.init !== true) return false;
|
|
7411
|
-
setStateCallSites.set(reference.identifier, firstElement);
|
|
7412
|
-
}
|
|
7413
|
-
}
|
|
7414
|
-
return true;
|
|
7415
|
-
} else if (resolved.identifiers.some((identifier) => identifier === firstElement)) {
|
|
7416
|
-
if (name === "useState") {
|
|
7417
|
-
const references = resolved.references;
|
|
7418
|
-
for (const reference of references) stateVariables.add(reference.identifier);
|
|
7419
|
-
}
|
|
7420
|
-
return false;
|
|
7421
|
-
}
|
|
7422
|
-
}
|
|
7423
|
-
} else if (name === "useTransition") {
|
|
7424
|
-
if (id.type === "ArrayPattern" && id.elements.length === 2 && Array.isArray(resolved.identifiers)) {
|
|
7425
|
-
const secondNode = id.elements[1] ?? null;
|
|
7426
|
-
const secondElement = secondNode?.type === "AssignmentPattern" ? secondNode.left : secondNode;
|
|
7427
|
-
if (resolved.identifiers.some((identifier) => identifier === secondElement)) return true;
|
|
7428
|
-
}
|
|
7429
|
-
}
|
|
7430
|
-
return false;
|
|
7431
|
-
}
|
|
7432
|
-
function isFunctionWithoutCapturedValues(resolved) {
|
|
7433
|
-
if (!isArray(resolved.defs)) return false;
|
|
7434
|
-
const def = resolved.defs[0];
|
|
7435
|
-
if (def == null) return false;
|
|
7436
|
-
if (def.node == null || def.node.id == null) return false;
|
|
7437
|
-
const fnNode = def.node;
|
|
7438
|
-
const childScopes = componentScope?.childScopes || [];
|
|
7439
|
-
let fnScope = null;
|
|
7440
|
-
for (const childScope of childScopes) {
|
|
7441
|
-
const childScopeBlock = childScope.block;
|
|
7442
|
-
if (fnNode.type === "FunctionDeclaration" && childScopeBlock === fnNode || fnNode.type === "VariableDeclarator" && childScopeBlock.parent === fnNode) {
|
|
7443
|
-
fnScope = childScope;
|
|
7444
|
-
break;
|
|
7445
|
-
}
|
|
7446
|
-
}
|
|
7447
|
-
if (fnScope == null) return false;
|
|
7448
|
-
for (const ref of fnScope.through) {
|
|
7449
|
-
if (ref.resolved == null) continue;
|
|
7450
|
-
if (pureScopes.has(ref.resolved.scope) && !memoizedIsStableKnownHookValue(ref.resolved)) return false;
|
|
7451
|
-
}
|
|
7452
|
-
return true;
|
|
7453
|
-
}
|
|
7454
|
-
const memoizedIsStableKnownHookValue = memoizeWithWeakMap((resolved) => isStableKnownHookValue(resolved) || isConfiguredStableHookValue(resolved, options.hooks), stableKnownValueCache);
|
|
7455
|
-
const memoizedIsFunctionWithoutCapturedValues = memoizeWithWeakMap(isFunctionWithoutCapturedValues, functionWithoutCapturedValueCache);
|
|
7456
|
-
const currentRefsInEffectCleanup = /* @__PURE__ */ new Map();
|
|
7457
|
-
function isInsideEffectCleanup(reference) {
|
|
7458
|
-
let curScope = reference.from;
|
|
7459
|
-
let isInReturnedFunction = false;
|
|
7460
|
-
while (curScope != null && curScope.block !== node) {
|
|
7461
|
-
if (curScope.type === "function") isInReturnedFunction = curScope.block.parent != null && curScope.block.parent.type === "ReturnStatement";
|
|
7462
|
-
curScope = curScope.upper;
|
|
7463
|
-
}
|
|
7464
|
-
return isInReturnedFunction;
|
|
7465
|
-
}
|
|
7466
|
-
const dependencies = /* @__PURE__ */ new Map();
|
|
7467
|
-
const optionalChains = /* @__PURE__ */ new Map();
|
|
7468
|
-
gatherDependenciesRecursively(scope);
|
|
7469
|
-
function gatherDependenciesRecursively(currentScope) {
|
|
7470
|
-
for (const reference of currentScope.references) {
|
|
7471
|
-
if (!reference.resolved) continue;
|
|
7472
|
-
if (!pureScopes.has(reference.resolved.scope)) continue;
|
|
7473
|
-
const referenceNode = fastFindReferenceWithParent(node, reference.identifier);
|
|
7474
|
-
if (referenceNode == null) continue;
|
|
7475
|
-
const dependencyNode = getDependency(referenceNode);
|
|
7476
|
-
const dependency = analyzePropertyChain(dependencyNode, optionalChains);
|
|
7477
|
-
if (isEffect && dependencyNode.type === "Identifier" && (dependencyNode.parent?.type === "MemberExpression" || dependencyNode.parent?.type === "OptionalMemberExpression") && !dependencyNode.parent.computed && dependencyNode.parent.property.type === "Identifier" && dependencyNode.parent.property.name === "current" && isInsideEffectCleanup(reference)) currentRefsInEffectCleanup.set(dependency, {
|
|
7478
|
-
reference,
|
|
7479
|
-
dependencyNode
|
|
7480
|
-
});
|
|
7481
|
-
if (dependencyNode.parent?.type === "TSTypeQuery" || dependencyNode.parent?.type === "TSTypeReference") continue;
|
|
7482
|
-
const def = reference.resolved.defs[0];
|
|
7483
|
-
if (def == null) continue;
|
|
7484
|
-
if (def.node != null && def.node.init === node.parent) continue;
|
|
7485
|
-
if (def.type === "TypeParameter" || dependencyNode.parent?.type === "GenericTypeAnnotation") continue;
|
|
7486
|
-
if (!dependencies.has(dependency)) {
|
|
7487
|
-
const resolved = reference.resolved;
|
|
7488
|
-
const isStable = memoizedIsStableKnownHookValue(resolved) || memoizedIsFunctionWithoutCapturedValues(resolved);
|
|
7489
|
-
dependencies.set(dependency, {
|
|
7490
|
-
isStable,
|
|
7491
|
-
references: [reference]
|
|
7492
|
-
});
|
|
7493
|
-
} else dependencies.get(dependency)?.references.push(reference);
|
|
7494
|
-
}
|
|
7495
|
-
for (const childScope of currentScope.childScopes) gatherDependenciesRecursively(childScope);
|
|
7496
|
-
}
|
|
7497
|
-
currentRefsInEffectCleanup.forEach(({ reference, dependencyNode }, dependency) => {
|
|
7498
|
-
const references = reference.resolved?.references || [];
|
|
7499
|
-
let foundCurrentAssignment = false;
|
|
7500
|
-
for (const ref of references) {
|
|
7501
|
-
const { identifier } = ref;
|
|
7502
|
-
const { parent } = identifier;
|
|
7503
|
-
if (parent != null && parent.type === "MemberExpression" && !parent.computed && parent.property.type === "Identifier" && parent.property.name === "current" && parent.parent?.type === "AssignmentExpression" && parent.parent.left === parent) {
|
|
7504
|
-
foundCurrentAssignment = true;
|
|
7505
|
-
break;
|
|
7506
|
-
}
|
|
7507
|
-
}
|
|
7508
|
-
if (foundCurrentAssignment) return;
|
|
7509
|
-
reportProblem({
|
|
7510
|
-
node: dependencyNode.parent.property,
|
|
7511
|
-
message: `The ref value '${dependency}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${dependency}.current' to a variable inside the effect, and use that variable in the cleanup function.`
|
|
7512
|
-
});
|
|
7513
|
-
});
|
|
7514
|
-
const staleAssignments = /* @__PURE__ */ new Set();
|
|
7515
|
-
function reportStaleAssignment(writeExpr, key) {
|
|
7516
|
-
if (staleAssignments.has(key)) return;
|
|
7517
|
-
staleAssignments.add(key);
|
|
7518
|
-
reportProblem({
|
|
7519
|
-
node: writeExpr,
|
|
7520
|
-
message: `Assignments to the '${key}' variable from inside React Hook ${getSourceCode().getText(reactiveHook)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${getSourceCode().getText(reactiveHook)}.`
|
|
7521
|
-
});
|
|
7522
|
-
}
|
|
7523
|
-
const stableDependencies = /* @__PURE__ */ new Set();
|
|
7524
|
-
dependencies.forEach(({ isStable, references }, key) => {
|
|
7525
|
-
if (isStable) stableDependencies.add(key);
|
|
7526
|
-
references.forEach((reference) => {
|
|
7527
|
-
if (reference.writeExpr) reportStaleAssignment(reference.writeExpr, key);
|
|
7528
|
-
});
|
|
7529
|
-
});
|
|
7530
|
-
if (staleAssignments.size > 0) return;
|
|
7531
|
-
if (!declaredDependenciesNode) {
|
|
7532
|
-
if (isAutoDepsHook) return;
|
|
7533
|
-
let setStateInsideEffectWithoutDeps = null;
|
|
7534
|
-
dependencies.forEach(({ references }, key) => {
|
|
7535
|
-
if (setStateInsideEffectWithoutDeps) return;
|
|
7536
|
-
references.forEach((reference) => {
|
|
7537
|
-
if (setStateInsideEffectWithoutDeps) return;
|
|
7538
|
-
const id = reference.identifier;
|
|
7539
|
-
if (!setStateCallSites.has(id)) return;
|
|
7540
|
-
let fnScope = reference.from;
|
|
7541
|
-
while (fnScope != null && fnScope.type !== "function") fnScope = fnScope.upper;
|
|
7542
|
-
if (fnScope?.block === node) setStateInsideEffectWithoutDeps = key;
|
|
7543
|
-
});
|
|
7544
|
-
});
|
|
7545
|
-
if (setStateInsideEffectWithoutDeps) {
|
|
7546
|
-
const { suggestedDependencies } = collectRecommendations({
|
|
7547
|
-
dependencies,
|
|
7548
|
-
declaredDependencies: [],
|
|
7549
|
-
stableDependencies,
|
|
7550
|
-
externalDependencies: /* @__PURE__ */ new Set(),
|
|
7551
|
-
isEffect: true
|
|
7552
|
-
});
|
|
7553
|
-
const suggestedDependenciesText = `[${suggestedDependencies.join(", ")}]`;
|
|
7554
|
-
const dependenciesArgument = callExpression.arguments[dependenciesIndex];
|
|
7555
|
-
const hasSpreadArgumentBeforeOrAtDependencies = callExpression.arguments.slice(0, dependenciesIndex + 1).some((argument) => argument?.type === "SpreadElement");
|
|
7556
|
-
let fix = null;
|
|
7557
|
-
if (!hasSpreadArgumentBeforeOrAtDependencies) {
|
|
7558
|
-
if (dependenciesArgument?.type === "Identifier" && dependenciesArgument.name === "undefined") fix = (fixer) => fixer.replaceText(dependenciesArgument, suggestedDependenciesText);
|
|
7559
|
-
else if (dependenciesArgument == null && dependenciesIndex === callExpression.arguments.length) {
|
|
7560
|
-
const closeParen = getSourceCode().getLastToken(callExpression);
|
|
7561
|
-
if (closeParen != null && closeParen.value === ")") {
|
|
7562
|
-
const tokenBeforeCloseParen = getSourceCode().getTokenBefore(closeParen);
|
|
7563
|
-
fix = tokenBeforeCloseParen?.value === "," ? (fixer) => fixer.insertTextAfter(tokenBeforeCloseParen, ` ${suggestedDependenciesText}`) : (fixer) => fixer.insertTextBefore(closeParen, `, ${suggestedDependenciesText}`);
|
|
7564
|
-
}
|
|
7565
|
-
}
|
|
7566
|
-
}
|
|
7567
|
-
const dependenciesArgumentText = dependenciesIndex === 1 ? "as a second argument" : `as the dependencies argument (index ${dependenciesIndex})`;
|
|
7568
|
-
const problem = {
|
|
7569
|
-
node: reactiveHook,
|
|
7570
|
-
message: `React Hook ${reactiveHookName} contains a call to '${setStateInsideEffectWithoutDeps}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass ${suggestedDependenciesText} ${dependenciesArgumentText} to the ${reactiveHookName} Hook.`
|
|
7571
|
-
};
|
|
7572
|
-
if (fix != null) problem.suggest = [{
|
|
7573
|
-
desc: `Add dependencies array: ${suggestedDependenciesText}`,
|
|
7574
|
-
fix
|
|
7575
|
-
}];
|
|
7576
|
-
reportProblem(problem);
|
|
7577
|
-
}
|
|
7578
|
-
return;
|
|
7579
|
-
}
|
|
7580
|
-
if (isAutoDepsHook && declaredDependenciesNode.type === "Literal" && declaredDependenciesNode.value === null) return;
|
|
7581
|
-
const declaredDependencies = [];
|
|
7582
|
-
const externalDependencies = /* @__PURE__ */ new Set();
|
|
7583
|
-
const isArrayExpression = declaredDependenciesNode.type === "ArrayExpression";
|
|
7584
|
-
const isTSAsArrayExpression = declaredDependenciesNode.type === "TSAsExpression" && declaredDependenciesNode.expression.type === "ArrayExpression";
|
|
7585
|
-
if (!isArrayExpression && !isTSAsArrayExpression) reportProblem({
|
|
7586
|
-
node: declaredDependenciesNode,
|
|
7587
|
-
message: `React Hook ${getSourceCode().getText(reactiveHook)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`
|
|
7588
|
-
});
|
|
7589
|
-
else (isTSAsArrayExpression ? declaredDependenciesNode.expression : declaredDependenciesNode).elements.forEach((declaredDependencyNode) => {
|
|
7590
|
-
if (declaredDependencyNode === null) return;
|
|
7591
|
-
if (declaredDependencyNode.type === "SpreadElement") {
|
|
7592
|
-
reportProblem({
|
|
7593
|
-
node: declaredDependencyNode,
|
|
7594
|
-
message: `React Hook ${getSourceCode().getText(reactiveHook)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`
|
|
7595
|
-
});
|
|
7596
|
-
return;
|
|
7597
|
-
}
|
|
7598
|
-
if (useEffectEventVariables.has(declaredDependencyNode)) reportProblem({
|
|
7599
|
-
node: declaredDependencyNode,
|
|
7600
|
-
message: `Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${getSourceCode().getText(declaredDependencyNode)}\` from the list.`,
|
|
7601
|
-
suggest: [{
|
|
7602
|
-
desc: `Remove the dependency \`${getSourceCode().getText(declaredDependencyNode)}\``,
|
|
7603
|
-
fix(fixer) {
|
|
7604
|
-
return fixer.removeRange(declaredDependencyNode.range);
|
|
7605
|
-
}
|
|
7606
|
-
}]
|
|
7607
|
-
});
|
|
7608
|
-
let declaredDependency;
|
|
7609
|
-
try {
|
|
7610
|
-
declaredDependency = analyzePropertyChain(declaredDependencyNode, null);
|
|
7611
|
-
} catch (error) {
|
|
7612
|
-
if (error instanceof Error && /Unsupported node type/.test(error.message)) {
|
|
7613
|
-
if (declaredDependencyNode.type === "Literal") {
|
|
7614
|
-
if (declaredDependencyNode.value && dependencies.has(declaredDependencyNode.value)) reportProblem({
|
|
7615
|
-
node: declaredDependencyNode,
|
|
7616
|
-
message: `The ${declaredDependencyNode.raw} literal is not a valid dependency because it never changes. Did you mean to include ${declaredDependencyNode.value} in the array instead?`
|
|
7617
|
-
});
|
|
7618
|
-
else reportProblem({
|
|
7619
|
-
node: declaredDependencyNode,
|
|
7620
|
-
message: `The ${declaredDependencyNode.raw} literal is not a valid dependency because it never changes. You can safely remove it.`
|
|
7621
|
-
});
|
|
7622
|
-
} else reportProblem({
|
|
7623
|
-
node: declaredDependencyNode,
|
|
7624
|
-
message: `React Hook ${getSourceCode().getText(reactiveHook)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`
|
|
7625
|
-
});
|
|
7626
|
-
return;
|
|
7627
|
-
} else throw error;
|
|
7628
|
-
}
|
|
7629
|
-
let maybeID = declaredDependencyNode;
|
|
7630
|
-
while (maybeID.type === "MemberExpression" || maybeID.type === "OptionalMemberExpression" || maybeID.type === "ChainExpression") maybeID = maybeID.object || maybeID.expression.object;
|
|
7631
|
-
const isDeclaredInComponent = !componentScope.through.some((ref) => ref.identifier === maybeID);
|
|
7632
|
-
declaredDependencies.push({
|
|
7633
|
-
key: declaredDependency,
|
|
7634
|
-
node: declaredDependencyNode
|
|
7635
|
-
});
|
|
7636
|
-
if (!isDeclaredInComponent) externalDependencies.add(declaredDependency);
|
|
7637
|
-
});
|
|
7638
|
-
const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies } = collectRecommendations({
|
|
7639
|
-
dependencies,
|
|
7640
|
-
declaredDependencies,
|
|
7641
|
-
stableDependencies,
|
|
7642
|
-
externalDependencies,
|
|
7643
|
-
isEffect
|
|
7644
|
-
});
|
|
7645
|
-
let suggestedDeps = suggestedDependencies;
|
|
7646
|
-
if (duplicateDependencies.size + missingDependencies.size + unnecessaryDependencies.size === 0) {
|
|
7647
|
-
scanForConstructions({
|
|
7648
|
-
declaredDependencies,
|
|
7649
|
-
declaredDependenciesNode,
|
|
7650
|
-
componentScope,
|
|
7651
|
-
scope
|
|
7652
|
-
}).forEach(({ construction, isUsedOutsideOfHook, depType }) => {
|
|
7653
|
-
const wrapperHook = depType === "function" ? "useCallback" : "useMemo";
|
|
7654
|
-
const constructionType = depType === "function" ? "definition" : "initialization";
|
|
7655
|
-
const defaultAdvice = `wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`;
|
|
7656
|
-
const advice = isUsedOutsideOfHook ? `To fix this, ${defaultAdvice}` : `Move it inside the ${reactiveHookName} callback. Alternatively, ${defaultAdvice}`;
|
|
7657
|
-
const causation = depType === "conditional" || depType === "logical expression" ? "could make" : "makes";
|
|
7658
|
-
const message = `The '${construction.name.name}' ${depType} ${causation} the dependencies of ${reactiveHookName} Hook (at line ${declaredDependenciesNode.loc?.start.line}) change on every render. ${advice}`;
|
|
7659
|
-
let suggest;
|
|
7660
|
-
if (isUsedOutsideOfHook && construction.type === "Variable" && depType === "function") suggest = [{
|
|
7661
|
-
desc: `Wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`,
|
|
7662
|
-
fix(fixer) {
|
|
7663
|
-
const [before, after] = wrapperHook === "useMemo" ? [`useMemo(() => { return `, "; })"] : ["useCallback(", ")"];
|
|
7664
|
-
return [fixer.insertTextBefore(construction.node.init, before), fixer.insertTextAfter(construction.node.init, after)];
|
|
7665
|
-
}
|
|
7666
|
-
}];
|
|
7667
|
-
reportProblem({
|
|
7668
|
-
node: construction.node,
|
|
7669
|
-
message,
|
|
7670
|
-
suggest
|
|
7671
|
-
});
|
|
7672
|
-
});
|
|
7673
|
-
return;
|
|
7674
|
-
}
|
|
7675
|
-
if (!isEffect && missingDependencies.size > 0) suggestedDeps = collectRecommendations({
|
|
7676
|
-
dependencies,
|
|
7677
|
-
declaredDependencies: [],
|
|
7678
|
-
stableDependencies,
|
|
7679
|
-
externalDependencies,
|
|
7680
|
-
isEffect
|
|
7681
|
-
}).suggestedDependencies;
|
|
7682
|
-
function areDeclaredDepsAlphabetized() {
|
|
7683
|
-
if (declaredDependencies.length === 0) return true;
|
|
7684
|
-
const declaredDepKeys = declaredDependencies.map((dep) => dep.key);
|
|
7685
|
-
const sortedDeclaredDepKeys = declaredDepKeys.slice().sort();
|
|
7686
|
-
return declaredDepKeys.join(",") === sortedDeclaredDepKeys.join(",");
|
|
7687
|
-
}
|
|
7688
|
-
if (areDeclaredDepsAlphabetized()) suggestedDeps.sort();
|
|
7689
|
-
function formatDependency(path) {
|
|
7690
|
-
const members = path.split(".");
|
|
7691
|
-
let finalPath = "";
|
|
7692
|
-
for (let i = 0; i < members.length; i++) {
|
|
7693
|
-
if (i !== 0) {
|
|
7694
|
-
const pathSoFar = members.slice(0, i + 1).join(".");
|
|
7695
|
-
const isOptional = optionalChains.get(pathSoFar) === true;
|
|
7696
|
-
finalPath += isOptional ? "?." : ".";
|
|
7697
|
-
}
|
|
7698
|
-
finalPath += members[i];
|
|
7699
|
-
}
|
|
7700
|
-
return finalPath;
|
|
7701
|
-
}
|
|
7702
|
-
function getWarningMessage(deps, singlePrefix, label, fixVerb) {
|
|
7703
|
-
if (deps.size === 0) return null;
|
|
7704
|
-
return (deps.size > 1 ? "" : singlePrefix + " ") + label + " " + (deps.size > 1 ? "dependencies" : "dependency") + ": " + joinEnglish(Array.from(deps).sort().map((name) => "'" + formatDependency(name) + "'")) + `. Either ${fixVerb} ${deps.size > 1 ? "them" : "it"} or remove the dependency array.`;
|
|
7705
|
-
}
|
|
7706
|
-
let extraWarning = "";
|
|
7707
|
-
if (unnecessaryDependencies.size > 0) {
|
|
7708
|
-
let badRef = null;
|
|
7709
|
-
Array.from(unnecessaryDependencies.keys()).forEach((key) => {
|
|
7710
|
-
if (badRef !== null) return;
|
|
7711
|
-
if (key.endsWith(".current")) badRef = key;
|
|
7712
|
-
});
|
|
7713
|
-
if (badRef !== null) extraWarning = ` Mutable values like '${badRef}' aren't valid dependencies because mutating them doesn't re-render the component.`;
|
|
7714
|
-
else if (externalDependencies.size > 0) {
|
|
7715
|
-
const dep = Array.from(externalDependencies)[0];
|
|
7716
|
-
if (!scope.set.has(dep)) extraWarning = ` Outer scope values like '${dep}' aren't valid dependencies because mutating them doesn't re-render the component.`;
|
|
7717
|
-
}
|
|
7718
|
-
}
|
|
7719
|
-
if (!extraWarning && missingDependencies.has("props")) {
|
|
7720
|
-
const propDep = dependencies.get("props");
|
|
7721
|
-
if (propDep == null) return;
|
|
7722
|
-
const refs = propDep.references;
|
|
7723
|
-
if (!Array.isArray(refs)) return;
|
|
7724
|
-
let isPropsOnlyUsedInMembers = true;
|
|
7725
|
-
for (const ref of refs) {
|
|
7726
|
-
const id = fastFindReferenceWithParent(componentScope.block, ref.identifier);
|
|
7727
|
-
if (!id) {
|
|
7728
|
-
isPropsOnlyUsedInMembers = false;
|
|
7729
|
-
break;
|
|
7730
|
-
}
|
|
7731
|
-
const parent = id.parent;
|
|
7732
|
-
if (parent == null) {
|
|
7733
|
-
isPropsOnlyUsedInMembers = false;
|
|
7734
|
-
break;
|
|
7735
|
-
}
|
|
7736
|
-
if (parent.type !== "MemberExpression" && parent.type !== "OptionalMemberExpression") {
|
|
7737
|
-
isPropsOnlyUsedInMembers = false;
|
|
7738
|
-
break;
|
|
7739
|
-
}
|
|
7740
|
-
}
|
|
7741
|
-
if (isPropsOnlyUsedInMembers) extraWarning = ` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${reactiveHookName} call and refer to those specific props inside ${getSourceCode().getText(reactiveHook)}.`;
|
|
7742
|
-
}
|
|
7743
|
-
if (!extraWarning && missingDependencies.size > 0) {
|
|
7744
|
-
let missingCallbackDep = null;
|
|
7745
|
-
missingDependencies.forEach((missingDep) => {
|
|
7746
|
-
if (missingCallbackDep) return;
|
|
7747
|
-
const topScopeRef = componentScope.set.get(missingDep);
|
|
7748
|
-
const usedDep = dependencies.get(missingDep);
|
|
7749
|
-
if (!usedDep?.references || usedDep?.references[0]?.resolved !== topScopeRef) return;
|
|
7750
|
-
const def = topScopeRef?.defs[0];
|
|
7751
|
-
if (def == null || def.name == null || def.type !== "Parameter") return;
|
|
7752
|
-
let isFunctionCall = false;
|
|
7753
|
-
let id;
|
|
7754
|
-
for (const reference of usedDep.references) {
|
|
7755
|
-
id = reference.identifier;
|
|
7756
|
-
if (id != null && id.parent != null && (id.parent.type === "CallExpression" || id.parent.type === "OptionalCallExpression") && id.parent.callee === id) {
|
|
7757
|
-
isFunctionCall = true;
|
|
7758
|
-
break;
|
|
7759
|
-
}
|
|
7760
|
-
}
|
|
7761
|
-
if (!isFunctionCall) return;
|
|
7762
|
-
missingCallbackDep = missingDep;
|
|
7763
|
-
});
|
|
7764
|
-
if (missingCallbackDep !== null) extraWarning = ` If '${missingCallbackDep}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`;
|
|
7765
|
-
}
|
|
7766
|
-
if (!extraWarning && missingDependencies.size > 0) {
|
|
7767
|
-
let setStateRecommendation = null;
|
|
7768
|
-
for (const missingDep of missingDependencies) {
|
|
7769
|
-
if (setStateRecommendation !== null) break;
|
|
7770
|
-
const references = dependencies.get(missingDep).references;
|
|
7771
|
-
let id;
|
|
7772
|
-
let maybeCall;
|
|
7773
|
-
for (const reference of references) {
|
|
7774
|
-
id = reference.identifier;
|
|
7775
|
-
maybeCall = id.parent;
|
|
7776
|
-
while (maybeCall != null && maybeCall !== componentScope.block) {
|
|
7777
|
-
if (maybeCall.type === "CallExpression") {
|
|
7778
|
-
const correspondingStateVariable = setStateCallSites.get(maybeCall.callee);
|
|
7779
|
-
if (correspondingStateVariable != null) {
|
|
7780
|
-
if ("name" in correspondingStateVariable && correspondingStateVariable.name === missingDep) setStateRecommendation = {
|
|
7781
|
-
missingDep,
|
|
7782
|
-
setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
|
|
7783
|
-
form: "updater"
|
|
7784
|
-
};
|
|
7785
|
-
else if (stateVariables.has(id)) setStateRecommendation = {
|
|
7786
|
-
missingDep,
|
|
7787
|
-
setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
|
|
7788
|
-
form: "reducer"
|
|
7789
|
-
};
|
|
7790
|
-
else {
|
|
7791
|
-
const resolved = reference.resolved;
|
|
7792
|
-
if (resolved != null) {
|
|
7793
|
-
const def = resolved.defs[0];
|
|
7794
|
-
if (def != null && def.type === "Parameter") setStateRecommendation = {
|
|
7795
|
-
missingDep,
|
|
7796
|
-
setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
|
|
7797
|
-
form: "inlineReducer"
|
|
7798
|
-
};
|
|
7799
|
-
}
|
|
7800
|
-
}
|
|
7801
|
-
break;
|
|
7802
|
-
}
|
|
7803
|
-
}
|
|
7804
|
-
maybeCall = maybeCall.parent;
|
|
7805
|
-
}
|
|
7806
|
-
if (setStateRecommendation !== null) break;
|
|
7807
|
-
}
|
|
7808
|
-
}
|
|
7809
|
-
if (setStateRecommendation !== null) switch (setStateRecommendation.form) {
|
|
7810
|
-
case "reducer":
|
|
7811
|
-
extraWarning = ` You can also replace multiple useState variables with useReducer if '${setStateRecommendation.setter}' needs the current value of '${setStateRecommendation.missingDep}'.`;
|
|
7812
|
-
break;
|
|
7813
|
-
case "inlineReducer":
|
|
7814
|
-
extraWarning = ` If '${setStateRecommendation.setter}' needs the current value of '${setStateRecommendation.missingDep}', you can also switch to useReducer instead of useState and read '${setStateRecommendation.missingDep}' in the reducer.`;
|
|
7815
|
-
break;
|
|
7816
|
-
case "updater":
|
|
7817
|
-
extraWarning = ` You can also do a functional update '${setStateRecommendation.setter}(${setStateRecommendation.missingDep.slice(0, 1)} => ...)' if you only need '${setStateRecommendation.missingDep}' in the '${setStateRecommendation.setter}' call.`;
|
|
7818
|
-
break;
|
|
7819
|
-
default: throw new Error("Unknown case.");
|
|
7820
|
-
}
|
|
7821
|
-
}
|
|
7822
|
-
reportProblem({
|
|
7823
|
-
node: declaredDependenciesNode,
|
|
7824
|
-
message: `React Hook ${getSourceCode().getText(reactiveHook)} has ` + (getWarningMessage(missingDependencies, "a", "missing", "include") || getWarningMessage(unnecessaryDependencies, "an", "unnecessary", "exclude") || getWarningMessage(duplicateDependencies, "a", "duplicate", "omit")) + extraWarning,
|
|
7825
|
-
suggest: [{
|
|
7826
|
-
desc: `Update the dependencies array to be: [${suggestedDeps.map(formatDependency).join(", ")}]`,
|
|
7827
|
-
fix(fixer) {
|
|
7828
|
-
return fixer.replaceText(declaredDependenciesNode, `[${suggestedDeps.map(formatDependency).join(", ")}]`);
|
|
7829
|
-
}
|
|
7830
|
-
}]
|
|
7831
|
-
});
|
|
7832
|
-
}
|
|
7833
|
-
function visitCallExpression(node) {
|
|
7834
|
-
const configuredHook = getReactiveHookConfig(node, options.hooks);
|
|
7835
|
-
const callbackIndex = configuredHook ? configuredHook.closureIndex : getReactiveHookCallbackIndex(node.callee, options);
|
|
7836
|
-
if (callbackIndex === -1) return;
|
|
7837
|
-
let callback = node.arguments[callbackIndex];
|
|
7838
|
-
const reactiveHook = node.callee;
|
|
7839
|
-
const nodeWithoutNamespace = getNodeWithoutReactNamespace(reactiveHook);
|
|
7840
|
-
const reactiveHookName = configuredHook?.name ?? ("name" in nodeWithoutNamespace ? nodeWithoutNamespace.name : "");
|
|
7841
|
-
const dependenciesIndex = configuredHook ? configuredHook.dependenciesIndex : callbackIndex + 1;
|
|
7842
|
-
const maybeNode = node.arguments[dependenciesIndex];
|
|
7843
|
-
const declaredDependenciesNode = maybeNode && !(maybeNode.type === "Identifier" && maybeNode.name === "undefined") ? maybeNode : void 0;
|
|
7844
|
-
const isEffect = /Effect($|[^a-z])/g.test(reactiveHookName);
|
|
7845
|
-
if (!callback) {
|
|
7846
|
-
if (configuredHook) {
|
|
7847
|
-
const builtInCallbackIndex = getReactiveHookCallbackIndex(reactiveHook, { additionalHooks: void 0 });
|
|
7848
|
-
const builtInCallback = builtInCallbackIndex === -1 ? null : node.arguments[builtInCallbackIndex];
|
|
7849
|
-
if (builtInCallbackIndex === -1 || builtInCallback != null) return;
|
|
7850
|
-
}
|
|
7851
|
-
reportProblem({
|
|
7852
|
-
node: reactiveHook,
|
|
7853
|
-
message: `React Hook ${reactiveHookName} requires an effect callback. Did you forget to pass a callback to the hook?`
|
|
7854
|
-
});
|
|
7855
|
-
return;
|
|
7856
|
-
}
|
|
7857
|
-
if (!maybeNode && isEffect && options.requireExplicitEffectDeps) reportProblem({
|
|
7858
|
-
node: reactiveHook,
|
|
7859
|
-
message: `React Hook ${reactiveHookName} always requires dependencies. Please add a dependency array or an explicit \`undefined\``
|
|
7860
|
-
});
|
|
7861
|
-
const isAutoDepsHook = options.experimental_autoDependenciesHooks.includes(reactiveHookName);
|
|
7862
|
-
if ((!declaredDependenciesNode || isAutoDepsHook && declaredDependenciesNode.type === "Literal" && declaredDependenciesNode.value === null) && !isEffect) {
|
|
7863
|
-
if (reactiveHookName === "useMemo" || reactiveHookName === "useCallback") reportProblem({
|
|
7864
|
-
node: reactiveHook,
|
|
7865
|
-
message: `React Hook ${reactiveHookName} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`
|
|
7866
|
-
});
|
|
7867
|
-
return;
|
|
7868
|
-
}
|
|
7869
|
-
while (callback.type === "TSAsExpression" || callback.type === "AsExpression") callback = callback.expression;
|
|
7870
|
-
switch (callback.type) {
|
|
7871
|
-
case "FunctionExpression":
|
|
7872
|
-
case "ArrowFunctionExpression":
|
|
7873
|
-
visitFunctionWithDependencies(callback, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect, isAutoDepsHook, node, dependenciesIndex);
|
|
7874
|
-
return;
|
|
7875
|
-
case "Identifier":
|
|
7876
|
-
if (!declaredDependenciesNode || isAutoDepsHook && declaredDependenciesNode.type === "Literal" && declaredDependenciesNode.value === null) return;
|
|
7877
|
-
if ("elements" in declaredDependenciesNode && declaredDependenciesNode.elements && declaredDependenciesNode.elements.some((el) => el && el.type === "Identifier" && el.name === callback.name)) return;
|
|
7878
|
-
const variable = getScope(callback).set.get(callback.name);
|
|
7879
|
-
if (variable == null || variable.defs == null) return;
|
|
7880
|
-
const def = variable.defs[0];
|
|
7881
|
-
if (!def || !def.node) break;
|
|
7882
|
-
if (def.type === "Parameter") {
|
|
7883
|
-
reportProblem({
|
|
7884
|
-
node: reactiveHook,
|
|
7885
|
-
message: getUnknownDependenciesMessage(reactiveHookName)
|
|
7886
|
-
});
|
|
7887
|
-
return;
|
|
7888
|
-
}
|
|
7889
|
-
if (def.type !== "Variable" && def.type !== "FunctionName") break;
|
|
7890
|
-
switch (def.node.type) {
|
|
7891
|
-
case "FunctionDeclaration":
|
|
7892
|
-
visitFunctionWithDependencies(def.node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect, isAutoDepsHook, node, dependenciesIndex);
|
|
7893
|
-
return;
|
|
7894
|
-
case "VariableDeclarator":
|
|
7895
|
-
const init = def.node.init;
|
|
7896
|
-
if (!init) break;
|
|
7897
|
-
switch (init.type) {
|
|
7898
|
-
case "ArrowFunctionExpression":
|
|
7899
|
-
case "FunctionExpression":
|
|
7900
|
-
visitFunctionWithDependencies(init, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect, isAutoDepsHook, node, dependenciesIndex);
|
|
7901
|
-
return;
|
|
7902
|
-
}
|
|
7903
|
-
}
|
|
7904
|
-
break;
|
|
7905
|
-
default:
|
|
7906
|
-
if (configuredHook) return;
|
|
7907
|
-
reportProblem({
|
|
7908
|
-
node: reactiveHook,
|
|
7909
|
-
message: getUnknownDependenciesMessage(reactiveHookName)
|
|
7910
|
-
});
|
|
7911
|
-
return;
|
|
7912
|
-
}
|
|
7913
|
-
reportProblem({
|
|
7914
|
-
node: reactiveHook,
|
|
7915
|
-
message: `React Hook ${reactiveHookName} has a missing dependency: '${callback.name}'. Either include it or remove the dependency array.`,
|
|
7916
|
-
suggest: [{
|
|
7917
|
-
desc: `Update the dependencies array to be: [${callback.name}]`,
|
|
7918
|
-
fix(fixer) {
|
|
7919
|
-
return fixer.replaceText(declaredDependenciesNode, `[${callback.name}]`);
|
|
7920
|
-
}
|
|
7921
|
-
}]
|
|
7922
|
-
});
|
|
7923
|
-
}
|
|
7924
|
-
return { CallExpression: visitCallExpression };
|
|
7925
|
-
}
|
|
7926
|
-
};
|
|
7927
|
-
function collectRecommendations({ dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect }) {
|
|
7928
|
-
const depTree = createDepTree();
|
|
7929
|
-
function createDepTree() {
|
|
7930
|
-
return {
|
|
7931
|
-
isUsed: false,
|
|
7932
|
-
isSatisfiedRecursively: false,
|
|
7933
|
-
isSubtreeUsed: false,
|
|
7934
|
-
children: /* @__PURE__ */ new Map()
|
|
7935
|
-
};
|
|
7936
|
-
}
|
|
7937
|
-
dependencies.forEach((_, key) => {
|
|
7938
|
-
const node = getOrCreateNodeByPath(depTree, key);
|
|
7939
|
-
node.isUsed = true;
|
|
7940
|
-
markAllParentsByPath(depTree, key, (parent) => {
|
|
7941
|
-
parent.isSubtreeUsed = true;
|
|
7942
|
-
});
|
|
7943
|
-
});
|
|
7944
|
-
declaredDependencies.forEach(({ key }) => {
|
|
7945
|
-
const node = getOrCreateNodeByPath(depTree, key);
|
|
7946
|
-
node.isSatisfiedRecursively = true;
|
|
7947
|
-
});
|
|
7948
|
-
stableDependencies.forEach((key) => {
|
|
7949
|
-
const node = getOrCreateNodeByPath(depTree, key);
|
|
7950
|
-
node.isSatisfiedRecursively = true;
|
|
7951
|
-
});
|
|
7952
|
-
function getOrCreateNodeByPath(rootNode, path) {
|
|
7953
|
-
const keys = path.split(".");
|
|
7954
|
-
let node = rootNode;
|
|
7955
|
-
for (const key of keys) {
|
|
7956
|
-
let child = node.children.get(key);
|
|
7957
|
-
if (!child) {
|
|
7958
|
-
child = createDepTree();
|
|
7959
|
-
node.children.set(key, child);
|
|
7960
|
-
}
|
|
7961
|
-
node = child;
|
|
7962
|
-
}
|
|
7963
|
-
return node;
|
|
7964
|
-
}
|
|
7965
|
-
function markAllParentsByPath(rootNode, path, fn) {
|
|
7966
|
-
const keys = path.split(".");
|
|
7967
|
-
let node = rootNode;
|
|
7968
|
-
for (const key of keys) {
|
|
7969
|
-
const child = node.children.get(key);
|
|
7970
|
-
if (!child) return;
|
|
7971
|
-
fn(child);
|
|
7972
|
-
node = child;
|
|
7973
|
-
}
|
|
7974
|
-
}
|
|
7975
|
-
const missingDependencies = /* @__PURE__ */ new Set();
|
|
7976
|
-
const satisfyingDependencies = /* @__PURE__ */ new Set();
|
|
7977
|
-
scanTreeRecursively(depTree, missingDependencies, satisfyingDependencies, (key) => key);
|
|
7978
|
-
function scanTreeRecursively(node, missingPaths, satisfyingPaths, keyToPath) {
|
|
7979
|
-
node.children.forEach((child, key) => {
|
|
7980
|
-
const path = keyToPath(key);
|
|
7981
|
-
if (child.isSatisfiedRecursively) {
|
|
7982
|
-
if (child.isSubtreeUsed) satisfyingPaths.add(path);
|
|
7983
|
-
return;
|
|
7984
|
-
}
|
|
7985
|
-
if (child.isUsed) {
|
|
7986
|
-
missingPaths.add(path);
|
|
7987
|
-
return;
|
|
7988
|
-
}
|
|
7989
|
-
scanTreeRecursively(child, missingPaths, satisfyingPaths, (childKey) => path + "." + childKey);
|
|
7990
|
-
});
|
|
7991
|
-
}
|
|
7992
|
-
const suggestedDependencies = [];
|
|
7993
|
-
const unnecessaryDependencies = /* @__PURE__ */ new Set();
|
|
7994
|
-
const duplicateDependencies = /* @__PURE__ */ new Set();
|
|
7995
|
-
declaredDependencies.forEach(({ key }) => {
|
|
7996
|
-
if (satisfyingDependencies.has(key)) {
|
|
7997
|
-
if (suggestedDependencies.indexOf(key) === -1) suggestedDependencies.push(key);
|
|
7998
|
-
else duplicateDependencies.add(key);
|
|
7999
|
-
} else if (isEffect && !key.endsWith(".current") && !externalDependencies.has(key)) {
|
|
8000
|
-
if (suggestedDependencies.indexOf(key) === -1) suggestedDependencies.push(key);
|
|
8001
|
-
} else unnecessaryDependencies.add(key);
|
|
8002
|
-
});
|
|
8003
|
-
missingDependencies.forEach((key) => {
|
|
8004
|
-
suggestedDependencies.push(key);
|
|
8005
|
-
});
|
|
8006
|
-
return {
|
|
8007
|
-
suggestedDependencies,
|
|
8008
|
-
unnecessaryDependencies,
|
|
8009
|
-
duplicateDependencies,
|
|
8010
|
-
missingDependencies
|
|
8011
|
-
};
|
|
8012
|
-
}
|
|
8013
|
-
function getConstructionExpressionType(node) {
|
|
8014
|
-
switch (node.type) {
|
|
8015
|
-
case "ObjectExpression": return "object";
|
|
8016
|
-
case "ArrayExpression": return "array";
|
|
8017
|
-
case "ArrowFunctionExpression":
|
|
8018
|
-
case "FunctionExpression": return "function";
|
|
8019
|
-
case "ClassExpression": return "class";
|
|
8020
|
-
case "ConditionalExpression":
|
|
8021
|
-
if (getConstructionExpressionType(node.consequent) != null || getConstructionExpressionType(node.alternate) != null) return "conditional";
|
|
8022
|
-
return null;
|
|
8023
|
-
case "LogicalExpression":
|
|
8024
|
-
if (getConstructionExpressionType(node.left) != null || getConstructionExpressionType(node.right) != null) return "logical expression";
|
|
8025
|
-
return null;
|
|
8026
|
-
case "JSXFragment": return "JSX fragment";
|
|
8027
|
-
case "JSXElement": return "JSX element";
|
|
8028
|
-
case "AssignmentExpression":
|
|
8029
|
-
if (getConstructionExpressionType(node.right) != null) return "assignment expression";
|
|
8030
|
-
return null;
|
|
8031
|
-
case "NewExpression": return "object construction";
|
|
8032
|
-
case "Literal":
|
|
8033
|
-
if (node.value instanceof RegExp) return "regular expression";
|
|
8034
|
-
return null;
|
|
8035
|
-
case "TypeCastExpression":
|
|
8036
|
-
case "AsExpression":
|
|
8037
|
-
case "TSAsExpression": return getConstructionExpressionType(node.expression);
|
|
8038
|
-
}
|
|
8039
|
-
return null;
|
|
8040
|
-
}
|
|
8041
|
-
function scanForConstructions({ declaredDependencies, declaredDependenciesNode, componentScope, scope }) {
|
|
8042
|
-
const constructions = declaredDependencies.map(({ key }) => {
|
|
8043
|
-
const ref = componentScope.variables.find((v) => v.name === key);
|
|
8044
|
-
if (ref == null) return null;
|
|
8045
|
-
const node = ref.defs[0];
|
|
8046
|
-
if (node == null) return null;
|
|
8047
|
-
if (node.type === "Variable" && node.node.type === "VariableDeclarator" && node.node.id.type === "Identifier" && node.node.init != null) {
|
|
8048
|
-
const constantExpressionType = getConstructionExpressionType(node.node.init);
|
|
8049
|
-
if (constantExpressionType) return [ref, constantExpressionType];
|
|
8050
|
-
}
|
|
8051
|
-
if (node.type === "FunctionName" && node.node.type === "FunctionDeclaration") return [ref, "function"];
|
|
8052
|
-
if (node.type === "ClassName" && node.node.type === "ClassDeclaration") return [ref, "class"];
|
|
8053
|
-
return null;
|
|
8054
|
-
}).filter(Boolean);
|
|
8055
|
-
function isUsedOutsideOfHook(ref) {
|
|
8056
|
-
let foundWriteExpr = false;
|
|
8057
|
-
for (const reference of ref.references) {
|
|
8058
|
-
if (reference.writeExpr) {
|
|
8059
|
-
if (foundWriteExpr) return true;
|
|
8060
|
-
else {
|
|
8061
|
-
foundWriteExpr = true;
|
|
8062
|
-
continue;
|
|
8063
|
-
}
|
|
8064
|
-
}
|
|
8065
|
-
let currentScope = reference.from;
|
|
8066
|
-
while (currentScope !== scope && currentScope != null) currentScope = currentScope.upper;
|
|
8067
|
-
if (currentScope !== scope) {
|
|
8068
|
-
if (!isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) return true;
|
|
8069
|
-
}
|
|
8070
|
-
}
|
|
8071
|
-
return false;
|
|
8072
|
-
}
|
|
8073
|
-
return constructions.map(([ref, depType]) => ({
|
|
8074
|
-
construction: ref.defs[0],
|
|
8075
|
-
depType,
|
|
8076
|
-
isUsedOutsideOfHook: isUsedOutsideOfHook(ref)
|
|
8077
|
-
}));
|
|
8078
|
-
}
|
|
8079
|
-
function getDependency(node) {
|
|
8080
|
-
if (node.parent && (node.parent.type === "MemberExpression" || node.parent.type === "OptionalMemberExpression") && node.parent.object === node && "name" in node.parent.property && node.parent.property.name !== "current" && !node.parent.computed && !(node.parent.parent != null && (node.parent.parent.type === "CallExpression" || node.parent.parent.type === "OptionalCallExpression") && node.parent.parent.callee === node.parent)) return getDependency(node.parent);
|
|
8081
|
-
else if (node.type === "MemberExpression" && node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node) return node.object;
|
|
8082
|
-
else return node;
|
|
8083
|
-
}
|
|
8084
|
-
function markNode(node, optionalChains, result) {
|
|
8085
|
-
if (optionalChains) {
|
|
8086
|
-
if ("optional" in node && node.optional) {
|
|
8087
|
-
if (!optionalChains.has(result)) optionalChains.set(result, true);
|
|
8088
|
-
} else optionalChains.set(result, false);
|
|
8089
|
-
}
|
|
8090
|
-
}
|
|
8091
|
-
function analyzePropertyChain(node, optionalChains) {
|
|
8092
|
-
if (node.type === "Identifier" || node.type === "JSXIdentifier") {
|
|
8093
|
-
const result = node.name;
|
|
8094
|
-
if (optionalChains) optionalChains.set(result, false);
|
|
8095
|
-
return result;
|
|
8096
|
-
} else if (node.type === "MemberExpression" && !node.computed) {
|
|
8097
|
-
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
8098
|
-
markNode(node, optionalChains, result);
|
|
8099
|
-
return result;
|
|
8100
|
-
} else if (node.type === "OptionalMemberExpression" && !node.computed) {
|
|
8101
|
-
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
8102
|
-
markNode(node, optionalChains, result);
|
|
8103
|
-
return result;
|
|
8104
|
-
} else if (node.type === "ChainExpression" && (!("computed" in node) || !node.computed)) {
|
|
8105
|
-
const expression = node.expression;
|
|
8106
|
-
if (expression.type === "CallExpression") throw new Error(`Unsupported node type: ${expression.type}`);
|
|
8107
|
-
const result = `${analyzePropertyChain(expression.object, optionalChains)}.${analyzePropertyChain(expression.property, null)}`;
|
|
8108
|
-
markNode(expression, optionalChains, result);
|
|
8109
|
-
return result;
|
|
8110
|
-
} else throw new Error(`Unsupported node type: ${node.type}`);
|
|
8111
|
-
}
|
|
8112
|
-
function getNodeWithoutReactNamespace(node) {
|
|
8113
|
-
if (node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "React" && node.property.type === "Identifier" && !node.computed) return node.property;
|
|
8114
|
-
return node;
|
|
8115
|
-
}
|
|
8116
|
-
function getReactiveHookCallbackIndex(calleeNode, options) {
|
|
8117
|
-
const node = getNodeWithoutReactNamespace(calleeNode);
|
|
8118
|
-
if (node.type !== "Identifier") return -1;
|
|
8119
|
-
switch (node.name) {
|
|
8120
|
-
case "useEffect":
|
|
8121
|
-
case "useLayoutEffect":
|
|
8122
|
-
case "useCallback":
|
|
8123
|
-
case "useMemo": return 0;
|
|
8124
|
-
case "useImperativeHandle": return 1;
|
|
8125
|
-
default: if (node === calleeNode && options && options.additionalHooks) {
|
|
8126
|
-
let name;
|
|
8127
|
-
try {
|
|
8128
|
-
name = analyzePropertyChain(node, null);
|
|
8129
|
-
} catch (error) {
|
|
8130
|
-
if (error instanceof Error && /Unsupported node type/.test(error.message)) return 0;
|
|
8131
|
-
else throw error;
|
|
8132
|
-
}
|
|
8133
|
-
if (options.additionalHooks instanceof RegExp) options.additionalHooks.lastIndex = 0;
|
|
8134
|
-
return options.additionalHooks.test(name) ? 0 : -1;
|
|
8135
|
-
} else return -1;
|
|
8136
|
-
}
|
|
8137
|
-
}
|
|
8138
|
-
function fastFindReferenceWithParent(start, target) {
|
|
8139
|
-
const queue = [start];
|
|
8140
|
-
let item;
|
|
8141
|
-
while (queue.length) {
|
|
8142
|
-
item = queue.shift();
|
|
8143
|
-
if (isSameIdentifier(item, target)) return item;
|
|
8144
|
-
if (!isAncestorNodeOf(item, target)) continue;
|
|
8145
|
-
for (const [key, value] of Object.entries(item)) {
|
|
8146
|
-
if (key === "parent") continue;
|
|
8147
|
-
if (isNodeLike(value)) {
|
|
8148
|
-
value.parent = item;
|
|
8149
|
-
queue.push(value);
|
|
8150
|
-
} else if (Array.isArray(value)) value.forEach((val) => {
|
|
8151
|
-
if (isNodeLike(val)) {
|
|
8152
|
-
val.parent = item;
|
|
8153
|
-
queue.push(val);
|
|
8154
|
-
}
|
|
8155
|
-
});
|
|
8156
|
-
}
|
|
8157
|
-
}
|
|
8158
|
-
return null;
|
|
8159
|
-
}
|
|
8160
|
-
function joinEnglish(arr) {
|
|
8161
|
-
let s = "";
|
|
8162
|
-
for (let i = 0; i < arr.length; i++) {
|
|
8163
|
-
s += arr[i];
|
|
8164
|
-
if (i === 0 && arr.length === 2) s += " and ";
|
|
8165
|
-
else if (i === arr.length - 2 && arr.length > 2) s += ", and ";
|
|
8166
|
-
else if (i < arr.length - 1) s += ", ";
|
|
8167
|
-
}
|
|
8168
|
-
return s;
|
|
8169
|
-
}
|
|
8170
|
-
function isNodeLike(val) {
|
|
8171
|
-
return typeof val === "object" && val !== null && !Array.isArray(val) && "type" in val && typeof val.type === "string";
|
|
8172
|
-
}
|
|
8173
|
-
function isSameIdentifier(a, b) {
|
|
8174
|
-
return (a.type === "Identifier" || a.type === "JSXIdentifier") && a.type === b.type && a.name === b.name && !!a.range && !!b.range && a.range[0] === b.range[0] && a.range[1] === b.range[1];
|
|
8175
|
-
}
|
|
8176
|
-
function isAncestorNodeOf(a, b) {
|
|
8177
|
-
return !!a.range && !!b.range && a.range[0] <= b.range[0] && a.range[1] >= b.range[1];
|
|
8178
|
-
}
|
|
8179
|
-
function isUseEffectEventIdentifier(node) {
|
|
8180
|
-
return node.type === "Identifier" && node.name === "useEffectEvent";
|
|
8181
|
-
}
|
|
8182
|
-
function getUnknownDependenciesMessage(reactiveHookName) {
|
|
8183
|
-
return `React Hook ${reactiveHookName} received a function whose dependencies are unknown. Pass an inline function instead.`;
|
|
8184
|
-
}
|
|
8185
7182
|
// src/rules/unsupported-syntax/lib.ts
|
|
8186
7183
|
function isEvalCall(node) {
|
|
8187
7184
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -8512,7 +7509,7 @@ const plugin = {
|
|
|
8512
7509
|
},
|
|
8513
7510
|
rules: {
|
|
8514
7511
|
"error-boundaries": error_boundaries_default,
|
|
8515
|
-
"exhaustive-deps": rule$
|
|
7512
|
+
"exhaustive-deps": rule$1,
|
|
8516
7513
|
globals: globals_default,
|
|
8517
7514
|
immutability: immutability_default,
|
|
8518
7515
|
"no-access-state-in-setstate": no_access_state_in_setstate_default,
|
|
@@ -8557,11 +7554,10 @@ const plugin = {
|
|
|
8557
7554
|
"no-use-context": no_use_context_default,
|
|
8558
7555
|
purity: purity_default,
|
|
8559
7556
|
refs: refs_default,
|
|
8560
|
-
"rules-of-hooks": rule
|
|
7557
|
+
"rules-of-hooks": rule,
|
|
8561
7558
|
"set-state-in-effect": set_state_in_effect_default,
|
|
8562
7559
|
"set-state-in-render": set_state_in_render_default,
|
|
8563
7560
|
"static-components": static_components_default,
|
|
8564
|
-
"unstable-exhaustive-deps": rule,
|
|
8565
7561
|
"unsupported-syntax": unsupported_syntax_default,
|
|
8566
7562
|
"use-memo": use_memo_default,
|
|
8567
7563
|
"use-state": use_state_default
|