@eslint-react/core 1.40.3 → 1.40.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.mts CHANGED
@@ -145,15 +145,23 @@ declare function getComponentFlagFromInitPath(initPath: FunctionComponent["initP
145
145
 
146
146
  type ComponentKind = "classComponent" | "functionComponent";
147
147
 
148
+ declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
148
149
  declare function isComponentDidMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
150
+ declare function isComponentDidUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
151
+ declare function isComponentWillMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
152
+ declare function isComponentWillReceiveProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
149
153
  declare function isComponentWillUnmount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
150
- declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
151
- declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
154
+ declare function isComponentWillUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
155
+ declare function isGetChildContext(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
156
+ declare function isGetDefaultProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
157
+ declare function isGetInitialState(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
158
+ declare function isGetSnapshotBeforeUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
159
+ declare function isShouldComponentUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
160
+ declare function isUnsafeComponentWillMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
161
+ declare function isUnsafeComponentWillReceiveProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
162
+ declare function isUnsafeComponentWillUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
152
163
  declare function isGetDerivedStateFromProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
153
- declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
154
- declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
155
- declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
156
- declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
164
+ declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
157
165
 
158
166
  declare const RE_COMPONENT_NAME: RegExp;
159
167
  declare const RE_COMPONENT_NAME_LOOSE: RegExp;
@@ -174,6 +182,46 @@ declare const isInversePhase: {
174
182
  (a: ComponentPhaseKind, b: ComponentPhaseKind): boolean;
175
183
  };
176
184
 
185
+ /**
186
+ * Check whether given node is a render function of a class component
187
+ * @example
188
+ * ```tsx
189
+ * class Component extends React.Component {
190
+ * render() {
191
+ * return <div />;
192
+ * }
193
+ * }
194
+ * ```
195
+ * @param node The AST node to check
196
+ * @returns `true` if node is a render function, `false` if not
197
+ */
198
+ declare function isRenderLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
199
+ /**
200
+ * Check whether given node is a function of a render function of a class component
201
+ * @example
202
+ * ```tsx
203
+ * class Component extends React.Component {
204
+ * render = () => <div />;
205
+ * ```
206
+ * @param node The AST node to check
207
+ * @returns `true` if node is a render function, `false` if not
208
+ */
209
+ declare function isFunctionOfRender(node: AST.TSESTreeFunction): boolean;
210
+
211
+ /**
212
+ * Check whether given node is a render method of a class component
213
+ * @example
214
+ * ```tsx
215
+ * class Component extends React.Component {
216
+ * renderHeader = () => <div />;
217
+ * renderFooter = () => <div />;
218
+ * }
219
+ * ```
220
+ * @param node The AST node to check
221
+ * @returns `true` if node is a render function, `false` if not
222
+ */
223
+ declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
224
+
177
225
  /**
178
226
  * Unsafe check whether given node is a render function
179
227
  * ```tsx
@@ -266,6 +314,21 @@ declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.
266
314
  * @returns `true` if node is inside class component's render block, `false` if not
267
315
  */
268
316
  declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
317
+ declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
318
+ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
319
+ /**
320
+ * Check whether given node is a function of a render method of a class component
321
+ * @example
322
+ * ```tsx
323
+ * class Component extends React.Component {
324
+ * renderHeader = () => <div />;
325
+ * renderFooter = () => <div />;
326
+ * }
327
+ * ```
328
+ * @param node The AST node to check
329
+ * @returns `true` if node is a render function, `false` if not
330
+ */
331
+ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
269
332
 
270
333
  /**
271
334
  * Check if a node is a React class component
@@ -418,4 +481,4 @@ declare const isCreateRefCall: isCallFromReact.ReturnType;
418
481
  declare const isForwardRefCall: isCallFromReact.ReturnType;
419
482
  declare const isMemoCall: isCallFromReact.ReturnType;
420
483
 
421
- export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type EffectKind, type FunctionComponent, type Hook, type HookKind, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, type SemanticEntry, type SemanticNode, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentNameLoose, isComponentWillUnmount, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
484
+ export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type EffectKind, type FunctionComponent, type Hook, type HookKind, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, type SemanticEntry, type SemanticNode, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRender, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.d.ts CHANGED
@@ -145,15 +145,23 @@ declare function getComponentFlagFromInitPath(initPath: FunctionComponent["initP
145
145
 
146
146
  type ComponentKind = "classComponent" | "functionComponent";
147
147
 
148
+ declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
148
149
  declare function isComponentDidMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
150
+ declare function isComponentDidUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
151
+ declare function isComponentWillMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
152
+ declare function isComponentWillReceiveProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
149
153
  declare function isComponentWillUnmount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
150
- declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
151
- declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
154
+ declare function isComponentWillUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
155
+ declare function isGetChildContext(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
156
+ declare function isGetDefaultProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
157
+ declare function isGetInitialState(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
158
+ declare function isGetSnapshotBeforeUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
159
+ declare function isShouldComponentUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
160
+ declare function isUnsafeComponentWillMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
161
+ declare function isUnsafeComponentWillReceiveProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
162
+ declare function isUnsafeComponentWillUpdate(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
152
163
  declare function isGetDerivedStateFromProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
153
- declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
154
- declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
155
- declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
156
- declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
164
+ declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
157
165
 
158
166
  declare const RE_COMPONENT_NAME: RegExp;
159
167
  declare const RE_COMPONENT_NAME_LOOSE: RegExp;
@@ -174,6 +182,46 @@ declare const isInversePhase: {
174
182
  (a: ComponentPhaseKind, b: ComponentPhaseKind): boolean;
175
183
  };
176
184
 
185
+ /**
186
+ * Check whether given node is a render function of a class component
187
+ * @example
188
+ * ```tsx
189
+ * class Component extends React.Component {
190
+ * render() {
191
+ * return <div />;
192
+ * }
193
+ * }
194
+ * ```
195
+ * @param node The AST node to check
196
+ * @returns `true` if node is a render function, `false` if not
197
+ */
198
+ declare function isRenderLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
199
+ /**
200
+ * Check whether given node is a function of a render function of a class component
201
+ * @example
202
+ * ```tsx
203
+ * class Component extends React.Component {
204
+ * render = () => <div />;
205
+ * ```
206
+ * @param node The AST node to check
207
+ * @returns `true` if node is a render function, `false` if not
208
+ */
209
+ declare function isFunctionOfRender(node: AST.TSESTreeFunction): boolean;
210
+
211
+ /**
212
+ * Check whether given node is a render method of a class component
213
+ * @example
214
+ * ```tsx
215
+ * class Component extends React.Component {
216
+ * renderHeader = () => <div />;
217
+ * renderFooter = () => <div />;
218
+ * }
219
+ * ```
220
+ * @param node The AST node to check
221
+ * @returns `true` if node is a render function, `false` if not
222
+ */
223
+ declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
224
+
177
225
  /**
178
226
  * Unsafe check whether given node is a render function
179
227
  * ```tsx
@@ -266,6 +314,21 @@ declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.
266
314
  * @returns `true` if node is inside class component's render block, `false` if not
267
315
  */
268
316
  declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
317
+ declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
318
+ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
319
+ /**
320
+ * Check whether given node is a function of a render method of a class component
321
+ * @example
322
+ * ```tsx
323
+ * class Component extends React.Component {
324
+ * renderHeader = () => <div />;
325
+ * renderFooter = () => <div />;
326
+ * }
327
+ * ```
328
+ * @param node The AST node to check
329
+ * @returns `true` if node is a render function, `false` if not
330
+ */
331
+ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
269
332
 
270
333
  /**
271
334
  * Check if a node is a React class component
@@ -418,4 +481,4 @@ declare const isCreateRefCall: isCallFromReact.ReturnType;
418
481
  declare const isForwardRefCall: isCallFromReact.ReturnType;
419
482
  declare const isMemoCall: isCallFromReact.ReturnType;
420
483
 
421
- export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type EffectKind, type FunctionComponent, type Hook, type HookKind, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, type SemanticEntry, type SemanticNode, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentNameLoose, isComponentWillUnmount, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
484
+ export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type EffectKind, type FunctionComponent, type Hook, type HookKind, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, type SemanticEntry, type SemanticNode, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRender, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var AST5 = require('@eslint-react/ast');
3
+ var AST6 = require('@eslint-react/ast');
4
4
  var eff = require('@eslint-react/eff');
5
5
  var JSX3 = require('@eslint-react/jsx');
6
6
  var shared = require('@eslint-react/shared');
@@ -30,7 +30,7 @@ function _interopNamespace(e) {
30
30
  return Object.freeze(n);
31
31
  }
32
32
 
33
- var AST5__namespace = /*#__PURE__*/_interopNamespace(AST5);
33
+ var AST6__namespace = /*#__PURE__*/_interopNamespace(AST6);
34
34
  var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
35
35
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
36
36
  var birecord__default = /*#__PURE__*/_interopDefault(birecord);
@@ -46,16 +46,7 @@ var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
46
46
  "[left.property.name='displayName']"
47
47
  ].join("");
48
48
 
49
- // src/hook/hook-name.ts
50
- var RE_HOOK_NAME = /^use[A-Z\d]/u;
51
- function isReactHookName(name) {
52
- return name === "use" || RE_HOOK_NAME.test(name);
53
- }
54
- function isReactHookNameLoose(name) {
55
- return name.startsWith("use");
56
- }
57
-
58
- // ../../node_modules/.pnpm/valibot@1.0.0_typescript@5.8.2/node_modules/valibot/dist/index.js
49
+ // ../../node_modules/.pnpm/valibot@1.0.0_typescript@5.8.3/node_modules/valibot/dist/index.js
59
50
  var store;
60
51
  // @__NO_SIDE_EFFECTS__
61
52
  function getGlobalConfig(config2) {
@@ -560,7 +551,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
560
551
  }
561
552
  const args = getRequireExpressionArguments(init);
562
553
  const arg0 = args?.[0];
563
- if (arg0 == null || !AST5__namespace.isKindOfLiteral(arg0, "string")) {
554
+ if (arg0 == null || !AST6__namespace.isLiteral(arg0, "string")) {
564
555
  return false;
565
556
  }
566
557
  return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
@@ -625,7 +616,7 @@ function isCallFromReactObject(objectName, propertyName) {
625
616
  });
626
617
  }
627
618
  function isInstanceIdEqual(context, a, b) {
628
- return AST5__namespace.isNodeEqual(a, b) || VAR__namespace.isNodeValueEqual(a, b, [
619
+ return AST6__namespace.isNodeEqual(a, b) || VAR__namespace.isNodeValueEqual(a, b, [
629
620
  context.sourceCode.getScope(a),
630
621
  context.sourceCode.getScope(b)
631
622
  ]);
@@ -661,10 +652,19 @@ var isCreateRefCall = isReactAPICall("createRef");
661
652
  var isForwardRefCall = isReactAPICall("forwardRef");
662
653
  var isMemoCall = isReactAPICall("memo");
663
654
 
655
+ // src/hook/hook-name.ts
656
+ var RE_HOOK_NAME = /^use[A-Z\d]/u;
657
+ function isReactHookName(name) {
658
+ return name === "use" || RE_HOOK_NAME.test(name);
659
+ }
660
+ function isReactHookNameLoose(name) {
661
+ return name.startsWith("use");
662
+ }
663
+
664
664
  // src/hook/is.ts
665
665
  function isReactHook(node) {
666
666
  if (node == null) return false;
667
- const id = AST5__namespace.getFunctionIdentifier(node);
667
+ const id = AST6__namespace.getFunctionIdentifier(node);
668
668
  return id?.name != null && isReactHookName(id.name);
669
669
  }
670
670
  function isReactHookCall(node) {
@@ -762,12 +762,23 @@ var isUseStateCall = eff.flip(isReactHookCallWithName)("useState");
762
762
  var isUseSyncExternalStoreCall = eff.flip(isReactHookCallWithName)("useSyncExternalStore");
763
763
  var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
764
764
 
765
- // src/hook/hook-collector.ts
765
+ // src/hook/hierarchy.ts
766
+ function isFunctionOfUseEffectSetup(node) {
767
+ if (node == null) return false;
768
+ return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
769
+ }
770
+ function isFunctionOfUseEffectCleanup(node) {
771
+ if (node == null) return false;
772
+ const returnStatement = AST6__namespace.findParentNode(node, AST6__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
773
+ const enclosingFunction = AST6__namespace.findParentNode(node, AST6__namespace.isFunction);
774
+ const functionOfReturnStatement = AST6__namespace.findParentNode(returnStatement, AST6__namespace.isFunction);
775
+ return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
776
+ }
766
777
  function useHookCollector() {
767
778
  const hooks = /* @__PURE__ */ new Map();
768
779
  const functionEntries = [];
769
780
  const onFunctionEnter = (node) => {
770
- const id = AST5__namespace.getFunctionIdentifier(node);
781
+ const id = AST6__namespace.getFunctionIdentifier(node);
771
782
  const key = shared.getId();
772
783
  const name = id?.name;
773
784
  if (name != null && isReactHookName(name)) {
@@ -846,6 +857,57 @@ var ComponentDetectionHint = {
846
857
  SkipClassProperty: 1n << 69n
847
858
  };
848
859
  var DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipEmptyArray | ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.StrictArray | ComponentDetectionHint.StrictConditional | ComponentDetectionHint.StrictLogical;
860
+ function isComponentDidCatch(node) {
861
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
862
+ }
863
+ function isComponentDidMount(node) {
864
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
865
+ }
866
+ function isComponentDidUpdate(node) {
867
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
868
+ }
869
+ function isComponentWillMount(node) {
870
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
871
+ }
872
+ function isComponentWillReceiveProps(node) {
873
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
874
+ }
875
+ function isComponentWillUnmount(node) {
876
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
877
+ }
878
+ function isComponentWillUpdate(node) {
879
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
880
+ }
881
+ function isGetChildContext(node) {
882
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
883
+ }
884
+ function isGetDefaultProps(node) {
885
+ return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
886
+ }
887
+ function isGetInitialState(node) {
888
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
889
+ }
890
+ function isGetSnapshotBeforeUpdate(node) {
891
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
892
+ }
893
+ function isShouldComponentUpdate(node) {
894
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
895
+ }
896
+ function isUnsafeComponentWillMount(node) {
897
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
898
+ }
899
+ function isUnsafeComponentWillReceiveProps(node) {
900
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
901
+ }
902
+ function isUnsafeComponentWillUpdate(node) {
903
+ return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
904
+ }
905
+ function isGetDerivedStateFromProps(node) {
906
+ return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
907
+ }
908
+ function isGetDerivedStateFromError(node) {
909
+ return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
910
+ }
849
911
  function isClassComponent(node) {
850
912
  if ("superClass" in node && node.superClass != null) {
851
913
  const re = /^(?:Pure)?Component$/u;
@@ -871,30 +933,35 @@ function isPureComponent(node) {
871
933
  return false;
872
934
  }
873
935
 
874
- // src/component/component-lifecycle.ts
875
- function isComponentDidMount(node) {
876
- return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
936
+ // src/component/component-render.ts
937
+ function isRenderLike(node) {
938
+ return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
877
939
  }
878
- function isComponentWillUnmount(node) {
879
- return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
940
+ function isFunctionOfRender(node) {
941
+ if (!isRenderLike(node.parent)) {
942
+ return false;
943
+ }
944
+ return isClassComponent(node.parent.parent.parent);
880
945
  }
881
- function isComponentDidCatch(node) {
882
- return AST5__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
946
+ function isRenderMethodLike(node) {
947
+ return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
883
948
  }
884
- function isGetDerivedStateFromError(node) {
885
- return AST5__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
949
+
950
+ // src/component/hierarchy.ts
951
+ function isChildrenOfCreateElement(context, node) {
952
+ const parent = node.parent;
953
+ if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
954
+ if (!isCreateElementCall(context, parent)) return false;
955
+ return parent.arguments.slice(2).some((arg) => arg === node);
886
956
  }
887
- function isGetDerivedStateFromProps(node) {
888
- return AST5__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
957
+ function isInsideRenderMethod(node) {
958
+ return AST6__namespace.findParentNode(node, (n) => isRenderLike(n) && isClassComponent(n.parent.parent)) != null;
889
959
  }
890
960
  function isFunctionOfComponentDidMount(node) {
891
- return AST5__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
961
+ return AST6__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
892
962
  }
893
963
  function isFunctionOfComponentWillUnmount(node) {
894
- return AST5__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
895
- }
896
- function isRenderMethodLike(node) {
897
- return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
964
+ return AST6__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
898
965
  }
899
966
  function isFunctionOfRenderMethod(node) {
900
967
  if (!isRenderMethodLike(node.parent)) {
@@ -902,15 +969,6 @@ function isFunctionOfRenderMethod(node) {
902
969
  }
903
970
  return isClassComponent(node.parent.parent.parent);
904
971
  }
905
- function isChildrenOfCreateElement(context, node) {
906
- const parent = node.parent;
907
- if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
908
- if (!isCreateElementCall(context, parent)) return false;
909
- return parent.arguments.slice(2).some((arg) => arg === node);
910
- }
911
- function isInsideRenderMethod(node) {
912
- return AST5__namespace.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
913
- }
914
972
 
915
973
  // src/component/component-definition.ts
916
974
  var isFunctionOfClassMethod = tsPattern.isMatching({
@@ -943,12 +1001,12 @@ function isValidComponentDefinition(context, node, hint) {
943
1001
  if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
944
1002
  return false;
945
1003
  }
946
- if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST5__namespace.isArrayMapCallLoose(node.parent)) {
1004
+ if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST6__namespace.isArrayMapCallLoose(node.parent)) {
947
1005
  return false;
948
1006
  }
949
- const boundaryNode = AST5__namespace.findParentNode(
1007
+ const boundaryNode = AST6__namespace.findParentNode(
950
1008
  node,
951
- AST5__namespace.isOneOf([
1009
+ AST6__namespace.isOneOf([
952
1010
  types.AST_NODE_TYPES.JSXExpressionContainer,
953
1011
  types.AST_NODE_TYPES.ArrowFunctionExpression,
954
1012
  types.AST_NODE_TYPES.FunctionExpression,
@@ -969,7 +1027,7 @@ function isComponentWrapperCallLoose(context, node) {
969
1027
 
970
1028
  // src/component/component-id.ts
971
1029
  function getFunctionComponentId(context, node) {
972
- const functionId = AST5__namespace.getFunctionIdentifier(node);
1030
+ const functionId = AST6__namespace.getFunctionIdentifier(node);
973
1031
  if (functionId != null) {
974
1032
  return functionId;
975
1033
  }
@@ -996,10 +1054,10 @@ var ComponentFlag = {
996
1054
  // src/component/component-init-path.ts
997
1055
  function getComponentFlagFromInitPath(initPath) {
998
1056
  let flag = ComponentFlag.None;
999
- if (initPath != null && AST5__namespace.hasCallInFunctionInitPath("memo", initPath)) {
1057
+ if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("memo", initPath)) {
1000
1058
  flag |= ComponentFlag.Memo;
1001
1059
  }
1002
- if (initPath != null && AST5__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
1060
+ if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
1003
1061
  flag |= ComponentFlag.ForwardRef;
1004
1062
  }
1005
1063
  return flag;
@@ -1030,7 +1088,6 @@ function useComponentCollector(context, options = {}) {
1030
1088
  collectHookCalls = false,
1031
1089
  hint = DEFAULT_COMPONENT_DETECTION_HINT
1032
1090
  } = options;
1033
- const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
1034
1091
  const components = /* @__PURE__ */ new Map();
1035
1092
  const functionEntries = [];
1036
1093
  const getCurrentEntry = () => functionEntries.at(-1);
@@ -1042,8 +1099,8 @@ function useComponentCollector(context, options = {}) {
1042
1099
  const entry = functionEntries.at(-1);
1043
1100
  if (entry == null) return;
1044
1101
  if (!entry.isComponent) return functionEntries.pop();
1045
- const shouldDrop = AST5__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
1046
- return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXLike(r.argument, jsxCtx, hint);
1102
+ const shouldDrop = AST6__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
1103
+ return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJsxLike(context.sourceCode, r.argument, hint);
1047
1104
  });
1048
1105
  if (shouldDrop) {
1049
1106
  components.delete(entry.key);
@@ -1067,9 +1124,9 @@ function useComponentCollector(context, options = {}) {
1067
1124
  const entry = getCurrentEntry();
1068
1125
  if (entry == null) return;
1069
1126
  const { body } = entry.node;
1070
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXLike(body, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
1127
+ const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
1071
1128
  if (!isComponent) return;
1072
- const initPath = AST5__namespace.getFunctionInitPath(entry.node);
1129
+ const initPath = AST6__namespace.getFunctionInitPath(entry.node);
1073
1130
  const id = getFunctionComponentId(context, entry.node);
1074
1131
  const name = getComponentNameFromId(id);
1075
1132
  const key = shared.getId();
@@ -1107,10 +1164,10 @@ function useComponentCollector(context, options = {}) {
1107
1164
  "ReturnStatement[type]"(node) {
1108
1165
  const entry = getCurrentEntry();
1109
1166
  if (entry == null) return;
1110
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXLike(node.argument, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
1167
+ const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
1111
1168
  if (!isComponent) return;
1112
1169
  entry.isComponent = true;
1113
- const initPath = AST5__namespace.getFunctionInitPath(entry.node);
1170
+ const initPath = AST6__namespace.getFunctionInitPath(entry.node);
1114
1171
  const id = getFunctionComponentId(context, entry.node);
1115
1172
  const name = getComponentNameFromId(id);
1116
1173
  components.set(entry.key, {
@@ -1141,7 +1198,7 @@ function useComponentCollectorLegacy() {
1141
1198
  if (!isClassComponent(node)) {
1142
1199
  return;
1143
1200
  }
1144
- const id = AST5__namespace.getClassIdentifier(node);
1201
+ const id = AST6__namespace.getClassIdentifier(node);
1145
1202
  const key = shared.getId();
1146
1203
  const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
1147
1204
  components.set(
@@ -1174,14 +1231,12 @@ var ComponentPhaseRelevance = birecord__default.default({
1174
1231
  var isInversePhase = eff.dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
1175
1232
  function isRenderFunctionLoose(context, node) {
1176
1233
  const { body, parent } = node;
1177
- if (AST5__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
1234
+ if (AST6__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
1178
1235
  return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
1179
1236
  }
1180
- return JSX3__namespace.isJSXLike(
1237
+ return JSX3__namespace.isJsxLike(
1238
+ context.sourceCode,
1181
1239
  body,
1182
- {
1183
- getScope: (node2) => context.sourceCode.getScope(node2)
1184
- },
1185
1240
  JSX3__namespace.JSXDetectionHint.SkipNullLiteral | JSX3__namespace.JSXDetectionHint.SkipUndefined | JSX3__namespace.JSXDetectionHint.StrictLogical | JSX3__namespace.JSXDetectionHint.StrictConditional
1186
1241
  );
1187
1242
  }
@@ -1189,7 +1244,7 @@ function isRenderPropLoose(context, node) {
1189
1244
  if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
1190
1245
  return false;
1191
1246
  }
1192
- return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST5__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
1247
+ return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST6__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
1193
1248
  }
1194
1249
  function isDirectValueOfRenderPropertyLoose(node) {
1195
1250
  const matching = (node2) => {
@@ -1201,7 +1256,7 @@ function isDeclaredInRenderPropLoose(node) {
1201
1256
  if (isDirectValueOfRenderPropertyLoose(node)) {
1202
1257
  return true;
1203
1258
  }
1204
- const parent = AST5__namespace.findParentNode(node, AST5__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
1259
+ const parent = AST6__namespace.findParentNode(node, AST6__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
1205
1260
  if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
1206
1261
  return false;
1207
1262
  }
@@ -1209,22 +1264,11 @@ function isDeclaredInRenderPropLoose(node) {
1209
1264
  }
1210
1265
  function isThisSetState(node) {
1211
1266
  const { callee } = node;
1212
- return callee.type === types.AST_NODE_TYPES.MemberExpression && AST5__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
1267
+ return callee.type === types.AST_NODE_TYPES.MemberExpression && AST6__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
1213
1268
  }
1214
1269
  function isAssignmentToThisState(node) {
1215
1270
  const { left } = node;
1216
- return left.type === types.AST_NODE_TYPES.MemberExpression && AST5__namespace.isThisExpression(left.object) && AST5__namespace.getPropertyName(left.property) === "state";
1217
- }
1218
- function isFunctionOfUseEffectSetup(node) {
1219
- if (node == null) return false;
1220
- return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
1221
- }
1222
- function isFunctionOfUseEffectCleanup(node) {
1223
- if (node == null) return false;
1224
- const returnStatement = AST5__namespace.findParentNode(node, AST5__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
1225
- const enclosingFunction = AST5__namespace.findParentNode(node, AST5__namespace.isFunction);
1226
- const functionOfReturnStatement = AST5__namespace.findParentNode(returnStatement, AST5__namespace.isFunction);
1227
- return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
1271
+ return left.type === types.AST_NODE_TYPES.MemberExpression && AST6__namespace.isThisExpression(left.object) && AST6__namespace.getPropertyName(left.property) === "state";
1228
1272
  }
1229
1273
 
1230
1274
  exports.ComponentDetectionHint = ComponentDetectionHint;
@@ -1259,9 +1303,13 @@ exports.isCloneElement = isCloneElement;
1259
1303
  exports.isCloneElementCall = isCloneElementCall;
1260
1304
  exports.isComponentDidCatch = isComponentDidCatch;
1261
1305
  exports.isComponentDidMount = isComponentDidMount;
1306
+ exports.isComponentDidUpdate = isComponentDidUpdate;
1262
1307
  exports.isComponentName = isComponentName;
1263
1308
  exports.isComponentNameLoose = isComponentNameLoose;
1309
+ exports.isComponentWillMount = isComponentWillMount;
1310
+ exports.isComponentWillReceiveProps = isComponentWillReceiveProps;
1264
1311
  exports.isComponentWillUnmount = isComponentWillUnmount;
1312
+ exports.isComponentWillUpdate = isComponentWillUpdate;
1265
1313
  exports.isComponentWrapperCall = isComponentWrapperCall;
1266
1314
  exports.isComponentWrapperCallLoose = isComponentWrapperCallLoose;
1267
1315
  exports.isCreateContext = isCreateContext;
@@ -1280,11 +1328,16 @@ exports.isFromReactObject = isFromReactObject;
1280
1328
  exports.isFromReactStrict = isFromReactStrict;
1281
1329
  exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
1282
1330
  exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
1331
+ exports.isFunctionOfRender = isFunctionOfRender;
1283
1332
  exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
1284
1333
  exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
1285
1334
  exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
1335
+ exports.isGetChildContext = isGetChildContext;
1336
+ exports.isGetDefaultProps = isGetDefaultProps;
1286
1337
  exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
1287
1338
  exports.isGetDerivedStateFromProps = isGetDerivedStateFromProps;
1339
+ exports.isGetInitialState = isGetInitialState;
1340
+ exports.isGetSnapshotBeforeUpdate = isGetSnapshotBeforeUpdate;
1288
1341
  exports.isInitializedFromReact = isInitializedFromReact;
1289
1342
  exports.isInsideRenderMethod = isInsideRenderMethod;
1290
1343
  exports.isInstanceIdEqual = isInstanceIdEqual;
@@ -1302,9 +1355,14 @@ exports.isReactHookCallWithNameLoose = isReactHookCallWithNameLoose;
1302
1355
  exports.isReactHookName = isReactHookName;
1303
1356
  exports.isReactHookNameLoose = isReactHookNameLoose;
1304
1357
  exports.isRenderFunctionLoose = isRenderFunctionLoose;
1358
+ exports.isRenderLike = isRenderLike;
1305
1359
  exports.isRenderMethodLike = isRenderMethodLike;
1306
1360
  exports.isRenderPropLoose = isRenderPropLoose;
1361
+ exports.isShouldComponentUpdate = isShouldComponentUpdate;
1307
1362
  exports.isThisSetState = isThisSetState;
1363
+ exports.isUnsafeComponentWillMount = isUnsafeComponentWillMount;
1364
+ exports.isUnsafeComponentWillReceiveProps = isUnsafeComponentWillReceiveProps;
1365
+ exports.isUnsafeComponentWillUpdate = isUnsafeComponentWillUpdate;
1308
1366
  exports.isUseActionStateCall = isUseActionStateCall;
1309
1367
  exports.isUseCall = isUseCall;
1310
1368
  exports.isUseCallbackCall = isUseCallbackCall;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import * as AST5 from '@eslint-react/ast';
1
+ import * as AST6 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';
@@ -19,16 +19,7 @@ var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
19
19
  "[left.property.name='displayName']"
20
20
  ].join("");
21
21
 
22
- // src/hook/hook-name.ts
23
- var RE_HOOK_NAME = /^use[A-Z\d]/u;
24
- function isReactHookName(name) {
25
- return name === "use" || RE_HOOK_NAME.test(name);
26
- }
27
- function isReactHookNameLoose(name) {
28
- return name.startsWith("use");
29
- }
30
-
31
- // ../../node_modules/.pnpm/valibot@1.0.0_typescript@5.8.2/node_modules/valibot/dist/index.js
22
+ // ../../node_modules/.pnpm/valibot@1.0.0_typescript@5.8.3/node_modules/valibot/dist/index.js
32
23
  var store;
33
24
  // @__NO_SIDE_EFFECTS__
34
25
  function getGlobalConfig(config2) {
@@ -533,7 +524,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
533
524
  }
534
525
  const args = getRequireExpressionArguments(init);
535
526
  const arg0 = args?.[0];
536
- if (arg0 == null || !AST5.isKindOfLiteral(arg0, "string")) {
527
+ if (arg0 == null || !AST6.isLiteral(arg0, "string")) {
537
528
  return false;
538
529
  }
539
530
  return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
@@ -598,7 +589,7 @@ function isCallFromReactObject(objectName, propertyName) {
598
589
  });
599
590
  }
600
591
  function isInstanceIdEqual(context, a, b) {
601
- return AST5.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [
592
+ return AST6.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [
602
593
  context.sourceCode.getScope(a),
603
594
  context.sourceCode.getScope(b)
604
595
  ]);
@@ -634,10 +625,19 @@ var isCreateRefCall = isReactAPICall("createRef");
634
625
  var isForwardRefCall = isReactAPICall("forwardRef");
635
626
  var isMemoCall = isReactAPICall("memo");
636
627
 
628
+ // src/hook/hook-name.ts
629
+ var RE_HOOK_NAME = /^use[A-Z\d]/u;
630
+ function isReactHookName(name) {
631
+ return name === "use" || RE_HOOK_NAME.test(name);
632
+ }
633
+ function isReactHookNameLoose(name) {
634
+ return name.startsWith("use");
635
+ }
636
+
637
637
  // src/hook/is.ts
638
638
  function isReactHook(node) {
639
639
  if (node == null) return false;
640
- const id = AST5.getFunctionIdentifier(node);
640
+ const id = AST6.getFunctionIdentifier(node);
641
641
  return id?.name != null && isReactHookName(id.name);
642
642
  }
643
643
  function isReactHookCall(node) {
@@ -735,12 +735,23 @@ var isUseStateCall = flip(isReactHookCallWithName)("useState");
735
735
  var isUseSyncExternalStoreCall = flip(isReactHookCallWithName)("useSyncExternalStore");
736
736
  var isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
737
737
 
738
- // src/hook/hook-collector.ts
738
+ // src/hook/hierarchy.ts
739
+ function isFunctionOfUseEffectSetup(node) {
740
+ if (node == null) return false;
741
+ 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);
742
+ }
743
+ function isFunctionOfUseEffectCleanup(node) {
744
+ if (node == null) return false;
745
+ const returnStatement = AST6.findParentNode(node, AST6.is(AST_NODE_TYPES.ReturnStatement));
746
+ const enclosingFunction = AST6.findParentNode(node, AST6.isFunction);
747
+ const functionOfReturnStatement = AST6.findParentNode(returnStatement, AST6.isFunction);
748
+ return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
749
+ }
739
750
  function useHookCollector() {
740
751
  const hooks = /* @__PURE__ */ new Map();
741
752
  const functionEntries = [];
742
753
  const onFunctionEnter = (node) => {
743
- const id = AST5.getFunctionIdentifier(node);
754
+ const id = AST6.getFunctionIdentifier(node);
744
755
  const key = getId();
745
756
  const name = id?.name;
746
757
  if (name != null && isReactHookName(name)) {
@@ -819,6 +830,57 @@ var ComponentDetectionHint = {
819
830
  SkipClassProperty: 1n << 69n
820
831
  };
821
832
  var DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipEmptyArray | ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.StrictArray | ComponentDetectionHint.StrictConditional | ComponentDetectionHint.StrictLogical;
833
+ function isComponentDidCatch(node) {
834
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
835
+ }
836
+ function isComponentDidMount(node) {
837
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
838
+ }
839
+ function isComponentDidUpdate(node) {
840
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
841
+ }
842
+ function isComponentWillMount(node) {
843
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
844
+ }
845
+ function isComponentWillReceiveProps(node) {
846
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
847
+ }
848
+ function isComponentWillUnmount(node) {
849
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
850
+ }
851
+ function isComponentWillUpdate(node) {
852
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
853
+ }
854
+ function isGetChildContext(node) {
855
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
856
+ }
857
+ function isGetDefaultProps(node) {
858
+ return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
859
+ }
860
+ function isGetInitialState(node) {
861
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
862
+ }
863
+ function isGetSnapshotBeforeUpdate(node) {
864
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
865
+ }
866
+ function isShouldComponentUpdate(node) {
867
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
868
+ }
869
+ function isUnsafeComponentWillMount(node) {
870
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
871
+ }
872
+ function isUnsafeComponentWillReceiveProps(node) {
873
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
874
+ }
875
+ function isUnsafeComponentWillUpdate(node) {
876
+ return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
877
+ }
878
+ function isGetDerivedStateFromProps(node) {
879
+ return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
880
+ }
881
+ function isGetDerivedStateFromError(node) {
882
+ return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
883
+ }
822
884
  function isClassComponent(node) {
823
885
  if ("superClass" in node && node.superClass != null) {
824
886
  const re = /^(?:Pure)?Component$/u;
@@ -844,30 +906,35 @@ function isPureComponent(node) {
844
906
  return false;
845
907
  }
846
908
 
847
- // src/component/component-lifecycle.ts
848
- function isComponentDidMount(node) {
849
- return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
909
+ // src/component/component-render.ts
910
+ function isRenderLike(node) {
911
+ return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
850
912
  }
851
- function isComponentWillUnmount(node) {
852
- return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
913
+ function isFunctionOfRender(node) {
914
+ if (!isRenderLike(node.parent)) {
915
+ return false;
916
+ }
917
+ return isClassComponent(node.parent.parent.parent);
853
918
  }
854
- function isComponentDidCatch(node) {
855
- return AST5.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
919
+ function isRenderMethodLike(node) {
920
+ return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
856
921
  }
857
- function isGetDerivedStateFromError(node) {
858
- return AST5.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
922
+
923
+ // src/component/hierarchy.ts
924
+ function isChildrenOfCreateElement(context, node) {
925
+ const parent = node.parent;
926
+ if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
927
+ if (!isCreateElementCall(context, parent)) return false;
928
+ return parent.arguments.slice(2).some((arg) => arg === node);
859
929
  }
860
- function isGetDerivedStateFromProps(node) {
861
- return AST5.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
930
+ function isInsideRenderMethod(node) {
931
+ return AST6.findParentNode(node, (n) => isRenderLike(n) && isClassComponent(n.parent.parent)) != null;
862
932
  }
863
933
  function isFunctionOfComponentDidMount(node) {
864
- return AST5.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
934
+ return AST6.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
865
935
  }
866
936
  function isFunctionOfComponentWillUnmount(node) {
867
- return AST5.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
868
- }
869
- function isRenderMethodLike(node) {
870
- return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
937
+ return AST6.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
871
938
  }
872
939
  function isFunctionOfRenderMethod(node) {
873
940
  if (!isRenderMethodLike(node.parent)) {
@@ -875,15 +942,6 @@ function isFunctionOfRenderMethod(node) {
875
942
  }
876
943
  return isClassComponent(node.parent.parent.parent);
877
944
  }
878
- function isChildrenOfCreateElement(context, node) {
879
- const parent = node.parent;
880
- if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
881
- if (!isCreateElementCall(context, parent)) return false;
882
- return parent.arguments.slice(2).some((arg) => arg === node);
883
- }
884
- function isInsideRenderMethod(node) {
885
- return AST5.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
886
- }
887
945
 
888
946
  // src/component/component-definition.ts
889
947
  var isFunctionOfClassMethod = isMatching({
@@ -916,12 +974,12 @@ function isValidComponentDefinition(context, node, hint) {
916
974
  if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
917
975
  return false;
918
976
  }
919
- if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST5.isArrayMapCallLoose(node.parent)) {
977
+ if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST6.isArrayMapCallLoose(node.parent)) {
920
978
  return false;
921
979
  }
922
- const boundaryNode = AST5.findParentNode(
980
+ const boundaryNode = AST6.findParentNode(
923
981
  node,
924
- AST5.isOneOf([
982
+ AST6.isOneOf([
925
983
  AST_NODE_TYPES.JSXExpressionContainer,
926
984
  AST_NODE_TYPES.ArrowFunctionExpression,
927
985
  AST_NODE_TYPES.FunctionExpression,
@@ -942,7 +1000,7 @@ function isComponentWrapperCallLoose(context, node) {
942
1000
 
943
1001
  // src/component/component-id.ts
944
1002
  function getFunctionComponentId(context, node) {
945
- const functionId = AST5.getFunctionIdentifier(node);
1003
+ const functionId = AST6.getFunctionIdentifier(node);
946
1004
  if (functionId != null) {
947
1005
  return functionId;
948
1006
  }
@@ -969,10 +1027,10 @@ var ComponentFlag = {
969
1027
  // src/component/component-init-path.ts
970
1028
  function getComponentFlagFromInitPath(initPath) {
971
1029
  let flag = ComponentFlag.None;
972
- if (initPath != null && AST5.hasCallInFunctionInitPath("memo", initPath)) {
1030
+ if (initPath != null && AST6.hasCallInFunctionInitPath("memo", initPath)) {
973
1031
  flag |= ComponentFlag.Memo;
974
1032
  }
975
- if (initPath != null && AST5.hasCallInFunctionInitPath("forwardRef", initPath)) {
1033
+ if (initPath != null && AST6.hasCallInFunctionInitPath("forwardRef", initPath)) {
976
1034
  flag |= ComponentFlag.ForwardRef;
977
1035
  }
978
1036
  return flag;
@@ -1003,7 +1061,6 @@ function useComponentCollector(context, options = {}) {
1003
1061
  collectHookCalls = false,
1004
1062
  hint = DEFAULT_COMPONENT_DETECTION_HINT
1005
1063
  } = options;
1006
- const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
1007
1064
  const components = /* @__PURE__ */ new Map();
1008
1065
  const functionEntries = [];
1009
1066
  const getCurrentEntry = () => functionEntries.at(-1);
@@ -1015,8 +1072,8 @@ function useComponentCollector(context, options = {}) {
1015
1072
  const entry = functionEntries.at(-1);
1016
1073
  if (entry == null) return;
1017
1074
  if (!entry.isComponent) return functionEntries.pop();
1018
- const shouldDrop = AST5.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
1019
- return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXLike(r.argument, jsxCtx, hint);
1075
+ const shouldDrop = AST6.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
1076
+ return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJsxLike(context.sourceCode, r.argument, hint);
1020
1077
  });
1021
1078
  if (shouldDrop) {
1022
1079
  components.delete(entry.key);
@@ -1040,9 +1097,9 @@ function useComponentCollector(context, options = {}) {
1040
1097
  const entry = getCurrentEntry();
1041
1098
  if (entry == null) return;
1042
1099
  const { body } = entry.node;
1043
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXLike(body, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
1100
+ const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
1044
1101
  if (!isComponent) return;
1045
- const initPath = AST5.getFunctionInitPath(entry.node);
1102
+ const initPath = AST6.getFunctionInitPath(entry.node);
1046
1103
  const id = getFunctionComponentId(context, entry.node);
1047
1104
  const name = getComponentNameFromId(id);
1048
1105
  const key = getId();
@@ -1080,10 +1137,10 @@ function useComponentCollector(context, options = {}) {
1080
1137
  "ReturnStatement[type]"(node) {
1081
1138
  const entry = getCurrentEntry();
1082
1139
  if (entry == null) return;
1083
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXLike(node.argument, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
1140
+ const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
1084
1141
  if (!isComponent) return;
1085
1142
  entry.isComponent = true;
1086
- const initPath = AST5.getFunctionInitPath(entry.node);
1143
+ const initPath = AST6.getFunctionInitPath(entry.node);
1087
1144
  const id = getFunctionComponentId(context, entry.node);
1088
1145
  const name = getComponentNameFromId(id);
1089
1146
  components.set(entry.key, {
@@ -1114,7 +1171,7 @@ function useComponentCollectorLegacy() {
1114
1171
  if (!isClassComponent(node)) {
1115
1172
  return;
1116
1173
  }
1117
- const id = AST5.getClassIdentifier(node);
1174
+ const id = AST6.getClassIdentifier(node);
1118
1175
  const key = getId();
1119
1176
  const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
1120
1177
  components.set(
@@ -1147,14 +1204,12 @@ var ComponentPhaseRelevance = birecord({
1147
1204
  var isInversePhase = dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
1148
1205
  function isRenderFunctionLoose(context, node) {
1149
1206
  const { body, parent } = node;
1150
- if (AST5.getFunctionIdentifier(node)?.name.startsWith("render")) {
1207
+ if (AST6.getFunctionIdentifier(node)?.name.startsWith("render")) {
1151
1208
  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");
1152
1209
  }
1153
- return JSX3.isJSXLike(
1210
+ return JSX3.isJsxLike(
1211
+ context.sourceCode,
1154
1212
  body,
1155
- {
1156
- getScope: (node2) => context.sourceCode.getScope(node2)
1157
- },
1158
1213
  JSX3.JSXDetectionHint.SkipNullLiteral | JSX3.JSXDetectionHint.SkipUndefined | JSX3.JSXDetectionHint.StrictLogical | JSX3.JSXDetectionHint.StrictConditional
1159
1214
  );
1160
1215
  }
@@ -1162,7 +1217,7 @@ function isRenderPropLoose(context, node) {
1162
1217
  if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
1163
1218
  return false;
1164
1219
  }
1165
- return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST5.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
1220
+ return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST6.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
1166
1221
  }
1167
1222
  function isDirectValueOfRenderPropertyLoose(node) {
1168
1223
  const matching = (node2) => {
@@ -1174,7 +1229,7 @@ function isDeclaredInRenderPropLoose(node) {
1174
1229
  if (isDirectValueOfRenderPropertyLoose(node)) {
1175
1230
  return true;
1176
1231
  }
1177
- const parent = AST5.findParentNode(node, AST5.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
1232
+ const parent = AST6.findParentNode(node, AST6.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
1178
1233
  if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
1179
1234
  return false;
1180
1235
  }
@@ -1182,22 +1237,11 @@ function isDeclaredInRenderPropLoose(node) {
1182
1237
  }
1183
1238
  function isThisSetState(node) {
1184
1239
  const { callee } = node;
1185
- return callee.type === AST_NODE_TYPES.MemberExpression && AST5.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
1240
+ return callee.type === AST_NODE_TYPES.MemberExpression && AST6.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
1186
1241
  }
1187
1242
  function isAssignmentToThisState(node) {
1188
1243
  const { left } = node;
1189
- return left.type === AST_NODE_TYPES.MemberExpression && AST5.isThisExpression(left.object) && AST5.getPropertyName(left.property) === "state";
1190
- }
1191
- function isFunctionOfUseEffectSetup(node) {
1192
- if (node == null) return false;
1193
- 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);
1194
- }
1195
- function isFunctionOfUseEffectCleanup(node) {
1196
- if (node == null) return false;
1197
- const returnStatement = AST5.findParentNode(node, AST5.is(AST_NODE_TYPES.ReturnStatement));
1198
- const enclosingFunction = AST5.findParentNode(node, AST5.isFunction);
1199
- const functionOfReturnStatement = AST5.findParentNode(returnStatement, AST5.isFunction);
1200
- return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
1244
+ return left.type === AST_NODE_TYPES.MemberExpression && AST6.isThisExpression(left.object) && AST6.getPropertyName(left.property) === "state";
1201
1245
  }
1202
1246
 
1203
- export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentNameLoose, isComponentWillUnmount, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
1247
+ export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRender, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.40.3",
3
+ "version": "1.40.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": {
@@ -41,12 +41,12 @@
41
41
  "@typescript-eslint/utils": "^8.29.0",
42
42
  "birecord": "^0.1.1",
43
43
  "ts-pattern": "^5.7.0",
44
- "@eslint-react/ast": "1.40.3",
45
- "@eslint-react/kit": "1.40.3",
46
- "@eslint-react/eff": "1.40.3",
47
- "@eslint-react/shared": "1.40.3",
48
- "@eslint-react/var": "1.40.3",
49
- "@eslint-react/jsx": "1.40.3"
44
+ "@eslint-react/ast": "1.40.4-beta.4",
45
+ "@eslint-react/eff": "1.40.4-beta.4",
46
+ "@eslint-react/kit": "1.40.4-beta.4",
47
+ "@eslint-react/var": "1.40.4-beta.4",
48
+ "@eslint-react/shared": "1.40.4-beta.4",
49
+ "@eslint-react/jsx": "1.40.4-beta.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "tsup": "^8.4.0",