@eslint-react/core 1.24.0-next.13 → 1.24.0-next.15

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
@@ -108,9 +108,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint, opti
108
108
  readonly listeners: {
109
109
  readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
110
110
  readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
111
- readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
112
- left: TSESTree.MemberExpression;
113
- }) => void;
114
111
  readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
115
112
  readonly ":function[type]:exit": () => {
116
113
  key: string;
@@ -136,6 +133,17 @@ declare function useComponentCollectorLegacy(): {
136
133
  };
137
134
  };
138
135
 
136
+ /**
137
+ * The ESQuery selector for a component display name assignment expression
138
+ */
139
+ declare const COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR: string;
140
+ /**
141
+ * Check if the node is a component display name assignment expression
142
+ * @param node The AST node
143
+ * @returns `true` if the node is a component display name assignment
144
+ */
145
+ declare function isComponentDisplayNameAssignment(node: TSESTree.Node | _): node is TSESTree.AssignmentExpression;
146
+
139
147
  declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, context: RuleContext): TSESTree.Identifier | TSESTree.Identifier[] | _;
140
148
 
141
149
  type ERComponentKind = "classComponent" | "functionComponent";
@@ -355,7 +363,7 @@ type IsCallFromReactMember = {
355
363
  };
356
364
  declare function isCallFromReactMember(pragmaMemberName: string, name: string): IsCallFromReactMember;
357
365
 
358
- declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
366
+ declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
359
367
 
360
368
  /**********************************************
361
369
  * DO NOT MODIFY THIS FILE MANUALLY *
@@ -2579,4 +2587,4 @@ declare const isMemoCall: {
2579
2587
  (node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
2580
2588
  };
2581
2589
 
2582
- export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2590
+ export { COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDisplayNameAssignment, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.d.ts CHANGED
@@ -108,9 +108,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint, opti
108
108
  readonly listeners: {
109
109
  readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
110
110
  readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
111
- readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
112
- left: TSESTree.MemberExpression;
113
- }) => void;
114
111
  readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
115
112
  readonly ":function[type]:exit": () => {
116
113
  key: string;
@@ -136,6 +133,17 @@ declare function useComponentCollectorLegacy(): {
136
133
  };
137
134
  };
138
135
 
136
+ /**
137
+ * The ESQuery selector for a component display name assignment expression
138
+ */
139
+ declare const COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR: string;
140
+ /**
141
+ * Check if the node is a component display name assignment expression
142
+ * @param node The AST node
143
+ * @returns `true` if the node is a component display name assignment
144
+ */
145
+ declare function isComponentDisplayNameAssignment(node: TSESTree.Node | _): node is TSESTree.AssignmentExpression;
146
+
139
147
  declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, context: RuleContext): TSESTree.Identifier | TSESTree.Identifier[] | _;
140
148
 
141
149
  type ERComponentKind = "classComponent" | "functionComponent";
@@ -355,7 +363,7 @@ type IsCallFromReactMember = {
355
363
  };
356
364
  declare function isCallFromReactMember(pragmaMemberName: string, name: string): IsCallFromReactMember;
357
365
 
358
- declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
366
+ declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
359
367
 
360
368
  /**********************************************
361
369
  * DO NOT MODIFY THIS FILE MANUALLY *
@@ -2579,4 +2587,4 @@ declare const isMemoCall: {
2579
2587
  (node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
2580
2588
  };
2581
2589
 
2582
- export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2590
+ export { COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDisplayNameAssignment, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
34
34
  var birecord__default = /*#__PURE__*/_interopDefault(birecord);
35
35
 
36
36
  // src/component/component-collector.ts
37
- function isInitializedFromReact(name, initialScope, importSource = "react") {
37
+ function isInitializedFromReact(name, importSource, initialScope) {
38
38
  return name.toLowerCase() === "react" || VAR__namespace.isInitializedFromSource(
39
39
  name,
40
40
  importSource,
@@ -52,12 +52,13 @@ function isFromReact(name) {
52
52
  }
53
53
  return node.name === name;
54
54
  }
55
+ const importSource = settings.importSource ?? shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
55
56
  const initialScope = context.sourceCode.getScope(node);
56
57
  if (node.type === types.AST_NODE_TYPES.MemberExpression) {
57
- return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, initialScope, settings.importSource);
58
+ return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
58
59
  }
59
60
  if (node.name === name) {
60
- return isInitializedFromReact(name, initialScope, settings.importSource);
61
+ return isInitializedFromReact(name, importSource, initialScope);
61
62
  }
62
63
  return false;
63
64
  };
@@ -77,14 +78,15 @@ function isFromReactMember(memberName, name) {
77
78
  }
78
79
  return false;
79
80
  }
81
+ const importSource = settings.importSource ?? shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
80
82
  const initialScope = context.sourceCode.getScope(node);
81
83
  if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) {
82
84
  return false;
83
85
  }
84
86
  if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
85
- return isInitializedFromReact(node.object.name, initialScope, settings.importSource);
87
+ return isInitializedFromReact(node.object.name, importSource, initialScope);
86
88
  }
87
- if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, initialScope, settings.importSource) && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
89
+ if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, importSource, initialScope) && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
88
90
  return node.object.property.name === memberName;
89
91
  }
90
92
  return false;
@@ -186,13 +188,14 @@ function isReactHookCall(node) {
186
188
  function isReactHookCallWithName(node, context) {
187
189
  if (node == null) return eff.returnFalse;
188
190
  const settings = shared.unsafeDecodeSettings(context.settings);
191
+ const importSource = settings.importSource ?? "react";
192
+ const initialScope = context.sourceCode.getScope(node);
189
193
  return (name) => {
190
- const initialScope = context.sourceCode.getScope(node);
191
194
  switch (true) {
192
195
  case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === name):
193
- return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
196
+ return !settings.strictImportCheck || isInitializedFromReact(name, importSource, initialScope);
194
197
  case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
195
- return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
198
+ return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
196
199
  default:
197
200
  return false;
198
201
  }
@@ -213,13 +216,14 @@ function isReactHookCallWithNameLoose(node) {
213
216
  }
214
217
  function isReactHookCallWithNameAlias(name, context, alias) {
215
218
  const settings = shared.unsafeDecodeSettings(context);
219
+ const importSource = settings.importSource ?? "react";
216
220
  return (node) => {
217
221
  const initialScope = context.sourceCode.getScope(node);
218
222
  switch (true) {
219
223
  case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === name):
220
- return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
224
+ return !settings.strictImportCheck || isInitializedFromReact(name, importSource, initialScope);
221
225
  case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
222
- return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
226
+ return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
223
227
  default:
224
228
  return alias.some(isReactHookCallWithNameLoose(node));
225
229
  }
@@ -331,6 +335,17 @@ var ERComponentHint = {
331
335
  SkipClassProperty: 1n << 69n
332
336
  };
333
337
  var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipMapCallback | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefined | ERComponentHint.SkipEmptyArray | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
338
+ var COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
339
+ "AssignmentExpression",
340
+ "[type]",
341
+ "[operator='=']",
342
+ "[left.type='MemberExpression']",
343
+ "[left.property.name='displayName']"
344
+ ].join("");
345
+ function isComponentDisplayNameAssignment(node) {
346
+ if (node == null) return false;
347
+ return node.type === types.AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === types.AST_NODE_TYPES.MemberExpression && node.left.property.type === types.AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
348
+ }
334
349
 
335
350
  // src/component/component-flag.ts
336
351
  var ERClassComponentFlag = {
@@ -483,7 +498,6 @@ function getComponentFlag(initPath) {
483
498
  }
484
499
  return flag;
485
500
  }
486
- var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
487
501
  function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
488
502
  const { collectDisplayName = false, collectHookCalls = false } = options;
489
503
  const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
@@ -549,8 +563,9 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
549
563
  });
550
564
  },
551
565
  ...collectDisplayName ? {
552
- [displayNameAssignmentSelector](node) {
566
+ [COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR](node) {
553
567
  const { left, right } = node;
568
+ if (left.type !== types.AST_NODE_TYPES.MemberExpression) return;
554
569
  const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
555
570
  const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
556
571
  if (component == null) {
@@ -694,6 +709,7 @@ function isFunctionOfUseEffectCleanup(node) {
694
709
  return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
695
710
  }
696
711
 
712
+ exports.COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR = COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR;
697
713
  exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
698
714
  exports.ERClassComponentFlag = ERClassComponentFlag;
699
715
  exports.ERComponentHint = ERComponentHint;
@@ -722,6 +738,7 @@ exports.isCloneElement = isCloneElement;
722
738
  exports.isCloneElementCall = isCloneElementCall;
723
739
  exports.isComponentDidCatch = isComponentDidCatch;
724
740
  exports.isComponentDidMount = isComponentDidMount;
741
+ exports.isComponentDisplayNameAssignment = isComponentDisplayNameAssignment;
725
742
  exports.isComponentName = isComponentName;
726
743
  exports.isComponentWillUnmount = isComponentWillUnmount;
727
744
  exports.isCreateContext = isCreateContext;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as AST8 from '@eslint-react/ast';
2
2
  import { flip, dual, _, returnFalse } from '@eslint-react/eff';
3
3
  import * as JSX3 from '@eslint-react/jsx';
4
- import { unsafeDecodeSettings, getId } from '@eslint-react/shared';
4
+ import { unsafeDecodeSettings, DEFAULT_ESLINT_REACT_SETTINGS, getId } from '@eslint-react/shared';
5
5
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
6
6
  import * as VAR from '@eslint-react/var';
7
7
  import birecord from 'birecord';
8
8
 
9
9
  // src/component/component-collector.ts
10
- function isInitializedFromReact(name, initialScope, importSource = "react") {
10
+ function isInitializedFromReact(name, importSource, initialScope) {
11
11
  return name.toLowerCase() === "react" || VAR.isInitializedFromSource(
12
12
  name,
13
13
  importSource,
@@ -25,12 +25,13 @@ function isFromReact(name) {
25
25
  }
26
26
  return node.name === name;
27
27
  }
28
+ const importSource = settings.importSource ?? DEFAULT_ESLINT_REACT_SETTINGS.importSource;
28
29
  const initialScope = context.sourceCode.getScope(node);
29
30
  if (node.type === AST_NODE_TYPES.MemberExpression) {
30
- return node.object.type === AST_NODE_TYPES.Identifier && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, initialScope, settings.importSource);
31
+ return node.object.type === AST_NODE_TYPES.Identifier && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
31
32
  }
32
33
  if (node.name === name) {
33
- return isInitializedFromReact(name, initialScope, settings.importSource);
34
+ return isInitializedFromReact(name, importSource, initialScope);
34
35
  }
35
36
  return false;
36
37
  };
@@ -50,14 +51,15 @@ function isFromReactMember(memberName, name) {
50
51
  }
51
52
  return false;
52
53
  }
54
+ const importSource = settings.importSource ?? DEFAULT_ESLINT_REACT_SETTINGS.importSource;
53
55
  const initialScope = context.sourceCode.getScope(node);
54
56
  if (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== name) {
55
57
  return false;
56
58
  }
57
59
  if (node.object.type === AST_NODE_TYPES.Identifier && node.object.name === memberName) {
58
- return isInitializedFromReact(node.object.name, initialScope, settings.importSource);
60
+ return isInitializedFromReact(node.object.name, importSource, initialScope);
59
61
  }
60
- if (node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, initialScope, settings.importSource) && node.object.property.type === AST_NODE_TYPES.Identifier) {
62
+ if (node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, importSource, initialScope) && node.object.property.type === AST_NODE_TYPES.Identifier) {
61
63
  return node.object.property.name === memberName;
62
64
  }
63
65
  return false;
@@ -159,13 +161,14 @@ function isReactHookCall(node) {
159
161
  function isReactHookCallWithName(node, context) {
160
162
  if (node == null) return returnFalse;
161
163
  const settings = unsafeDecodeSettings(context.settings);
164
+ const importSource = settings.importSource ?? "react";
165
+ const initialScope = context.sourceCode.getScope(node);
162
166
  return (name) => {
163
- const initialScope = context.sourceCode.getScope(node);
164
167
  switch (true) {
165
168
  case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === name):
166
- return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
169
+ return !settings.strictImportCheck || isInitializedFromReact(name, importSource, initialScope);
167
170
  case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
168
- return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
171
+ return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
169
172
  default:
170
173
  return false;
171
174
  }
@@ -186,13 +189,14 @@ function isReactHookCallWithNameLoose(node) {
186
189
  }
187
190
  function isReactHookCallWithNameAlias(name, context, alias) {
188
191
  const settings = unsafeDecodeSettings(context);
192
+ const importSource = settings.importSource ?? "react";
189
193
  return (node) => {
190
194
  const initialScope = context.sourceCode.getScope(node);
191
195
  switch (true) {
192
196
  case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === name):
193
- return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
197
+ return !settings.strictImportCheck || isInitializedFromReact(name, importSource, initialScope);
194
198
  case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
195
- return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
199
+ return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
196
200
  default:
197
201
  return alias.some(isReactHookCallWithNameLoose(node));
198
202
  }
@@ -304,6 +308,17 @@ var ERComponentHint = {
304
308
  SkipClassProperty: 1n << 69n
305
309
  };
306
310
  var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipMapCallback | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefined | ERComponentHint.SkipEmptyArray | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
311
+ var COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
312
+ "AssignmentExpression",
313
+ "[type]",
314
+ "[operator='=']",
315
+ "[left.type='MemberExpression']",
316
+ "[left.property.name='displayName']"
317
+ ].join("");
318
+ function isComponentDisplayNameAssignment(node) {
319
+ if (node == null) return false;
320
+ return node.type === AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === AST_NODE_TYPES.MemberExpression && node.left.property.type === AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
321
+ }
307
322
 
308
323
  // src/component/component-flag.ts
309
324
  var ERClassComponentFlag = {
@@ -456,7 +471,6 @@ function getComponentFlag(initPath) {
456
471
  }
457
472
  return flag;
458
473
  }
459
- var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
460
474
  function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
461
475
  const { collectDisplayName = false, collectHookCalls = false } = options;
462
476
  const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
@@ -522,8 +536,9 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
522
536
  });
523
537
  },
524
538
  ...collectDisplayName ? {
525
- [displayNameAssignmentSelector](node) {
539
+ [COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR](node) {
526
540
  const { left, right } = node;
541
+ if (left.type !== AST_NODE_TYPES.MemberExpression) return;
527
542
  const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : _;
528
543
  const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
529
544
  if (component == null) {
@@ -667,4 +682,4 @@ function isFunctionOfUseEffectCleanup(node) {
667
682
  return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
668
683
  }
669
684
 
670
- export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
685
+ export { COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR, DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDisplayNameAssignment, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.24.0-next.13",
3
+ "version": "1.24.0-next.15",
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": {
@@ -39,11 +39,11 @@
39
39
  "@typescript-eslint/utils": "^8.20.0",
40
40
  "birecord": "^0.1.1",
41
41
  "ts-pattern": "^5.6.0",
42
- "@eslint-react/ast": "1.24.0-next.13",
43
- "@eslint-react/jsx": "1.24.0-next.13",
44
- "@eslint-react/shared": "1.24.0-next.13",
45
- "@eslint-react/var": "1.24.0-next.13",
46
- "@eslint-react/eff": "1.24.0-next.13"
42
+ "@eslint-react/ast": "1.24.0-next.15",
43
+ "@eslint-react/eff": "1.24.0-next.15",
44
+ "@eslint-react/shared": "1.24.0-next.15",
45
+ "@eslint-react/jsx": "1.24.0-next.15",
46
+ "@eslint-react/var": "1.24.0-next.15"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.3.5",