@eslint-react/core 3.0.0-next.1 → 3.0.0-next.12

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
@@ -78,19 +78,19 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
78
78
  declare const isMemoCall: isReactAPICall.ReturnType;
79
79
  declare const isLazyCall: isReactAPICall.ReturnType;
80
80
  //#endregion
81
- //#region src/component/component-detection-hint.d.ts
81
+ //#region src/component/component-detection.d.ts
82
82
  type ComponentDetectionHint = bigint;
83
83
  /**
84
84
  * Hints for component collector
85
85
  */
86
86
  declare const ComponentDetectionHint: {
87
- readonly DoNotIncludeFunctionDefinedOnObjectMethod: bigint;
87
+ readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
88
+ readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
89
+ readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
90
+ readonly DoNotIncludeFunctionDefinedInArrayPattern: bigint;
88
91
  readonly DoNotIncludeFunctionDefinedOnClassMethod: bigint;
89
92
  readonly DoNotIncludeFunctionDefinedOnClassProperty: bigint;
90
- readonly DoNotIncludeFunctionDefinedInArrayPattern: bigint;
91
- readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
92
- readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
93
- readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
93
+ readonly DoNotIncludeFunctionDefinedOnObjectMethod: bigint;
94
94
  readonly None: 0n;
95
95
  readonly DoNotIncludeJsxWithNullValue: bigint;
96
96
  readonly DoNotIncludeJsxWithNumberValue: bigint;
@@ -108,6 +108,15 @@ declare const ComponentDetectionHint: {
108
108
  * Default component detection hint
109
109
  */
110
110
  declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
111
+ /**
112
+ * Determine if a function node represents a valid React component definition
113
+ *
114
+ * @param context The rule context
115
+ * @param node The function node to analyze
116
+ * @param hint Component detection hints (bit flags) to customize detection logic
117
+ * @returns `true` if the node is considered a component definition
118
+ */
119
+ declare function isComponentDefinition(context: RuleContext, node: ast.TSESTreeFunction, hint: bigint): boolean;
111
120
  //#endregion
112
121
  //#region src/semantic/semantic-node.d.ts
113
122
  /**
@@ -155,19 +164,6 @@ interface SemanticFunc extends SemanticNode {
155
164
  typeParameters: TSESTree.TSTypeParameterDeclaration | unit;
156
165
  }
157
166
  //#endregion
158
- //#region src/component/component-flag.d.ts
159
- type ComponentFlag = bigint;
160
- /**
161
- * Component flag constants
162
- */
163
- declare const ComponentFlag: {
164
- /** No flags set */None: bigint; /** Indicates the component is a pure component (e.g., extends PureComponent) */
165
- PureComponent: bigint; /** Indicates the component creates elements using `createElement` instead of JSX */
166
- CreateElement: bigint; /** Indicates the component is memoized (e.g., React.memo) */
167
- Memo: bigint; /** Indicates the component forwards a ref (e.g., React.forwardRef) */
168
- ForwardRef: bigint;
169
- };
170
- //#endregion
171
167
  //#region src/component/component-semantic-node.d.ts
172
168
  /**
173
169
  * Represents a React Function Component
@@ -188,11 +184,11 @@ interface FunctionComponentSemanticNode extends SemanticNode {
188
184
  /**
189
185
  * Flags describing the component's characteristics
190
186
  */
191
- flag: ComponentFlag;
187
+ flag: bigint;
192
188
  /**
193
189
  * Hint for how the component was detected
194
190
  */
195
- hint: ComponentDetectionHint;
191
+ hint: bigint;
196
192
  /**
197
193
  * List of expressions returned by the component
198
194
  */
@@ -241,11 +237,11 @@ interface ClassComponentSemanticNode extends SemanticNode {
241
237
  /**
242
238
  * Flags describing the component's characteristics
243
239
  */
244
- flag: ComponentFlag;
240
+ flag: bigint;
245
241
  /**
246
242
  * Hint for how the component was detected
247
243
  */
248
- hint: ComponentDetectionHint;
244
+ hint: bigint;
249
245
  /**
250
246
  * List of methods and properties in the class
251
247
  */
@@ -314,16 +310,23 @@ declare function isThisSetState(node: TSESTree$1.CallExpression): boolean;
314
310
  */
315
311
  declare function isAssignmentToThisState(node: TSESTree$1.AssignmentExpression): boolean;
316
312
  //#endregion
317
- //#region src/component/component-definition.d.ts
313
+ //#region src/component/component-flag.d.ts
318
314
  /**
319
- * Determine if a function node represents a valid React component definition
320
- *
321
- * @param context The rule context
322
- * @param node The function node to analyze
323
- * @param hint Component detection hints (bit flags) to customize detection logic
324
- * @returns `true` if the node is considered a component definition
315
+ * Component flag constants
325
316
  */
326
- declare function isComponentDefinition(context: RuleContext, node: ast.TSESTreeFunction, hint: bigint): boolean;
317
+ declare const ComponentFlag: {
318
+ /** Indicates the component creates elements using `createElement` instead of JSX */CreateElement: bigint; /** Indicates the component forwards a ref (e.g., React.forwardRef) */
319
+ ForwardRef: bigint; /** Indicates the component is memoized (e.g., React.memo) */
320
+ Memo: bigint; /** No flags set */
321
+ None: bigint; /** Indicates the component is a pure component (e.g., extends PureComponent) */
322
+ PureComponent: bigint;
323
+ };
324
+ /**
325
+ * Get component flag from init path
326
+ * @param initPath The init path of the function component
327
+ * @returns The component flag
328
+ */
329
+ declare function getComponentFlagFromInitPath(initPath: FunctionComponentSemanticNode["initPath"]): bigint;
327
330
  //#endregion
328
331
  //#region src/component/component-id.d.ts
329
332
  /**
@@ -334,15 +337,8 @@ declare function isComponentDefinition(context: RuleContext, node: ast.TSESTreeF
334
337
  */
335
338
  declare function getFunctionComponentId(context: RuleContext, node: ast.TSESTreeFunction): ast.FunctionID | unit;
336
339
  //#endregion
337
- //#region src/component/component-init-path.d.ts
338
- /**
339
- * Get component flag from init path
340
- * @param initPath The init path of the function component
341
- * @returns The component flag
342
- */
343
- declare function getComponentFlagFromInitPath(initPath: FunctionComponentSemanticNode["initPath"]): bigint;
344
- //#endregion
345
- //#region src/component/component-is.d.ts
340
+ //#region src/component/component-kind.d.ts
341
+ type ComponentKind = "class-component" | "pure-component" | "function-component";
346
342
  /**
347
343
  * Check if a node is a React class component
348
344
  * @param node The AST node to check
@@ -356,21 +352,7 @@ declare function isClassComponent(node: TSESTree.Node): node is ast.TSESTreeClas
356
352
  */
357
353
  declare function isPureComponent(node: TSESTree.Node): boolean;
358
354
  //#endregion
359
- //#region src/component/component-method-callback.d.ts
360
- /**
361
- * Check if the given node is a componentDidMount callback
362
- * @param node The node to check
363
- * @returns True if the node is a componentDidMount callback, false otherwise
364
- */
365
- declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
366
- /**
367
- * Check if the given node is a componentWillUnmount callback
368
- * @param node The node to check
369
- * @returns True if the node is a componentWillUnmount callback, false otherwise
370
- */
371
- declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
372
- //#endregion
373
- //#region src/component/component-method-is.d.ts
355
+ //#region src/component/component-method.d.ts
374
356
  declare const isRender: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
375
357
  declare const isComponentDidCatch: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
376
358
  declare const isComponentDidMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
@@ -389,6 +371,18 @@ declare const isUnsafeComponentWillUpdate: (node: TSESTree.Node) => node is ast.
389
371
  declare const isGetDefaultProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
390
372
  declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
391
373
  declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
374
+ /**
375
+ * Check if the given node is a componentDidMount callback
376
+ * @param node The node to check
377
+ * @returns True if the node is a componentDidMount callback, false otherwise
378
+ */
379
+ declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
380
+ /**
381
+ * Check if the given node is a componentWillUnmount callback
382
+ * @param node The node to check
383
+ * @returns True if the node is a componentWillUnmount callback, false otherwise
384
+ */
385
+ declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
392
386
  //#endregion
393
387
  //#region src/component/component-name.d.ts
394
388
  /**
@@ -510,7 +504,7 @@ declare function isComponentWrapperCallbackLoose(context: RuleContext, node: TSE
510
504
  /**
511
505
  * Represents the kind of a React function
512
506
  */
513
- type ComponentKind = "client-function" | "server-function";
507
+ type FunctionKind = "client-function" | "server-function";
514
508
  //#endregion
515
509
  //#region src/function/function-semantic-node.d.ts
516
510
  /**
@@ -544,7 +538,7 @@ type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null
544
538
  * @param test Optional test function to customize component or hook identification
545
539
  * @returns The enclosing component or hook node, or `null` if none is ASAST.
546
540
  */
547
- declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | undefined;
541
+ declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
548
542
  //#endregion
549
543
  //#region src/hierarchy/is-inside-component-or-hook.d.ts
550
544
  /**
@@ -742,7 +736,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: ast.T
742
736
  readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
743
737
  } | {
744
738
  readonly kind: "expression";
745
- readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
739
+ readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
746
740
  readonly toStatic: () => unknown;
747
741
  } | {
748
742
  readonly kind: "element";
@@ -750,7 +744,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: ast.T
750
744
  readonly toStatic: () => undefined;
751
745
  } | {
752
746
  readonly kind: "spreadChild";
753
- readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
747
+ readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
754
748
  readonly toStatic: () => undefined;
755
749
  } | {
756
750
  readonly kind: "spreadProps";
@@ -889,7 +883,10 @@ declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSEST
889
883
  */
890
884
  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;
891
885
  //#endregion
892
- //#region src/ref/is-from-ref.d.ts
886
+ //#region src/ref/ref-id.d.ts
887
+ declare function isRefId(node: TSESTree.Expression | TSESTree.PrivateIdentifier): boolean;
888
+ //#endregion
889
+ //#region src/ref/ref-init.d.ts
893
890
  /**
894
891
  * Check if the variable with the given name is initialized or derived from a ref
895
892
  * @param name The variable name
@@ -911,6 +908,6 @@ declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expre
911
908
  * @param name The name to check
912
909
  * @returns True if the name is "ref" or ends with "Ref"
913
910
  */
914
- declare function isRefName(name: string): boolean;
911
+ declare function isRefLikeName(name: string): boolean;
915
912
  //#endregion
916
- export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentKind, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponentSemanticNode, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefName, 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 };
913
+ export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentKind, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponentSemanticNode, FunctionKind, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, 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
@@ -260,7 +260,7 @@ function isHookId(id) {
260
260
 
261
261
  //#endregion
262
262
  //#region src/hook/hook-collector.ts
263
- const idGen$2 = new IdGenerator("hook_");
263
+ const idGen$2 = new IdGenerator("hook:");
264
264
  /**
265
265
  * Get a ctx and visitor object for the rule to collect hooks
266
266
  * @param context The ESLint rule context
@@ -666,27 +666,7 @@ function findParentJsxAttribute(node, test = constTrue) {
666
666
  }
667
667
 
668
668
  //#endregion
669
- //#region src/component/component-detection-hint.ts
670
- /**
671
- * Hints for component collector
672
- */
673
- const ComponentDetectionHint = {
674
- ...JsxDetectionHint,
675
- DoNotIncludeFunctionDefinedOnObjectMethod: 1n << 64n,
676
- DoNotIncludeFunctionDefinedOnClassMethod: 1n << 65n,
677
- DoNotIncludeFunctionDefinedOnClassProperty: 1n << 66n,
678
- DoNotIncludeFunctionDefinedInArrayPattern: 1n << 67n,
679
- DoNotIncludeFunctionDefinedInArrayExpression: 1n << 68n,
680
- DoNotIncludeFunctionDefinedAsArrayMapCallback: 1n << 69n,
681
- DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: 1n << 70n
682
- };
683
- /**
684
- * Default component detection hint
685
- */
686
- const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
687
-
688
- //#endregion
689
- //#region src/component/component-is.ts
669
+ //#region src/component/component-kind.ts
690
670
  /**
691
671
  * Check if a node is a React class component
692
672
  * @param node The AST node to check
@@ -832,9 +812,26 @@ function isRenderMethodLike(node) {
832
812
  }
833
813
 
834
814
  //#endregion
835
- //#region src/component/component-definition.ts
815
+ //#region src/component/component-detection.ts
836
816
  /**
837
- * Check if the given node is a function within a render method of a class component.
817
+ * Hints for component collector
818
+ */
819
+ const ComponentDetectionHint = {
820
+ ...JsxDetectionHint,
821
+ DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: 1n << 17n,
822
+ DoNotIncludeFunctionDefinedAsArrayMapCallback: 1n << 16n,
823
+ DoNotIncludeFunctionDefinedInArrayExpression: 1n << 15n,
824
+ DoNotIncludeFunctionDefinedInArrayPattern: 1n << 14n,
825
+ DoNotIncludeFunctionDefinedOnClassMethod: 1n << 12n,
826
+ DoNotIncludeFunctionDefinedOnClassProperty: 1n << 13n,
827
+ DoNotIncludeFunctionDefinedOnObjectMethod: 1n << 11n
828
+ };
829
+ /**
830
+ * Default component detection hint
831
+ */
832
+ const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
833
+ /**
834
+ * Check if the given node is a function within a render method of a class component
838
835
  *
839
836
  * @param node The AST node to check
840
837
  * @returns `true` if the node is a render function inside a class component
@@ -860,13 +857,13 @@ function isRenderMethodCallback(node) {
860
857
  */
861
858
  function shouldExcludeBasedOnHint(node, hint) {
862
859
  switch (true) {
863
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression: return true;
864
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return true;
865
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return true;
866
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern: return true;
867
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression && node.parent.type === AST_NODE_TYPES.ArrayExpression: return true;
868
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map": return true;
869
- case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "flatMap": return true;
860
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod);
861
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod);
862
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty);
863
+ case node.parent.type === AST_NODE_TYPES.ArrayPattern: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern);
864
+ case node.parent.type === AST_NODE_TYPES.ArrayExpression: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression);
865
+ case node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map": return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback);
866
+ case node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "flatMap": return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback);
870
867
  }
871
868
  return false;
872
869
  }
@@ -913,15 +910,12 @@ function isComponentDefinition(context, node, hint) {
913
910
  * Component flag constants
914
911
  */
915
912
  const ComponentFlag = {
916
- None: 0n,
917
- PureComponent: 1n << 0n,
918
913
  CreateElement: 1n << 1n,
914
+ ForwardRef: 1n << 3n,
919
915
  Memo: 1n << 2n,
920
- ForwardRef: 1n << 3n
916
+ None: 0n,
917
+ PureComponent: 1n << 0n
921
918
  };
922
-
923
- //#endregion
924
- //#region src/component/component-init-path.ts
925
919
  /**
926
920
  * Get component flag from init path
927
921
  * @param initPath The init path of the function component
@@ -936,7 +930,7 @@ function getComponentFlagFromInitPath(initPath) {
936
930
 
937
931
  //#endregion
938
932
  //#region src/component/component-collector.ts
939
- const idGen$1 = new IdGenerator("function_component_");
933
+ const idGen$1 = new IdGenerator("function-component:");
940
934
  /**
941
935
  * Get a ctx and visitor object for the rule to collect function components
942
936
  * @param context The ESLint rule context
@@ -1036,7 +1030,7 @@ function useComponentCollector(context, options = {}) {
1036
1030
 
1037
1031
  //#endregion
1038
1032
  //#region src/component/component-collector-legacy.ts
1039
- const idGen = new IdGenerator("class_component_");
1033
+ const idGen = new IdGenerator("class-component:");
1040
1034
  /**
1041
1035
  * Get a ctx and visitor object for the rule to collect class componentss
1042
1036
  * @param context The ESLint rule context
@@ -1094,7 +1088,7 @@ function isAssignmentToThisState(node) {
1094
1088
  }
1095
1089
 
1096
1090
  //#endregion
1097
- //#region src/component/component-method-is.ts
1091
+ //#region src/component/component-method.ts
1098
1092
  /**
1099
1093
  * Create a lifecycle method checker function
1100
1094
  * @param methodName The lifecycle method name
@@ -1121,9 +1115,6 @@ const isUnsafeComponentWillUpdate = createLifecycleChecker("UNSAFE_componentWill
1121
1115
  const isGetDefaultProps = createLifecycleChecker("getDefaultProps", true);
1122
1116
  const isGetDerivedStateFromProps = createLifecycleChecker("getDerivedStateFromProps", true);
1123
1117
  const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromError", true);
1124
-
1125
- //#endregion
1126
- //#region src/component/component-method-callback.ts
1127
1118
  /**
1128
1119
  * Check if the given node is a componentDidMount callback
1129
1120
  * @param node The node to check
@@ -1255,12 +1246,18 @@ function isInsideComponentOrHook(node) {
1255
1246
  * @param name The name to check
1256
1247
  * @returns True if the name is "ref" or ends with "Ref"
1257
1248
  */
1258
- function isRefName(name) {
1249
+ function isRefLikeName(name) {
1259
1250
  return name === "ref" || name.endsWith("Ref");
1260
1251
  }
1261
1252
 
1262
1253
  //#endregion
1263
- //#region src/ref/is-from-ref.ts
1254
+ //#region src/ref/ref-id.ts
1255
+ function isRefId(node) {
1256
+ return node.type === AST_NODE_TYPES.Identifier && isRefLikeName(node.name);
1257
+ }
1258
+
1259
+ //#endregion
1260
+ //#region src/ref/ref-init.ts
1264
1261
  /**
1265
1262
  * Check if the variable with the given name is initialized or derived from a ref
1266
1263
  * @param name The variable name
@@ -1282,7 +1279,7 @@ function getRefInit(name, initialScope) {
1282
1279
  const init = node.init;
1283
1280
  if (init == null) continue;
1284
1281
  switch (true) {
1285
- case init.type === AST_NODE_TYPES$1.MemberExpression && init.object.type === AST_NODE_TYPES$1.Identifier && isRefName(init.object.name): return init;
1282
+ case init.type === AST_NODE_TYPES$1.MemberExpression && init.object.type === AST_NODE_TYPES$1.Identifier && isRefLikeName(init.object.name): return init;
1286
1283
  case init.type === AST_NODE_TYPES$1.CallExpression && isUseRefCall(init): return init;
1287
1284
  }
1288
1285
  }
@@ -1290,4 +1287,4 @@ function getRefInit(name, initialScope) {
1290
1287
  }
1291
1288
 
1292
1289
  //#endregion
1293
- export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefName, 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 };
1290
+ export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, 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": "3.0.0-next.1",
3
+ "version": "3.0.0-next.12",
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": {
@@ -30,14 +30,14 @@
30
30
  "./package.json"
31
31
  ],
32
32
  "dependencies": {
33
- "@typescript-eslint/scope-manager": "^8.56.0",
34
- "@typescript-eslint/types": "^8.56.0",
35
- "@typescript-eslint/utils": "^8.56.0",
33
+ "@typescript-eslint/scope-manager": "canary",
34
+ "@typescript-eslint/types": "canary",
35
+ "@typescript-eslint/utils": "canary",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/ast": "3.0.0-next.1",
38
- "@eslint-react/eff": "3.0.0-next.1",
39
- "@eslint-react/var": "3.0.0-next.1",
40
- "@eslint-react/shared": "3.0.0-next.1"
37
+ "@eslint-react/ast": "3.0.0-next.12",
38
+ "@eslint-react/eff": "3.0.0-next.12",
39
+ "@eslint-react/var": "3.0.0-next.12",
40
+ "@eslint-react/shared": "3.0.0-next.12"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsdown": "^0.20.3",