@eslint-react/core 1.24.0-next.2 → 1.24.0-next.3

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
@@ -79,7 +79,11 @@ interface ERClassComponent extends ERSemanticNode {
79
79
  }
80
80
  type ERComponent = ERClassComponent | ERFunctionComponent;
81
81
 
82
- declare function useComponentCollector(context: RuleContext, hint?: bigint): {
82
+ interface ComponentCollectorOptions {
83
+ collectDisplayName?: boolean;
84
+ collectHookCalls?: boolean;
85
+ }
86
+ declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: ComponentCollectorOptions): {
83
87
  readonly ctx: {
84
88
  readonly getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
85
89
  readonly getCurrentEntries: () => {
@@ -96,6 +100,11 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
96
100
  } | undefined;
97
101
  };
98
102
  readonly listeners: {
103
+ readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
104
+ readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
105
+ readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
106
+ left: TSESTree.MemberExpression;
107
+ }) => void;
99
108
  readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
100
109
  readonly ":function[type]:exit": () => {
101
110
  key: string;
@@ -104,11 +113,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
104
113
  isComponent: boolean;
105
114
  } | undefined;
106
115
  readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
107
- readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.AssignmentExpression & {
108
- left: TSESTree.MemberExpression;
109
- }) => void;
110
- readonly "CallExpression[type]:exit": (node: TSESTree.CallExpression) => void;
111
- readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
112
116
  };
113
117
  };
114
118
 
@@ -2575,4 +2579,4 @@ declare const isMemoCall: {
2575
2579
  (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2576
2580
  };
2577
2581
 
2578
- export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2582
+ export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.d.ts CHANGED
@@ -79,7 +79,11 @@ interface ERClassComponent extends ERSemanticNode {
79
79
  }
80
80
  type ERComponent = ERClassComponent | ERFunctionComponent;
81
81
 
82
- declare function useComponentCollector(context: RuleContext, hint?: bigint): {
82
+ interface ComponentCollectorOptions {
83
+ collectDisplayName?: boolean;
84
+ collectHookCalls?: boolean;
85
+ }
86
+ declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: ComponentCollectorOptions): {
83
87
  readonly ctx: {
84
88
  readonly getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
85
89
  readonly getCurrentEntries: () => {
@@ -96,6 +100,11 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
96
100
  } | undefined;
97
101
  };
98
102
  readonly listeners: {
103
+ readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
104
+ readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
105
+ readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
106
+ left: TSESTree.MemberExpression;
107
+ }) => void;
99
108
  readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
100
109
  readonly ":function[type]:exit": () => {
101
110
  key: string;
@@ -104,11 +113,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
104
113
  isComponent: boolean;
105
114
  } | undefined;
106
115
  readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
107
- readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.AssignmentExpression & {
108
- left: TSESTree.MemberExpression;
109
- }) => void;
110
- readonly "CallExpression[type]:exit": (node: TSESTree.CallExpression) => void;
111
- readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
112
116
  };
113
117
  };
114
118
 
@@ -2575,4 +2579,4 @@ declare const isMemoCall: {
2575
2579
  (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2576
2580
  };
2577
2581
 
2578
- export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2582
+ export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -328,13 +328,7 @@ function useHookCollector() {
328
328
  if (hook == null) {
329
329
  return;
330
330
  }
331
- hooks.set(hook.key, {
332
- ...hook,
333
- hookCalls: [
334
- ...hook.hookCalls,
335
- node
336
- ]
337
- });
331
+ hook.hookCalls.push(node);
338
332
  }
339
333
  };
340
334
  return { ctx, listeners };
@@ -489,7 +483,9 @@ function getComponentFlag(initPath) {
489
483
  }
490
484
  return flag;
491
485
  }
492
- function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
486
+ var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
487
+ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
488
+ const { collectDisplayName = false, collectHookCalls = false } = options;
493
489
  const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
494
490
  const components = /* @__PURE__ */ new Map();
495
491
  const functionEntries = [];
@@ -552,29 +548,29 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
552
548
  initPath
553
549
  });
554
550
  },
555
- "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"(node) {
556
- const { left, right } = node;
557
- const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
558
- const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
559
- if (component == null) {
560
- return;
561
- }
562
- components.set(component.key, {
563
- ...component,
564
- displayName: right
565
- });
566
- },
567
- "CallExpression[type]:exit"(node) {
568
- if (!isReactHookCall(node)) {
569
- return;
551
+ ...collectDisplayName ? {
552
+ [displayNameAssignmentSelector](node) {
553
+ const { left, right } = node;
554
+ const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
555
+ const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
556
+ if (component == null) {
557
+ return;
558
+ }
559
+ component.displayName = right;
570
560
  }
571
- const entry = getCurrentEntry();
572
- if (entry == null) {
573
- return;
561
+ } : {},
562
+ ...collectHookCalls ? {
563
+ "CallExpression[type]:exit"(node) {
564
+ if (!isReactHookCall(node)) {
565
+ return;
566
+ }
567
+ const entry = getCurrentEntry();
568
+ if (entry == null) {
569
+ return;
570
+ }
571
+ entry.hookCalls.push(node);
574
572
  }
575
- functionEntries.pop();
576
- functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
577
- },
573
+ } : {},
578
574
  "ReturnStatement[type]"(node) {
579
575
  const entry = getCurrentEntry();
580
576
  if (entry == null) {
package/dist/index.mjs CHANGED
@@ -304,13 +304,7 @@ function useHookCollector() {
304
304
  if (hook == null) {
305
305
  return;
306
306
  }
307
- hooks.set(hook.key, {
308
- ...hook,
309
- hookCalls: [
310
- ...hook.hookCalls,
311
- node
312
- ]
313
- });
307
+ hook.hookCalls.push(node);
314
308
  }
315
309
  };
316
310
  return { ctx, listeners };
@@ -465,7 +459,9 @@ function getComponentFlag(initPath) {
465
459
  }
466
460
  return flag;
467
461
  }
468
- function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
462
+ var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
463
+ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
464
+ const { collectDisplayName = false, collectHookCalls = false } = options;
469
465
  const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
470
466
  const components = /* @__PURE__ */ new Map();
471
467
  const functionEntries = [];
@@ -528,29 +524,29 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
528
524
  initPath
529
525
  });
530
526
  },
531
- "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"(node) {
532
- const { left, right } = node;
533
- const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : _;
534
- const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
535
- if (component == null) {
536
- return;
537
- }
538
- components.set(component.key, {
539
- ...component,
540
- displayName: right
541
- });
542
- },
543
- "CallExpression[type]:exit"(node) {
544
- if (!isReactHookCall(node)) {
545
- return;
527
+ ...collectDisplayName ? {
528
+ [displayNameAssignmentSelector](node) {
529
+ const { left, right } = node;
530
+ const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : _;
531
+ const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
532
+ if (component == null) {
533
+ return;
534
+ }
535
+ component.displayName = right;
546
536
  }
547
- const entry = getCurrentEntry();
548
- if (entry == null) {
549
- return;
537
+ } : {},
538
+ ...collectHookCalls ? {
539
+ "CallExpression[type]:exit"(node) {
540
+ if (!isReactHookCall(node)) {
541
+ return;
542
+ }
543
+ const entry = getCurrentEntry();
544
+ if (entry == null) {
545
+ return;
546
+ }
547
+ entry.hookCalls.push(node);
550
548
  }
551
- functionEntries.pop();
552
- functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
553
- },
549
+ } : {},
554
550
  "ReturnStatement[type]"(node) {
555
551
  const entry = getCurrentEntry();
556
552
  if (entry == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.24.0-next.2",
3
+ "version": "1.24.0-next.3",
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": {
@@ -38,12 +38,12 @@
38
38
  "@typescript-eslint/types": "^8.19.1",
39
39
  "@typescript-eslint/utils": "^8.19.1",
40
40
  "ts-pattern": "^5.6.0",
41
- "@eslint-react/ast": "1.24.0-next.2",
42
- "@eslint-react/shared": "1.24.0-next.2",
43
- "@eslint-react/jsx": "1.24.0-next.2",
44
- "@eslint-react/types": "1.24.0-next.2",
45
- "@eslint-react/eff": "1.24.0-next.2",
46
- "@eslint-react/var": "1.24.0-next.2"
41
+ "@eslint-react/ast": "1.24.0-next.3",
42
+ "@eslint-react/jsx": "1.24.0-next.3",
43
+ "@eslint-react/shared": "1.24.0-next.3",
44
+ "@eslint-react/eff": "1.24.0-next.3",
45
+ "@eslint-react/types": "1.24.0-next.3",
46
+ "@eslint-react/var": "1.24.0-next.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.3.5",