@eslint-react/core 1.27.1-beta.5 → 1.27.1-beta.8

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
@@ -100,14 +100,6 @@ type FunctionEntry = {
100
100
  hookCalls: TSESTree.CallExpression[];
101
101
  isComponent: boolean;
102
102
  };
103
- /**
104
- * Get a ctx and listeners for the rule to collect function components
105
- * @param context The ESLint rule context
106
- * @param hint The hint to use
107
- * @param options The options to use
108
- * @returns The component collector
109
- */
110
- declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: useComponentCollector.Options): useComponentCollector.ReturnType;
111
103
  declare namespace useComponentCollector {
112
104
  type Options = {
113
105
  collectDisplayName?: boolean;
@@ -122,12 +114,15 @@ declare namespace useComponentCollector {
122
114
  listeners: ESLintUtils.RuleListener;
123
115
  };
124
116
  }
125
-
126
117
  /**
127
- * Get a ctx and listeners for the rule to collect class components
128
- * @returns The context and listeners for the rule
118
+ * Get a ctx and listeners for the rule to collect function components
119
+ * @param context The ESLint rule context
120
+ * @param hint The hint to use
121
+ * @param options The options to use
122
+ * @returns The component collector
129
123
  */
130
- declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
124
+ declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: useComponentCollector.Options): useComponentCollector.ReturnType;
125
+
131
126
  declare namespace useComponentCollectorLegacy {
132
127
  type ReturnType = {
133
128
  ctx: {
@@ -136,6 +131,11 @@ declare namespace useComponentCollectorLegacy {
136
131
  listeners: ESLintUtils.RuleListener;
137
132
  };
138
133
  }
134
+ /**
135
+ * Get a ctx and listeners for the rule to collect class components
136
+ * @returns The context and listeners for the rule
137
+ */
138
+ declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
139
139
 
140
140
  declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, context: RuleContext): TSESTree.Identifier | TSESTree.Identifier[] | _;
141
141
 
@@ -279,7 +279,6 @@ interface ERHook extends ERSemanticNode {
279
279
  hookCalls: TSESTree.CallExpression[];
280
280
  }
281
281
 
282
- declare function useHookCollector(): useHookCollector.ReturnType;
283
282
  declare namespace useHookCollector {
284
283
  type ReturnType = {
285
284
  ctx: {
@@ -288,6 +287,7 @@ declare namespace useHookCollector {
288
287
  listeners: ESLintUtils.RuleListener;
289
288
  };
290
289
  }
290
+ declare function useHookCollector(): useHookCollector.ReturnType;
291
291
 
292
292
  type ERHookKind = "custom" | "useActionState" | "useCallback" | "useContext" | "useDebugValue" | "useDeferredValue" | "useEffect" | "useId" | "useImperativeHandle" | "useInsertionEffect" | "useLayoutEffect" | "useMemo" | "useOptimistic" | "useReducer" | "useRef" | "useState" | "useSyncExternalStore" | "useTransition";
293
293
 
@@ -350,14 +350,13 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
350
350
  * @returns A function that checks if a given node is a member expression of a Pragma member.
351
351
  */
352
352
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
353
- declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
354
353
  declare namespace isCallFromReact {
355
354
  type ReturnType = {
356
355
  (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
357
356
  (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
358
357
  };
359
358
  }
360
- declare function isCallFromReactMember(pragmaMemberName: string, name: string): isCallFromReactMember.ReturnType;
359
+ declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
361
360
  declare namespace isCallFromReactMember {
362
361
  type ReturnType = {
363
362
  (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
@@ -368,8 +367,16 @@ declare namespace isCallFromReactMember {
368
367
  };
369
368
  };
370
369
  }
370
+ declare function isCallFromReactMember(pragmaMemberName: string, name: string): isCallFromReactMember.ReturnType;
371
371
 
372
- declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
372
+ /**
373
+ * Check if an identifier is initialized from react
374
+ * @param name The top-level identifier's name
375
+ * @param source The import source to check against
376
+ * @param initialScope Initial scope to search for the identifier
377
+ * @returns Whether the identifier is initialized from react
378
+ */
379
+ declare function isInitializedFromReact(name: string, source: string, initialScope: Scope): boolean;
373
380
 
374
381
  /**********************************************
375
382
  * DO NOT MODIFY THIS FILE MANUALLY *
@@ -1860,7 +1867,7 @@ declare interface TSImportEqualsRequireDeclaration extends TSImportEqualsDeclara
1860
1867
  declare interface TSImportType extends BaseNode {
1861
1868
  type: AST_NODE_TYPES.TSImportType;
1862
1869
  argument: TypeNode;
1863
- attributes: ImportAttribute[];
1870
+ options: ObjectExpression | null;
1864
1871
  qualifier: EntityName | null;
1865
1872
  typeArguments: TSTypeParameterInstantiation | null;
1866
1873
  }
package/dist/index.d.ts CHANGED
@@ -100,14 +100,6 @@ type FunctionEntry = {
100
100
  hookCalls: TSESTree.CallExpression[];
101
101
  isComponent: boolean;
102
102
  };
103
- /**
104
- * Get a ctx and listeners for the rule to collect function components
105
- * @param context The ESLint rule context
106
- * @param hint The hint to use
107
- * @param options The options to use
108
- * @returns The component collector
109
- */
110
- declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: useComponentCollector.Options): useComponentCollector.ReturnType;
111
103
  declare namespace useComponentCollector {
112
104
  type Options = {
113
105
  collectDisplayName?: boolean;
@@ -122,12 +114,15 @@ declare namespace useComponentCollector {
122
114
  listeners: ESLintUtils.RuleListener;
123
115
  };
124
116
  }
125
-
126
117
  /**
127
- * Get a ctx and listeners for the rule to collect class components
128
- * @returns The context and listeners for the rule
118
+ * Get a ctx and listeners for the rule to collect function components
119
+ * @param context The ESLint rule context
120
+ * @param hint The hint to use
121
+ * @param options The options to use
122
+ * @returns The component collector
129
123
  */
130
- declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
124
+ declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: useComponentCollector.Options): useComponentCollector.ReturnType;
125
+
131
126
  declare namespace useComponentCollectorLegacy {
132
127
  type ReturnType = {
133
128
  ctx: {
@@ -136,6 +131,11 @@ declare namespace useComponentCollectorLegacy {
136
131
  listeners: ESLintUtils.RuleListener;
137
132
  };
138
133
  }
134
+ /**
135
+ * Get a ctx and listeners for the rule to collect class components
136
+ * @returns The context and listeners for the rule
137
+ */
138
+ declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
139
139
 
140
140
  declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, context: RuleContext): TSESTree.Identifier | TSESTree.Identifier[] | _;
141
141
 
@@ -279,7 +279,6 @@ interface ERHook extends ERSemanticNode {
279
279
  hookCalls: TSESTree.CallExpression[];
280
280
  }
281
281
 
282
- declare function useHookCollector(): useHookCollector.ReturnType;
283
282
  declare namespace useHookCollector {
284
283
  type ReturnType = {
285
284
  ctx: {
@@ -288,6 +287,7 @@ declare namespace useHookCollector {
288
287
  listeners: ESLintUtils.RuleListener;
289
288
  };
290
289
  }
290
+ declare function useHookCollector(): useHookCollector.ReturnType;
291
291
 
292
292
  type ERHookKind = "custom" | "useActionState" | "useCallback" | "useContext" | "useDebugValue" | "useDeferredValue" | "useEffect" | "useId" | "useImperativeHandle" | "useInsertionEffect" | "useLayoutEffect" | "useMemo" | "useOptimistic" | "useReducer" | "useRef" | "useState" | "useSyncExternalStore" | "useTransition";
293
293
 
@@ -350,14 +350,13 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
350
350
  * @returns A function that checks if a given node is a member expression of a Pragma member.
351
351
  */
352
352
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
353
- declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
354
353
  declare namespace isCallFromReact {
355
354
  type ReturnType = {
356
355
  (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
357
356
  (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
358
357
  };
359
358
  }
360
- declare function isCallFromReactMember(pragmaMemberName: string, name: string): isCallFromReactMember.ReturnType;
359
+ declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
361
360
  declare namespace isCallFromReactMember {
362
361
  type ReturnType = {
363
362
  (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
@@ -368,8 +367,16 @@ declare namespace isCallFromReactMember {
368
367
  };
369
368
  };
370
369
  }
370
+ declare function isCallFromReactMember(pragmaMemberName: string, name: string): isCallFromReactMember.ReturnType;
371
371
 
372
- declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
372
+ /**
373
+ * Check if an identifier is initialized from react
374
+ * @param name The top-level identifier's name
375
+ * @param source The import source to check against
376
+ * @param initialScope Initial scope to search for the identifier
377
+ * @returns Whether the identifier is initialized from react
378
+ */
379
+ declare function isInitializedFromReact(name: string, source: string, initialScope: Scope): boolean;
373
380
 
374
381
  /**********************************************
375
382
  * DO NOT MODIFY THIS FILE MANUALLY *
@@ -1860,7 +1867,7 @@ declare interface TSImportEqualsRequireDeclaration extends TSImportEqualsDeclara
1860
1867
  declare interface TSImportType extends BaseNode {
1861
1868
  type: AST_NODE_TYPES.TSImportType;
1862
1869
  argument: TypeNode;
1863
- attributes: ImportAttribute[];
1870
+ options: ObjectExpression | null;
1864
1871
  qualifier: EntityName | null;
1865
1872
  typeArguments: TSTypeParameterInstantiation | null;
1866
1873
  }
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var AST8 = require('@eslint-react/ast');
3
+ var AST9 = 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');
7
7
  var types = require('@typescript-eslint/types');
8
8
  var VAR = require('@eslint-react/var');
9
+ var tsPattern = require('ts-pattern');
9
10
  var birecord = require('birecord');
10
11
 
11
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -28,7 +29,7 @@ function _interopNamespace(e) {
28
29
  return Object.freeze(n);
29
30
  }
30
31
 
31
- var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
32
+ var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
32
33
  var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
33
34
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
34
35
  var birecord__default = /*#__PURE__*/_interopDefault(birecord);
@@ -45,12 +46,30 @@ function isDisplayNameAssignment(node) {
45
46
  if (node == null) return false;
46
47
  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";
47
48
  }
48
- function isInitializedFromReact(name, importSource, initialScope) {
49
- return name.toLowerCase() === "react" || VAR__namespace.isInitializedFromSource(
50
- name,
51
- importSource,
52
- initialScope
53
- );
49
+ function getRequireExpressionArguments(node) {
50
+ return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.CallExpression, arguments: tsPattern.P.select(), callee: { type: types.AST_NODE_TYPES.Identifier, name: "require" } }, eff.identity).with({ type: types.AST_NODE_TYPES.MemberExpression, object: tsPattern.P.select() }, getRequireExpressionArguments).otherwise(() => eff._);
51
+ }
52
+ function isInitializedFromReact(name, source, initialScope) {
53
+ if (name.toLowerCase() === "react") return true;
54
+ const latestDef = VAR__namespace.findVariable(name, initialScope)?.defs.at(-1);
55
+ if (latestDef == null) return false;
56
+ const { node, parent } = latestDef;
57
+ if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
58
+ const { init } = node;
59
+ if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
60
+ return isInitializedFromReact(init.object.name, source, initialScope);
61
+ }
62
+ if (init.type === types.AST_NODE_TYPES.Identifier) {
63
+ return isInitializedFromReact(init.name, source, initialScope);
64
+ }
65
+ const args = getRequireExpressionArguments(init);
66
+ const arg0 = args?.[0];
67
+ if (arg0 == null || !AST9__namespace.isStringLiteral(arg0)) {
68
+ return false;
69
+ }
70
+ return arg0.value === source || arg0.value.startsWith(`${source}/`);
71
+ }
72
+ return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
54
73
  }
55
74
 
56
75
  // src/utils/is-from-react.ts
@@ -78,12 +97,8 @@ function isFromReactMember(memberName, name) {
78
97
  return (node, context) => {
79
98
  const settings = shared.unsafeDecodeSettings(context.settings);
80
99
  if (!settings.strictImportCheck) {
81
- if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) {
82
- return false;
83
- }
84
- if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
85
- return true;
86
- }
100
+ if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) return false;
101
+ if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) return true;
87
102
  if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
88
103
  return node.object.property.name === memberName;
89
104
  }
@@ -105,23 +120,15 @@ function isFromReactMember(memberName, name) {
105
120
  }
106
121
  function isCallFromReact(name) {
107
122
  return eff.dual(2, (node, context) => {
108
- if (node.type !== types.AST_NODE_TYPES.CallExpression) {
109
- return false;
110
- }
111
- if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) {
112
- return false;
113
- }
123
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
124
+ if (!AST9__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
114
125
  return isFromReact(name)(node.callee, context);
115
126
  });
116
127
  }
117
128
  function isCallFromReactMember(pragmaMemberName, name) {
118
129
  return eff.dual(2, (node, context) => {
119
- if (node.type !== types.AST_NODE_TYPES.CallExpression) {
120
- return false;
121
- }
122
- if (!AST8__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) {
123
- return false;
124
- }
130
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
131
+ if (!AST9__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
125
132
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
126
133
  });
127
134
  }
@@ -158,9 +165,9 @@ var isMemoCall = isReactAPICallWithName("memo");
158
165
 
159
166
  // src/element/hierarchy.ts
160
167
  function isInsideCreateElementProps(node, context) {
161
- const call = AST8__namespace.findParentNode(node, isCreateElementCall(context));
168
+ const call = AST9__namespace.findParentNode(node, isCreateElementCall(context));
162
169
  if (call == null) return false;
163
- const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
170
+ const prop = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
164
171
  if (prop == null) return false;
165
172
  return prop === call.arguments[1];
166
173
  }
@@ -180,7 +187,7 @@ function isReactHookName(name) {
180
187
  // src/hook/is.ts
181
188
  function isReactHook(node) {
182
189
  if (node == null) return eff._;
183
- const id = AST8__namespace.getFunctionIdentifier(node);
190
+ const id = AST9__namespace.getFunctionIdentifier(node);
184
191
  return id?.name != null && isReactHookName(id.name);
185
192
  }
186
193
  function isReactHookCall(node) {
@@ -272,13 +279,13 @@ var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
272
279
 
273
280
  // src/hook/hierarchy.ts
274
281
  function isInsideReactHook(node) {
275
- return isReactHook(AST8__namespace.findParentNode(node, AST8__namespace.isFunction));
282
+ return isReactHook(AST9__namespace.findParentNode(node, AST9__namespace.isFunction));
276
283
  }
277
284
  function useHookCollector() {
278
285
  const hooks = /* @__PURE__ */ new Map();
279
286
  const functionEntries = [];
280
287
  const onFunctionEnter = (node) => {
281
- const id = AST8__namespace.getFunctionIdentifier(node);
288
+ const id = AST9__namespace.getFunctionIdentifier(node);
282
289
  const key = shared.getId();
283
290
  const name = id?.name;
284
291
  if (name != null && isReactHookName(name)) {
@@ -374,7 +381,7 @@ function isComponentWrapperCall(node, context) {
374
381
  return isMemoCall(node, context) || isForwardRefCall(node, context) || isReactHookCallWithNameLoose(node)("useCallback");
375
382
  }
376
383
  function getFunctionComponentIdentifier(node, context) {
377
- const functionId = AST8__namespace.getFunctionIdentifier(node);
384
+ const functionId = AST9__namespace.getFunctionIdentifier(node);
378
385
  if (functionId != null) {
379
386
  return functionId;
380
387
  }
@@ -414,28 +421,28 @@ function isPureComponent(node) {
414
421
 
415
422
  // src/component/component-lifecycle.ts
416
423
  function isComponentDidMount(node) {
417
- return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
424
+ return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
418
425
  }
419
426
  function isComponentWillUnmount(node) {
420
- return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
427
+ return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
421
428
  }
422
429
  function isComponentDidCatch(node) {
423
- return AST8__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
430
+ return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
424
431
  }
425
432
  function isGetDerivedStateFromError(node) {
426
- return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
433
+ return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
427
434
  }
428
435
  function isGetDerivedStateFromProps(node) {
429
- return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
436
+ return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
430
437
  }
431
438
  function isFunctionOfComponentDidMount(node) {
432
- return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
439
+ return AST9__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
433
440
  }
434
441
  function isFunctionOfComponentWillUnmount(node) {
435
- return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
442
+ return AST9__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
436
443
  }
437
444
  function isRenderMethodLike(node) {
438
- return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
445
+ return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
439
446
  }
440
447
  function isFunctionOfRenderMethod(node) {
441
448
  if (!isRenderMethodLike(node.parent)) {
@@ -444,7 +451,7 @@ function isFunctionOfRenderMethod(node) {
444
451
  return isClassComponent(node.parent.parent.parent);
445
452
  }
446
453
  function isInsideRenderMethod(node) {
447
- return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
454
+ return AST9__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
448
455
  }
449
456
  var RE_COMPONENT_NAME = /^_?[A-Z]/u;
450
457
  function getComponentNameFromIdentifier(node) {
@@ -476,7 +483,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
476
483
  const entry = functionEntries.at(-1);
477
484
  if (entry == null) return;
478
485
  if (!entry.isComponent) return functionEntries.pop();
479
- const shouldDrop = AST8__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
486
+ const shouldDrop = AST9__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
480
487
  return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
481
488
  });
482
489
  if (shouldDrop) {
@@ -503,7 +510,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
503
510
  const { body } = entry.node;
504
511
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
505
512
  if (!isComponent) return;
506
- const initPath = AST8__namespace.getFunctionInitPath(entry.node);
513
+ const initPath = AST9__namespace.getFunctionInitPath(entry.node);
507
514
  const id = getFunctionComponentIdentifier(entry.node, context);
508
515
  const name = getComponentNameFromIdentifier(id);
509
516
  const key = shared.getId();
@@ -544,7 +551,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
544
551
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
545
552
  if (!isComponent) return;
546
553
  entry.isComponent = true;
547
- const initPath = AST8__namespace.getFunctionInitPath(entry.node);
554
+ const initPath = AST9__namespace.getFunctionInitPath(entry.node);
548
555
  const id = getFunctionComponentIdentifier(entry.node, context);
549
556
  const name = getComponentNameFromIdentifier(id);
550
557
  components.set(entry.key, {
@@ -567,21 +574,21 @@ function hasValidHierarchy(node, context, hint) {
567
574
  if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) {
568
575
  return false;
569
576
  }
570
- if (hint & ERComponentHint.SkipMapCallback && AST8__namespace.isMapCallLoose(node.parent)) {
577
+ if (hint & ERComponentHint.SkipMapCallback && AST9__namespace.isMapCallLoose(node.parent)) {
571
578
  return false;
572
579
  }
573
- if (hint & ERComponentHint.SkipObjectMethod && AST8__namespace.isFunctionOfObjectMethod(node.parent)) {
580
+ if (hint & ERComponentHint.SkipObjectMethod && AST9__namespace.isFunctionOfObjectMethod(node.parent)) {
574
581
  return false;
575
582
  }
576
- if (hint & ERComponentHint.SkipClassMethod && AST8__namespace.isFunctionOfClassMethod(node.parent)) {
583
+ if (hint & ERComponentHint.SkipClassMethod && AST9__namespace.isFunctionOfClassMethod(node.parent)) {
577
584
  return false;
578
585
  }
579
- if (hint & ERComponentHint.SkipClassProperty && AST8__namespace.isFunctionOfClassProperty(node.parent)) {
586
+ if (hint & ERComponentHint.SkipClassProperty && AST9__namespace.isFunctionOfClassProperty(node.parent)) {
580
587
  return false;
581
588
  }
582
- const boundaryNode = AST8__namespace.findParentNode(
589
+ const boundaryNode = AST9__namespace.findParentNode(
583
590
  node,
584
- AST8__namespace.isOneOf([
591
+ AST9__namespace.isOneOf([
585
592
  types.AST_NODE_TYPES.JSXExpressionContainer,
586
593
  types.AST_NODE_TYPES.ArrowFunctionExpression,
587
594
  types.AST_NODE_TYPES.FunctionExpression,
@@ -593,10 +600,10 @@ function hasValidHierarchy(node, context, hint) {
593
600
  }
594
601
  function getComponentFlag(initPath) {
595
602
  let flag = ERComponentFlag.None;
596
- if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo", initPath)) {
603
+ if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("memo", initPath)) {
597
604
  flag |= ERComponentFlag.Memo;
598
605
  }
599
- if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
606
+ if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
600
607
  flag |= ERComponentFlag.ForwardRef;
601
608
  }
602
609
  return flag;
@@ -613,7 +620,7 @@ function useComponentCollectorLegacy() {
613
620
  if (!isClassComponent(node)) {
614
621
  return;
615
622
  }
616
- const id = AST8__namespace.getClassIdentifier(node);
623
+ const id = AST9__namespace.getClassIdentifier(node);
617
624
  const key = shared.getId();
618
625
  const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
619
626
  components.set(
@@ -646,7 +653,7 @@ var ERPhaseRelevance = birecord__default.default({
646
653
  var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
647
654
  function isRenderFunctionLoose(node, context) {
648
655
  const { body, parent } = node;
649
- if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
656
+ if (AST9__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
650
657
  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");
651
658
  }
652
659
  return JSX3__namespace.isJSXValue(
@@ -661,7 +668,7 @@ function isRenderPropLoose(node, context) {
661
668
  if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
662
669
  return false;
663
670
  }
664
- return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
671
+ return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST9__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
665
672
  }
666
673
  function isDirectValueOfRenderPropertyLoose(node) {
667
674
  const matching = (node2) => {
@@ -673,7 +680,7 @@ function isDeclaredInRenderPropLoose(node) {
673
680
  if (isDirectValueOfRenderPropertyLoose(node)) {
674
681
  return true;
675
682
  }
676
- const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
683
+ const parent = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
677
684
  if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
678
685
  return false;
679
686
  }
@@ -681,16 +688,16 @@ function isDeclaredInRenderPropLoose(node) {
681
688
  }
682
689
  function isThisSetState(node) {
683
690
  const { callee } = node;
684
- return callee.type === types.AST_NODE_TYPES.MemberExpression && AST8__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
691
+ return callee.type === types.AST_NODE_TYPES.MemberExpression && AST9__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
685
692
  }
686
693
  function isFunctionOfUseEffectSetup(node) {
687
694
  if (node == null) return eff._;
688
695
  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);
689
696
  }
690
697
  function isFunctionOfUseEffectCleanup(node) {
691
- const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
692
- const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
693
- const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
698
+ const nearReturn = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
699
+ const nearFunction = AST9__namespace.findParentNode(node, AST9__namespace.isFunction);
700
+ const nearFunctionOfReturn = AST9__namespace.findParentNode(nearReturn, AST9__namespace.isFunction);
694
701
  return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
695
702
  }
696
703
 
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import * as AST8 from '@eslint-react/ast';
2
- import { flip, dual, constFalse, _ } from '@eslint-react/eff';
1
+ import * as AST9 from '@eslint-react/ast';
2
+ import { flip, dual, constFalse, identity, _ } from '@eslint-react/eff';
3
3
  import * as JSX3 from '@eslint-react/jsx';
4
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
+ import { match, P } from 'ts-pattern';
7
8
  import birecord from 'birecord';
8
9
 
9
10
  // src/component/component-collector.ts
@@ -18,12 +19,30 @@ function isDisplayNameAssignment(node) {
18
19
  if (node == null) return false;
19
20
  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";
20
21
  }
21
- function isInitializedFromReact(name, importSource, initialScope) {
22
- return name.toLowerCase() === "react" || VAR.isInitializedFromSource(
23
- name,
24
- importSource,
25
- initialScope
26
- );
22
+ function getRequireExpressionArguments(node) {
23
+ return match(node).with({ type: AST_NODE_TYPES.CallExpression, arguments: P.select(), callee: { type: AST_NODE_TYPES.Identifier, name: "require" } }, identity).with({ type: AST_NODE_TYPES.MemberExpression, object: P.select() }, getRequireExpressionArguments).otherwise(() => _);
24
+ }
25
+ function isInitializedFromReact(name, source, initialScope) {
26
+ if (name.toLowerCase() === "react") return true;
27
+ const latestDef = VAR.findVariable(name, initialScope)?.defs.at(-1);
28
+ if (latestDef == null) return false;
29
+ const { node, parent } = latestDef;
30
+ if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
31
+ const { init } = node;
32
+ if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
33
+ return isInitializedFromReact(init.object.name, source, initialScope);
34
+ }
35
+ if (init.type === AST_NODE_TYPES.Identifier) {
36
+ return isInitializedFromReact(init.name, source, initialScope);
37
+ }
38
+ const args = getRequireExpressionArguments(init);
39
+ const arg0 = args?.[0];
40
+ if (arg0 == null || !AST9.isStringLiteral(arg0)) {
41
+ return false;
42
+ }
43
+ return arg0.value === source || arg0.value.startsWith(`${source}/`);
44
+ }
45
+ return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
27
46
  }
28
47
 
29
48
  // src/utils/is-from-react.ts
@@ -51,12 +70,8 @@ function isFromReactMember(memberName, name) {
51
70
  return (node, context) => {
52
71
  const settings = unsafeDecodeSettings(context.settings);
53
72
  if (!settings.strictImportCheck) {
54
- if (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== name) {
55
- return false;
56
- }
57
- if (node.object.type === AST_NODE_TYPES.Identifier && node.object.name === memberName) {
58
- return true;
59
- }
73
+ if (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== name) return false;
74
+ if (node.object.type === AST_NODE_TYPES.Identifier && node.object.name === memberName) return true;
60
75
  if (node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && node.object.property.type === AST_NODE_TYPES.Identifier) {
61
76
  return node.object.property.name === memberName;
62
77
  }
@@ -78,23 +93,15 @@ function isFromReactMember(memberName, name) {
78
93
  }
79
94
  function isCallFromReact(name) {
80
95
  return dual(2, (node, context) => {
81
- if (node.type !== AST_NODE_TYPES.CallExpression) {
82
- return false;
83
- }
84
- if (!AST8.isOneOf([AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression])(node.callee)) {
85
- return false;
86
- }
96
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
97
+ if (!AST9.isOneOf([AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
87
98
  return isFromReact(name)(node.callee, context);
88
99
  });
89
100
  }
90
101
  function isCallFromReactMember(pragmaMemberName, name) {
91
102
  return dual(2, (node, context) => {
92
- if (node.type !== AST_NODE_TYPES.CallExpression) {
93
- return false;
94
- }
95
- if (!AST8.is(AST_NODE_TYPES.MemberExpression)(node.callee)) {
96
- return false;
97
- }
103
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
104
+ if (!AST9.is(AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
98
105
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
99
106
  });
100
107
  }
@@ -131,9 +138,9 @@ var isMemoCall = isReactAPICallWithName("memo");
131
138
 
132
139
  // src/element/hierarchy.ts
133
140
  function isInsideCreateElementProps(node, context) {
134
- const call = AST8.findParentNode(node, isCreateElementCall(context));
141
+ const call = AST9.findParentNode(node, isCreateElementCall(context));
135
142
  if (call == null) return false;
136
- const prop = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
143
+ const prop = AST9.findParentNode(node, AST9.is(AST_NODE_TYPES.ObjectExpression));
137
144
  if (prop == null) return false;
138
145
  return prop === call.arguments[1];
139
146
  }
@@ -153,7 +160,7 @@ function isReactHookName(name) {
153
160
  // src/hook/is.ts
154
161
  function isReactHook(node) {
155
162
  if (node == null) return _;
156
- const id = AST8.getFunctionIdentifier(node);
163
+ const id = AST9.getFunctionIdentifier(node);
157
164
  return id?.name != null && isReactHookName(id.name);
158
165
  }
159
166
  function isReactHookCall(node) {
@@ -245,13 +252,13 @@ var isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
245
252
 
246
253
  // src/hook/hierarchy.ts
247
254
  function isInsideReactHook(node) {
248
- return isReactHook(AST8.findParentNode(node, AST8.isFunction));
255
+ return isReactHook(AST9.findParentNode(node, AST9.isFunction));
249
256
  }
250
257
  function useHookCollector() {
251
258
  const hooks = /* @__PURE__ */ new Map();
252
259
  const functionEntries = [];
253
260
  const onFunctionEnter = (node) => {
254
- const id = AST8.getFunctionIdentifier(node);
261
+ const id = AST9.getFunctionIdentifier(node);
255
262
  const key = getId();
256
263
  const name = id?.name;
257
264
  if (name != null && isReactHookName(name)) {
@@ -347,7 +354,7 @@ function isComponentWrapperCall(node, context) {
347
354
  return isMemoCall(node, context) || isForwardRefCall(node, context) || isReactHookCallWithNameLoose(node)("useCallback");
348
355
  }
349
356
  function getFunctionComponentIdentifier(node, context) {
350
- const functionId = AST8.getFunctionIdentifier(node);
357
+ const functionId = AST9.getFunctionIdentifier(node);
351
358
  if (functionId != null) {
352
359
  return functionId;
353
360
  }
@@ -387,28 +394,28 @@ function isPureComponent(node) {
387
394
 
388
395
  // src/component/component-lifecycle.ts
389
396
  function isComponentDidMount(node) {
390
- return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
397
+ return AST9.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
391
398
  }
392
399
  function isComponentWillUnmount(node) {
393
- return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
400
+ return AST9.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
394
401
  }
395
402
  function isComponentDidCatch(node) {
396
- return AST8.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
403
+ return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
397
404
  }
398
405
  function isGetDerivedStateFromError(node) {
399
- return AST8.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
406
+ return AST9.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
400
407
  }
401
408
  function isGetDerivedStateFromProps(node) {
402
- return AST8.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
409
+ return AST9.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
403
410
  }
404
411
  function isFunctionOfComponentDidMount(node) {
405
- return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
412
+ return AST9.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
406
413
  }
407
414
  function isFunctionOfComponentWillUnmount(node) {
408
- return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
415
+ return AST9.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
409
416
  }
410
417
  function isRenderMethodLike(node) {
411
- return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
418
+ return AST9.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
412
419
  }
413
420
  function isFunctionOfRenderMethod(node) {
414
421
  if (!isRenderMethodLike(node.parent)) {
@@ -417,7 +424,7 @@ function isFunctionOfRenderMethod(node) {
417
424
  return isClassComponent(node.parent.parent.parent);
418
425
  }
419
426
  function isInsideRenderMethod(node) {
420
- return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
427
+ return AST9.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
421
428
  }
422
429
  var RE_COMPONENT_NAME = /^_?[A-Z]/u;
423
430
  function getComponentNameFromIdentifier(node) {
@@ -449,7 +456,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
449
456
  const entry = functionEntries.at(-1);
450
457
  if (entry == null) return;
451
458
  if (!entry.isComponent) return functionEntries.pop();
452
- const shouldDrop = AST8.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
459
+ const shouldDrop = AST9.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
453
460
  return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXValue(r.argument, jsxCtx, hint);
454
461
  });
455
462
  if (shouldDrop) {
@@ -476,7 +483,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
476
483
  const { body } = entry.node;
477
484
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
478
485
  if (!isComponent) return;
479
- const initPath = AST8.getFunctionInitPath(entry.node);
486
+ const initPath = AST9.getFunctionInitPath(entry.node);
480
487
  const id = getFunctionComponentIdentifier(entry.node, context);
481
488
  const name = getComponentNameFromIdentifier(id);
482
489
  const key = getId();
@@ -517,7 +524,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
517
524
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
518
525
  if (!isComponent) return;
519
526
  entry.isComponent = true;
520
- const initPath = AST8.getFunctionInitPath(entry.node);
527
+ const initPath = AST9.getFunctionInitPath(entry.node);
521
528
  const id = getFunctionComponentIdentifier(entry.node, context);
522
529
  const name = getComponentNameFromIdentifier(id);
523
530
  components.set(entry.key, {
@@ -540,21 +547,21 @@ function hasValidHierarchy(node, context, hint) {
540
547
  if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) {
541
548
  return false;
542
549
  }
543
- if (hint & ERComponentHint.SkipMapCallback && AST8.isMapCallLoose(node.parent)) {
550
+ if (hint & ERComponentHint.SkipMapCallback && AST9.isMapCallLoose(node.parent)) {
544
551
  return false;
545
552
  }
546
- if (hint & ERComponentHint.SkipObjectMethod && AST8.isFunctionOfObjectMethod(node.parent)) {
553
+ if (hint & ERComponentHint.SkipObjectMethod && AST9.isFunctionOfObjectMethod(node.parent)) {
547
554
  return false;
548
555
  }
549
- if (hint & ERComponentHint.SkipClassMethod && AST8.isFunctionOfClassMethod(node.parent)) {
556
+ if (hint & ERComponentHint.SkipClassMethod && AST9.isFunctionOfClassMethod(node.parent)) {
550
557
  return false;
551
558
  }
552
- if (hint & ERComponentHint.SkipClassProperty && AST8.isFunctionOfClassProperty(node.parent)) {
559
+ if (hint & ERComponentHint.SkipClassProperty && AST9.isFunctionOfClassProperty(node.parent)) {
553
560
  return false;
554
561
  }
555
- const boundaryNode = AST8.findParentNode(
562
+ const boundaryNode = AST9.findParentNode(
556
563
  node,
557
- AST8.isOneOf([
564
+ AST9.isOneOf([
558
565
  AST_NODE_TYPES.JSXExpressionContainer,
559
566
  AST_NODE_TYPES.ArrowFunctionExpression,
560
567
  AST_NODE_TYPES.FunctionExpression,
@@ -566,10 +573,10 @@ function hasValidHierarchy(node, context, hint) {
566
573
  }
567
574
  function getComponentFlag(initPath) {
568
575
  let flag = ERComponentFlag.None;
569
- if (initPath != null && AST8.hasCallInFunctionInitPath("memo", initPath)) {
576
+ if (initPath != null && AST9.hasCallInFunctionInitPath("memo", initPath)) {
570
577
  flag |= ERComponentFlag.Memo;
571
578
  }
572
- if (initPath != null && AST8.hasCallInFunctionInitPath("forwardRef", initPath)) {
579
+ if (initPath != null && AST9.hasCallInFunctionInitPath("forwardRef", initPath)) {
573
580
  flag |= ERComponentFlag.ForwardRef;
574
581
  }
575
582
  return flag;
@@ -586,7 +593,7 @@ function useComponentCollectorLegacy() {
586
593
  if (!isClassComponent(node)) {
587
594
  return;
588
595
  }
589
- const id = AST8.getClassIdentifier(node);
596
+ const id = AST9.getClassIdentifier(node);
590
597
  const key = getId();
591
598
  const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
592
599
  components.set(
@@ -619,7 +626,7 @@ var ERPhaseRelevance = birecord({
619
626
  var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
620
627
  function isRenderFunctionLoose(node, context) {
621
628
  const { body, parent } = node;
622
- if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
629
+ if (AST9.getFunctionIdentifier(node)?.name.startsWith("render")) {
623
630
  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");
624
631
  }
625
632
  return JSX3.isJSXValue(
@@ -634,7 +641,7 @@ function isRenderPropLoose(node, context) {
634
641
  if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
635
642
  return false;
636
643
  }
637
- return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
644
+ return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST9.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
638
645
  }
639
646
  function isDirectValueOfRenderPropertyLoose(node) {
640
647
  const matching = (node2) => {
@@ -646,7 +653,7 @@ function isDeclaredInRenderPropLoose(node) {
646
653
  if (isDirectValueOfRenderPropertyLoose(node)) {
647
654
  return true;
648
655
  }
649
- const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
656
+ const parent = AST9.findParentNode(node, AST9.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
650
657
  if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
651
658
  return false;
652
659
  }
@@ -654,16 +661,16 @@ function isDeclaredInRenderPropLoose(node) {
654
661
  }
655
662
  function isThisSetState(node) {
656
663
  const { callee } = node;
657
- return callee.type === AST_NODE_TYPES.MemberExpression && AST8.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
664
+ return callee.type === AST_NODE_TYPES.MemberExpression && AST9.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
658
665
  }
659
666
  function isFunctionOfUseEffectSetup(node) {
660
667
  if (node == null) return _;
661
668
  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);
662
669
  }
663
670
  function isFunctionOfUseEffectCleanup(node) {
664
- const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
665
- const nearFunction = AST8.findParentNode(node, AST8.isFunction);
666
- const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
671
+ const nearReturn = AST9.findParentNode(node, AST9.is(AST_NODE_TYPES.ReturnStatement));
672
+ const nearFunction = AST9.findParentNode(node, AST9.isFunction);
673
+ const nearFunctionOfReturn = AST9.findParentNode(nearReturn, AST9.isFunction);
667
674
  return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
668
675
  }
669
676
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.27.1-beta.5",
3
+ "version": "1.27.1-beta.8",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -35,17 +35,17 @@
35
35
  "./package.json"
36
36
  ],
37
37
  "dependencies": {
38
- "@typescript-eslint/scope-manager": "^8.24.1",
39
- "@typescript-eslint/type-utils": "^8.24.1",
40
- "@typescript-eslint/types": "^8.24.1",
41
- "@typescript-eslint/utils": "^8.24.1",
38
+ "@typescript-eslint/scope-manager": "^8.25.0",
39
+ "@typescript-eslint/type-utils": "^8.25.0",
40
+ "@typescript-eslint/types": "^8.25.0",
41
+ "@typescript-eslint/utils": "^8.25.0",
42
42
  "birecord": "^0.1.1",
43
43
  "ts-pattern": "^5.6.2",
44
- "@eslint-react/ast": "1.27.1-beta.5",
45
- "@eslint-react/eff": "1.27.1-beta.5",
46
- "@eslint-react/shared": "1.27.1-beta.5",
47
- "@eslint-react/var": "1.27.1-beta.5",
48
- "@eslint-react/jsx": "1.27.1-beta.5"
44
+ "@eslint-react/ast": "1.27.1-beta.8",
45
+ "@eslint-react/eff": "1.27.1-beta.8",
46
+ "@eslint-react/var": "1.27.1-beta.8",
47
+ "@eslint-react/shared": "1.27.1-beta.8",
48
+ "@eslint-react/jsx": "1.27.1-beta.8"
49
49
  },
50
50
  "devDependencies": {
51
51
  "tsup": "^8.3.6",