@eslint-react/core 2.7.4-next.2 → 2.7.4-next.4
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.ts +74 -100
- package/dist/index.js +91 -133
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,84 @@
|
|
|
1
1
|
import * as AST from "@eslint-react/ast";
|
|
2
2
|
import { unit } from "@eslint-react/eff";
|
|
3
|
-
import { RegExpLike, RuleContext } from "@eslint-react/shared";
|
|
4
3
|
import { TSESTree } from "@typescript-eslint/types";
|
|
4
|
+
import { RegExpLike, RuleContext } from "@eslint-react/shared";
|
|
5
5
|
import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
6
6
|
import * as birecord0 from "birecord";
|
|
7
7
|
import { Scope } from "@typescript-eslint/scope-manager";
|
|
8
8
|
import * as typescript0 from "typescript";
|
|
9
9
|
|
|
10
|
+
//#region src/api/is-from-react.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a variable is initialized from React import
|
|
13
|
+
* @param name The variable name
|
|
14
|
+
* @param initialScope The initial scope
|
|
15
|
+
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
16
|
+
* @returns True if the variable is initialized from React import
|
|
17
|
+
*/
|
|
18
|
+
declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/api/is-from-react-native.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a variable is initialized from React Native import
|
|
23
|
+
* @param name The variable name
|
|
24
|
+
* @param initialScope The initial scope
|
|
25
|
+
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
26
|
+
* @returns True if the variable is initialized from React Native import
|
|
27
|
+
*/
|
|
28
|
+
declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/api/is-react-api.d.ts
|
|
31
|
+
declare namespace isReactAPI {
|
|
32
|
+
type ReturnType = {
|
|
33
|
+
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
34
|
+
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the node is a React API identifier or member expression
|
|
39
|
+
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
40
|
+
* @returns A predicate function to check if a node matches the API
|
|
41
|
+
*/
|
|
42
|
+
declare function isReactAPI(api: string): isReactAPI.ReturnType;
|
|
43
|
+
declare namespace isReactAPICall {
|
|
44
|
+
type ReturnType = {
|
|
45
|
+
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression;
|
|
46
|
+
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks if the node is a call expression to a specific React API
|
|
51
|
+
* @param api The React API name to check against
|
|
52
|
+
* @returns A predicate function to check if a node is a call to the API
|
|
53
|
+
*/
|
|
54
|
+
declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
|
|
55
|
+
declare const isCaptureOwnerStack: isReactAPI.ReturnType;
|
|
56
|
+
declare const isChildrenCount: isReactAPI.ReturnType;
|
|
57
|
+
declare const isChildrenForEach: isReactAPI.ReturnType;
|
|
58
|
+
declare const isChildrenMap: isReactAPI.ReturnType;
|
|
59
|
+
declare const isChildrenOnly: isReactAPI.ReturnType;
|
|
60
|
+
declare const isChildrenToArray: isReactAPI.ReturnType;
|
|
61
|
+
declare const isCloneElement: isReactAPI.ReturnType;
|
|
62
|
+
declare const isCreateContext: isReactAPI.ReturnType;
|
|
63
|
+
declare const isCreateElement: isReactAPI.ReturnType;
|
|
64
|
+
declare const isCreateRef: isReactAPI.ReturnType;
|
|
65
|
+
declare const isForwardRef: isReactAPI.ReturnType;
|
|
66
|
+
declare const isMemo: isReactAPI.ReturnType;
|
|
67
|
+
declare const isLazy: isReactAPI.ReturnType;
|
|
68
|
+
declare const isCaptureOwnerStackCall: isReactAPICall.ReturnType;
|
|
69
|
+
declare const isChildrenCountCall: isReactAPICall.ReturnType;
|
|
70
|
+
declare const isChildrenForEachCall: isReactAPICall.ReturnType;
|
|
71
|
+
declare const isChildrenMapCall: isReactAPICall.ReturnType;
|
|
72
|
+
declare const isChildrenOnlyCall: isReactAPICall.ReturnType;
|
|
73
|
+
declare const isChildrenToArrayCall: isReactAPICall.ReturnType;
|
|
74
|
+
declare const isCloneElementCall: isReactAPICall.ReturnType;
|
|
75
|
+
declare const isCreateContextCall: isReactAPICall.ReturnType;
|
|
76
|
+
declare const isCreateElementCall: isReactAPICall.ReturnType;
|
|
77
|
+
declare const isCreateRefCall: isReactAPICall.ReturnType;
|
|
78
|
+
declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
79
|
+
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
80
|
+
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
81
|
+
//#endregion
|
|
10
82
|
//#region src/component/component-detection-hint.d.ts
|
|
11
83
|
type ComponentDetectionHint = bigint;
|
|
12
84
|
/**
|
|
@@ -431,20 +503,6 @@ declare function isComponentWrapperCallback(context: RuleContext, node: TSESTree
|
|
|
431
503
|
*/
|
|
432
504
|
declare function isComponentWrapperCallbackLoose(context: RuleContext, node: TSESTree.Node): boolean;
|
|
433
505
|
//#endregion
|
|
434
|
-
//#region src/hierarchy/find-enclosing-assignment-target.d.ts
|
|
435
|
-
/**
|
|
436
|
-
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
437
|
-
*
|
|
438
|
-
* @todo Verify correctness and completeness of this function
|
|
439
|
-
* @param node The starting node
|
|
440
|
-
* @returns The enclosing assignment target node, or undefined if not found
|
|
441
|
-
*/
|
|
442
|
-
declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | 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.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
|
|
443
|
-
/**
|
|
444
|
-
* Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
|
|
445
|
-
*/
|
|
446
|
-
type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
|
|
447
|
-
//#endregion
|
|
448
506
|
//#region src/hierarchy/find-enclosing-component-or-hook.d.ts
|
|
449
507
|
type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null) => boolean;
|
|
450
508
|
/**
|
|
@@ -784,88 +842,4 @@ declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSEST
|
|
|
784
842
|
*/
|
|
785
843
|
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
786
844
|
//#endregion
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Checks if a variable is initialized from React import
|
|
790
|
-
* @param name The variable name
|
|
791
|
-
* @param initialScope The initial scope
|
|
792
|
-
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
793
|
-
* @returns True if the variable is initialized from React import
|
|
794
|
-
*/
|
|
795
|
-
declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
796
|
-
/**
|
|
797
|
-
* Check if an identifier node is initialized from React
|
|
798
|
-
* @param node The identifier node to check
|
|
799
|
-
* @param initialScope Initial scope to search for the identifier
|
|
800
|
-
* @param importSource The import source to check against
|
|
801
|
-
* @returns Whether the identifier node is initialized from React
|
|
802
|
-
*/
|
|
803
|
-
declare function isFromReact(node: TSESTree.Identifier | TSESTree.JSXIdentifier, initialScope: Scope, importSource?: string): boolean;
|
|
804
|
-
//#endregion
|
|
805
|
-
//#region src/utils/is-from-react-native.d.ts
|
|
806
|
-
/**
|
|
807
|
-
* Checks if a variable is initialized from React Native import
|
|
808
|
-
* @param name The variable name
|
|
809
|
-
* @param initialScope The initial scope
|
|
810
|
-
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
811
|
-
* @returns True if the variable is initialized from React Native import
|
|
812
|
-
*/
|
|
813
|
-
declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
814
|
-
//#endregion
|
|
815
|
-
//#region src/utils/is-instance-id-equal.d.ts
|
|
816
|
-
/** @internal */
|
|
817
|
-
declare function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
818
|
-
//#endregion
|
|
819
|
-
//#region src/utils/is-react-api.d.ts
|
|
820
|
-
declare namespace isReactAPI {
|
|
821
|
-
type ReturnType = {
|
|
822
|
-
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
823
|
-
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Checks if the node is a React API identifier or member expression
|
|
828
|
-
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
829
|
-
* @returns A predicate function to check if a node matches the API
|
|
830
|
-
*/
|
|
831
|
-
declare function isReactAPI(api: string): isReactAPI.ReturnType;
|
|
832
|
-
declare namespace isReactAPICall {
|
|
833
|
-
type ReturnType = {
|
|
834
|
-
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression;
|
|
835
|
-
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
/**
|
|
839
|
-
* Checks if the node is a call expression to a specific React API
|
|
840
|
-
* @param api The React API name to check against
|
|
841
|
-
* @returns A predicate function to check if a node is a call to the API
|
|
842
|
-
*/
|
|
843
|
-
declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
|
|
844
|
-
declare const isCaptureOwnerStack: isReactAPI.ReturnType;
|
|
845
|
-
declare const isChildrenCount: isReactAPI.ReturnType;
|
|
846
|
-
declare const isChildrenForEach: isReactAPI.ReturnType;
|
|
847
|
-
declare const isChildrenMap: isReactAPI.ReturnType;
|
|
848
|
-
declare const isChildrenOnly: isReactAPI.ReturnType;
|
|
849
|
-
declare const isChildrenToArray: isReactAPI.ReturnType;
|
|
850
|
-
declare const isCloneElement: isReactAPI.ReturnType;
|
|
851
|
-
declare const isCreateContext: isReactAPI.ReturnType;
|
|
852
|
-
declare const isCreateElement: isReactAPI.ReturnType;
|
|
853
|
-
declare const isCreateRef: isReactAPI.ReturnType;
|
|
854
|
-
declare const isForwardRef: isReactAPI.ReturnType;
|
|
855
|
-
declare const isMemo: isReactAPI.ReturnType;
|
|
856
|
-
declare const isLazy: isReactAPI.ReturnType;
|
|
857
|
-
declare const isCaptureOwnerStackCall: isReactAPICall.ReturnType;
|
|
858
|
-
declare const isChildrenCountCall: isReactAPICall.ReturnType;
|
|
859
|
-
declare const isChildrenForEachCall: isReactAPICall.ReturnType;
|
|
860
|
-
declare const isChildrenMapCall: isReactAPICall.ReturnType;
|
|
861
|
-
declare const isChildrenOnlyCall: isReactAPICall.ReturnType;
|
|
862
|
-
declare const isChildrenToArrayCall: isReactAPICall.ReturnType;
|
|
863
|
-
declare const isCloneElementCall: isReactAPICall.ReturnType;
|
|
864
|
-
declare const isCreateContextCall: isReactAPICall.ReturnType;
|
|
865
|
-
declare const isCreateElementCall: isReactAPICall.ReturnType;
|
|
866
|
-
declare const isCreateRefCall: isReactAPICall.ReturnType;
|
|
867
|
-
declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
868
|
-
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
869
|
-
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
870
|
-
//#endregion
|
|
871
|
-
export { AssignmentTarget, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findEnclosingAssignmentTarget, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
845
|
+
export { ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,101 @@
|
|
|
1
|
+
import { findImportSource, findProperty, findVariable, getVariableDefinitionNode } from "@eslint-react/var";
|
|
1
2
|
import * as AST from "@eslint-react/ast";
|
|
2
3
|
import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
|
|
3
|
-
import { IdGenerator, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
5
|
-
import {
|
|
5
|
+
import { IdGenerator, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
|
|
6
6
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/utils";
|
|
9
9
|
import birecord from "birecord";
|
|
10
10
|
|
|
11
|
+
//#region src/api/is-from-react.ts
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a variable is initialized from React import
|
|
14
|
+
* @param name The variable name
|
|
15
|
+
* @param initialScope The initial scope
|
|
16
|
+
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
17
|
+
* @returns True if the variable is initialized from React import
|
|
18
|
+
*/
|
|
19
|
+
function isInitializedFromReact(name, initialScope, importSource = "react") {
|
|
20
|
+
return name.toLowerCase() === "react" || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/api/is-from-react-native.ts
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a variable is initialized from React Native import
|
|
27
|
+
* @param name The variable name
|
|
28
|
+
* @param initialScope The initial scope
|
|
29
|
+
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
30
|
+
* @returns True if the variable is initialized from React Native import
|
|
31
|
+
*/
|
|
32
|
+
function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
|
|
33
|
+
return [
|
|
34
|
+
"react_native",
|
|
35
|
+
"reactnative",
|
|
36
|
+
"rn"
|
|
37
|
+
].includes(name.toLowerCase()) || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/api/is-react-api.ts
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the node is a React API identifier or member expression
|
|
44
|
+
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
45
|
+
* @returns A predicate function to check if a node matches the API
|
|
46
|
+
*/
|
|
47
|
+
function isReactAPI(api) {
|
|
48
|
+
const func = (context, node) => {
|
|
49
|
+
if (node == null) return false;
|
|
50
|
+
const getText = (n) => context.sourceCode.getText(n);
|
|
51
|
+
const name = AST.toStringFormat(node, getText);
|
|
52
|
+
if (name === api) return true;
|
|
53
|
+
if (name.substring(name.indexOf(".") + 1) === api) return true;
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
return dual(2, func);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the node is a call expression to a specific React API
|
|
60
|
+
* @param api The React API name to check against
|
|
61
|
+
* @returns A predicate function to check if a node is a call to the API
|
|
62
|
+
*/
|
|
63
|
+
function isReactAPICall(api) {
|
|
64
|
+
const func = (context, node) => {
|
|
65
|
+
if (node == null) return false;
|
|
66
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
67
|
+
return isReactAPI(api)(context, node.callee);
|
|
68
|
+
};
|
|
69
|
+
return dual(2, func);
|
|
70
|
+
}
|
|
71
|
+
const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
|
|
72
|
+
const isChildrenCount = isReactAPI("Children.count");
|
|
73
|
+
const isChildrenForEach = isReactAPI("Children.forEach");
|
|
74
|
+
const isChildrenMap = isReactAPI("Children.map");
|
|
75
|
+
const isChildrenOnly = isReactAPI("Children.only");
|
|
76
|
+
const isChildrenToArray = isReactAPI("Children.toArray");
|
|
77
|
+
const isCloneElement = isReactAPI("cloneElement");
|
|
78
|
+
const isCreateContext = isReactAPI("createContext");
|
|
79
|
+
const isCreateElement = isReactAPI("createElement");
|
|
80
|
+
const isCreateRef = isReactAPI("createRef");
|
|
81
|
+
const isForwardRef = isReactAPI("forwardRef");
|
|
82
|
+
const isMemo = isReactAPI("memo");
|
|
83
|
+
const isLazy = isReactAPI("lazy");
|
|
84
|
+
const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
|
|
85
|
+
const isChildrenCountCall = isReactAPICall("Children.count");
|
|
86
|
+
const isChildrenForEachCall = isReactAPICall("Children.forEach");
|
|
87
|
+
const isChildrenMapCall = isReactAPICall("Children.map");
|
|
88
|
+
const isChildrenOnlyCall = isReactAPICall("Children.only");
|
|
89
|
+
const isChildrenToArrayCall = isReactAPICall("Children.toArray");
|
|
90
|
+
const isCloneElementCall = isReactAPICall("cloneElement");
|
|
91
|
+
const isCreateContextCall = isReactAPICall("createContext");
|
|
92
|
+
const isCreateElementCall = isReactAPICall("createElement");
|
|
93
|
+
const isCreateRefCall = isReactAPICall("createRef");
|
|
94
|
+
const isForwardRefCall = isReactAPICall("forwardRef");
|
|
95
|
+
const isMemoCall = isReactAPICall("memo");
|
|
96
|
+
const isLazyCall = isReactAPICall("lazy");
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
11
99
|
//#region src/hook/hook-name.ts
|
|
12
100
|
const REACT_BUILTIN_HOOK_NAMES = [
|
|
13
101
|
"use",
|
|
@@ -582,116 +670,6 @@ function findParentJsxAttribute(node, test = constTrue) {
|
|
|
582
670
|
return AST.findParentNode(node, guard);
|
|
583
671
|
}
|
|
584
672
|
|
|
585
|
-
//#endregion
|
|
586
|
-
//#region src/utils/is-from-react.ts
|
|
587
|
-
/**
|
|
588
|
-
* Checks if a variable is initialized from React import
|
|
589
|
-
* @param name The variable name
|
|
590
|
-
* @param initialScope The initial scope
|
|
591
|
-
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
592
|
-
* @returns True if the variable is initialized from React import
|
|
593
|
-
*/
|
|
594
|
-
function isInitializedFromReact(name, initialScope, importSource = "react") {
|
|
595
|
-
return name.toLowerCase() === "react" || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Check if an identifier node is initialized from React
|
|
599
|
-
* @param node The identifier node to check
|
|
600
|
-
* @param initialScope Initial scope to search for the identifier
|
|
601
|
-
* @param importSource The import source to check against
|
|
602
|
-
* @returns Whether the identifier node is initialized from React
|
|
603
|
-
*/
|
|
604
|
-
function isFromReact(node, initialScope, importSource = "react") {
|
|
605
|
-
const name = node.name;
|
|
606
|
-
switch (true) {
|
|
607
|
-
case node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.Identifier: return isInitializedFromReact(node.parent.object.name, initialScope, importSource);
|
|
608
|
-
case node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.JSXIdentifier: return isInitializedFromReact(node.parent.object.name, initialScope, importSource);
|
|
609
|
-
default: return isInitializedFromReact(name, initialScope, importSource);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
//#endregion
|
|
614
|
-
//#region src/utils/is-from-react-native.ts
|
|
615
|
-
/**
|
|
616
|
-
* Checks if a variable is initialized from React Native import
|
|
617
|
-
* @param name The variable name
|
|
618
|
-
* @param initialScope The initial scope
|
|
619
|
-
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
620
|
-
* @returns True if the variable is initialized from React Native import
|
|
621
|
-
*/
|
|
622
|
-
function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
|
|
623
|
-
return [
|
|
624
|
-
"react_native",
|
|
625
|
-
"reactnative",
|
|
626
|
-
"rn"
|
|
627
|
-
].includes(name.toLowerCase()) || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
//#endregion
|
|
631
|
-
//#region src/utils/is-instance-id-equal.ts
|
|
632
|
-
/** @internal */
|
|
633
|
-
function isInstanceIdEqual(context, a, b) {
|
|
634
|
-
return AST.isNodeEqual(a, b) || isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
//#endregion
|
|
638
|
-
//#region src/utils/is-react-api.ts
|
|
639
|
-
/**
|
|
640
|
-
* Checks if the node is a React API identifier or member expression
|
|
641
|
-
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
642
|
-
* @returns A predicate function to check if a node matches the API
|
|
643
|
-
*/
|
|
644
|
-
function isReactAPI(api) {
|
|
645
|
-
const func = (context, node) => {
|
|
646
|
-
if (node == null) return false;
|
|
647
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
648
|
-
const name = AST.toStringFormat(node, getText);
|
|
649
|
-
if (name === api) return true;
|
|
650
|
-
if (name.substring(name.indexOf(".") + 1) === api) return true;
|
|
651
|
-
return false;
|
|
652
|
-
};
|
|
653
|
-
return dual(2, func);
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Checks if the node is a call expression to a specific React API
|
|
657
|
-
* @param api The React API name to check against
|
|
658
|
-
* @returns A predicate function to check if a node is a call to the API
|
|
659
|
-
*/
|
|
660
|
-
function isReactAPICall(api) {
|
|
661
|
-
const func = (context, node) => {
|
|
662
|
-
if (node == null) return false;
|
|
663
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
664
|
-
return isReactAPI(api)(context, node.callee);
|
|
665
|
-
};
|
|
666
|
-
return dual(2, func);
|
|
667
|
-
}
|
|
668
|
-
const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
|
|
669
|
-
const isChildrenCount = isReactAPI("Children.count");
|
|
670
|
-
const isChildrenForEach = isReactAPI("Children.forEach");
|
|
671
|
-
const isChildrenMap = isReactAPI("Children.map");
|
|
672
|
-
const isChildrenOnly = isReactAPI("Children.only");
|
|
673
|
-
const isChildrenToArray = isReactAPI("Children.toArray");
|
|
674
|
-
const isCloneElement = isReactAPI("cloneElement");
|
|
675
|
-
const isCreateContext = isReactAPI("createContext");
|
|
676
|
-
const isCreateElement = isReactAPI("createElement");
|
|
677
|
-
const isCreateRef = isReactAPI("createRef");
|
|
678
|
-
const isForwardRef = isReactAPI("forwardRef");
|
|
679
|
-
const isMemo = isReactAPI("memo");
|
|
680
|
-
const isLazy = isReactAPI("lazy");
|
|
681
|
-
const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
|
|
682
|
-
const isChildrenCountCall = isReactAPICall("Children.count");
|
|
683
|
-
const isChildrenForEachCall = isReactAPICall("Children.forEach");
|
|
684
|
-
const isChildrenMapCall = isReactAPICall("Children.map");
|
|
685
|
-
const isChildrenOnlyCall = isReactAPICall("Children.only");
|
|
686
|
-
const isChildrenToArrayCall = isReactAPICall("Children.toArray");
|
|
687
|
-
const isCloneElementCall = isReactAPICall("cloneElement");
|
|
688
|
-
const isCreateContextCall = isReactAPICall("createContext");
|
|
689
|
-
const isCreateElementCall = isReactAPICall("createElement");
|
|
690
|
-
const isCreateRefCall = isReactAPICall("createRef");
|
|
691
|
-
const isForwardRefCall = isReactAPICall("forwardRef");
|
|
692
|
-
const isMemoCall = isReactAPICall("memo");
|
|
693
|
-
const isLazyCall = isReactAPICall("lazy");
|
|
694
|
-
|
|
695
673
|
//#endregion
|
|
696
674
|
//#region src/component/component-detection-hint.ts
|
|
697
675
|
/**
|
|
@@ -1260,26 +1238,6 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1260
1238
|
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
1261
1239
|
}
|
|
1262
1240
|
|
|
1263
|
-
//#endregion
|
|
1264
|
-
//#region src/hierarchy/find-enclosing-assignment-target.ts
|
|
1265
|
-
/** eslint-disable jsdoc/require-param */
|
|
1266
|
-
/**
|
|
1267
|
-
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
1268
|
-
*
|
|
1269
|
-
* @todo Verify correctness and completeness of this function
|
|
1270
|
-
* @param node The starting node
|
|
1271
|
-
* @returns The enclosing assignment target node, or undefined if not found
|
|
1272
|
-
*/
|
|
1273
|
-
function findEnclosingAssignmentTarget(node) {
|
|
1274
|
-
switch (true) {
|
|
1275
|
-
case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
|
|
1276
|
-
case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
|
|
1277
|
-
case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
|
|
1278
|
-
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
|
|
1279
|
-
default: return findEnclosingAssignmentTarget(node.parent);
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
1241
|
//#endregion
|
|
1284
1242
|
//#region src/hierarchy/find-enclosing-component-or-hook.ts
|
|
1285
1243
|
/**
|
|
@@ -1314,4 +1272,4 @@ function isInsideComponentOrHook(node) {
|
|
|
1314
1272
|
}
|
|
1315
1273
|
|
|
1316
1274
|
//#endregion
|
|
1317
|
-
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES,
|
|
1275
|
+
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInsideComponentOrHook, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "2.7.4-next.
|
|
3
|
+
"version": "2.7.4-next.4",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@typescript-eslint/utils": "^8.53.1",
|
|
36
36
|
"birecord": "^0.1.1",
|
|
37
37
|
"ts-pattern": "^5.9.0",
|
|
38
|
-
"@eslint-react/ast": "2.7.4-next.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
41
|
-
"@eslint-react/
|
|
38
|
+
"@eslint-react/ast": "2.7.4-next.4",
|
|
39
|
+
"@eslint-react/shared": "2.7.4-next.4",
|
|
40
|
+
"@eslint-react/var": "2.7.4-next.4",
|
|
41
|
+
"@eslint-react/eff": "2.7.4-next.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsdown": "^0.20.0-beta.4",
|