@eslint-react/core 1.48.3 → 2.0.0-next.0
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 +12 -33
- package/dist/index.d.ts +12 -33
- package/dist/index.js +145 -171
- package/dist/index.mjs +145 -166
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { RuleContext } from '@eslint-react/kit';
|
|
1
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
3
|
import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
3
4
|
import * as AST from '@eslint-react/ast';
|
|
4
5
|
import { _ } from '@eslint-react/eff';
|
|
5
|
-
import { RuleContext } from '@eslint-react/kit';
|
|
6
6
|
import * as birecord from 'birecord';
|
|
7
7
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
8
8
|
import * as VAR from '@eslint-react/var';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether inside `createElement`'s children.
|
|
12
|
+
* @param context The rule context
|
|
13
|
+
* @param node The AST node to check
|
|
14
|
+
* @returns `true` if the node is inside createElement's children
|
|
15
|
+
*/
|
|
16
|
+
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
17
|
+
|
|
10
18
|
type ComponentDetectionHint = bigint;
|
|
11
19
|
/**
|
|
12
20
|
* Hints for component collector
|
|
@@ -155,33 +163,6 @@ declare namespace useComponentCollectorLegacy {
|
|
|
155
163
|
*/
|
|
156
164
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
157
165
|
|
|
158
|
-
declare function isValidComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Determines whether inside `createElement`'s children.
|
|
162
|
-
* @param context The rule context
|
|
163
|
-
* @param node The AST node to check
|
|
164
|
-
* @returns `true` if the node is inside createElement's children
|
|
165
|
-
*/
|
|
166
|
-
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
167
|
-
/**
|
|
168
|
-
* Check whether given node is declared inside class component's render block
|
|
169
|
-
* ```tsx
|
|
170
|
-
* class Component extends React.Component {
|
|
171
|
-
* render() {
|
|
172
|
-
* class NestedClassComponent extends React.Component {
|
|
173
|
-
* render() { return <div />; }
|
|
174
|
-
* }
|
|
175
|
-
* const nestedFunctionComponent = () => <div />;
|
|
176
|
-
* }
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
* @param node The AST node being checked
|
|
180
|
-
* @returns `true` if node is inside class component's render block, `false` if not
|
|
181
|
-
*/
|
|
182
|
-
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
183
|
-
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
184
|
-
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
185
166
|
/**
|
|
186
167
|
* Check whether given node is a function of a render method of a class component
|
|
187
168
|
* @example
|
|
@@ -195,6 +176,7 @@ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
|
195
176
|
* @returns `true` if node is a render function, `false` if not
|
|
196
177
|
*/
|
|
197
178
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
179
|
+
declare function isValidComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
198
180
|
|
|
199
181
|
declare function getFunctionComponentId(context: RuleContext, node: AST.TSESTreeFunction): TSESTree.Identifier | TSESTree.Identifier[] | _;
|
|
200
182
|
|
|
@@ -366,9 +348,6 @@ declare namespace useHookCollector {
|
|
|
366
348
|
}
|
|
367
349
|
declare function useHookCollector(): useHookCollector.ReturnType;
|
|
368
350
|
|
|
369
|
-
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean;
|
|
370
|
-
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node | _): boolean;
|
|
371
|
-
|
|
372
351
|
declare function isReactHook(node: AST.TSESTreeFunction | _): boolean;
|
|
373
352
|
/**
|
|
374
353
|
* Check if the given node is a React Hook call by its name.
|
|
@@ -507,7 +486,7 @@ declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | n
|
|
|
507
486
|
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
508
487
|
|
|
509
488
|
/** @internal */
|
|
510
|
-
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.
|
|
489
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
|
|
511
490
|
|
|
512
491
|
/**
|
|
513
492
|
* Check if an identifier is initialized from react
|
|
@@ -562,4 +541,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
|
562
541
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
563
542
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
564
543
|
|
|
565
|
-
export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, type HookKind, JSXDetectionHint, type SemanticEntry, type SemanticNode, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement,
|
|
544
|
+
export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, type HookKind, JSXDetectionHint, type SemanticEntry, type SemanticNode, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { RuleContext } from '@eslint-react/kit';
|
|
1
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
3
|
import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
3
4
|
import * as AST from '@eslint-react/ast';
|
|
4
5
|
import { _ } from '@eslint-react/eff';
|
|
5
|
-
import { RuleContext } from '@eslint-react/kit';
|
|
6
6
|
import * as birecord from 'birecord';
|
|
7
7
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
8
8
|
import * as VAR from '@eslint-react/var';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether inside `createElement`'s children.
|
|
12
|
+
* @param context The rule context
|
|
13
|
+
* @param node The AST node to check
|
|
14
|
+
* @returns `true` if the node is inside createElement's children
|
|
15
|
+
*/
|
|
16
|
+
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
17
|
+
|
|
10
18
|
type ComponentDetectionHint = bigint;
|
|
11
19
|
/**
|
|
12
20
|
* Hints for component collector
|
|
@@ -155,33 +163,6 @@ declare namespace useComponentCollectorLegacy {
|
|
|
155
163
|
*/
|
|
156
164
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
157
165
|
|
|
158
|
-
declare function isValidComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Determines whether inside `createElement`'s children.
|
|
162
|
-
* @param context The rule context
|
|
163
|
-
* @param node The AST node to check
|
|
164
|
-
* @returns `true` if the node is inside createElement's children
|
|
165
|
-
*/
|
|
166
|
-
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
167
|
-
/**
|
|
168
|
-
* Check whether given node is declared inside class component's render block
|
|
169
|
-
* ```tsx
|
|
170
|
-
* class Component extends React.Component {
|
|
171
|
-
* render() {
|
|
172
|
-
* class NestedClassComponent extends React.Component {
|
|
173
|
-
* render() { return <div />; }
|
|
174
|
-
* }
|
|
175
|
-
* const nestedFunctionComponent = () => <div />;
|
|
176
|
-
* }
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
* @param node The AST node being checked
|
|
180
|
-
* @returns `true` if node is inside class component's render block, `false` if not
|
|
181
|
-
*/
|
|
182
|
-
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
183
|
-
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
184
|
-
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
185
166
|
/**
|
|
186
167
|
* Check whether given node is a function of a render method of a class component
|
|
187
168
|
* @example
|
|
@@ -195,6 +176,7 @@ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
|
195
176
|
* @returns `true` if node is a render function, `false` if not
|
|
196
177
|
*/
|
|
197
178
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
179
|
+
declare function isValidComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
198
180
|
|
|
199
181
|
declare function getFunctionComponentId(context: RuleContext, node: AST.TSESTreeFunction): TSESTree.Identifier | TSESTree.Identifier[] | _;
|
|
200
182
|
|
|
@@ -366,9 +348,6 @@ declare namespace useHookCollector {
|
|
|
366
348
|
}
|
|
367
349
|
declare function useHookCollector(): useHookCollector.ReturnType;
|
|
368
350
|
|
|
369
|
-
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean;
|
|
370
|
-
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node | _): boolean;
|
|
371
|
-
|
|
372
351
|
declare function isReactHook(node: AST.TSESTreeFunction | _): boolean;
|
|
373
352
|
/**
|
|
374
353
|
* Check if the given node is a React Hook call by its name.
|
|
@@ -507,7 +486,7 @@ declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | n
|
|
|
507
486
|
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
508
487
|
|
|
509
488
|
/** @internal */
|
|
510
|
-
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.
|
|
489
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
|
|
511
490
|
|
|
512
491
|
/**
|
|
513
492
|
* Check if an identifier is initialized from react
|
|
@@ -562,4 +541,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
|
562
541
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
563
542
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
564
543
|
|
|
565
|
-
export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, type HookKind, JSXDetectionHint, type SemanticEntry, type SemanticNode, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement,
|
|
544
|
+
export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, type HookKind, JSXDetectionHint, type SemanticEntry, type SemanticNode, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var types = require('@typescript-eslint/types');
|
|
4
|
+
var AST14 = require('@eslint-react/ast');
|
|
4
5
|
var eff = require('@eslint-react/eff');
|
|
5
6
|
var kit = require('@eslint-react/kit');
|
|
6
7
|
var shared = require('@eslint-react/shared');
|
|
7
|
-
var types = require('@typescript-eslint/types');
|
|
8
8
|
var VAR3 = require('@eslint-react/var');
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
10
|
var birecord = require('birecord');
|
|
@@ -29,61 +29,16 @@ function _interopNamespace(e) {
|
|
|
29
29
|
return Object.freeze(n);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var AST14__namespace = /*#__PURE__*/_interopNamespace(AST14);
|
|
33
33
|
var VAR3__namespace = /*#__PURE__*/_interopNamespace(VAR3);
|
|
34
34
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
35
35
|
|
|
36
|
-
// src/component/component-
|
|
37
|
-
function getInstanceId(node, prev) {
|
|
38
|
-
switch (true) {
|
|
39
|
-
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
40
|
-
return node.id;
|
|
41
|
-
case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
42
|
-
return node.left;
|
|
43
|
-
case (node.type === types.AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
44
|
-
return node.key;
|
|
45
|
-
case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
|
|
46
|
-
return eff._;
|
|
47
|
-
default:
|
|
48
|
-
return getInstanceId(node.parent, node);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function getRequireExpressionArguments(node) {
|
|
52
|
-
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(() => null);
|
|
53
|
-
}
|
|
54
|
-
function isInitializedFromReact(name, importSource, initialScope) {
|
|
55
|
-
if (name.toLowerCase() === "react") return true;
|
|
56
|
-
const latestDef = VAR3__namespace.findVariable(name, initialScope)?.defs.at(-1);
|
|
57
|
-
if (latestDef == null) return false;
|
|
58
|
-
const { node, parent } = latestDef;
|
|
59
|
-
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
60
|
-
const { init } = node;
|
|
61
|
-
if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
|
|
62
|
-
return isInitializedFromReact(init.object.name, importSource, initialScope);
|
|
63
|
-
}
|
|
64
|
-
if (init.type === types.AST_NODE_TYPES.Identifier) {
|
|
65
|
-
return isInitializedFromReact(init.name, importSource, initialScope);
|
|
66
|
-
}
|
|
67
|
-
const args = getRequireExpressionArguments(init);
|
|
68
|
-
const arg0 = args?.[0];
|
|
69
|
-
if (arg0 == null || !AST9__namespace.isLiteral(arg0, "string")) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
73
|
-
}
|
|
74
|
-
return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
|
|
75
|
-
}
|
|
76
|
-
function isInstanceIdEqual(context, a, b) {
|
|
77
|
-
return AST9__namespace.isNodeEqual(a, b) || VAR3__namespace.isNodeValueEqual(a, b, [
|
|
78
|
-
context.sourceCode.getScope(a),
|
|
79
|
-
context.sourceCode.getScope(b)
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
36
|
+
// src/component/component-children.ts
|
|
82
37
|
function isReactAPI(api) {
|
|
83
38
|
const func = (context, node) => {
|
|
84
39
|
if (node == null) return false;
|
|
85
40
|
const getText = (n) => context.sourceCode.getText(n);
|
|
86
|
-
const name =
|
|
41
|
+
const name = AST14__namespace.toString(node, getText);
|
|
87
42
|
if (name === api) return true;
|
|
88
43
|
if (name.substring(name.indexOf(".") + 1) === api) return true;
|
|
89
44
|
return false;
|
|
@@ -125,6 +80,59 @@ var isForwardRefCall = isReactAPICall("forwardRef");
|
|
|
125
80
|
var isMemoCall = isReactAPICall("memo");
|
|
126
81
|
var isLazyCall = isReactAPICall("lazy");
|
|
127
82
|
|
|
83
|
+
// src/component/component-children.ts
|
|
84
|
+
function isChildrenOfCreateElement(context, node) {
|
|
85
|
+
const parent = node.parent;
|
|
86
|
+
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
87
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
88
|
+
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
89
|
+
}
|
|
90
|
+
function getInstanceId(node, prev) {
|
|
91
|
+
switch (true) {
|
|
92
|
+
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
93
|
+
return node.id;
|
|
94
|
+
case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
95
|
+
return node.left;
|
|
96
|
+
case (node.type === types.AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
97
|
+
return node.key;
|
|
98
|
+
case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
|
|
99
|
+
return eff._;
|
|
100
|
+
default:
|
|
101
|
+
return getInstanceId(node.parent, node);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function getRequireExpressionArguments(node) {
|
|
105
|
+
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(() => null);
|
|
106
|
+
}
|
|
107
|
+
function isInitializedFromReact(name, importSource, initialScope) {
|
|
108
|
+
if (name.toLowerCase() === "react") return true;
|
|
109
|
+
const latestDef = VAR3__namespace.findVariable(name, initialScope)?.defs.at(-1);
|
|
110
|
+
if (latestDef == null) return false;
|
|
111
|
+
const { node, parent } = latestDef;
|
|
112
|
+
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
113
|
+
const { init } = node;
|
|
114
|
+
if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
|
|
115
|
+
return isInitializedFromReact(init.object.name, importSource, initialScope);
|
|
116
|
+
}
|
|
117
|
+
if (init.type === types.AST_NODE_TYPES.Identifier) {
|
|
118
|
+
return isInitializedFromReact(init.name, importSource, initialScope);
|
|
119
|
+
}
|
|
120
|
+
const args = getRequireExpressionArguments(init);
|
|
121
|
+
const arg0 = args?.[0];
|
|
122
|
+
if (arg0 == null || !AST14__namespace.isLiteral(arg0, "string")) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
126
|
+
}
|
|
127
|
+
return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
|
|
128
|
+
}
|
|
129
|
+
function isInstanceIdEqual(context, a, b) {
|
|
130
|
+
return AST14__namespace.isNodeEqual(a, b) || VAR3__namespace.isNodeValueEqual(a, b, [
|
|
131
|
+
context.sourceCode.getScope(a),
|
|
132
|
+
context.sourceCode.getScope(b)
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
|
|
128
136
|
// src/hook/hook-name.ts
|
|
129
137
|
function isReactHookName(name) {
|
|
130
138
|
return name === "use" || /^use[A-Z0-9]/.test(name);
|
|
@@ -133,7 +141,7 @@ function isReactHookName(name) {
|
|
|
133
141
|
// src/hook/hook-is.ts
|
|
134
142
|
function isReactHook(node) {
|
|
135
143
|
if (node == null) return false;
|
|
136
|
-
const id =
|
|
144
|
+
const id = AST14__namespace.getFunctionId(node);
|
|
137
145
|
return id?.name != null && isReactHookName(id.name);
|
|
138
146
|
}
|
|
139
147
|
function isReactHookCall(node) {
|
|
@@ -236,7 +244,7 @@ function useHookCollector() {
|
|
|
236
244
|
const hooks = /* @__PURE__ */ new Map();
|
|
237
245
|
const functionEntries = [];
|
|
238
246
|
const onFunctionEnter = (node) => {
|
|
239
|
-
const id =
|
|
247
|
+
const id = AST14__namespace.getFunctionId(node);
|
|
240
248
|
const key = shared.getId();
|
|
241
249
|
const name = id?.name;
|
|
242
250
|
if (name != null && isReactHookName(name)) {
|
|
@@ -284,18 +292,6 @@ function useHookCollector() {
|
|
|
284
292
|
};
|
|
285
293
|
return { ctx, listeners };
|
|
286
294
|
}
|
|
287
|
-
function isFunctionOfUseEffectSetup(node) {
|
|
288
|
-
if (node == null) return false;
|
|
289
|
-
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);
|
|
290
|
-
}
|
|
291
|
-
function isFunctionOfUseEffectCleanup(node) {
|
|
292
|
-
if (node == null) return false;
|
|
293
|
-
const pReturn = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
294
|
-
const pFunction = AST9__namespace.findParentNode(node, AST9__namespace.isFunction);
|
|
295
|
-
const pFunctionOfReturn = AST9__namespace.findParentNode(pReturn, AST9__namespace.isFunction);
|
|
296
|
-
if (pFunction !== pFunctionOfReturn) return false;
|
|
297
|
-
return isFunctionOfUseEffectSetup(pFunction);
|
|
298
|
-
}
|
|
299
295
|
function stringifyJsx(node) {
|
|
300
296
|
switch (node.type) {
|
|
301
297
|
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
@@ -409,7 +405,7 @@ function isJsxText(node) {
|
|
|
409
405
|
}
|
|
410
406
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
411
407
|
if (node == null) return false;
|
|
412
|
-
if (
|
|
408
|
+
if (AST14__namespace.isJSX(node)) return true;
|
|
413
409
|
switch (node.type) {
|
|
414
410
|
case types.AST_NODE_TYPES.Literal: {
|
|
415
411
|
switch (typeof node.value) {
|
|
@@ -483,7 +479,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
483
479
|
if (name === "undefined") {
|
|
484
480
|
return !(hint & JSXDetectionHint.SkipUndefined);
|
|
485
481
|
}
|
|
486
|
-
if (
|
|
482
|
+
if (AST14__namespace.isJSXTagNameExpression(node)) {
|
|
487
483
|
return true;
|
|
488
484
|
}
|
|
489
485
|
const variable = VAR3__namespace.findVariable(name, code.getScope(node));
|
|
@@ -514,7 +510,7 @@ function findParentAttribute(node, test = eff.constTrue) {
|
|
|
514
510
|
const guard = (node2) => {
|
|
515
511
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
516
512
|
};
|
|
517
|
-
return
|
|
513
|
+
return AST14__namespace.findParentNode(node, guard);
|
|
518
514
|
}
|
|
519
515
|
function isHostElement(context, node) {
|
|
520
516
|
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
@@ -585,91 +581,8 @@ function isPureComponent(node) {
|
|
|
585
581
|
}
|
|
586
582
|
return false;
|
|
587
583
|
}
|
|
588
|
-
function isComponentDidCatch(node) {
|
|
589
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
590
|
-
}
|
|
591
|
-
function isComponentDidMount(node) {
|
|
592
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
593
|
-
}
|
|
594
|
-
function isComponentDidUpdate(node) {
|
|
595
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
596
|
-
}
|
|
597
|
-
function isComponentWillMount(node) {
|
|
598
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
599
|
-
}
|
|
600
|
-
function isComponentWillReceiveProps(node) {
|
|
601
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
602
|
-
}
|
|
603
|
-
function isComponentWillUnmount(node) {
|
|
604
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
605
|
-
}
|
|
606
|
-
function isComponentWillUpdate(node) {
|
|
607
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
608
|
-
}
|
|
609
|
-
function isGetChildContext(node) {
|
|
610
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
|
|
611
|
-
}
|
|
612
|
-
function isGetDefaultProps(node) {
|
|
613
|
-
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
|
|
614
|
-
}
|
|
615
|
-
function isGetInitialState(node) {
|
|
616
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
|
|
617
|
-
}
|
|
618
|
-
function isGetSnapshotBeforeUpdate(node) {
|
|
619
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
|
|
620
|
-
}
|
|
621
|
-
function isShouldComponentUpdate(node) {
|
|
622
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
623
|
-
}
|
|
624
|
-
function isUnsafeComponentWillMount(node) {
|
|
625
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
626
|
-
}
|
|
627
|
-
function isUnsafeComponentWillReceiveProps(node) {
|
|
628
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
629
|
-
}
|
|
630
|
-
function isUnsafeComponentWillUpdate(node) {
|
|
631
|
-
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
632
|
-
}
|
|
633
|
-
function isGetDerivedStateFromProps(node) {
|
|
634
|
-
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
635
|
-
}
|
|
636
|
-
function isGetDerivedStateFromError(node) {
|
|
637
|
-
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
638
|
-
}
|
|
639
|
-
function isRenderLike(node) {
|
|
640
|
-
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;
|
|
641
|
-
}
|
|
642
|
-
function isFunctionOfRender(node) {
|
|
643
|
-
if (!isRenderLike(node.parent)) {
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
return isClassComponent(node.parent.parent.parent);
|
|
647
|
-
}
|
|
648
584
|
function isRenderMethodLike(node) {
|
|
649
|
-
return
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/component/component-hierarchy.ts
|
|
653
|
-
function isChildrenOfCreateElement(context, node) {
|
|
654
|
-
const parent = node.parent;
|
|
655
|
-
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
656
|
-
if (!isCreateElementCall(context, parent)) return false;
|
|
657
|
-
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
658
|
-
}
|
|
659
|
-
function isInsideRenderMethod(node) {
|
|
660
|
-
return AST9__namespace.findParentNode(node, (n) => isRenderLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
661
|
-
}
|
|
662
|
-
function isFunctionOfComponentDidMount(node) {
|
|
663
|
-
return AST9__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
664
|
-
}
|
|
665
|
-
function isFunctionOfComponentWillUnmount(node) {
|
|
666
|
-
return AST9__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
667
|
-
}
|
|
668
|
-
function isFunctionOfRenderMethod(node) {
|
|
669
|
-
if (!isRenderMethodLike(node.parent)) {
|
|
670
|
-
return false;
|
|
671
|
-
}
|
|
672
|
-
return isClassComponent(node.parent.parent.parent);
|
|
585
|
+
return AST14__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
673
586
|
}
|
|
674
587
|
|
|
675
588
|
// src/component/component-definition.ts
|
|
@@ -690,6 +603,12 @@ var isFunctionOfObjectMethod = tsPattern.isMatching({
|
|
|
690
603
|
}
|
|
691
604
|
}
|
|
692
605
|
});
|
|
606
|
+
function isFunctionOfRenderMethod(node) {
|
|
607
|
+
if (!isRenderMethodLike(node.parent)) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
return isClassComponent(node.parent.parent.parent);
|
|
611
|
+
}
|
|
693
612
|
function isValidComponentDefinition(context, node, hint) {
|
|
694
613
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
695
614
|
return false;
|
|
@@ -703,12 +622,12 @@ function isValidComponentDefinition(context, node, hint) {
|
|
|
703
622
|
if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
704
623
|
return false;
|
|
705
624
|
}
|
|
706
|
-
if (hint & ComponentDetectionHint.SkipArrayMapArgument &&
|
|
625
|
+
if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST14__namespace.isArrayMapCall(node.parent)) {
|
|
707
626
|
return false;
|
|
708
627
|
}
|
|
709
|
-
const significantParent =
|
|
628
|
+
const significantParent = AST14__namespace.findParentNode(
|
|
710
629
|
node,
|
|
711
|
-
|
|
630
|
+
AST14__namespace.isOneOf([
|
|
712
631
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
713
632
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
714
633
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -729,7 +648,7 @@ function isComponentWrapperCallLoose(context, node) {
|
|
|
729
648
|
|
|
730
649
|
// src/component/component-id.ts
|
|
731
650
|
function getFunctionComponentId(context, node) {
|
|
732
|
-
const functionId =
|
|
651
|
+
const functionId = AST14__namespace.getFunctionId(node);
|
|
733
652
|
if (functionId != null) {
|
|
734
653
|
return functionId;
|
|
735
654
|
}
|
|
@@ -756,10 +675,10 @@ var ComponentFlag = {
|
|
|
756
675
|
// src/component/component-init-path.ts
|
|
757
676
|
function getComponentFlagFromInitPath(initPath) {
|
|
758
677
|
let flag = ComponentFlag.None;
|
|
759
|
-
if (initPath != null &&
|
|
678
|
+
if (initPath != null && AST14__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
760
679
|
flag |= ComponentFlag.Memo;
|
|
761
680
|
}
|
|
762
|
-
if (initPath != null &&
|
|
681
|
+
if (initPath != null && AST14__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
763
682
|
flag |= ComponentFlag.ForwardRef;
|
|
764
683
|
}
|
|
765
684
|
return flag;
|
|
@@ -799,7 +718,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
799
718
|
const entry = functionEntries.at(-1);
|
|
800
719
|
if (entry == null) return;
|
|
801
720
|
if (!entry.isComponent) return functionEntries.pop();
|
|
802
|
-
const shouldDrop =
|
|
721
|
+
const shouldDrop = AST14__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
803
722
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !isJsxLike(context.sourceCode, r.argument, hint);
|
|
804
723
|
});
|
|
805
724
|
if (shouldDrop) {
|
|
@@ -826,7 +745,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
826
745
|
const { body } = entry.node;
|
|
827
746
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
828
747
|
if (!isComponent) return;
|
|
829
|
-
const initPath =
|
|
748
|
+
const initPath = AST14__namespace.getFunctionInitPath(entry.node);
|
|
830
749
|
const id = getFunctionComponentId(context, entry.node);
|
|
831
750
|
const name = getComponentNameFromId(id);
|
|
832
751
|
const key = shared.getId();
|
|
@@ -867,7 +786,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
867
786
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
868
787
|
if (!isComponent) return;
|
|
869
788
|
entry.isComponent = true;
|
|
870
|
-
const initPath =
|
|
789
|
+
const initPath = AST14__namespace.getFunctionInitPath(entry.node);
|
|
871
790
|
const id = getFunctionComponentId(context, entry.node);
|
|
872
791
|
const name = getComponentNameFromId(id);
|
|
873
792
|
components.set(entry.key, {
|
|
@@ -898,7 +817,7 @@ function useComponentCollectorLegacy() {
|
|
|
898
817
|
if (!isClassComponent(node)) {
|
|
899
818
|
return;
|
|
900
819
|
}
|
|
901
|
-
const id =
|
|
820
|
+
const id = AST14__namespace.getClassId(node);
|
|
902
821
|
const key = shared.getId();
|
|
903
822
|
const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
|
|
904
823
|
components.set(
|
|
@@ -924,14 +843,74 @@ function useComponentCollectorLegacy() {
|
|
|
924
843
|
};
|
|
925
844
|
return { ctx, listeners };
|
|
926
845
|
}
|
|
846
|
+
function isComponentDidCatch(node) {
|
|
847
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
848
|
+
}
|
|
849
|
+
function isComponentDidMount(node) {
|
|
850
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
851
|
+
}
|
|
852
|
+
function isComponentDidUpdate(node) {
|
|
853
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
854
|
+
}
|
|
855
|
+
function isComponentWillMount(node) {
|
|
856
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
857
|
+
}
|
|
858
|
+
function isComponentWillReceiveProps(node) {
|
|
859
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
860
|
+
}
|
|
861
|
+
function isComponentWillUnmount(node) {
|
|
862
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
863
|
+
}
|
|
864
|
+
function isComponentWillUpdate(node) {
|
|
865
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
866
|
+
}
|
|
867
|
+
function isGetChildContext(node) {
|
|
868
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
|
|
869
|
+
}
|
|
870
|
+
function isGetDefaultProps(node) {
|
|
871
|
+
return AST14__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
|
|
872
|
+
}
|
|
873
|
+
function isGetInitialState(node) {
|
|
874
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
|
|
875
|
+
}
|
|
876
|
+
function isGetSnapshotBeforeUpdate(node) {
|
|
877
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
|
|
878
|
+
}
|
|
879
|
+
function isShouldComponentUpdate(node) {
|
|
880
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
881
|
+
}
|
|
882
|
+
function isUnsafeComponentWillMount(node) {
|
|
883
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
884
|
+
}
|
|
885
|
+
function isUnsafeComponentWillReceiveProps(node) {
|
|
886
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
887
|
+
}
|
|
888
|
+
function isUnsafeComponentWillUpdate(node) {
|
|
889
|
+
return AST14__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
890
|
+
}
|
|
891
|
+
function isGetDerivedStateFromProps(node) {
|
|
892
|
+
return AST14__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
893
|
+
}
|
|
894
|
+
function isGetDerivedStateFromError(node) {
|
|
895
|
+
return AST14__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
896
|
+
}
|
|
927
897
|
var ComponentPhaseRelevance = birecord__default.default({
|
|
928
898
|
mount: "unmount",
|
|
929
899
|
setup: "cleanup"
|
|
930
900
|
});
|
|
931
901
|
var isInversePhase = eff.dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
|
|
902
|
+
function isRenderLike(node) {
|
|
903
|
+
return AST14__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
904
|
+
}
|
|
905
|
+
function isFunctionOfRender(node) {
|
|
906
|
+
if (!isRenderLike(node.parent)) {
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
return isClassComponent(node.parent.parent.parent);
|
|
910
|
+
}
|
|
932
911
|
function isRenderFunctionLoose(context, node) {
|
|
933
912
|
const { body, parent } = node;
|
|
934
|
-
if (
|
|
913
|
+
if (AST14__namespace.getFunctionId(node)?.name.startsWith("render")) {
|
|
935
914
|
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");
|
|
936
915
|
}
|
|
937
916
|
return isJsxLike(
|
|
@@ -944,7 +923,7 @@ function isRenderPropLoose(context, node) {
|
|
|
944
923
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
945
924
|
return false;
|
|
946
925
|
}
|
|
947
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
926
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST14__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
948
927
|
}
|
|
949
928
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
950
929
|
const matching = (node2) => {
|
|
@@ -956,7 +935,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
956
935
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
957
936
|
return true;
|
|
958
937
|
}
|
|
959
|
-
const parent =
|
|
938
|
+
const parent = AST14__namespace.findParentNode(node, AST14__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
960
939
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
961
940
|
return false;
|
|
962
941
|
}
|
|
@@ -964,11 +943,11 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
964
943
|
}
|
|
965
944
|
function isThisSetState(node) {
|
|
966
945
|
const { callee } = node;
|
|
967
|
-
return callee.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
946
|
+
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST14__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
968
947
|
}
|
|
969
948
|
function isAssignmentToThisState(node) {
|
|
970
949
|
const { left } = node;
|
|
971
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
950
|
+
return left.type === types.AST_NODE_TYPES.MemberExpression && AST14__namespace.isThisExpression(left.object) && AST14__namespace.getPropertyName(left.property) === "state";
|
|
972
951
|
}
|
|
973
952
|
|
|
974
953
|
exports.ComponentDetectionHint = ComponentDetectionHint;
|
|
@@ -1029,12 +1008,8 @@ exports.isDirectValueOfRenderPropertyLoose = isDirectValueOfRenderPropertyLoose;
|
|
|
1029
1008
|
exports.isForwardRef = isForwardRef;
|
|
1030
1009
|
exports.isForwardRefCall = isForwardRefCall;
|
|
1031
1010
|
exports.isFragmentElement = isFragmentElement;
|
|
1032
|
-
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
1033
|
-
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
1034
1011
|
exports.isFunctionOfRender = isFunctionOfRender;
|
|
1035
1012
|
exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
|
|
1036
|
-
exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
|
|
1037
|
-
exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
|
|
1038
1013
|
exports.isGetChildContext = isGetChildContext;
|
|
1039
1014
|
exports.isGetDefaultProps = isGetDefaultProps;
|
|
1040
1015
|
exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
|
|
@@ -1043,7 +1018,6 @@ exports.isGetInitialState = isGetInitialState;
|
|
|
1043
1018
|
exports.isGetSnapshotBeforeUpdate = isGetSnapshotBeforeUpdate;
|
|
1044
1019
|
exports.isHostElement = isHostElement;
|
|
1045
1020
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
1046
|
-
exports.isInsideRenderMethod = isInsideRenderMethod;
|
|
1047
1021
|
exports.isInstanceIdEqual = isInstanceIdEqual;
|
|
1048
1022
|
exports.isInversePhase = isInversePhase;
|
|
1049
1023
|
exports.isJsxLike = isJsxLike;
|
package/dist/index.mjs
CHANGED
|
@@ -1,63 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
|
+
import * as AST14 from '@eslint-react/ast';
|
|
2
3
|
import { flip, dual, constFalse, identity, constTrue, _ } from '@eslint-react/eff';
|
|
3
4
|
import { RegExp, Selector } from '@eslint-react/kit';
|
|
4
5
|
import { coerceSettings, DEFAULT_ESLINT_REACT_SETTINGS, getId } from '@eslint-react/shared';
|
|
5
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
6
6
|
import * as VAR3 from '@eslint-react/var';
|
|
7
7
|
import { isMatching, P, match } from 'ts-pattern';
|
|
8
8
|
import birecord from 'birecord';
|
|
9
9
|
|
|
10
|
-
// src/component/component-
|
|
11
|
-
function getInstanceId(node, prev) {
|
|
12
|
-
switch (true) {
|
|
13
|
-
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
14
|
-
return node.id;
|
|
15
|
-
case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
16
|
-
return node.left;
|
|
17
|
-
case (node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
18
|
-
return node.key;
|
|
19
|
-
case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
|
|
20
|
-
return _;
|
|
21
|
-
default:
|
|
22
|
-
return getInstanceId(node.parent, node);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function getRequireExpressionArguments(node) {
|
|
26
|
-
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(() => null);
|
|
27
|
-
}
|
|
28
|
-
function isInitializedFromReact(name, importSource, initialScope) {
|
|
29
|
-
if (name.toLowerCase() === "react") return true;
|
|
30
|
-
const latestDef = VAR3.findVariable(name, initialScope)?.defs.at(-1);
|
|
31
|
-
if (latestDef == null) return false;
|
|
32
|
-
const { node, parent } = latestDef;
|
|
33
|
-
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
34
|
-
const { init } = node;
|
|
35
|
-
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
|
|
36
|
-
return isInitializedFromReact(init.object.name, importSource, initialScope);
|
|
37
|
-
}
|
|
38
|
-
if (init.type === AST_NODE_TYPES.Identifier) {
|
|
39
|
-
return isInitializedFromReact(init.name, importSource, initialScope);
|
|
40
|
-
}
|
|
41
|
-
const args = getRequireExpressionArguments(init);
|
|
42
|
-
const arg0 = args?.[0];
|
|
43
|
-
if (arg0 == null || !AST9.isLiteral(arg0, "string")) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
47
|
-
}
|
|
48
|
-
return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
|
|
49
|
-
}
|
|
50
|
-
function isInstanceIdEqual(context, a, b) {
|
|
51
|
-
return AST9.isNodeEqual(a, b) || VAR3.isNodeValueEqual(a, b, [
|
|
52
|
-
context.sourceCode.getScope(a),
|
|
53
|
-
context.sourceCode.getScope(b)
|
|
54
|
-
]);
|
|
55
|
-
}
|
|
10
|
+
// src/component/component-children.ts
|
|
56
11
|
function isReactAPI(api) {
|
|
57
12
|
const func = (context, node) => {
|
|
58
13
|
if (node == null) return false;
|
|
59
14
|
const getText = (n) => context.sourceCode.getText(n);
|
|
60
|
-
const name =
|
|
15
|
+
const name = AST14.toString(node, getText);
|
|
61
16
|
if (name === api) return true;
|
|
62
17
|
if (name.substring(name.indexOf(".") + 1) === api) return true;
|
|
63
18
|
return false;
|
|
@@ -99,6 +54,59 @@ var isForwardRefCall = isReactAPICall("forwardRef");
|
|
|
99
54
|
var isMemoCall = isReactAPICall("memo");
|
|
100
55
|
var isLazyCall = isReactAPICall("lazy");
|
|
101
56
|
|
|
57
|
+
// src/component/component-children.ts
|
|
58
|
+
function isChildrenOfCreateElement(context, node) {
|
|
59
|
+
const parent = node.parent;
|
|
60
|
+
if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
61
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
62
|
+
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
63
|
+
}
|
|
64
|
+
function getInstanceId(node, prev) {
|
|
65
|
+
switch (true) {
|
|
66
|
+
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
67
|
+
return node.id;
|
|
68
|
+
case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
69
|
+
return node.left;
|
|
70
|
+
case (node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
71
|
+
return node.key;
|
|
72
|
+
case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
|
|
73
|
+
return _;
|
|
74
|
+
default:
|
|
75
|
+
return getInstanceId(node.parent, node);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getRequireExpressionArguments(node) {
|
|
79
|
+
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(() => null);
|
|
80
|
+
}
|
|
81
|
+
function isInitializedFromReact(name, importSource, initialScope) {
|
|
82
|
+
if (name.toLowerCase() === "react") return true;
|
|
83
|
+
const latestDef = VAR3.findVariable(name, initialScope)?.defs.at(-1);
|
|
84
|
+
if (latestDef == null) return false;
|
|
85
|
+
const { node, parent } = latestDef;
|
|
86
|
+
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
87
|
+
const { init } = node;
|
|
88
|
+
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
|
|
89
|
+
return isInitializedFromReact(init.object.name, importSource, initialScope);
|
|
90
|
+
}
|
|
91
|
+
if (init.type === AST_NODE_TYPES.Identifier) {
|
|
92
|
+
return isInitializedFromReact(init.name, importSource, initialScope);
|
|
93
|
+
}
|
|
94
|
+
const args = getRequireExpressionArguments(init);
|
|
95
|
+
const arg0 = args?.[0];
|
|
96
|
+
if (arg0 == null || !AST14.isLiteral(arg0, "string")) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
100
|
+
}
|
|
101
|
+
return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
|
|
102
|
+
}
|
|
103
|
+
function isInstanceIdEqual(context, a, b) {
|
|
104
|
+
return AST14.isNodeEqual(a, b) || VAR3.isNodeValueEqual(a, b, [
|
|
105
|
+
context.sourceCode.getScope(a),
|
|
106
|
+
context.sourceCode.getScope(b)
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
102
110
|
// src/hook/hook-name.ts
|
|
103
111
|
function isReactHookName(name) {
|
|
104
112
|
return name === "use" || /^use[A-Z0-9]/.test(name);
|
|
@@ -107,7 +115,7 @@ function isReactHookName(name) {
|
|
|
107
115
|
// src/hook/hook-is.ts
|
|
108
116
|
function isReactHook(node) {
|
|
109
117
|
if (node == null) return false;
|
|
110
|
-
const id =
|
|
118
|
+
const id = AST14.getFunctionId(node);
|
|
111
119
|
return id?.name != null && isReactHookName(id.name);
|
|
112
120
|
}
|
|
113
121
|
function isReactHookCall(node) {
|
|
@@ -210,7 +218,7 @@ function useHookCollector() {
|
|
|
210
218
|
const hooks = /* @__PURE__ */ new Map();
|
|
211
219
|
const functionEntries = [];
|
|
212
220
|
const onFunctionEnter = (node) => {
|
|
213
|
-
const id =
|
|
221
|
+
const id = AST14.getFunctionId(node);
|
|
214
222
|
const key = getId();
|
|
215
223
|
const name = id?.name;
|
|
216
224
|
if (name != null && isReactHookName(name)) {
|
|
@@ -258,18 +266,6 @@ function useHookCollector() {
|
|
|
258
266
|
};
|
|
259
267
|
return { ctx, listeners };
|
|
260
268
|
}
|
|
261
|
-
function isFunctionOfUseEffectSetup(node) {
|
|
262
|
-
if (node == null) return false;
|
|
263
|
-
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);
|
|
264
|
-
}
|
|
265
|
-
function isFunctionOfUseEffectCleanup(node) {
|
|
266
|
-
if (node == null) return false;
|
|
267
|
-
const pReturn = AST9.findParentNode(node, AST9.is(AST_NODE_TYPES.ReturnStatement));
|
|
268
|
-
const pFunction = AST9.findParentNode(node, AST9.isFunction);
|
|
269
|
-
const pFunctionOfReturn = AST9.findParentNode(pReturn, AST9.isFunction);
|
|
270
|
-
if (pFunction !== pFunctionOfReturn) return false;
|
|
271
|
-
return isFunctionOfUseEffectSetup(pFunction);
|
|
272
|
-
}
|
|
273
269
|
function stringifyJsx(node) {
|
|
274
270
|
switch (node.type) {
|
|
275
271
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
@@ -383,7 +379,7 @@ function isJsxText(node) {
|
|
|
383
379
|
}
|
|
384
380
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
385
381
|
if (node == null) return false;
|
|
386
|
-
if (
|
|
382
|
+
if (AST14.isJSX(node)) return true;
|
|
387
383
|
switch (node.type) {
|
|
388
384
|
case AST_NODE_TYPES.Literal: {
|
|
389
385
|
switch (typeof node.value) {
|
|
@@ -457,7 +453,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
457
453
|
if (name === "undefined") {
|
|
458
454
|
return !(hint & JSXDetectionHint.SkipUndefined);
|
|
459
455
|
}
|
|
460
|
-
if (
|
|
456
|
+
if (AST14.isJSXTagNameExpression(node)) {
|
|
461
457
|
return true;
|
|
462
458
|
}
|
|
463
459
|
const variable = VAR3.findVariable(name, code.getScope(node));
|
|
@@ -488,7 +484,7 @@ function findParentAttribute(node, test = constTrue) {
|
|
|
488
484
|
const guard = (node2) => {
|
|
489
485
|
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
490
486
|
};
|
|
491
|
-
return
|
|
487
|
+
return AST14.findParentNode(node, guard);
|
|
492
488
|
}
|
|
493
489
|
function isHostElement(context, node) {
|
|
494
490
|
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
@@ -559,91 +555,8 @@ function isPureComponent(node) {
|
|
|
559
555
|
}
|
|
560
556
|
return false;
|
|
561
557
|
}
|
|
562
|
-
function isComponentDidCatch(node) {
|
|
563
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
564
|
-
}
|
|
565
|
-
function isComponentDidMount(node) {
|
|
566
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
567
|
-
}
|
|
568
|
-
function isComponentDidUpdate(node) {
|
|
569
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
570
|
-
}
|
|
571
|
-
function isComponentWillMount(node) {
|
|
572
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
573
|
-
}
|
|
574
|
-
function isComponentWillReceiveProps(node) {
|
|
575
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
576
|
-
}
|
|
577
|
-
function isComponentWillUnmount(node) {
|
|
578
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
579
|
-
}
|
|
580
|
-
function isComponentWillUpdate(node) {
|
|
581
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
582
|
-
}
|
|
583
|
-
function isGetChildContext(node) {
|
|
584
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
|
|
585
|
-
}
|
|
586
|
-
function isGetDefaultProps(node) {
|
|
587
|
-
return AST9.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
|
|
588
|
-
}
|
|
589
|
-
function isGetInitialState(node) {
|
|
590
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
|
|
591
|
-
}
|
|
592
|
-
function isGetSnapshotBeforeUpdate(node) {
|
|
593
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
|
|
594
|
-
}
|
|
595
|
-
function isShouldComponentUpdate(node) {
|
|
596
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
597
|
-
}
|
|
598
|
-
function isUnsafeComponentWillMount(node) {
|
|
599
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
600
|
-
}
|
|
601
|
-
function isUnsafeComponentWillReceiveProps(node) {
|
|
602
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
603
|
-
}
|
|
604
|
-
function isUnsafeComponentWillUpdate(node) {
|
|
605
|
-
return AST9.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
606
|
-
}
|
|
607
|
-
function isGetDerivedStateFromProps(node) {
|
|
608
|
-
return AST9.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
609
|
-
}
|
|
610
|
-
function isGetDerivedStateFromError(node) {
|
|
611
|
-
return AST9.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
612
|
-
}
|
|
613
|
-
function isRenderLike(node) {
|
|
614
|
-
return AST9.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
615
|
-
}
|
|
616
|
-
function isFunctionOfRender(node) {
|
|
617
|
-
if (!isRenderLike(node.parent)) {
|
|
618
|
-
return false;
|
|
619
|
-
}
|
|
620
|
-
return isClassComponent(node.parent.parent.parent);
|
|
621
|
-
}
|
|
622
558
|
function isRenderMethodLike(node) {
|
|
623
|
-
return
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// src/component/component-hierarchy.ts
|
|
627
|
-
function isChildrenOfCreateElement(context, node) {
|
|
628
|
-
const parent = node.parent;
|
|
629
|
-
if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
630
|
-
if (!isCreateElementCall(context, parent)) return false;
|
|
631
|
-
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
632
|
-
}
|
|
633
|
-
function isInsideRenderMethod(node) {
|
|
634
|
-
return AST9.findParentNode(node, (n) => isRenderLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
635
|
-
}
|
|
636
|
-
function isFunctionOfComponentDidMount(node) {
|
|
637
|
-
return AST9.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
638
|
-
}
|
|
639
|
-
function isFunctionOfComponentWillUnmount(node) {
|
|
640
|
-
return AST9.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
641
|
-
}
|
|
642
|
-
function isFunctionOfRenderMethod(node) {
|
|
643
|
-
if (!isRenderMethodLike(node.parent)) {
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
return isClassComponent(node.parent.parent.parent);
|
|
559
|
+
return AST14.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
647
560
|
}
|
|
648
561
|
|
|
649
562
|
// src/component/component-definition.ts
|
|
@@ -664,6 +577,12 @@ var isFunctionOfObjectMethod = isMatching({
|
|
|
664
577
|
}
|
|
665
578
|
}
|
|
666
579
|
});
|
|
580
|
+
function isFunctionOfRenderMethod(node) {
|
|
581
|
+
if (!isRenderMethodLike(node.parent)) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
return isClassComponent(node.parent.parent.parent);
|
|
585
|
+
}
|
|
667
586
|
function isValidComponentDefinition(context, node, hint) {
|
|
668
587
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
669
588
|
return false;
|
|
@@ -677,12 +596,12 @@ function isValidComponentDefinition(context, node, hint) {
|
|
|
677
596
|
if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
678
597
|
return false;
|
|
679
598
|
}
|
|
680
|
-
if (hint & ComponentDetectionHint.SkipArrayMapArgument &&
|
|
599
|
+
if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST14.isArrayMapCall(node.parent)) {
|
|
681
600
|
return false;
|
|
682
601
|
}
|
|
683
|
-
const significantParent =
|
|
602
|
+
const significantParent = AST14.findParentNode(
|
|
684
603
|
node,
|
|
685
|
-
|
|
604
|
+
AST14.isOneOf([
|
|
686
605
|
AST_NODE_TYPES.JSXExpressionContainer,
|
|
687
606
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
688
607
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -703,7 +622,7 @@ function isComponentWrapperCallLoose(context, node) {
|
|
|
703
622
|
|
|
704
623
|
// src/component/component-id.ts
|
|
705
624
|
function getFunctionComponentId(context, node) {
|
|
706
|
-
const functionId =
|
|
625
|
+
const functionId = AST14.getFunctionId(node);
|
|
707
626
|
if (functionId != null) {
|
|
708
627
|
return functionId;
|
|
709
628
|
}
|
|
@@ -730,10 +649,10 @@ var ComponentFlag = {
|
|
|
730
649
|
// src/component/component-init-path.ts
|
|
731
650
|
function getComponentFlagFromInitPath(initPath) {
|
|
732
651
|
let flag = ComponentFlag.None;
|
|
733
|
-
if (initPath != null &&
|
|
652
|
+
if (initPath != null && AST14.hasCallInFunctionInitPath("memo", initPath)) {
|
|
734
653
|
flag |= ComponentFlag.Memo;
|
|
735
654
|
}
|
|
736
|
-
if (initPath != null &&
|
|
655
|
+
if (initPath != null && AST14.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
737
656
|
flag |= ComponentFlag.ForwardRef;
|
|
738
657
|
}
|
|
739
658
|
return flag;
|
|
@@ -773,7 +692,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
773
692
|
const entry = functionEntries.at(-1);
|
|
774
693
|
if (entry == null) return;
|
|
775
694
|
if (!entry.isComponent) return functionEntries.pop();
|
|
776
|
-
const shouldDrop =
|
|
695
|
+
const shouldDrop = AST14.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
777
696
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !isJsxLike(context.sourceCode, r.argument, hint);
|
|
778
697
|
});
|
|
779
698
|
if (shouldDrop) {
|
|
@@ -800,7 +719,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
800
719
|
const { body } = entry.node;
|
|
801
720
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
802
721
|
if (!isComponent) return;
|
|
803
|
-
const initPath =
|
|
722
|
+
const initPath = AST14.getFunctionInitPath(entry.node);
|
|
804
723
|
const id = getFunctionComponentId(context, entry.node);
|
|
805
724
|
const name = getComponentNameFromId(id);
|
|
806
725
|
const key = getId();
|
|
@@ -841,7 +760,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
841
760
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
842
761
|
if (!isComponent) return;
|
|
843
762
|
entry.isComponent = true;
|
|
844
|
-
const initPath =
|
|
763
|
+
const initPath = AST14.getFunctionInitPath(entry.node);
|
|
845
764
|
const id = getFunctionComponentId(context, entry.node);
|
|
846
765
|
const name = getComponentNameFromId(id);
|
|
847
766
|
components.set(entry.key, {
|
|
@@ -872,7 +791,7 @@ function useComponentCollectorLegacy() {
|
|
|
872
791
|
if (!isClassComponent(node)) {
|
|
873
792
|
return;
|
|
874
793
|
}
|
|
875
|
-
const id =
|
|
794
|
+
const id = AST14.getClassId(node);
|
|
876
795
|
const key = getId();
|
|
877
796
|
const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
|
|
878
797
|
components.set(
|
|
@@ -898,14 +817,74 @@ function useComponentCollectorLegacy() {
|
|
|
898
817
|
};
|
|
899
818
|
return { ctx, listeners };
|
|
900
819
|
}
|
|
820
|
+
function isComponentDidCatch(node) {
|
|
821
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
822
|
+
}
|
|
823
|
+
function isComponentDidMount(node) {
|
|
824
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
825
|
+
}
|
|
826
|
+
function isComponentDidUpdate(node) {
|
|
827
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
828
|
+
}
|
|
829
|
+
function isComponentWillMount(node) {
|
|
830
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
831
|
+
}
|
|
832
|
+
function isComponentWillReceiveProps(node) {
|
|
833
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
834
|
+
}
|
|
835
|
+
function isComponentWillUnmount(node) {
|
|
836
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
837
|
+
}
|
|
838
|
+
function isComponentWillUpdate(node) {
|
|
839
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
840
|
+
}
|
|
841
|
+
function isGetChildContext(node) {
|
|
842
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
|
|
843
|
+
}
|
|
844
|
+
function isGetDefaultProps(node) {
|
|
845
|
+
return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
|
|
846
|
+
}
|
|
847
|
+
function isGetInitialState(node) {
|
|
848
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
|
|
849
|
+
}
|
|
850
|
+
function isGetSnapshotBeforeUpdate(node) {
|
|
851
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
|
|
852
|
+
}
|
|
853
|
+
function isShouldComponentUpdate(node) {
|
|
854
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
855
|
+
}
|
|
856
|
+
function isUnsafeComponentWillMount(node) {
|
|
857
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
858
|
+
}
|
|
859
|
+
function isUnsafeComponentWillReceiveProps(node) {
|
|
860
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
861
|
+
}
|
|
862
|
+
function isUnsafeComponentWillUpdate(node) {
|
|
863
|
+
return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
864
|
+
}
|
|
865
|
+
function isGetDerivedStateFromProps(node) {
|
|
866
|
+
return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
867
|
+
}
|
|
868
|
+
function isGetDerivedStateFromError(node) {
|
|
869
|
+
return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
870
|
+
}
|
|
901
871
|
var ComponentPhaseRelevance = birecord({
|
|
902
872
|
mount: "unmount",
|
|
903
873
|
setup: "cleanup"
|
|
904
874
|
});
|
|
905
875
|
var isInversePhase = dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
|
|
876
|
+
function isRenderLike(node) {
|
|
877
|
+
return AST14.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
878
|
+
}
|
|
879
|
+
function isFunctionOfRender(node) {
|
|
880
|
+
if (!isRenderLike(node.parent)) {
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
return isClassComponent(node.parent.parent.parent);
|
|
884
|
+
}
|
|
906
885
|
function isRenderFunctionLoose(context, node) {
|
|
907
886
|
const { body, parent } = node;
|
|
908
|
-
if (
|
|
887
|
+
if (AST14.getFunctionId(node)?.name.startsWith("render")) {
|
|
909
888
|
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");
|
|
910
889
|
}
|
|
911
890
|
return isJsxLike(
|
|
@@ -918,7 +897,7 @@ function isRenderPropLoose(context, node) {
|
|
|
918
897
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
919
898
|
return false;
|
|
920
899
|
}
|
|
921
|
-
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer &&
|
|
900
|
+
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST14.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
922
901
|
}
|
|
923
902
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
924
903
|
const matching = (node2) => {
|
|
@@ -930,7 +909,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
930
909
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
931
910
|
return true;
|
|
932
911
|
}
|
|
933
|
-
const parent =
|
|
912
|
+
const parent = AST14.findParentNode(node, AST14.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
934
913
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
935
914
|
return false;
|
|
936
915
|
}
|
|
@@ -938,11 +917,11 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
938
917
|
}
|
|
939
918
|
function isThisSetState(node) {
|
|
940
919
|
const { callee } = node;
|
|
941
|
-
return callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
920
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && AST14.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
942
921
|
}
|
|
943
922
|
function isAssignmentToThisState(node) {
|
|
944
923
|
const { left } = node;
|
|
945
|
-
return left.type === AST_NODE_TYPES.MemberExpression &&
|
|
924
|
+
return left.type === AST_NODE_TYPES.MemberExpression && AST14.isThisExpression(left.object) && AST14.getPropertyName(left.property) === "state";
|
|
946
925
|
}
|
|
947
926
|
|
|
948
|
-
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement,
|
|
927
|
+
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.30.1",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.7.0",
|
|
44
|
-
"@eslint-react/ast": "
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "2.0.0-next.0",
|
|
45
|
+
"@eslint-react/kit": "2.0.0-next.0",
|
|
46
|
+
"@eslint-react/eff": "2.0.0-next.0",
|
|
47
|
+
"@eslint-react/shared": "2.0.0-next.0",
|
|
48
|
+
"@eslint-react/var": "2.0.0-next.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.4.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"bun": ">=1.0.15",
|
|
56
|
-
"node": ">=
|
|
56
|
+
"node": ">=20.19.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|