@eslint-react/core 3.0.0-next.59 → 3.0.0-next.60
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 +10 -19
- package/dist/index.js +46 -36
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,15 @@ import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
|
6
6
|
import { Scope } from "@typescript-eslint/scope-manager";
|
|
7
7
|
import * as typescript from "typescript";
|
|
8
8
|
|
|
9
|
+
//#region src/api/find-import-source.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Find the import source of a variable
|
|
12
|
+
* @param name The variable name
|
|
13
|
+
* @param initialScope The initial scope to search
|
|
14
|
+
* @returns The import source or undefined if not found
|
|
15
|
+
*/
|
|
16
|
+
declare function findImportSource(name: string, initialScope: Scope): string | undefined;
|
|
17
|
+
//#endregion
|
|
9
18
|
//#region src/api/is-from-react.d.ts
|
|
10
19
|
/**
|
|
11
20
|
* Check if a variable is initialized from React import
|
|
@@ -488,24 +497,6 @@ interface ServerFunctionSemanticNode extends SemanticFunc {
|
|
|
488
497
|
*/
|
|
489
498
|
type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticNode;
|
|
490
499
|
//#endregion
|
|
491
|
-
//#region src/hierarchy/find-enclosing-component-or-hook.d.ts
|
|
492
|
-
type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null) => boolean;
|
|
493
|
-
/**
|
|
494
|
-
* Find the enclosing React component or hook for a given AST node
|
|
495
|
-
* @param node The AST node to start the search from
|
|
496
|
-
* @param test Optional test function to customize component or hook identification
|
|
497
|
-
* @returns The enclosing component or hook node, or `null` if none is ASAST.
|
|
498
|
-
*/
|
|
499
|
-
declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
|
|
500
|
-
//#endregion
|
|
501
|
-
//#region src/hierarchy/is-inside-component-or-hook.d.ts
|
|
502
|
-
/**
|
|
503
|
-
* Check if a given AST node is inside a React component or hook
|
|
504
|
-
* @param node The AST node to check
|
|
505
|
-
* @returns True if the node is inside a component or hook, false otherwise
|
|
506
|
-
*/
|
|
507
|
-
declare function isInsideComponentOrHook(node: TSESTree.Node | unit): boolean;
|
|
508
|
-
//#endregion
|
|
509
500
|
//#region src/hook/hook-callback.d.ts
|
|
510
501
|
/**
|
|
511
502
|
* Determine if a node is the setup function passed to a useEffect-like hook
|
|
@@ -868,4 +859,4 @@ declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expre
|
|
|
868
859
|
*/
|
|
869
860
|
declare function isRefLikeName(name: string): boolean;
|
|
870
861
|
//#endregion
|
|
871
|
-
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT,
|
|
862
|
+
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentSemanticNode, FunctionKind, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findImportSource, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderMethodCallback, isRenderMethodLike, 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,12 +1,55 @@
|
|
|
1
|
-
import { findImportSource, findVariable, getVariableInitializer } from "@eslint-react/var";
|
|
2
1
|
import * as ast from "@eslint-react/ast";
|
|
3
2
|
import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
|
|
3
|
+
import { findVariable, getVariableInitializer } from "@eslint-react/var";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
5
|
+
import { P, match } from "ts-pattern";
|
|
5
6
|
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
7
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
7
|
-
import { P, match } from "ts-pattern";
|
|
8
8
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/utils";
|
|
9
9
|
|
|
10
|
+
//#region src/api/find-import-source.ts
|
|
11
|
+
/**
|
|
12
|
+
* Get the arguments of a require expression
|
|
13
|
+
* @param node The node to match
|
|
14
|
+
* @returns The require expression arguments or undefined if the node is not a require expression
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
function getRequireExpressionArguments(node) {
|
|
18
|
+
return match(node).with({
|
|
19
|
+
type: AST_NODE_TYPES.CallExpression,
|
|
20
|
+
arguments: P.select(),
|
|
21
|
+
callee: {
|
|
22
|
+
type: AST_NODE_TYPES.Identifier,
|
|
23
|
+
name: "require"
|
|
24
|
+
}
|
|
25
|
+
}, identity).with({
|
|
26
|
+
type: AST_NODE_TYPES.MemberExpression,
|
|
27
|
+
object: P.select()
|
|
28
|
+
}, getRequireExpressionArguments).otherwise(() => null);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Find the import source of a variable
|
|
32
|
+
* @param name The variable name
|
|
33
|
+
* @param initialScope The initial scope to search
|
|
34
|
+
* @returns The import source or undefined if not found
|
|
35
|
+
*/
|
|
36
|
+
function findImportSource(name, initialScope) {
|
|
37
|
+
const latestDef = findVariable(name, initialScope)?.defs.at(-1);
|
|
38
|
+
if (latestDef == null) return unit;
|
|
39
|
+
const { node, parent } = latestDef;
|
|
40
|
+
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
41
|
+
const { init } = node;
|
|
42
|
+
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return findImportSource(init.object.name, initialScope);
|
|
43
|
+
if (init.type === AST_NODE_TYPES.Identifier) return findImportSource(init.name, initialScope);
|
|
44
|
+
const arg0 = getRequireExpressionArguments(init)?.[0];
|
|
45
|
+
if (arg0 == null || !ast.isLiteral(arg0, "string")) return unit;
|
|
46
|
+
return arg0.value;
|
|
47
|
+
}
|
|
48
|
+
if (parent?.type === AST_NODE_TYPES.ImportDeclaration) return parent.source.value;
|
|
49
|
+
return unit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
10
53
|
//#region src/api/is-from-react.ts
|
|
11
54
|
/**
|
|
12
55
|
* Check if a variable is initialized from React import
|
|
@@ -1119,39 +1162,6 @@ function useComponentCollectorLegacy(context) {
|
|
|
1119
1162
|
};
|
|
1120
1163
|
}
|
|
1121
1164
|
|
|
1122
|
-
//#endregion
|
|
1123
|
-
//#region src/hierarchy/find-enclosing-component-or-hook.ts
|
|
1124
|
-
/**
|
|
1125
|
-
* Find the enclosing React component or hook for a given AST node
|
|
1126
|
-
* @param node The AST node to start the search from
|
|
1127
|
-
* @param test Optional test function to customize component or hook identification
|
|
1128
|
-
* @returns The enclosing component or hook node, or `null` if none is ASAST.
|
|
1129
|
-
*/
|
|
1130
|
-
function findEnclosingComponentOrHook(node, test = (n, name) => {
|
|
1131
|
-
if (name == null) return false;
|
|
1132
|
-
return isComponentNameLoose(name) || isHookName(name);
|
|
1133
|
-
}) {
|
|
1134
|
-
const enclosingNode = ast.findParentNode(node, (n) => {
|
|
1135
|
-
if (!ast.isFunction(n)) return false;
|
|
1136
|
-
return test(n, match(ast.getFunctionId(n)).with({ type: AST_NODE_TYPES.Identifier }, (id) => id.name).with({
|
|
1137
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
1138
|
-
property: { type: AST_NODE_TYPES.Identifier }
|
|
1139
|
-
}, (me) => me.property.name).otherwise(() => null));
|
|
1140
|
-
});
|
|
1141
|
-
return ast.isFunction(enclosingNode) ? enclosingNode : unit;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
//#endregion
|
|
1145
|
-
//#region src/hierarchy/is-inside-component-or-hook.ts
|
|
1146
|
-
/**
|
|
1147
|
-
* Check if a given AST node is inside a React component or hook
|
|
1148
|
-
* @param node The AST node to check
|
|
1149
|
-
* @returns True if the node is inside a component or hook, false otherwise
|
|
1150
|
-
*/
|
|
1151
|
-
function isInsideComponentOrHook(node) {
|
|
1152
|
-
return findEnclosingComponentOrHook(node) != null;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
1165
|
//#endregion
|
|
1156
1166
|
//#region src/ref/ref-name.ts
|
|
1157
1167
|
/**
|
|
@@ -1200,4 +1210,4 @@ function getRefInit(name, initialScope) {
|
|
|
1200
1210
|
}
|
|
1201
1211
|
|
|
1202
1212
|
//#endregion
|
|
1203
|
-
export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES,
|
|
1213
|
+
export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findImportSource, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, 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, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderMethodCallback, isRenderMethodLike, 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": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.60",
|
|
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": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@typescript-eslint/types": "canary",
|
|
35
35
|
"@typescript-eslint/utils": "canary",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "3.0.0-next.
|
|
38
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
37
|
+
"@eslint-react/ast": "3.0.0-next.60",
|
|
38
|
+
"@eslint-react/eff": "3.0.0-next.60",
|
|
39
|
+
"@eslint-react/shared": "3.0.0-next.60",
|
|
40
|
+
"@eslint-react/var": "3.0.0-next.60"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsdown": "^0.21.0-beta.2",
|