@eslint-react/core 2.5.7-next.0 → 2.5.7-next.3
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 +26 -13
- package/dist/index.js +19 -12
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -175,7 +175,7 @@ interface ClassComponent extends SemanticNode {
|
|
|
175
175
|
type Component = ClassComponent | FunctionComponent;
|
|
176
176
|
//#endregion
|
|
177
177
|
//#region src/component/component-collector.d.ts
|
|
178
|
-
type FunctionEntry = {
|
|
178
|
+
type FunctionEntry$1 = {
|
|
179
179
|
key: string;
|
|
180
180
|
node: AST.TSESTreeFunction;
|
|
181
181
|
hookCalls: TSESTree.CallExpression[];
|
|
@@ -190,8 +190,8 @@ declare namespace useComponentCollector {
|
|
|
190
190
|
type ReturnType = {
|
|
191
191
|
ctx: {
|
|
192
192
|
getAllComponents: (node: TSESTree.Program) => FunctionComponent[];
|
|
193
|
-
getCurrentEntries: () => FunctionEntry[];
|
|
194
|
-
getCurrentEntry: () => FunctionEntry | unit;
|
|
193
|
+
getCurrentEntries: () => FunctionEntry$1[];
|
|
194
|
+
getCurrentEntry: () => FunctionEntry$1 | unit;
|
|
195
195
|
};
|
|
196
196
|
listeners: ESLintUtils.RuleListener;
|
|
197
197
|
};
|
|
@@ -420,10 +420,17 @@ interface Hook extends SemanticNode {
|
|
|
420
420
|
}
|
|
421
421
|
//#endregion
|
|
422
422
|
//#region src/hook/hook-collector.d.ts
|
|
423
|
+
type FunctionEntry = {
|
|
424
|
+
key: string;
|
|
425
|
+
node: AST.TSESTreeFunction;
|
|
426
|
+
isHook: boolean;
|
|
427
|
+
};
|
|
423
428
|
declare namespace useHookCollector {
|
|
424
429
|
type ReturnType = {
|
|
425
430
|
ctx: {
|
|
426
431
|
getAllHooks(node: TSESTree$1.Program): Hook[];
|
|
432
|
+
getCurrentEntries(): FunctionEntry[];
|
|
433
|
+
getCurrentEntry(): FunctionEntry | unit;
|
|
427
434
|
};
|
|
428
435
|
listeners: ESLintUtils.RuleListener;
|
|
429
436
|
};
|
|
@@ -572,7 +579,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
|
|
|
572
579
|
readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
|
|
573
580
|
} | {
|
|
574
581
|
readonly kind: "expression";
|
|
575
|
-
readonly node: TSESTree.
|
|
582
|
+
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
576
583
|
readonly toStatic: () => unknown;
|
|
577
584
|
} | {
|
|
578
585
|
readonly kind: "element";
|
|
@@ -580,7 +587,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
|
|
|
580
587
|
readonly toStatic: () => undefined;
|
|
581
588
|
} | {
|
|
582
589
|
readonly kind: "spreadChild";
|
|
583
|
-
readonly node: TSESTree.
|
|
590
|
+
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
584
591
|
readonly toStatic: () => undefined;
|
|
585
592
|
} | {
|
|
586
593
|
readonly kind: "spreadProps";
|
|
@@ -682,9 +689,10 @@ declare function isJsxHostElement(context: RuleContext, node: TSESTree.Node): bo
|
|
|
682
689
|
* @param context ESLint rule context
|
|
683
690
|
* @param node AST node to check
|
|
684
691
|
* @param jsxConfig Optional JSX configuration
|
|
692
|
+
* @param jsxConfig.jsxFragmentFactory Name of the fragment factory (e.g., React.Fragment)
|
|
685
693
|
* @returns boolean indicating if the element is a Fragment
|
|
686
694
|
*/
|
|
687
|
-
declare function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node, jsxConfig?: JsxConfig): boolean;
|
|
695
|
+
declare function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node, jsxConfig?: Pick<JsxConfig, "jsxFragmentFactory">): boolean;
|
|
688
696
|
//#endregion
|
|
689
697
|
//#region src/jsx/jsx-element-type.d.ts
|
|
690
698
|
/**
|
|
@@ -718,14 +726,19 @@ declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSEST
|
|
|
718
726
|
*/
|
|
719
727
|
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;
|
|
720
728
|
//#endregion
|
|
721
|
-
//#region src/utils/
|
|
729
|
+
//#region src/utils/find-enclosing-assignment-target.d.ts
|
|
722
730
|
/**
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
* @
|
|
726
|
-
* @
|
|
731
|
+
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
732
|
+
*
|
|
733
|
+
* @todo Verify correctness and completeness of this function
|
|
734
|
+
* @param node The starting node
|
|
735
|
+
* @returns The enclosing assignment target node, or undefined if not found
|
|
736
|
+
*/
|
|
737
|
+
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;
|
|
738
|
+
/**
|
|
739
|
+
* Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
|
|
727
740
|
*/
|
|
728
|
-
|
|
741
|
+
type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
|
|
729
742
|
//#endregion
|
|
730
743
|
//#region src/utils/is-from-react.d.ts
|
|
731
744
|
/**
|
|
@@ -803,4 +816,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
|
803
816
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
804
817
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
805
818
|
//#endregion
|
|
806
|
-
export { ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId,
|
|
819
|
+
export { AssignmentTarget, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findEnclosingAssignmentTarget, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, 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, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -135,6 +135,7 @@ const idGen$2 = new IdGenerator("hook_");
|
|
|
135
135
|
function useHookCollector() {
|
|
136
136
|
const hooks = /* @__PURE__ */ new Map();
|
|
137
137
|
const functionEntries = [];
|
|
138
|
+
const getCurrentEntry = () => functionEntries.at(-1);
|
|
138
139
|
const onFunctionEnter = (node) => {
|
|
139
140
|
const id = AST.getFunctionId(node);
|
|
140
141
|
const key = idGen$2.next();
|
|
@@ -167,15 +168,19 @@ function useHookCollector() {
|
|
|
167
168
|
functionEntries.pop();
|
|
168
169
|
};
|
|
169
170
|
return {
|
|
170
|
-
ctx: {
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
ctx: {
|
|
172
|
+
getAllHooks(node) {
|
|
173
|
+
return [...hooks.values()];
|
|
174
|
+
},
|
|
175
|
+
getCurrentEntries: () => functionEntries,
|
|
176
|
+
getCurrentEntry
|
|
177
|
+
},
|
|
173
178
|
listeners: {
|
|
174
179
|
":function[type]": onFunctionEnter,
|
|
175
180
|
":function[type]:exit": onFunctionExit,
|
|
176
181
|
"CallExpression[type]"(node) {
|
|
177
182
|
if (!isReactHookCall(node)) return;
|
|
178
|
-
const fEntry =
|
|
183
|
+
const fEntry = getCurrentEntry();
|
|
179
184
|
if (fEntry?.key == null) return;
|
|
180
185
|
const hook = hooks.get(fEntry.key);
|
|
181
186
|
if (hook == null) return;
|
|
@@ -541,6 +546,7 @@ function isJsxHostElement(context, node) {
|
|
|
541
546
|
* @param context ESLint rule context
|
|
542
547
|
* @param node AST node to check
|
|
543
548
|
* @param jsxConfig Optional JSX configuration
|
|
549
|
+
* @param jsxConfig.jsxFragmentFactory Name of the fragment factory (e.g., React.Fragment)
|
|
544
550
|
* @returns boolean indicating if the element is a Fragment
|
|
545
551
|
*/
|
|
546
552
|
function isJsxFragmentElement(context, node, jsxConfig) {
|
|
@@ -567,21 +573,22 @@ function findParentJsxAttribute(node, test = constTrue) {
|
|
|
567
573
|
}
|
|
568
574
|
|
|
569
575
|
//#endregion
|
|
570
|
-
//#region src/utils/
|
|
576
|
+
//#region src/utils/find-enclosing-assignment-target.ts
|
|
571
577
|
/** eslint-disable jsdoc/require-param */
|
|
572
578
|
/**
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
* @
|
|
576
|
-
* @
|
|
579
|
+
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
580
|
+
*
|
|
581
|
+
* @todo Verify correctness and completeness of this function
|
|
582
|
+
* @param node The starting node
|
|
583
|
+
* @returns The enclosing assignment target node, or undefined if not found
|
|
577
584
|
*/
|
|
578
|
-
function
|
|
585
|
+
function findEnclosingAssignmentTarget(node) {
|
|
579
586
|
switch (true) {
|
|
580
587
|
case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
|
|
581
588
|
case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
|
|
582
589
|
case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
|
|
583
590
|
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
|
|
584
|
-
default: return
|
|
591
|
+
default: return findEnclosingAssignmentTarget(node.parent);
|
|
585
592
|
}
|
|
586
593
|
}
|
|
587
594
|
|
|
@@ -1220,4 +1227,4 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1220
1227
|
}
|
|
1221
1228
|
|
|
1222
1229
|
//#endregion
|
|
1223
|
-
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId,
|
|
1230
|
+
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingAssignmentTarget, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, 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, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, 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.5.7-next.
|
|
3
|
+
"version": "2.5.7-next.3",
|
|
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.0",
|
|
36
36
|
"birecord": "^0.1.1",
|
|
37
37
|
"ts-pattern": "^5.9.0",
|
|
38
|
-
"@eslint-react/ast": "2.5.7-next.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/var": "2.5.7-next.
|
|
41
|
-
"@eslint-react/
|
|
38
|
+
"@eslint-react/ast": "2.5.7-next.3",
|
|
39
|
+
"@eslint-react/shared": "2.5.7-next.3",
|
|
40
|
+
"@eslint-react/var": "2.5.7-next.3",
|
|
41
|
+
"@eslint-react/eff": "2.5.7-next.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsdown": "^0.20.0-beta.1",
|