@eslint-react/core 1.28.0 → 1.28.1-beta.1
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.d.mts +39 -2067
- package/dist/index.d.ts +39 -2067
- package/dist/index.js +108 -123
- package/dist/index.mjs +104 -117
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as AST7 from '@eslint-react/ast';
|
|
2
2
|
import { flip, dual, constFalse, identity, _ } from '@eslint-react/eff';
|
|
3
3
|
import * as JSX3 from '@eslint-react/jsx';
|
|
4
4
|
import { DEFAULT_ESLINT_REACT_SETTINGS as DEFAULT_ESLINT_REACT_SETTINGS$1, unsafeDecodeSettings, getId } from '@eslint-react/shared';
|
|
@@ -481,6 +481,17 @@ var ESLintReactSettingsSchema = object({
|
|
|
481
481
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
482
482
|
...parse(ESLintReactSettingsSchema, {}),
|
|
483
483
|
importSource: "react"};
|
|
484
|
+
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
485
|
+
"AssignmentExpression",
|
|
486
|
+
"[type]",
|
|
487
|
+
"[operator='=']",
|
|
488
|
+
"[left.type='MemberExpression']",
|
|
489
|
+
"[left.property.name='displayName']"
|
|
490
|
+
].join("");
|
|
491
|
+
function isDisplayNameAssignment(node) {
|
|
492
|
+
if (node == null) return false;
|
|
493
|
+
return node.type === AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === AST_NODE_TYPES.MemberExpression && node.left.property.type === AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
|
|
494
|
+
}
|
|
484
495
|
function getRequireExpressionArguments(node) {
|
|
485
496
|
return match(node).with({ type: AST_NODE_TYPES.CallExpression, arguments: P.select(), callee: { type: AST_NODE_TYPES.Identifier, name: "require" } }, identity).with({ type: AST_NODE_TYPES.MemberExpression, object: P.select() }, getRequireExpressionArguments).otherwise(() => _);
|
|
486
497
|
}
|
|
@@ -499,7 +510,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
499
510
|
}
|
|
500
511
|
const args = getRequireExpressionArguments(init);
|
|
501
512
|
const arg0 = args?.[0];
|
|
502
|
-
if (arg0 == null || !
|
|
513
|
+
if (arg0 == null || !AST7.isKindOfLiteral(arg0, "string")) {
|
|
503
514
|
return false;
|
|
504
515
|
}
|
|
505
516
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -510,113 +521,89 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
510
521
|
// src/utils/is-from-react.ts
|
|
511
522
|
var defaultImportSource = DEFAULT_ESLINT_REACT_SETTINGS$1.importSource;
|
|
512
523
|
function isFromReactLoose(node, name) {
|
|
513
|
-
|
|
514
|
-
|
|
524
|
+
switch (node?.type) {
|
|
525
|
+
case AST_NODE_TYPES.Identifier:
|
|
526
|
+
return node.name === name;
|
|
527
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
528
|
+
return node.object.type === AST_NODE_TYPES.Identifier && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === name;
|
|
529
|
+
default:
|
|
530
|
+
return false;
|
|
515
531
|
}
|
|
516
|
-
return node.name === name;
|
|
517
532
|
}
|
|
518
533
|
function isFromReactStrict(node, name, importSource, initialScope) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
534
|
+
switch (node?.type) {
|
|
535
|
+
case AST_NODE_TYPES.Identifier:
|
|
536
|
+
return node.name === name && isInitializedFromReact(name, importSource, initialScope);
|
|
537
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
538
|
+
return node.object.type === AST_NODE_TYPES.Identifier && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
|
|
539
|
+
default:
|
|
540
|
+
return false;
|
|
524
541
|
}
|
|
525
|
-
return false;
|
|
526
542
|
}
|
|
527
543
|
function isFromReact(name) {
|
|
528
|
-
return (context, node) => {
|
|
544
|
+
return dual(2, (context, node) => {
|
|
545
|
+
if (node == null) return false;
|
|
529
546
|
const { importSource = defaultImportSource, skipImportCheck = true } = unsafeDecodeSettings(context.settings);
|
|
530
547
|
if (skipImportCheck) return isFromReactLoose(node, name);
|
|
531
548
|
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
function isFromReactMemberLoose(node, memberName, name) {
|
|
535
|
-
const { object: object2, property } = node;
|
|
536
|
-
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== name) return false;
|
|
537
|
-
if (object2.type === AST_NODE_TYPES.Identifier && object2.name === memberName) return true;
|
|
538
|
-
if (object2.type === AST_NODE_TYPES.MemberExpression && object2.object.type === AST_NODE_TYPES.Identifier && object2.property.type === AST_NODE_TYPES.Identifier) {
|
|
539
|
-
return object2.property.name === memberName;
|
|
540
|
-
}
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
function isFromReactMemberStrict(node, memberName, name, importSource, initialScope) {
|
|
544
|
-
const { object: object2, property } = node;
|
|
545
|
-
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== name) {
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
if (object2.type === AST_NODE_TYPES.Identifier && object2.name === memberName) {
|
|
549
|
-
return isInitializedFromReact(object2.name, importSource, initialScope);
|
|
550
|
-
}
|
|
551
|
-
if (object2.type === AST_NODE_TYPES.MemberExpression && object2.object.type === AST_NODE_TYPES.Identifier && isInitializedFromReact(object2.object.name, importSource, initialScope) && object2.property.type === AST_NODE_TYPES.Identifier) {
|
|
552
|
-
return object2.property.name === memberName;
|
|
553
|
-
}
|
|
554
|
-
return false;
|
|
549
|
+
});
|
|
555
550
|
}
|
|
556
|
-
function
|
|
557
|
-
return (context, node) => {
|
|
551
|
+
function isFromReactObject(objectName, propertyName) {
|
|
552
|
+
return dual(2, (context, node) => {
|
|
553
|
+
if (node?.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
558
554
|
const { importSource = defaultImportSource, skipImportCheck = true } = unsafeDecodeSettings(context.settings);
|
|
559
|
-
|
|
560
|
-
return
|
|
561
|
-
|
|
555
|
+
const { object: object2, property } = node;
|
|
556
|
+
if (skipImportCheck) return isFromReactLoose(object2, objectName) && isFromReactLoose(property, propertyName);
|
|
557
|
+
return isFromReactStrict(
|
|
558
|
+
object2,
|
|
559
|
+
objectName,
|
|
560
|
+
importSource,
|
|
561
|
+
context.sourceCode.getScope(object2)
|
|
562
|
+
) && isFromReactLoose(property, propertyName);
|
|
563
|
+
});
|
|
562
564
|
}
|
|
563
|
-
|
|
564
|
-
// src/utils/is-call-from-react.ts
|
|
565
565
|
function isCallFromReact(name) {
|
|
566
566
|
return dual(2, (context, node) => {
|
|
567
567
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
568
|
-
if (!AST8.isOneOf([AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
|
|
569
568
|
return isFromReact(name)(context, node.callee);
|
|
570
569
|
});
|
|
571
570
|
}
|
|
572
|
-
function
|
|
571
|
+
function isCallFromReactObject(objectName, propertyName) {
|
|
573
572
|
return dual(2, (context, node) => {
|
|
574
573
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
575
|
-
|
|
576
|
-
return isFromReactMember(pragmaMemberName, name)(context, node.callee);
|
|
574
|
+
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
577
575
|
});
|
|
578
576
|
}
|
|
579
|
-
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
580
|
-
"AssignmentExpression",
|
|
581
|
-
"[type]",
|
|
582
|
-
"[operator='=']",
|
|
583
|
-
"[left.type='MemberExpression']",
|
|
584
|
-
"[left.property.name='displayName']"
|
|
585
|
-
].join("");
|
|
586
|
-
function isDisplayNameAssignment(node) {
|
|
587
|
-
if (node == null) return false;
|
|
588
|
-
return node.type === AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === AST_NODE_TYPES.MemberExpression && node.left.property.type === AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
|
|
589
|
-
}
|
|
590
577
|
|
|
591
578
|
// src/utils/is-react-api.ts
|
|
592
|
-
function
|
|
593
|
-
return
|
|
594
|
-
}
|
|
595
|
-
function
|
|
596
|
-
return
|
|
597
|
-
}
|
|
598
|
-
var isChildrenCount =
|
|
599
|
-
var isChildrenForEach =
|
|
600
|
-
var isChildrenMap =
|
|
601
|
-
var isChildrenOnly =
|
|
602
|
-
var isChildrenToArray =
|
|
603
|
-
var isCloneElement =
|
|
604
|
-
var isCreateContext =
|
|
605
|
-
var isCreateElement =
|
|
606
|
-
var isCreateRef =
|
|
607
|
-
var isForwardRef =
|
|
608
|
-
var isMemo =
|
|
609
|
-
var isChildrenCountCall =
|
|
610
|
-
var isChildrenForEachCall =
|
|
611
|
-
var isChildrenMapCall =
|
|
612
|
-
var isChildrenOnlyCall =
|
|
613
|
-
var isChildrenToArrayCall =
|
|
614
|
-
var isCloneElementCall =
|
|
615
|
-
var isCreateContextCall =
|
|
616
|
-
var isCreateElementCall =
|
|
617
|
-
var isCreateRefCall =
|
|
618
|
-
var isForwardRefCall =
|
|
619
|
-
var isMemoCall =
|
|
579
|
+
function isReactAPI(arg0, arg1) {
|
|
580
|
+
return arg1 == null ? isFromReact(arg0) : isFromReactObject(arg0, arg1);
|
|
581
|
+
}
|
|
582
|
+
function isReactAPICall(arg0, arg1) {
|
|
583
|
+
return arg1 == null ? isCallFromReact(arg0) : isCallFromReactObject(arg0, arg1);
|
|
584
|
+
}
|
|
585
|
+
var isChildrenCount = isReactAPI("Children", "count");
|
|
586
|
+
var isChildrenForEach = isReactAPI("Children", "forEach");
|
|
587
|
+
var isChildrenMap = isReactAPI("Children", "map");
|
|
588
|
+
var isChildrenOnly = isReactAPI("Children", "only");
|
|
589
|
+
var isChildrenToArray = isReactAPI("Children", "toArray");
|
|
590
|
+
var isCloneElement = isReactAPI("cloneElement");
|
|
591
|
+
var isCreateContext = isReactAPI("createContext");
|
|
592
|
+
var isCreateElement = isReactAPI("createElement");
|
|
593
|
+
var isCreateRef = isReactAPI("createRef");
|
|
594
|
+
var isForwardRef = isReactAPI("forwardRef");
|
|
595
|
+
var isMemo = isReactAPI("memo");
|
|
596
|
+
var isChildrenCountCall = isReactAPICall("Children", "count");
|
|
597
|
+
var isChildrenForEachCall = isReactAPICall("Children", "forEach");
|
|
598
|
+
var isChildrenMapCall = isReactAPICall("Children", "map");
|
|
599
|
+
var isChildrenOnlyCall = isReactAPICall("Children", "only");
|
|
600
|
+
var isChildrenToArrayCall = isReactAPICall("Children", "toArray");
|
|
601
|
+
var isCloneElementCall = isReactAPICall("cloneElement");
|
|
602
|
+
var isCreateContextCall = isReactAPICall("createContext");
|
|
603
|
+
var isCreateElementCall = isReactAPICall("createElement");
|
|
604
|
+
var isCreateRefCall = isReactAPICall("createRef");
|
|
605
|
+
var isForwardRefCall = isReactAPICall("forwardRef");
|
|
606
|
+
var isMemoCall = isReactAPICall("memo");
|
|
620
607
|
|
|
621
608
|
// src/hook/hook-name.ts
|
|
622
609
|
var RE_HOOK_NAME = /^use[A-Z\d]/u;
|
|
@@ -627,7 +614,7 @@ function isReactHookName(name) {
|
|
|
627
614
|
// src/hook/is.ts
|
|
628
615
|
function isReactHook(node) {
|
|
629
616
|
if (node == null) return _;
|
|
630
|
-
const id =
|
|
617
|
+
const id = AST7.getFunctionIdentifier(node);
|
|
631
618
|
return id?.name != null && isReactHookName(id.name);
|
|
632
619
|
}
|
|
633
620
|
function isReactHookCall(node) {
|
|
@@ -723,13 +710,13 @@ var isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
|
|
|
723
710
|
|
|
724
711
|
// src/hook/hierarchy.ts
|
|
725
712
|
function isInsideReactHook(node) {
|
|
726
|
-
return isReactHook(
|
|
713
|
+
return isReactHook(AST7.findParentNode(node, AST7.isFunction));
|
|
727
714
|
}
|
|
728
715
|
function useHookCollector() {
|
|
729
716
|
const hooks = /* @__PURE__ */ new Map();
|
|
730
717
|
const functionEntries = [];
|
|
731
718
|
const onFunctionEnter = (node) => {
|
|
732
|
-
const id =
|
|
719
|
+
const id = AST7.getFunctionIdentifier(node);
|
|
733
720
|
const key = getId();
|
|
734
721
|
const name = id?.name;
|
|
735
722
|
if (name != null && isReactHookName(name)) {
|
|
@@ -825,7 +812,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
825
812
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
826
813
|
}
|
|
827
814
|
function getFunctionComponentIdentifier(context, node) {
|
|
828
|
-
const functionId =
|
|
815
|
+
const functionId = AST7.getFunctionIdentifier(node);
|
|
829
816
|
if (functionId != null) {
|
|
830
817
|
return functionId;
|
|
831
818
|
}
|
|
@@ -853,9 +840,9 @@ function hasNoneOrValidComponentName(context, node) {
|
|
|
853
840
|
return name != null && isComponentName(name);
|
|
854
841
|
}
|
|
855
842
|
function isInsideCreateElementProps(context, node) {
|
|
856
|
-
const call =
|
|
843
|
+
const call = AST7.findParentNode(node, isCreateElementCall(context));
|
|
857
844
|
if (call == null) return false;
|
|
858
|
-
const prop =
|
|
845
|
+
const prop = AST7.findParentNode(node, AST7.is(AST_NODE_TYPES.ObjectExpression));
|
|
859
846
|
if (prop == null) return false;
|
|
860
847
|
return prop === call.arguments[1];
|
|
861
848
|
}
|
|
@@ -892,28 +879,28 @@ function isPureComponent(node) {
|
|
|
892
879
|
|
|
893
880
|
// src/component/component-lifecycle.ts
|
|
894
881
|
function isComponentDidMount(node) {
|
|
895
|
-
return
|
|
882
|
+
return AST7.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
896
883
|
}
|
|
897
884
|
function isComponentWillUnmount(node) {
|
|
898
|
-
return
|
|
885
|
+
return AST7.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
899
886
|
}
|
|
900
887
|
function isComponentDidCatch(node) {
|
|
901
|
-
return
|
|
888
|
+
return AST7.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
902
889
|
}
|
|
903
890
|
function isGetDerivedStateFromError(node) {
|
|
904
|
-
return
|
|
891
|
+
return AST7.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
905
892
|
}
|
|
906
893
|
function isGetDerivedStateFromProps(node) {
|
|
907
|
-
return
|
|
894
|
+
return AST7.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
908
895
|
}
|
|
909
896
|
function isFunctionOfComponentDidMount(node) {
|
|
910
|
-
return
|
|
897
|
+
return AST7.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
911
898
|
}
|
|
912
899
|
function isFunctionOfComponentWillUnmount(node) {
|
|
913
|
-
return
|
|
900
|
+
return AST7.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
914
901
|
}
|
|
915
902
|
function isRenderMethodLike(node) {
|
|
916
|
-
return
|
|
903
|
+
return AST7.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
917
904
|
}
|
|
918
905
|
function isFunctionOfRenderMethod(node) {
|
|
919
906
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -922,7 +909,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
922
909
|
return isClassComponent(node.parent.parent.parent);
|
|
923
910
|
}
|
|
924
911
|
function isInsideRenderMethod(node) {
|
|
925
|
-
return
|
|
912
|
+
return AST7.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
926
913
|
}
|
|
927
914
|
|
|
928
915
|
// src/component/hierarchy.ts
|
|
@@ -930,7 +917,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
930
917
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
931
918
|
return false;
|
|
932
919
|
}
|
|
933
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
920
|
+
if (hint & ERComponentHint.SkipMapCallback && AST7.isMapCallLoose(node.parent)) {
|
|
934
921
|
return false;
|
|
935
922
|
}
|
|
936
923
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -942,9 +929,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
942
929
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
943
930
|
return false;
|
|
944
931
|
}
|
|
945
|
-
const boundaryNode =
|
|
932
|
+
const boundaryNode = AST7.findParentNode(
|
|
946
933
|
node,
|
|
947
|
-
|
|
934
|
+
AST7.isOneOf([
|
|
948
935
|
AST_NODE_TYPES.JSXExpressionContainer,
|
|
949
936
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
950
937
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -979,7 +966,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
979
966
|
const entry = functionEntries.at(-1);
|
|
980
967
|
if (entry == null) return;
|
|
981
968
|
if (!entry.isComponent) return functionEntries.pop();
|
|
982
|
-
const shouldDrop =
|
|
969
|
+
const shouldDrop = AST7.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
983
970
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXValue(r.argument, jsxCtx, hint);
|
|
984
971
|
});
|
|
985
972
|
if (shouldDrop) {
|
|
@@ -1006,7 +993,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1006
993
|
const { body } = entry.node;
|
|
1007
994
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1008
995
|
if (!isComponent) return;
|
|
1009
|
-
const initPath =
|
|
996
|
+
const initPath = AST7.getFunctionInitPath(entry.node);
|
|
1010
997
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1011
998
|
const name = getComponentNameFromIdentifier(id);
|
|
1012
999
|
const key = getId();
|
|
@@ -1047,7 +1034,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1047
1034
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1048
1035
|
if (!isComponent) return;
|
|
1049
1036
|
entry.isComponent = true;
|
|
1050
|
-
const initPath =
|
|
1037
|
+
const initPath = AST7.getFunctionInitPath(entry.node);
|
|
1051
1038
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1052
1039
|
const name = getComponentNameFromIdentifier(id);
|
|
1053
1040
|
components.set(entry.key, {
|
|
@@ -1068,10 +1055,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1068
1055
|
}
|
|
1069
1056
|
function getComponentFlag(initPath) {
|
|
1070
1057
|
let flag = ERComponentFlag.None;
|
|
1071
|
-
if (initPath != null &&
|
|
1058
|
+
if (initPath != null && AST7.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1072
1059
|
flag |= ERComponentFlag.Memo;
|
|
1073
1060
|
}
|
|
1074
|
-
if (initPath != null &&
|
|
1061
|
+
if (initPath != null && AST7.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1075
1062
|
flag |= ERComponentFlag.ForwardRef;
|
|
1076
1063
|
}
|
|
1077
1064
|
return flag;
|
|
@@ -1088,7 +1075,7 @@ function useComponentCollectorLegacy() {
|
|
|
1088
1075
|
if (!isClassComponent(node)) {
|
|
1089
1076
|
return;
|
|
1090
1077
|
}
|
|
1091
|
-
const id =
|
|
1078
|
+
const id = AST7.getClassIdentifier(node);
|
|
1092
1079
|
const key = getId();
|
|
1093
1080
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1094
1081
|
components.set(
|
|
@@ -1121,7 +1108,7 @@ var ERPhaseRelevance = birecord({
|
|
|
1121
1108
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1122
1109
|
function isRenderFunctionLoose(context, node) {
|
|
1123
1110
|
const { body, parent } = node;
|
|
1124
|
-
if (
|
|
1111
|
+
if (AST7.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1125
1112
|
return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
1126
1113
|
}
|
|
1127
1114
|
return JSX3.isJSXValue(
|
|
@@ -1136,7 +1123,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1136
1123
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
1137
1124
|
return false;
|
|
1138
1125
|
}
|
|
1139
|
-
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1126
|
+
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST7.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1140
1127
|
}
|
|
1141
1128
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1142
1129
|
const matching = (node2) => {
|
|
@@ -1148,7 +1135,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1148
1135
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1149
1136
|
return true;
|
|
1150
1137
|
}
|
|
1151
|
-
const parent =
|
|
1138
|
+
const parent = AST7.findParentNode(node, AST7.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1152
1139
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
1153
1140
|
return false;
|
|
1154
1141
|
}
|
|
@@ -1156,17 +1143,17 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1156
1143
|
}
|
|
1157
1144
|
function isThisSetState(node) {
|
|
1158
1145
|
const { callee } = node;
|
|
1159
|
-
return callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
1146
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && AST7.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1160
1147
|
}
|
|
1161
1148
|
function isFunctionOfUseEffectSetup(node) {
|
|
1162
1149
|
if (node == null) return _;
|
|
1163
1150
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
1164
1151
|
}
|
|
1165
1152
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1166
|
-
const nearReturn =
|
|
1167
|
-
const nearFunction =
|
|
1168
|
-
const nearFunctionOfReturn =
|
|
1153
|
+
const nearReturn = AST7.findParentNode(node, AST7.is(AST_NODE_TYPES.ReturnStatement));
|
|
1154
|
+
const nearFunction = AST7.findParentNode(node, AST7.isFunction);
|
|
1155
|
+
const nearFunctionOfReturn = AST7.findParentNode(nearReturn, AST7.isFunction);
|
|
1169
1156
|
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
1170
1157
|
}
|
|
1171
1158
|
|
|
1172
|
-
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, ERComponentFlag, ERComponentHint, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact,
|
|
1159
|
+
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, ERComponentFlag, ERComponentHint, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isDisplayNameAssignment, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.1-beta.1",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.25.0",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.6.2",
|
|
44
|
-
"@eslint-react/ast": "1.28.
|
|
45
|
-
"@eslint-react/eff": "1.28.
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/var": "1.28.
|
|
44
|
+
"@eslint-react/ast": "1.28.1-beta.1",
|
|
45
|
+
"@eslint-react/eff": "1.28.1-beta.1",
|
|
46
|
+
"@eslint-react/shared": "1.28.1-beta.1",
|
|
47
|
+
"@eslint-react/jsx": "1.28.1-beta.1",
|
|
48
|
+
"@eslint-react/var": "1.28.1-beta.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.4.0",
|