@eslint-react/core 2.7.4-beta.1 → 2.7.4-beta.4

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.ts CHANGED
@@ -1,12 +1,84 @@
1
1
  import * as AST from "@eslint-react/ast";
2
2
  import { unit } from "@eslint-react/eff";
3
- import { RegExpLike, RuleContext } from "@eslint-react/shared";
4
3
  import { TSESTree } from "@typescript-eslint/types";
4
+ import { RegExpLike, RuleContext } from "@eslint-react/shared";
5
5
  import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
6
6
  import * as birecord0 from "birecord";
7
7
  import { Scope } from "@typescript-eslint/scope-manager";
8
8
  import * as typescript0 from "typescript";
9
9
 
10
+ //#region src/api/is-from-react.d.ts
11
+ /**
12
+ * Checks if a variable is initialized from React import
13
+ * @param name The variable name
14
+ * @param initialScope The initial scope
15
+ * @param importSource Alternative import source of React (e.g., "preact/compat")
16
+ * @returns True if the variable is initialized from React import
17
+ */
18
+ declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
19
+ //#endregion
20
+ //#region src/api/is-from-react-native.d.ts
21
+ /**
22
+ * Checks if a variable is initialized from React Native import
23
+ * @param name The variable name
24
+ * @param initialScope The initial scope
25
+ * @param importSource Alternative import source of React Native (e.g., "react-native-web")
26
+ * @returns True if the variable is initialized from React Native import
27
+ */
28
+ declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
29
+ //#endregion
30
+ //#region src/api/is-react-api.d.ts
31
+ declare namespace isReactAPI {
32
+ type ReturnType = {
33
+ (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
34
+ (context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
35
+ };
36
+ }
37
+ /**
38
+ * Checks if the node is a React API identifier or member expression
39
+ * @param api The React API name to check against (e.g., "useState", "React.memo")
40
+ * @returns A predicate function to check if a node matches the API
41
+ */
42
+ declare function isReactAPI(api: string): isReactAPI.ReturnType;
43
+ declare namespace isReactAPICall {
44
+ type ReturnType = {
45
+ (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression;
46
+ (context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
47
+ };
48
+ }
49
+ /**
50
+ * Checks if the node is a call expression to a specific React API
51
+ * @param api The React API name to check against
52
+ * @returns A predicate function to check if a node is a call to the API
53
+ */
54
+ declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
55
+ declare const isCaptureOwnerStack: isReactAPI.ReturnType;
56
+ declare const isChildrenCount: isReactAPI.ReturnType;
57
+ declare const isChildrenForEach: isReactAPI.ReturnType;
58
+ declare const isChildrenMap: isReactAPI.ReturnType;
59
+ declare const isChildrenOnly: isReactAPI.ReturnType;
60
+ declare const isChildrenToArray: isReactAPI.ReturnType;
61
+ declare const isCloneElement: isReactAPI.ReturnType;
62
+ declare const isCreateContext: isReactAPI.ReturnType;
63
+ declare const isCreateElement: isReactAPI.ReturnType;
64
+ declare const isCreateRef: isReactAPI.ReturnType;
65
+ declare const isForwardRef: isReactAPI.ReturnType;
66
+ declare const isMemo: isReactAPI.ReturnType;
67
+ declare const isLazy: isReactAPI.ReturnType;
68
+ declare const isCaptureOwnerStackCall: isReactAPICall.ReturnType;
69
+ declare const isChildrenCountCall: isReactAPICall.ReturnType;
70
+ declare const isChildrenForEachCall: isReactAPICall.ReturnType;
71
+ declare const isChildrenMapCall: isReactAPICall.ReturnType;
72
+ declare const isChildrenOnlyCall: isReactAPICall.ReturnType;
73
+ declare const isChildrenToArrayCall: isReactAPICall.ReturnType;
74
+ declare const isCloneElementCall: isReactAPICall.ReturnType;
75
+ declare const isCreateContextCall: isReactAPICall.ReturnType;
76
+ declare const isCreateElementCall: isReactAPICall.ReturnType;
77
+ declare const isCreateRefCall: isReactAPICall.ReturnType;
78
+ declare const isForwardRefCall: isReactAPICall.ReturnType;
79
+ declare const isMemoCall: isReactAPICall.ReturnType;
80
+ declare const isLazyCall: isReactAPICall.ReturnType;
81
+ //#endregion
10
82
  //#region src/component/component-detection-hint.d.ts
11
83
  type ComponentDetectionHint = bigint;
12
84
  /**
@@ -431,20 +503,6 @@ declare function isComponentWrapperCallback(context: RuleContext, node: TSESTree
431
503
  */
432
504
  declare function isComponentWrapperCallbackLoose(context: RuleContext, node: TSESTree.Node): boolean;
433
505
  //#endregion
434
- //#region src/hierarchy/find-enclosing-assignment-target.d.ts
435
- /**
436
- * Finds the enclosing assignment target (variable, property, etc.) for a given node
437
- *
438
- * @todo Verify correctness and completeness of this function
439
- * @param node The starting node
440
- * @returns The enclosing assignment target node, or undefined if not found
441
- */
442
- declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
443
- /**
444
- * Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
445
- */
446
- type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
447
- //#endregion
448
506
  //#region src/hierarchy/find-enclosing-component-or-hook.d.ts
449
507
  type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null) => boolean;
450
508
  /**
@@ -784,80 +842,4 @@ declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSEST
784
842
  */
785
843
  declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
786
844
  //#endregion
787
- //#region src/utils/is-from-react.d.ts
788
- /**
789
- * Checks if a variable is initialized from React import
790
- * @param name The variable name
791
- * @param initialScope The initial scope
792
- * @param importSource Alternative import source of React (e.g., "preact/compat")
793
- * @returns True if the variable is initialized from React import
794
- */
795
- declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
796
- //#endregion
797
- //#region src/utils/is-from-react-native.d.ts
798
- /**
799
- * Checks if a variable is initialized from React Native import
800
- * @param name The variable name
801
- * @param initialScope The initial scope
802
- * @param importSource Alternative import source of React Native (e.g., "react-native-web")
803
- * @returns True if the variable is initialized from React Native import
804
- */
805
- declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
806
- //#endregion
807
- //#region src/utils/is-instance-id-equal.d.ts
808
- /** @internal */
809
- declare function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
810
- //#endregion
811
- //#region src/utils/is-react-api.d.ts
812
- declare namespace isReactAPI {
813
- type ReturnType = {
814
- (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
815
- (context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
816
- };
817
- }
818
- /**
819
- * Checks if the node is a React API identifier or member expression
820
- * @param api The React API name to check against (e.g., "useState", "React.memo")
821
- * @returns A predicate function to check if a node matches the API
822
- */
823
- declare function isReactAPI(api: string): isReactAPI.ReturnType;
824
- declare namespace isReactAPICall {
825
- type ReturnType = {
826
- (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression;
827
- (context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
828
- };
829
- }
830
- /**
831
- * Checks if the node is a call expression to a specific React API
832
- * @param api The React API name to check against
833
- * @returns A predicate function to check if a node is a call to the API
834
- */
835
- declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
836
- declare const isCaptureOwnerStack: isReactAPI.ReturnType;
837
- declare const isChildrenCount: isReactAPI.ReturnType;
838
- declare const isChildrenForEach: isReactAPI.ReturnType;
839
- declare const isChildrenMap: isReactAPI.ReturnType;
840
- declare const isChildrenOnly: isReactAPI.ReturnType;
841
- declare const isChildrenToArray: isReactAPI.ReturnType;
842
- declare const isCloneElement: isReactAPI.ReturnType;
843
- declare const isCreateContext: isReactAPI.ReturnType;
844
- declare const isCreateElement: isReactAPI.ReturnType;
845
- declare const isCreateRef: isReactAPI.ReturnType;
846
- declare const isForwardRef: isReactAPI.ReturnType;
847
- declare const isMemo: isReactAPI.ReturnType;
848
- declare const isLazy: isReactAPI.ReturnType;
849
- declare const isCaptureOwnerStackCall: isReactAPICall.ReturnType;
850
- declare const isChildrenCountCall: isReactAPICall.ReturnType;
851
- declare const isChildrenForEachCall: isReactAPICall.ReturnType;
852
- declare const isChildrenMapCall: isReactAPICall.ReturnType;
853
- declare const isChildrenOnlyCall: isReactAPICall.ReturnType;
854
- declare const isChildrenToArrayCall: isReactAPICall.ReturnType;
855
- declare const isCloneElementCall: isReactAPICall.ReturnType;
856
- declare const isCreateContextCall: isReactAPICall.ReturnType;
857
- declare const isCreateElementCall: isReactAPICall.ReturnType;
858
- declare const isCreateRefCall: isReactAPICall.ReturnType;
859
- declare const isForwardRefCall: isReactAPICall.ReturnType;
860
- declare const isMemoCall: isReactAPICall.ReturnType;
861
- declare const isLazyCall: isReactAPICall.ReturnType;
862
- //#endregion
863
- export { AssignmentTarget, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findEnclosingAssignmentTarget, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
845
+ export { ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -1,13 +1,101 @@
1
+ import { findImportSource, findProperty, findVariable, getVariableDefinitionNode } from "@eslint-react/var";
1
2
  import * as AST from "@eslint-react/ast";
2
3
  import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
3
- import { IdGenerator, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
4
4
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
5
- import { findImportSource, findProperty, findVariable, getVariableDefinitionNode, isNodeValueEqual } from "@eslint-react/var";
5
+ import { IdGenerator, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
6
6
  import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
7
7
  import { P, match } from "ts-pattern";
8
8
  import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/utils";
9
9
  import birecord from "birecord";
10
10
 
11
+ //#region src/api/is-from-react.ts
12
+ /**
13
+ * Checks if a variable is initialized from React import
14
+ * @param name The variable name
15
+ * @param initialScope The initial scope
16
+ * @param importSource Alternative import source of React (e.g., "preact/compat")
17
+ * @returns True if the variable is initialized from React import
18
+ */
19
+ function isInitializedFromReact(name, initialScope, importSource = "react") {
20
+ return name.toLowerCase() === "react" || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/api/is-from-react-native.ts
25
+ /**
26
+ * Checks if a variable is initialized from React Native import
27
+ * @param name The variable name
28
+ * @param initialScope The initial scope
29
+ * @param importSource Alternative import source of React Native (e.g., "react-native-web")
30
+ * @returns True if the variable is initialized from React Native import
31
+ */
32
+ function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
33
+ return [
34
+ "react_native",
35
+ "reactnative",
36
+ "rn"
37
+ ].includes(name.toLowerCase()) || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
38
+ }
39
+
40
+ //#endregion
41
+ //#region src/api/is-react-api.ts
42
+ /**
43
+ * Checks if the node is a React API identifier or member expression
44
+ * @param api The React API name to check against (e.g., "useState", "React.memo")
45
+ * @returns A predicate function to check if a node matches the API
46
+ */
47
+ function isReactAPI(api) {
48
+ const func = (context, node) => {
49
+ if (node == null) return false;
50
+ const getText = (n) => context.sourceCode.getText(n);
51
+ const name = AST.toStringFormat(node, getText);
52
+ if (name === api) return true;
53
+ if (name.substring(name.indexOf(".") + 1) === api) return true;
54
+ return false;
55
+ };
56
+ return dual(2, func);
57
+ }
58
+ /**
59
+ * Checks if the node is a call expression to a specific React API
60
+ * @param api The React API name to check against
61
+ * @returns A predicate function to check if a node is a call to the API
62
+ */
63
+ function isReactAPICall(api) {
64
+ const func = (context, node) => {
65
+ if (node == null) return false;
66
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
67
+ return isReactAPI(api)(context, node.callee);
68
+ };
69
+ return dual(2, func);
70
+ }
71
+ const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
72
+ const isChildrenCount = isReactAPI("Children.count");
73
+ const isChildrenForEach = isReactAPI("Children.forEach");
74
+ const isChildrenMap = isReactAPI("Children.map");
75
+ const isChildrenOnly = isReactAPI("Children.only");
76
+ const isChildrenToArray = isReactAPI("Children.toArray");
77
+ const isCloneElement = isReactAPI("cloneElement");
78
+ const isCreateContext = isReactAPI("createContext");
79
+ const isCreateElement = isReactAPI("createElement");
80
+ const isCreateRef = isReactAPI("createRef");
81
+ const isForwardRef = isReactAPI("forwardRef");
82
+ const isMemo = isReactAPI("memo");
83
+ const isLazy = isReactAPI("lazy");
84
+ const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
85
+ const isChildrenCountCall = isReactAPICall("Children.count");
86
+ const isChildrenForEachCall = isReactAPICall("Children.forEach");
87
+ const isChildrenMapCall = isReactAPICall("Children.map");
88
+ const isChildrenOnlyCall = isReactAPICall("Children.only");
89
+ const isChildrenToArrayCall = isReactAPICall("Children.toArray");
90
+ const isCloneElementCall = isReactAPICall("cloneElement");
91
+ const isCreateContextCall = isReactAPICall("createContext");
92
+ const isCreateElementCall = isReactAPICall("createElement");
93
+ const isCreateRefCall = isReactAPICall("createRef");
94
+ const isForwardRefCall = isReactAPICall("forwardRef");
95
+ const isMemoCall = isReactAPICall("memo");
96
+ const isLazyCall = isReactAPICall("lazy");
97
+
98
+ //#endregion
11
99
  //#region src/hook/hook-name.ts
12
100
  const REACT_BUILTIN_HOOK_NAMES = [
13
101
  "use",
@@ -582,101 +670,6 @@ function findParentJsxAttribute(node, test = constTrue) {
582
670
  return AST.findParentNode(node, guard);
583
671
  }
584
672
 
585
- //#endregion
586
- //#region src/utils/is-from-react.ts
587
- /**
588
- * Checks if a variable is initialized from React import
589
- * @param name The variable name
590
- * @param initialScope The initial scope
591
- * @param importSource Alternative import source of React (e.g., "preact/compat")
592
- * @returns True if the variable is initialized from React import
593
- */
594
- function isInitializedFromReact(name, initialScope, importSource = "react") {
595
- return name.toLowerCase() === "react" || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
596
- }
597
-
598
- //#endregion
599
- //#region src/utils/is-from-react-native.ts
600
- /**
601
- * Checks if a variable is initialized from React Native import
602
- * @param name The variable name
603
- * @param initialScope The initial scope
604
- * @param importSource Alternative import source of React Native (e.g., "react-native-web")
605
- * @returns True if the variable is initialized from React Native import
606
- */
607
- function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
608
- return [
609
- "react_native",
610
- "reactnative",
611
- "rn"
612
- ].includes(name.toLowerCase()) || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
613
- }
614
-
615
- //#endregion
616
- //#region src/utils/is-instance-id-equal.ts
617
- /** @internal */
618
- function isInstanceIdEqual(context, a, b) {
619
- return AST.isNodeEqual(a, b) || isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
620
- }
621
-
622
- //#endregion
623
- //#region src/utils/is-react-api.ts
624
- /**
625
- * Checks if the node is a React API identifier or member expression
626
- * @param api The React API name to check against (e.g., "useState", "React.memo")
627
- * @returns A predicate function to check if a node matches the API
628
- */
629
- function isReactAPI(api) {
630
- const func = (context, node) => {
631
- if (node == null) return false;
632
- const getText = (n) => context.sourceCode.getText(n);
633
- const name = AST.toStringFormat(node, getText);
634
- if (name === api) return true;
635
- if (name.substring(name.indexOf(".") + 1) === api) return true;
636
- return false;
637
- };
638
- return dual(2, func);
639
- }
640
- /**
641
- * Checks if the node is a call expression to a specific React API
642
- * @param api The React API name to check against
643
- * @returns A predicate function to check if a node is a call to the API
644
- */
645
- function isReactAPICall(api) {
646
- const func = (context, node) => {
647
- if (node == null) return false;
648
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
649
- return isReactAPI(api)(context, node.callee);
650
- };
651
- return dual(2, func);
652
- }
653
- const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
654
- const isChildrenCount = isReactAPI("Children.count");
655
- const isChildrenForEach = isReactAPI("Children.forEach");
656
- const isChildrenMap = isReactAPI("Children.map");
657
- const isChildrenOnly = isReactAPI("Children.only");
658
- const isChildrenToArray = isReactAPI("Children.toArray");
659
- const isCloneElement = isReactAPI("cloneElement");
660
- const isCreateContext = isReactAPI("createContext");
661
- const isCreateElement = isReactAPI("createElement");
662
- const isCreateRef = isReactAPI("createRef");
663
- const isForwardRef = isReactAPI("forwardRef");
664
- const isMemo = isReactAPI("memo");
665
- const isLazy = isReactAPI("lazy");
666
- const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
667
- const isChildrenCountCall = isReactAPICall("Children.count");
668
- const isChildrenForEachCall = isReactAPICall("Children.forEach");
669
- const isChildrenMapCall = isReactAPICall("Children.map");
670
- const isChildrenOnlyCall = isReactAPICall("Children.only");
671
- const isChildrenToArrayCall = isReactAPICall("Children.toArray");
672
- const isCloneElementCall = isReactAPICall("cloneElement");
673
- const isCreateContextCall = isReactAPICall("createContext");
674
- const isCreateElementCall = isReactAPICall("createElement");
675
- const isCreateRefCall = isReactAPICall("createRef");
676
- const isForwardRefCall = isReactAPICall("forwardRef");
677
- const isMemoCall = isReactAPICall("memo");
678
- const isLazyCall = isReactAPICall("lazy");
679
-
680
673
  //#endregion
681
674
  //#region src/component/component-detection-hint.ts
682
675
  /**
@@ -1245,26 +1238,6 @@ function isDeclaredInRenderPropLoose(node) {
1245
1238
  return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
1246
1239
  }
1247
1240
 
1248
- //#endregion
1249
- //#region src/hierarchy/find-enclosing-assignment-target.ts
1250
- /** eslint-disable jsdoc/require-param */
1251
- /**
1252
- * Finds the enclosing assignment target (variable, property, etc.) for a given node
1253
- *
1254
- * @todo Verify correctness and completeness of this function
1255
- * @param node The starting node
1256
- * @returns The enclosing assignment target node, or undefined if not found
1257
- */
1258
- function findEnclosingAssignmentTarget(node) {
1259
- switch (true) {
1260
- case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
1261
- case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
1262
- case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
1263
- case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
1264
- default: return findEnclosingAssignmentTarget(node.parent);
1265
- }
1266
- }
1267
-
1268
1241
  //#endregion
1269
1242
  //#region src/hierarchy/find-enclosing-component-or-hook.ts
1270
1243
  /**
@@ -1299,4 +1272,4 @@ function isInsideComponentOrHook(node) {
1299
1272
  }
1300
1273
 
1301
1274
  //#endregion
1302
- export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingAssignmentTarget, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
1275
+ export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.7.4-beta.1",
3
+ "version": "2.7.4-beta.4",
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": {
@@ -35,10 +35,10 @@
35
35
  "@typescript-eslint/utils": "^8.53.1",
36
36
  "birecord": "^0.1.1",
37
37
  "ts-pattern": "^5.9.0",
38
- "@eslint-react/ast": "2.7.4-beta.1",
39
- "@eslint-react/eff": "2.7.4-beta.1",
40
- "@eslint-react/shared": "2.7.4-beta.1",
41
- "@eslint-react/var": "2.7.4-beta.1"
38
+ "@eslint-react/ast": "2.7.4-beta.4",
39
+ "@eslint-react/eff": "2.7.4-beta.4",
40
+ "@eslint-react/shared": "2.7.4-beta.4",
41
+ "@eslint-react/var": "2.7.4-beta.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsdown": "^0.20.0-beta.4",