@eslint-react/core 1.24.0-next.6 → 1.24.0-next.9

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
@@ -1,11 +1,11 @@
1
1
  import * as AST from '@eslint-react/ast';
2
- import { _ } from '@eslint-react/eff';
3
- import { TSESTree } from '@typescript-eslint/types';
4
2
  import * as _eslint_react_shared from '@eslint-react/shared';
5
3
  import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
4
+ import { TSESTree } from '@typescript-eslint/types';
5
+ import { _ } from '@eslint-react/eff';
6
6
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
7
- import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
8
7
  import * as birecord from 'birecord';
8
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
9
9
  import { Scope } from '@typescript-eslint/scope-manager';
10
10
  import { SyntaxKind } from 'typescript';
11
11
 
@@ -73,7 +73,7 @@ interface ERClassComponent extends ERSemanticNode {
73
73
  node: AST.TSESTreeClass;
74
74
  flag: ERClassComponentFlag;
75
75
  hint: ERComponentHint;
76
- methods: Array<TSESTree.MethodDefinition | TSESTree.PropertyDefinition>;
76
+ methods: AST.TSESTreeMethodOrProperty[];
77
77
  displayName: _ | TSESTree.Expression;
78
78
  }
79
79
  type ERComponent = ERClassComponent | ERFunctionComponent;
@@ -129,19 +129,14 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
129
129
 
130
130
  type ERComponentKind = "classComponent" | "functionComponent";
131
131
 
132
- declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
133
- declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
134
- declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
135
- declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
136
-
137
- type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
138
- type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
139
-
140
- declare const RE_COMPONENT_NAME: RegExp;
141
- declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
142
- declare function isComponentName(name: string): boolean;
143
-
144
- declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
132
+ declare function isComponentDidMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
133
+ declare function isComponentWillUnmount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
134
+ declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
135
+ declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
136
+ declare function isGetDerivedStateFromProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
137
+ declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
138
+ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
139
+ declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
145
140
  declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
146
141
  /**
147
142
  * Check whether given node is declared inside class component's render block
@@ -158,7 +153,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
158
153
  * @param node The AST node being checked
159
154
  * @returns `true` if node is inside class component's render block, `false` if not
160
155
  */
161
- declare function isInsideRenderMethod(node: TSESTree$1.Node): boolean;
156
+ declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
157
+
158
+ type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
159
+ type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
160
+
161
+ declare const RE_COMPONENT_NAME: RegExp;
162
+ declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
163
+ declare function isComponentName(name: string): boolean;
164
+ declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
165
+
166
+ type EREffectPhaseKind = "cleanup" | "setup";
167
+ type ERLifecyclePhaseKind = "mount" | "unmount";
168
+ type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
169
+ declare const ERPhaseRelevance: birecord.BiRecord<{
170
+ readonly mount: "unmount";
171
+ readonly setup: "cleanup";
172
+ }>;
173
+ declare const isInversePhase: {
174
+ (a: ERPhaseKind): (b: ERPhaseKind) => boolean;
175
+ (a: ERPhaseKind, b: ERPhaseKind): boolean;
176
+ };
177
+
178
+ /**
179
+ * Unsafe check whether given node is a render function
180
+ * ```jsx
181
+ * const renderRow = () => <div />
182
+ * ` ^^^^^^^^^^^^`
183
+ * _ = <Component renderRow={() => <div />} />
184
+ * ` ^^^^^^^^^^^^^ `
185
+ * ```
186
+ * @param node The AST node to check
187
+ * @param context The rule context
188
+ * @returns `true` if node is a render function, `false` if not
189
+ */
190
+ declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
191
+ /**
192
+ * Unsafe check whether given JSXAttribute is a render prop
193
+ * ```jsx
194
+ * _ = <Component renderRow={() => <div />} />
195
+ * ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
196
+ * ```
197
+ * @param node The AST node to check
198
+ * @param context The rule context
199
+ * @returns `true` if node is a render prop, `false` if not
200
+ */
201
+ declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
202
+ /**
203
+ * Unsafe check whether given node is declared directly inside a render property
204
+ * ```jsx
205
+ * const rows = { render: () => <div /> }
206
+ * ` ^^^^^^^^^^^^^ `
207
+ * _ = <Component rows={ [{ render: () => <div /> }] } />
208
+ * ` ^^^^^^^^^^^^^ `
209
+ * ```
210
+ * @internal
211
+ * @param node The AST node to check
212
+ * @returns `true` if component is declared inside a render property, `false` if not
213
+ */
214
+ declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
215
+ /**
216
+ * Unsafe check whether given node is declared inside a render prop
217
+ * ```jsx
218
+ * _ = <Component renderRow={"node"} />
219
+ * ` ^^^^^^ `
220
+ * _ = <Component rows={ [{ render: "node" }] } />
221
+ * ` ^^^^^^ `
222
+ * ```
223
+ * @param node The AST node to check
224
+ * @returns `true` if component is declared inside a render prop, `false` if not
225
+ */
226
+ declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
227
+
228
+ type ERStateKind = "actionState" | "state";
229
+ declare function isThisSetState(node: TSESTree.CallExpression): boolean;
162
230
 
163
231
  /**
164
232
  * Check if a node is a React class component
@@ -173,14 +241,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
173
241
  */
174
242
  declare function isPureComponent(node: TSESTree.Node): boolean;
175
243
 
176
- declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
177
-
178
244
  type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
179
245
 
180
- declare function isSetupFunction(node: TSESTree.Node | _): boolean | undefined;
181
- declare function isCleanupFunction(node: TSESTree.Node): boolean | undefined;
246
+ declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
247
+ declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
182
248
 
183
- declare function getElementNameAndRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
249
+ declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
184
250
 
185
251
  /**
186
252
  * Determines whether inside `createElement`'s props.
@@ -250,80 +316,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
250
316
  declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
251
317
  declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
252
318
 
253
- declare const ERPhaseRelevance: birecord.BiRecord<{
254
- readonly mount: "unmount";
255
- readonly setup: "cleanup";
256
- }>;
257
-
258
- type EREffectPhaseKind = "cleanup" | "setup";
259
- type ERLifecyclePhaseKind = "mount" | "unmount";
260
- type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
261
-
262
- declare const isInversePhase: {
263
- (a: ERPhaseKind): (b: ERPhaseKind) => boolean;
264
- (a: ERPhaseKind, b: ERPhaseKind): boolean;
265
- };
266
-
267
- /**
268
- * Unsafe check whether given node is declared directly inside a render property
269
- * ```jsx
270
- * const rows = { render: () => <div /> }
271
- * ` ^^^^^^^^^^^^^ `
272
- * _ = <Component rows={ [{ render: () => <div /> }] } />
273
- * ` ^^^^^^^^^^^^^ `
274
- * ```
275
- * @internal
276
- * @param node The AST node to check
277
- * @returns `true` if component is declared inside a render property, `false` if not
278
- */
279
- declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
280
- /**
281
- * Unsafe check whether given node is declared inside a render prop
282
- * ```jsx
283
- * _ = <Component renderRow={"node"} />
284
- * ` ^^^^^^ `
285
- * _ = <Component rows={ [{ render: "node" }] } />
286
- * ` ^^^^^^ `
287
- * ```
288
- * @param node The AST node to check
289
- * @returns `true` if component is declared inside a render prop, `false` if not
290
- */
291
- declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
292
-
293
- /**
294
- * Unsafe check whether given node is a render function
295
- * ```jsx
296
- * const renderRow = () => <div />
297
- * ` ^^^^^^^^^^^^`
298
- * _ = <Component renderRow={() => <div />} />
299
- * ` ^^^^^^^^^^^^^ `
300
- * ```
301
- * @param node The AST node to check
302
- * @param context The rule context
303
- * @returns `true` if node is a render function, `false` if not
304
- */
305
- declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
306
- /**
307
- * Unsafe check whether given JSXAttribute is a render prop
308
- * ```jsx
309
- * _ = <Component renderRow={() => <div />} />
310
- * ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
311
- * ```
312
- * @param node The AST node to check
313
- * @param context The rule context
314
- * @returns `true` if node is a render prop, `false` if not
315
- */
316
- declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
317
-
318
319
  interface ERSemanticEntry {
319
320
  node: TSESTree.Node;
320
321
  phase: ERPhaseKind;
321
322
  }
322
323
 
323
- declare function isThisSetState(node: TSESTree.CallExpression): boolean;
324
-
325
- type ERStateKind = "actionState" | "state";
326
-
327
324
  declare const getId: () => string;
328
325
 
329
326
  /**
@@ -2578,4 +2575,4 @@ declare const isMemoCall: {
2578
2575
  (node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
2579
2576
  };
2580
2577
 
2581
- 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 };
2578
+ 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, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, 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 };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as AST from '@eslint-react/ast';
2
- import { _ } from '@eslint-react/eff';
3
- import { TSESTree } from '@typescript-eslint/types';
4
2
  import * as _eslint_react_shared from '@eslint-react/shared';
5
3
  import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
4
+ import { TSESTree } from '@typescript-eslint/types';
5
+ import { _ } from '@eslint-react/eff';
6
6
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
7
- import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
8
7
  import * as birecord from 'birecord';
8
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
9
9
  import { Scope } from '@typescript-eslint/scope-manager';
10
10
  import { SyntaxKind } from 'typescript';
11
11
 
@@ -73,7 +73,7 @@ interface ERClassComponent extends ERSemanticNode {
73
73
  node: AST.TSESTreeClass;
74
74
  flag: ERClassComponentFlag;
75
75
  hint: ERComponentHint;
76
- methods: Array<TSESTree.MethodDefinition | TSESTree.PropertyDefinition>;
76
+ methods: AST.TSESTreeMethodOrProperty[];
77
77
  displayName: _ | TSESTree.Expression;
78
78
  }
79
79
  type ERComponent = ERClassComponent | ERFunctionComponent;
@@ -129,19 +129,14 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
129
129
 
130
130
  type ERComponentKind = "classComponent" | "functionComponent";
131
131
 
132
- declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
133
- declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
134
- declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
135
- declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
136
-
137
- type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
138
- type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
139
-
140
- declare const RE_COMPONENT_NAME: RegExp;
141
- declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
142
- declare function isComponentName(name: string): boolean;
143
-
144
- declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
132
+ declare function isComponentDidMount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
133
+ declare function isComponentWillUnmount(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
134
+ declare function isComponentDidCatch(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
135
+ declare function isGetDerivedStateFromError(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
136
+ declare function isGetDerivedStateFromProps(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
137
+ declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
138
+ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
139
+ declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
145
140
  declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
146
141
  /**
147
142
  * Check whether given node is declared inside class component's render block
@@ -158,7 +153,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
158
153
  * @param node The AST node being checked
159
154
  * @returns `true` if node is inside class component's render block, `false` if not
160
155
  */
161
- declare function isInsideRenderMethod(node: TSESTree$1.Node): boolean;
156
+ declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
157
+
158
+ type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
159
+ type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
160
+
161
+ declare const RE_COMPONENT_NAME: RegExp;
162
+ declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
163
+ declare function isComponentName(name: string): boolean;
164
+ declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
165
+
166
+ type EREffectPhaseKind = "cleanup" | "setup";
167
+ type ERLifecyclePhaseKind = "mount" | "unmount";
168
+ type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
169
+ declare const ERPhaseRelevance: birecord.BiRecord<{
170
+ readonly mount: "unmount";
171
+ readonly setup: "cleanup";
172
+ }>;
173
+ declare const isInversePhase: {
174
+ (a: ERPhaseKind): (b: ERPhaseKind) => boolean;
175
+ (a: ERPhaseKind, b: ERPhaseKind): boolean;
176
+ };
177
+
178
+ /**
179
+ * Unsafe check whether given node is a render function
180
+ * ```jsx
181
+ * const renderRow = () => <div />
182
+ * ` ^^^^^^^^^^^^`
183
+ * _ = <Component renderRow={() => <div />} />
184
+ * ` ^^^^^^^^^^^^^ `
185
+ * ```
186
+ * @param node The AST node to check
187
+ * @param context The rule context
188
+ * @returns `true` if node is a render function, `false` if not
189
+ */
190
+ declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
191
+ /**
192
+ * Unsafe check whether given JSXAttribute is a render prop
193
+ * ```jsx
194
+ * _ = <Component renderRow={() => <div />} />
195
+ * ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
196
+ * ```
197
+ * @param node The AST node to check
198
+ * @param context The rule context
199
+ * @returns `true` if node is a render prop, `false` if not
200
+ */
201
+ declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
202
+ /**
203
+ * Unsafe check whether given node is declared directly inside a render property
204
+ * ```jsx
205
+ * const rows = { render: () => <div /> }
206
+ * ` ^^^^^^^^^^^^^ `
207
+ * _ = <Component rows={ [{ render: () => <div /> }] } />
208
+ * ` ^^^^^^^^^^^^^ `
209
+ * ```
210
+ * @internal
211
+ * @param node The AST node to check
212
+ * @returns `true` if component is declared inside a render property, `false` if not
213
+ */
214
+ declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
215
+ /**
216
+ * Unsafe check whether given node is declared inside a render prop
217
+ * ```jsx
218
+ * _ = <Component renderRow={"node"} />
219
+ * ` ^^^^^^ `
220
+ * _ = <Component rows={ [{ render: "node" }] } />
221
+ * ` ^^^^^^ `
222
+ * ```
223
+ * @param node The AST node to check
224
+ * @returns `true` if component is declared inside a render prop, `false` if not
225
+ */
226
+ declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
227
+
228
+ type ERStateKind = "actionState" | "state";
229
+ declare function isThisSetState(node: TSESTree.CallExpression): boolean;
162
230
 
163
231
  /**
164
232
  * Check if a node is a React class component
@@ -173,14 +241,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
173
241
  */
174
242
  declare function isPureComponent(node: TSESTree.Node): boolean;
175
243
 
176
- declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
177
-
178
244
  type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
179
245
 
180
- declare function isSetupFunction(node: TSESTree.Node | _): boolean | undefined;
181
- declare function isCleanupFunction(node: TSESTree.Node): boolean | undefined;
246
+ declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
247
+ declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
182
248
 
183
- declare function getElementNameAndRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
249
+ declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
184
250
 
185
251
  /**
186
252
  * Determines whether inside `createElement`'s props.
@@ -250,80 +316,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
250
316
  declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
251
317
  declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
252
318
 
253
- declare const ERPhaseRelevance: birecord.BiRecord<{
254
- readonly mount: "unmount";
255
- readonly setup: "cleanup";
256
- }>;
257
-
258
- type EREffectPhaseKind = "cleanup" | "setup";
259
- type ERLifecyclePhaseKind = "mount" | "unmount";
260
- type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
261
-
262
- declare const isInversePhase: {
263
- (a: ERPhaseKind): (b: ERPhaseKind) => boolean;
264
- (a: ERPhaseKind, b: ERPhaseKind): boolean;
265
- };
266
-
267
- /**
268
- * Unsafe check whether given node is declared directly inside a render property
269
- * ```jsx
270
- * const rows = { render: () => <div /> }
271
- * ` ^^^^^^^^^^^^^ `
272
- * _ = <Component rows={ [{ render: () => <div /> }] } />
273
- * ` ^^^^^^^^^^^^^ `
274
- * ```
275
- * @internal
276
- * @param node The AST node to check
277
- * @returns `true` if component is declared inside a render property, `false` if not
278
- */
279
- declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
280
- /**
281
- * Unsafe check whether given node is declared inside a render prop
282
- * ```jsx
283
- * _ = <Component renderRow={"node"} />
284
- * ` ^^^^^^ `
285
- * _ = <Component rows={ [{ render: "node" }] } />
286
- * ` ^^^^^^ `
287
- * ```
288
- * @param node The AST node to check
289
- * @returns `true` if component is declared inside a render prop, `false` if not
290
- */
291
- declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
292
-
293
- /**
294
- * Unsafe check whether given node is a render function
295
- * ```jsx
296
- * const renderRow = () => <div />
297
- * ` ^^^^^^^^^^^^`
298
- * _ = <Component renderRow={() => <div />} />
299
- * ` ^^^^^^^^^^^^^ `
300
- * ```
301
- * @param node The AST node to check
302
- * @param context The rule context
303
- * @returns `true` if node is a render function, `false` if not
304
- */
305
- declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
306
- /**
307
- * Unsafe check whether given JSXAttribute is a render prop
308
- * ```jsx
309
- * _ = <Component renderRow={() => <div />} />
310
- * ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
311
- * ```
312
- * @param node The AST node to check
313
- * @param context The rule context
314
- * @returns `true` if node is a render prop, `false` if not
315
- */
316
- declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
317
-
318
319
  interface ERSemanticEntry {
319
320
  node: TSESTree.Node;
320
321
  phase: ERPhaseKind;
321
322
  }
322
323
 
323
- declare function isThisSetState(node: TSESTree.CallExpression): boolean;
324
-
325
- type ERStateKind = "actionState" | "state";
326
-
327
324
  declare const getId: () => string;
328
325
 
329
326
  /**
@@ -2578,4 +2575,4 @@ declare const isMemoCall: {
2578
2575
  (node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
2579
2576
  };
2580
2577
 
2581
- 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 };
2578
+ 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, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, 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 };
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var JSX4 = require('@eslint-react/jsx');
6
6
  var types = require('@typescript-eslint/types');
7
7
  var VAR = require('@eslint-react/var');
8
8
  var shared = require('@eslint-react/shared');
9
+ require('ts-pattern');
9
10
  var birecord = require('birecord');
10
11
 
11
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -34,22 +35,22 @@ var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
34
35
  var birecord__default = /*#__PURE__*/_interopDefault(birecord);
35
36
 
36
37
  // src/component/component-collector.ts
37
- function getElementNameAndRepresentName(node, context, polymorphicPropName, additionalComponents = []) {
38
+ function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
38
39
  const name = JSX4__namespace.getElementName(node);
39
40
  if (name === name.toLowerCase()) return [name, name];
40
41
  const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
41
42
  if (component != null) return [name, component.as];
42
43
  if (polymorphicPropName == null) return [name, name];
43
44
  const initialScope = context.sourceCode.getScope(node);
44
- const polymorphicProp = JSX4__namespace.findPropInAttributes(
45
+ const attributeNode = JSX4__namespace.getAttributeNode(
45
46
  polymorphicPropName,
46
47
  initialScope,
47
48
  node.attributes
48
49
  );
49
- if (polymorphicProp == null) return [name, name];
50
- const polymorphicName = VAR__namespace.toResolved(JSX4__namespace.getPropValue(polymorphicProp, initialScope)).value;
51
- if (typeof polymorphicName === "string") {
52
- return [name, polymorphicName];
50
+ if (attributeNode == null) return [name, name];
51
+ const polymorphicPropValue = VAR__namespace.toResolved(JSX4__namespace.getAttributeStaticValue(attributeNode, initialScope)).value;
52
+ if (typeof polymorphicPropValue === "string") {
53
+ return [name, polymorphicPropValue];
53
54
  }
54
55
  return [name, name];
55
56
  }
@@ -393,14 +394,6 @@ function getFunctionComponentIdentifier(node, context) {
393
394
  }
394
395
  return eff._;
395
396
  }
396
- var RE_COMPONENT_NAME = /^_?[A-Z]/u;
397
- function getComponentNameFromIdentifier(node) {
398
- if (node == null) return eff._;
399
- return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
400
- }
401
- function isComponentName(name) {
402
- return RE_COMPONENT_NAME.test(name);
403
- }
404
397
  function isClassComponent(node) {
405
398
  if ("superClass" in node && node.superClass != null) {
406
399
  const re = /^(?:Pure)?Component$/u;
@@ -425,10 +418,29 @@ function isPureComponent(node) {
425
418
  }
426
419
  return false;
427
420
  }
428
-
429
- // src/component/component-render-method.ts
421
+ function isComponentDidMount(node) {
422
+ return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
423
+ }
424
+ function isComponentWillUnmount(node) {
425
+ return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
426
+ }
427
+ function isComponentDidCatch(node) {
428
+ return AST8__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
429
+ }
430
+ function isGetDerivedStateFromError(node) {
431
+ return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
432
+ }
433
+ function isGetDerivedStateFromProps(node) {
434
+ return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
435
+ }
436
+ function isFunctionOfComponentDidMount(node) {
437
+ return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
438
+ }
439
+ function isFunctionOfComponentWillUnmount(node) {
440
+ return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
441
+ }
430
442
  function isRenderMethodLike(node) {
431
- return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
443
+ 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;
432
444
  }
433
445
  function isFunctionOfRenderMethod(node) {
434
446
  if (!isRenderMethodLike(node.parent)) {
@@ -439,8 +451,14 @@ function isFunctionOfRenderMethod(node) {
439
451
  function isInsideRenderMethod(node) {
440
452
  return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
441
453
  }
442
-
443
- // src/component/misc.ts
454
+ var RE_COMPONENT_NAME = /^_?[A-Z]/u;
455
+ function getComponentNameFromIdentifier(node) {
456
+ if (node == null) return eff._;
457
+ return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
458
+ }
459
+ function isComponentName(name) {
460
+ return RE_COMPONENT_NAME.test(name);
461
+ }
444
462
  function hasNoneOrValidComponentName(node, context) {
445
463
  const id2 = getFunctionComponentIdentifier(node, context);
446
464
  if (id2 == null) return true;
@@ -643,49 +661,11 @@ function useComponentCollectorLegacy() {
643
661
  };
644
662
  return { ctx, listeners };
645
663
  }
646
- function isComponentDidMount(node) {
647
- return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
648
- }
649
- function isComponentWillUnmount(node) {
650
- return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
651
- }
652
- function isComponentDidMountFunction(node) {
653
- return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
654
- }
655
- function isComponentWillUnmountFunction(node) {
656
- return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
657
- }
658
- function isSetupFunction(node) {
659
- if (node == null) return eff._;
660
- 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);
661
- }
662
- function isCleanupFunction(node) {
663
- const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
664
- const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
665
- const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
666
- return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
667
- }
668
664
  var ERPhaseRelevance = birecord__default.default({
669
665
  mount: "unmount",
670
666
  setup: "cleanup"
671
667
  });
672
668
  var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
673
- function isDirectValueOfRenderPropertyLoose(node) {
674
- const matching = (node2) => {
675
- return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
676
- };
677
- return matching(node) || node.parent != null && matching(node.parent);
678
- }
679
- function isDeclaredInRenderPropLoose(node) {
680
- if (isDirectValueOfRenderPropertyLoose(node)) {
681
- return true;
682
- }
683
- const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
684
- if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
685
- return false;
686
- }
687
- return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
688
- }
689
669
  function isRenderFunctionLoose(node, context) {
690
670
  const { body, parent } = node;
691
671
  if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
@@ -705,10 +685,36 @@ function isRenderPropLoose(node, context) {
705
685
  }
706
686
  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);
707
687
  }
688
+ function isDirectValueOfRenderPropertyLoose(node) {
689
+ const matching = (node2) => {
690
+ return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
691
+ };
692
+ return matching(node) || node.parent != null && matching(node.parent);
693
+ }
694
+ function isDeclaredInRenderPropLoose(node) {
695
+ if (isDirectValueOfRenderPropertyLoose(node)) {
696
+ return true;
697
+ }
698
+ const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
699
+ if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
700
+ return false;
701
+ }
702
+ return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
703
+ }
708
704
  function isThisSetState(node) {
709
705
  const { callee } = node;
710
706
  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";
711
707
  }
708
+ function isFunctionOfUseEffectSetup(node) {
709
+ if (node == null) return eff._;
710
+ 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);
711
+ }
712
+ function isFunctionOfUseEffectCleanup(node) {
713
+ const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
714
+ const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
715
+ const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
716
+ return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
717
+ }
712
718
 
713
719
  exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
714
720
  exports.ERClassComponentFlag = ERClassComponentFlag;
@@ -718,7 +724,7 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
718
724
  exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
719
725
  exports.RE_HOOK_NAME = RE_HOOK_NAME;
720
726
  exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
721
- exports.getElementNameAndRepresentName = getElementNameAndRepresentName;
727
+ exports.getElementNameOnJsxAndHtml = getElementNameOnJsxAndHtml;
722
728
  exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
723
729
  exports.getId = getId;
724
730
  exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
@@ -736,14 +742,12 @@ exports.isChildrenOnlyCall = isChildrenOnlyCall;
736
742
  exports.isChildrenToArray = isChildrenToArray;
737
743
  exports.isChildrenToArrayCall = isChildrenToArrayCall;
738
744
  exports.isClassComponent = isClassComponent;
739
- exports.isCleanupFunction = isCleanupFunction;
740
745
  exports.isCloneElement = isCloneElement;
741
746
  exports.isCloneElementCall = isCloneElementCall;
747
+ exports.isComponentDidCatch = isComponentDidCatch;
742
748
  exports.isComponentDidMount = isComponentDidMount;
743
- exports.isComponentDidMountFunction = isComponentDidMountFunction;
744
749
  exports.isComponentName = isComponentName;
745
750
  exports.isComponentWillUnmount = isComponentWillUnmount;
746
- exports.isComponentWillUnmountFunction = isComponentWillUnmountFunction;
747
751
  exports.isCreateContext = isCreateContext;
748
752
  exports.isCreateContextCall = isCreateContextCall;
749
753
  exports.isCreateElement = isCreateElement;
@@ -756,7 +760,13 @@ exports.isForwardRef = isForwardRef;
756
760
  exports.isForwardRefCall = isForwardRefCall;
757
761
  exports.isFromReact = isFromReact;
758
762
  exports.isFromReactMember = isFromReactMember;
763
+ exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
764
+ exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
759
765
  exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
766
+ exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
767
+ exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
768
+ exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
769
+ exports.isGetDerivedStateFromProps = isGetDerivedStateFromProps;
760
770
  exports.isInitializedFromReact = isInitializedFromReact;
761
771
  exports.isInsideCreateElementProps = isInsideCreateElementProps;
762
772
  exports.isInsideReactHook = isInsideReactHook;
@@ -776,7 +786,6 @@ exports.isReactHookName = isReactHookName;
776
786
  exports.isRenderFunctionLoose = isRenderFunctionLoose;
777
787
  exports.isRenderMethodLike = isRenderMethodLike;
778
788
  exports.isRenderPropLoose = isRenderPropLoose;
779
- exports.isSetupFunction = isSetupFunction;
780
789
  exports.isThisSetState = isThisSetState;
781
790
  exports.isUseCallbackCall = isUseCallbackCall;
782
791
  exports.isUseContextCall = isUseContextCall;
package/dist/index.mjs CHANGED
@@ -4,25 +4,26 @@ import * as JSX4 from '@eslint-react/jsx';
4
4
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
5
  import * as VAR from '@eslint-react/var';
6
6
  import { unsafeDecodeSettings } from '@eslint-react/shared';
7
+ import 'ts-pattern';
7
8
  import birecord from 'birecord';
8
9
 
9
10
  // src/component/component-collector.ts
10
- function getElementNameAndRepresentName(node, context, polymorphicPropName, additionalComponents = []) {
11
+ function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
11
12
  const name = JSX4.getElementName(node);
12
13
  if (name === name.toLowerCase()) return [name, name];
13
14
  const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
14
15
  if (component != null) return [name, component.as];
15
16
  if (polymorphicPropName == null) return [name, name];
16
17
  const initialScope = context.sourceCode.getScope(node);
17
- const polymorphicProp = JSX4.findPropInAttributes(
18
+ const attributeNode = JSX4.getAttributeNode(
18
19
  polymorphicPropName,
19
20
  initialScope,
20
21
  node.attributes
21
22
  );
22
- if (polymorphicProp == null) return [name, name];
23
- const polymorphicName = VAR.toResolved(JSX4.getPropValue(polymorphicProp, initialScope)).value;
24
- if (typeof polymorphicName === "string") {
25
- return [name, polymorphicName];
23
+ if (attributeNode == null) return [name, name];
24
+ const polymorphicPropValue = VAR.toResolved(JSX4.getAttributeStaticValue(attributeNode, initialScope)).value;
25
+ if (typeof polymorphicPropValue === "string") {
26
+ return [name, polymorphicPropValue];
26
27
  }
27
28
  return [name, name];
28
29
  }
@@ -366,14 +367,6 @@ function getFunctionComponentIdentifier(node, context) {
366
367
  }
367
368
  return _;
368
369
  }
369
- var RE_COMPONENT_NAME = /^_?[A-Z]/u;
370
- function getComponentNameFromIdentifier(node) {
371
- if (node == null) return _;
372
- return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
373
- }
374
- function isComponentName(name) {
375
- return RE_COMPONENT_NAME.test(name);
376
- }
377
370
  function isClassComponent(node) {
378
371
  if ("superClass" in node && node.superClass != null) {
379
372
  const re = /^(?:Pure)?Component$/u;
@@ -398,10 +391,29 @@ function isPureComponent(node) {
398
391
  }
399
392
  return false;
400
393
  }
401
-
402
- // src/component/component-render-method.ts
394
+ function isComponentDidMount(node) {
395
+ return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
396
+ }
397
+ function isComponentWillUnmount(node) {
398
+ return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
399
+ }
400
+ function isComponentDidCatch(node) {
401
+ return AST8.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
402
+ }
403
+ function isGetDerivedStateFromError(node) {
404
+ return AST8.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
405
+ }
406
+ function isGetDerivedStateFromProps(node) {
407
+ return AST8.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
408
+ }
409
+ function isFunctionOfComponentDidMount(node) {
410
+ return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
411
+ }
412
+ function isFunctionOfComponentWillUnmount(node) {
413
+ return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
414
+ }
403
415
  function isRenderMethodLike(node) {
404
- return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
416
+ return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
405
417
  }
406
418
  function isFunctionOfRenderMethod(node) {
407
419
  if (!isRenderMethodLike(node.parent)) {
@@ -412,8 +424,14 @@ function isFunctionOfRenderMethod(node) {
412
424
  function isInsideRenderMethod(node) {
413
425
  return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
414
426
  }
415
-
416
- // src/component/misc.ts
427
+ var RE_COMPONENT_NAME = /^_?[A-Z]/u;
428
+ function getComponentNameFromIdentifier(node) {
429
+ if (node == null) return _;
430
+ return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
431
+ }
432
+ function isComponentName(name) {
433
+ return RE_COMPONENT_NAME.test(name);
434
+ }
417
435
  function hasNoneOrValidComponentName(node, context) {
418
436
  const id2 = getFunctionComponentIdentifier(node, context);
419
437
  if (id2 == null) return true;
@@ -616,49 +634,11 @@ function useComponentCollectorLegacy() {
616
634
  };
617
635
  return { ctx, listeners };
618
636
  }
619
- function isComponentDidMount(node) {
620
- return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
621
- }
622
- function isComponentWillUnmount(node) {
623
- return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
624
- }
625
- function isComponentDidMountFunction(node) {
626
- return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
627
- }
628
- function isComponentWillUnmountFunction(node) {
629
- return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
630
- }
631
- function isSetupFunction(node) {
632
- if (node == null) return _;
633
- 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);
634
- }
635
- function isCleanupFunction(node) {
636
- const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
637
- const nearFunction = AST8.findParentNode(node, AST8.isFunction);
638
- const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
639
- return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
640
- }
641
637
  var ERPhaseRelevance = birecord({
642
638
  mount: "unmount",
643
639
  setup: "cleanup"
644
640
  });
645
641
  var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
646
- function isDirectValueOfRenderPropertyLoose(node) {
647
- const matching = (node2) => {
648
- return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
649
- };
650
- return matching(node) || node.parent != null && matching(node.parent);
651
- }
652
- function isDeclaredInRenderPropLoose(node) {
653
- if (isDirectValueOfRenderPropertyLoose(node)) {
654
- return true;
655
- }
656
- const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
657
- if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
658
- return false;
659
- }
660
- return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
661
- }
662
642
  function isRenderFunctionLoose(node, context) {
663
643
  const { body, parent } = node;
664
644
  if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
@@ -678,9 +658,35 @@ function isRenderPropLoose(node, context) {
678
658
  }
679
659
  return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
680
660
  }
661
+ function isDirectValueOfRenderPropertyLoose(node) {
662
+ const matching = (node2) => {
663
+ return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
664
+ };
665
+ return matching(node) || node.parent != null && matching(node.parent);
666
+ }
667
+ function isDeclaredInRenderPropLoose(node) {
668
+ if (isDirectValueOfRenderPropertyLoose(node)) {
669
+ return true;
670
+ }
671
+ const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
672
+ if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
673
+ return false;
674
+ }
675
+ return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
676
+ }
681
677
  function isThisSetState(node) {
682
678
  const { callee } = node;
683
679
  return callee.type === AST_NODE_TYPES.MemberExpression && AST8.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
684
680
  }
681
+ function isFunctionOfUseEffectSetup(node) {
682
+ if (node == null) return _;
683
+ 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);
684
+ }
685
+ function isFunctionOfUseEffectCleanup(node) {
686
+ const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
687
+ const nearFunction = AST8.findParentNode(node, AST8.isFunction);
688
+ const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
689
+ return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
690
+ }
685
691
 
686
- export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, 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 };
692
+ export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.24.0-next.6",
3
+ "version": "1.24.0-next.9",
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": {
@@ -33,17 +33,17 @@
33
33
  "./package.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@typescript-eslint/scope-manager": "^8.19.1",
37
- "@typescript-eslint/type-utils": "^8.19.1",
38
- "@typescript-eslint/types": "^8.19.1",
39
- "@typescript-eslint/utils": "^8.19.1",
36
+ "@typescript-eslint/scope-manager": "^8.20.0",
37
+ "@typescript-eslint/type-utils": "^8.20.0",
38
+ "@typescript-eslint/types": "^8.20.0",
39
+ "@typescript-eslint/utils": "^8.20.0",
40
40
  "birecord": "^0.1.1",
41
41
  "ts-pattern": "^5.6.0",
42
- "@eslint-react/eff": "1.24.0-next.6",
43
- "@eslint-react/jsx": "1.24.0-next.6",
44
- "@eslint-react/ast": "1.24.0-next.6",
45
- "@eslint-react/shared": "1.24.0-next.6",
46
- "@eslint-react/var": "1.24.0-next.6"
42
+ "@eslint-react/ast": "1.24.0-next.9",
43
+ "@eslint-react/eff": "1.24.0-next.9",
44
+ "@eslint-react/jsx": "1.24.0-next.9",
45
+ "@eslint-react/var": "1.24.0-next.9",
46
+ "@eslint-react/shared": "1.24.0-next.9"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.3.5",