@eslint-react/core 1.28.1-next.5 → 1.28.1-next.7
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 +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +53 -31
- package/dist/index.mjs +51 -31
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -235,7 +235,7 @@ declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
|
235
235
|
type ERStateKind = "actionState" | "state";
|
|
236
236
|
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
237
237
|
|
|
238
|
-
/** internal */
|
|
238
|
+
/** @internal */
|
|
239
239
|
declare function hasValidHierarchy(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
240
240
|
|
|
241
241
|
/**
|
|
@@ -315,23 +315,34 @@ interface ERSemanticEntry {
|
|
|
315
315
|
phase: ERPhaseKind;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/** @internal */
|
|
319
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.Identifier | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | 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;
|
|
320
|
+
|
|
321
|
+
/** @internal */
|
|
318
322
|
declare function isFromReactLoose(node: TSESTree.Node | _, name: string): boolean;
|
|
323
|
+
/** @internal */
|
|
319
324
|
declare function isFromReactStrict(node: TSESTree.Node | _, name: string, importSource: string, initialScope: Scope): boolean;
|
|
325
|
+
/** @internal */
|
|
320
326
|
declare namespace isFromReact {
|
|
321
327
|
type ReturnType = {
|
|
322
328
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
323
329
|
(context: RuleContext, node: TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
324
330
|
};
|
|
325
331
|
}
|
|
332
|
+
/** @internal */
|
|
326
333
|
declare function isFromReact(name: string): isFromReact.ReturnType;
|
|
334
|
+
/** @internal */
|
|
327
335
|
declare function isFromReactObject(objectName: string, propertyName: string): isFromReact.ReturnType;
|
|
336
|
+
/** @internal */
|
|
328
337
|
declare namespace isCallFromReact {
|
|
329
338
|
type ReturnType = {
|
|
330
339
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
|
|
331
340
|
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
332
341
|
};
|
|
333
342
|
}
|
|
343
|
+
/** @internal */
|
|
334
344
|
declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
|
|
345
|
+
/** @internal */
|
|
335
346
|
declare function isCallFromReactObject(objectName: string, propertyName: string): isCallFromReact.ReturnType;
|
|
336
347
|
|
|
337
348
|
/**
|
|
@@ -343,6 +354,9 @@ declare function isCallFromReactObject(objectName: string, propertyName: string)
|
|
|
343
354
|
*/
|
|
344
355
|
declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
|
|
345
356
|
|
|
357
|
+
/** @internal */
|
|
358
|
+
declare function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
359
|
+
|
|
346
360
|
declare function isReactAPI(name: string): ReturnType<typeof isFromReact>;
|
|
347
361
|
declare function isReactAPI(objectName: string, propertyName: string): ReturnType<typeof isFromReactObject>;
|
|
348
362
|
declare function isReactAPICall(name: string): ReturnType<typeof isCallFromReact>;
|
|
@@ -370,4 +384,4 @@ declare const isCreateRefCall: isCallFromReact.ReturnType;
|
|
|
370
384
|
declare const isForwardRefCall: isCallFromReact.ReturnType;
|
|
371
385
|
declare const isMemoCall: isCallFromReact.ReturnType;
|
|
372
386
|
|
|
373
|
-
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ERClassComponent, type ERComponent, ERComponentFlag, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
387
|
+
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ERClassComponent, type ERComponent, ERComponentFlag, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, getInstanceId, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -235,7 +235,7 @@ declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
|
235
235
|
type ERStateKind = "actionState" | "state";
|
|
236
236
|
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
237
237
|
|
|
238
|
-
/** internal */
|
|
238
|
+
/** @internal */
|
|
239
239
|
declare function hasValidHierarchy(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
240
240
|
|
|
241
241
|
/**
|
|
@@ -315,23 +315,34 @@ interface ERSemanticEntry {
|
|
|
315
315
|
phase: ERPhaseKind;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/** @internal */
|
|
319
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.Identifier | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | 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;
|
|
320
|
+
|
|
321
|
+
/** @internal */
|
|
318
322
|
declare function isFromReactLoose(node: TSESTree.Node | _, name: string): boolean;
|
|
323
|
+
/** @internal */
|
|
319
324
|
declare function isFromReactStrict(node: TSESTree.Node | _, name: string, importSource: string, initialScope: Scope): boolean;
|
|
325
|
+
/** @internal */
|
|
320
326
|
declare namespace isFromReact {
|
|
321
327
|
type ReturnType = {
|
|
322
328
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
323
329
|
(context: RuleContext, node: TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
324
330
|
};
|
|
325
331
|
}
|
|
332
|
+
/** @internal */
|
|
326
333
|
declare function isFromReact(name: string): isFromReact.ReturnType;
|
|
334
|
+
/** @internal */
|
|
327
335
|
declare function isFromReactObject(objectName: string, propertyName: string): isFromReact.ReturnType;
|
|
336
|
+
/** @internal */
|
|
328
337
|
declare namespace isCallFromReact {
|
|
329
338
|
type ReturnType = {
|
|
330
339
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
|
|
331
340
|
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
332
341
|
};
|
|
333
342
|
}
|
|
343
|
+
/** @internal */
|
|
334
344
|
declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
|
|
345
|
+
/** @internal */
|
|
335
346
|
declare function isCallFromReactObject(objectName: string, propertyName: string): isCallFromReact.ReturnType;
|
|
336
347
|
|
|
337
348
|
/**
|
|
@@ -343,6 +354,9 @@ declare function isCallFromReactObject(objectName: string, propertyName: string)
|
|
|
343
354
|
*/
|
|
344
355
|
declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
|
|
345
356
|
|
|
357
|
+
/** @internal */
|
|
358
|
+
declare function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
359
|
+
|
|
346
360
|
declare function isReactAPI(name: string): ReturnType<typeof isFromReact>;
|
|
347
361
|
declare function isReactAPI(objectName: string, propertyName: string): ReturnType<typeof isFromReactObject>;
|
|
348
362
|
declare function isReactAPICall(name: string): ReturnType<typeof isCallFromReact>;
|
|
@@ -370,4 +384,4 @@ declare const isCreateRefCall: isCallFromReact.ReturnType;
|
|
|
370
384
|
declare const isForwardRefCall: isCallFromReact.ReturnType;
|
|
371
385
|
declare const isMemoCall: isCallFromReact.ReturnType;
|
|
372
386
|
|
|
373
|
-
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ERClassComponent, type ERComponent, ERComponentFlag, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
387
|
+
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, type ERClassComponent, type ERComponent, ERComponentFlag, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectPhaseKind, type ERFunctionComponent, type ERHook, type ERHookKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, getInstanceId, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AST6 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
5
|
var JSX3 = require('@eslint-react/jsx');
|
|
6
6
|
var shared = require('@eslint-react/shared');
|
|
@@ -29,7 +29,7 @@ function _interopNamespace(e) {
|
|
|
29
29
|
return Object.freeze(n);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var AST6__namespace = /*#__PURE__*/_interopNamespace(AST6);
|
|
33
33
|
var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
|
|
34
34
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
35
35
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
@@ -524,6 +524,20 @@ var ESLintReactSettingsSchema = object({
|
|
|
524
524
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
525
525
|
...parse(ESLintReactSettingsSchema, {}),
|
|
526
526
|
importSource: "react"};
|
|
527
|
+
function getInstanceId(node, prev) {
|
|
528
|
+
switch (true) {
|
|
529
|
+
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
530
|
+
return node.id;
|
|
531
|
+
case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
532
|
+
return node.left;
|
|
533
|
+
case (node.type === types.AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
534
|
+
return node.key;
|
|
535
|
+
case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
|
|
536
|
+
return eff._;
|
|
537
|
+
default:
|
|
538
|
+
return getInstanceId(node.parent, node);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
527
541
|
function getRequireExpressionArguments(node) {
|
|
528
542
|
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(() => eff._);
|
|
529
543
|
}
|
|
@@ -542,7 +556,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
542
556
|
}
|
|
543
557
|
const args = getRequireExpressionArguments(init);
|
|
544
558
|
const arg0 = args?.[0];
|
|
545
|
-
if (arg0 == null || !
|
|
559
|
+
if (arg0 == null || !AST6__namespace.isKindOfLiteral(arg0, "string")) {
|
|
546
560
|
return false;
|
|
547
561
|
}
|
|
548
562
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -606,6 +620,12 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
606
620
|
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
607
621
|
});
|
|
608
622
|
}
|
|
623
|
+
function isInstanceIdEqual(context, a, b) {
|
|
624
|
+
return AST6__namespace.isNodeEqual(a, b) || VAR__namespace.isNodeValueEqual(a, b, [
|
|
625
|
+
context.sourceCode.getScope(a),
|
|
626
|
+
context.sourceCode.getScope(b)
|
|
627
|
+
]);
|
|
628
|
+
}
|
|
609
629
|
|
|
610
630
|
// src/utils/is-react-api.ts
|
|
611
631
|
function isReactAPI(arg0, arg1) {
|
|
@@ -640,7 +660,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
640
660
|
// src/hook/is.ts
|
|
641
661
|
function isReactHook(node) {
|
|
642
662
|
if (node == null) return eff._;
|
|
643
|
-
const id =
|
|
663
|
+
const id = AST6__namespace.getFunctionIdentifier(node);
|
|
644
664
|
return id?.name != null && isReactHookName(id.name);
|
|
645
665
|
}
|
|
646
666
|
function isReactHookCall(node) {
|
|
@@ -739,7 +759,7 @@ function useHookCollector() {
|
|
|
739
759
|
const hooks = /* @__PURE__ */ new Map();
|
|
740
760
|
const functionEntries = [];
|
|
741
761
|
const onFunctionEnter = (node) => {
|
|
742
|
-
const id =
|
|
762
|
+
const id = AST6__namespace.getFunctionIdentifier(node);
|
|
743
763
|
const key = shared.getId();
|
|
744
764
|
const name = id?.name;
|
|
745
765
|
if (name != null && isReactHookName(name)) {
|
|
@@ -835,7 +855,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
835
855
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
836
856
|
}
|
|
837
857
|
function getFunctionComponentIdentifier(context, node) {
|
|
838
|
-
const functionId =
|
|
858
|
+
const functionId = AST6__namespace.getFunctionIdentifier(node);
|
|
839
859
|
if (functionId != null) {
|
|
840
860
|
return functionId;
|
|
841
861
|
}
|
|
@@ -889,28 +909,28 @@ function isPureComponent(node) {
|
|
|
889
909
|
|
|
890
910
|
// src/component/component-lifecycle.ts
|
|
891
911
|
function isComponentDidMount(node) {
|
|
892
|
-
return
|
|
912
|
+
return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
893
913
|
}
|
|
894
914
|
function isComponentWillUnmount(node) {
|
|
895
|
-
return
|
|
915
|
+
return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
896
916
|
}
|
|
897
917
|
function isComponentDidCatch(node) {
|
|
898
|
-
return
|
|
918
|
+
return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
899
919
|
}
|
|
900
920
|
function isGetDerivedStateFromError(node) {
|
|
901
|
-
return
|
|
921
|
+
return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
902
922
|
}
|
|
903
923
|
function isGetDerivedStateFromProps(node) {
|
|
904
|
-
return
|
|
924
|
+
return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
905
925
|
}
|
|
906
926
|
function isFunctionOfComponentDidMount(node) {
|
|
907
|
-
return
|
|
927
|
+
return AST6__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
908
928
|
}
|
|
909
929
|
function isFunctionOfComponentWillUnmount(node) {
|
|
910
|
-
return
|
|
930
|
+
return AST6__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
911
931
|
}
|
|
912
932
|
function isRenderMethodLike(node) {
|
|
913
|
-
return
|
|
933
|
+
return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
914
934
|
}
|
|
915
935
|
function isFunctionOfRenderMethod(node) {
|
|
916
936
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -919,7 +939,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
919
939
|
return isClassComponent(node.parent.parent.parent);
|
|
920
940
|
}
|
|
921
941
|
function isInsideRenderMethod(node) {
|
|
922
|
-
return
|
|
942
|
+
return AST6__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
923
943
|
}
|
|
924
944
|
|
|
925
945
|
// src/component/hierarchy.ts
|
|
@@ -927,7 +947,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
927
947
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
928
948
|
return false;
|
|
929
949
|
}
|
|
930
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
950
|
+
if (hint & ERComponentHint.SkipMapCallback && AST6__namespace.isMapCallLoose(node.parent)) {
|
|
931
951
|
return false;
|
|
932
952
|
}
|
|
933
953
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -939,9 +959,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
939
959
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
940
960
|
return false;
|
|
941
961
|
}
|
|
942
|
-
const boundaryNode =
|
|
962
|
+
const boundaryNode = AST6__namespace.findParentNode(
|
|
943
963
|
node,
|
|
944
|
-
|
|
964
|
+
AST6__namespace.isOneOf([
|
|
945
965
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
946
966
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
947
967
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -986,7 +1006,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
986
1006
|
const entry = functionEntries.at(-1);
|
|
987
1007
|
if (entry == null) return;
|
|
988
1008
|
if (!entry.isComponent) return functionEntries.pop();
|
|
989
|
-
const shouldDrop =
|
|
1009
|
+
const shouldDrop = AST6__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
990
1010
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
991
1011
|
});
|
|
992
1012
|
if (shouldDrop) {
|
|
@@ -1013,7 +1033,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1013
1033
|
const { body } = entry.node;
|
|
1014
1034
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1015
1035
|
if (!isComponent) return;
|
|
1016
|
-
const initPath =
|
|
1036
|
+
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
1017
1037
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1018
1038
|
const name = getComponentNameFromIdentifier(id);
|
|
1019
1039
|
const key = shared.getId();
|
|
@@ -1054,7 +1074,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1054
1074
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1055
1075
|
if (!isComponent) return;
|
|
1056
1076
|
entry.isComponent = true;
|
|
1057
|
-
const initPath =
|
|
1077
|
+
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
1058
1078
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1059
1079
|
const name = getComponentNameFromIdentifier(id);
|
|
1060
1080
|
components.set(entry.key, {
|
|
@@ -1075,10 +1095,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1075
1095
|
}
|
|
1076
1096
|
function getComponentFlag(initPath) {
|
|
1077
1097
|
let flag = ERComponentFlag.None;
|
|
1078
|
-
if (initPath != null &&
|
|
1098
|
+
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1079
1099
|
flag |= ERComponentFlag.Memo;
|
|
1080
1100
|
}
|
|
1081
|
-
if (initPath != null &&
|
|
1101
|
+
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1082
1102
|
flag |= ERComponentFlag.ForwardRef;
|
|
1083
1103
|
}
|
|
1084
1104
|
return flag;
|
|
@@ -1095,7 +1115,7 @@ function useComponentCollectorLegacy() {
|
|
|
1095
1115
|
if (!isClassComponent(node)) {
|
|
1096
1116
|
return;
|
|
1097
1117
|
}
|
|
1098
|
-
const id =
|
|
1118
|
+
const id = AST6__namespace.getClassIdentifier(node);
|
|
1099
1119
|
const key = shared.getId();
|
|
1100
1120
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1101
1121
|
components.set(
|
|
@@ -1128,7 +1148,7 @@ var ERPhaseRelevance = birecord__default.default({
|
|
|
1128
1148
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1129
1149
|
function isRenderFunctionLoose(context, node) {
|
|
1130
1150
|
const { body, parent } = node;
|
|
1131
|
-
if (
|
|
1151
|
+
if (AST6__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1132
1152
|
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");
|
|
1133
1153
|
}
|
|
1134
1154
|
return JSX3__namespace.isJSXValue(
|
|
@@ -1143,7 +1163,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1143
1163
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1144
1164
|
return false;
|
|
1145
1165
|
}
|
|
1146
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1166
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST6__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1147
1167
|
}
|
|
1148
1168
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1149
1169
|
const matching = (node2) => {
|
|
@@ -1155,7 +1175,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1155
1175
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1156
1176
|
return true;
|
|
1157
1177
|
}
|
|
1158
|
-
const parent =
|
|
1178
|
+
const parent = AST6__namespace.findParentNode(node, AST6__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1159
1179
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
1160
1180
|
return false;
|
|
1161
1181
|
}
|
|
@@ -1163,7 +1183,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1163
1183
|
}
|
|
1164
1184
|
function isThisSetState(node) {
|
|
1165
1185
|
const { callee } = node;
|
|
1166
|
-
return callee.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1186
|
+
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST6__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1167
1187
|
}
|
|
1168
1188
|
function isFunctionOfUseEffectSetup(node) {
|
|
1169
1189
|
if (node == null) return eff._;
|
|
@@ -1171,9 +1191,9 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1171
1191
|
}
|
|
1172
1192
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1173
1193
|
if (node == null) return eff._;
|
|
1174
|
-
const returnStatement =
|
|
1175
|
-
const enclosingFunction =
|
|
1176
|
-
const functionOfReturnStatement =
|
|
1194
|
+
const returnStatement = AST6__namespace.findParentNode(node, AST6__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
1195
|
+
const enclosingFunction = AST6__namespace.findParentNode(node, AST6__namespace.isFunction);
|
|
1196
|
+
const functionOfReturnStatement = AST6__namespace.findParentNode(returnStatement, AST6__namespace.isFunction);
|
|
1177
1197
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1178
1198
|
}
|
|
1179
1199
|
|
|
@@ -1186,6 +1206,7 @@ exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
|
1186
1206
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
1187
1207
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
1188
1208
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
1209
|
+
exports.getInstanceId = getInstanceId;
|
|
1189
1210
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
1190
1211
|
exports.hasValidHierarchy = hasValidHierarchy;
|
|
1191
1212
|
exports.isCallFromReact = isCallFromReact;
|
|
@@ -1230,6 +1251,7 @@ exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
|
|
|
1230
1251
|
exports.isGetDerivedStateFromProps = isGetDerivedStateFromProps;
|
|
1231
1252
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
1232
1253
|
exports.isInsideRenderMethod = isInsideRenderMethod;
|
|
1254
|
+
exports.isInstanceIdEqual = isInstanceIdEqual;
|
|
1233
1255
|
exports.isInversePhase = isInversePhase;
|
|
1234
1256
|
exports.isMemo = isMemo;
|
|
1235
1257
|
exports.isMemoCall = isMemoCall;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as AST6 from '@eslint-react/ast';
|
|
2
2
|
import { flip, dual, constFalse, identity, _ } from '@eslint-react/eff';
|
|
3
3
|
import * as JSX3 from '@eslint-react/jsx';
|
|
4
4
|
import { DEFAULT_ESLINT_REACT_SETTINGS as DEFAULT_ESLINT_REACT_SETTINGS$1, unsafeDecodeSettings, getId } from '@eslint-react/shared';
|
|
@@ -497,6 +497,20 @@ var ESLintReactSettingsSchema = object({
|
|
|
497
497
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
498
498
|
...parse(ESLintReactSettingsSchema, {}),
|
|
499
499
|
importSource: "react"};
|
|
500
|
+
function getInstanceId(node, prev) {
|
|
501
|
+
switch (true) {
|
|
502
|
+
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
503
|
+
return node.id;
|
|
504
|
+
case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
505
|
+
return node.left;
|
|
506
|
+
case (node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev):
|
|
507
|
+
return node.key;
|
|
508
|
+
case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
|
|
509
|
+
return _;
|
|
510
|
+
default:
|
|
511
|
+
return getInstanceId(node.parent, node);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
500
514
|
function getRequireExpressionArguments(node) {
|
|
501
515
|
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(() => _);
|
|
502
516
|
}
|
|
@@ -515,7 +529,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
515
529
|
}
|
|
516
530
|
const args = getRequireExpressionArguments(init);
|
|
517
531
|
const arg0 = args?.[0];
|
|
518
|
-
if (arg0 == null || !
|
|
532
|
+
if (arg0 == null || !AST6.isKindOfLiteral(arg0, "string")) {
|
|
519
533
|
return false;
|
|
520
534
|
}
|
|
521
535
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -579,6 +593,12 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
579
593
|
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
580
594
|
});
|
|
581
595
|
}
|
|
596
|
+
function isInstanceIdEqual(context, a, b) {
|
|
597
|
+
return AST6.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [
|
|
598
|
+
context.sourceCode.getScope(a),
|
|
599
|
+
context.sourceCode.getScope(b)
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
582
602
|
|
|
583
603
|
// src/utils/is-react-api.ts
|
|
584
604
|
function isReactAPI(arg0, arg1) {
|
|
@@ -613,7 +633,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
613
633
|
// src/hook/is.ts
|
|
614
634
|
function isReactHook(node) {
|
|
615
635
|
if (node == null) return _;
|
|
616
|
-
const id =
|
|
636
|
+
const id = AST6.getFunctionIdentifier(node);
|
|
617
637
|
return id?.name != null && isReactHookName(id.name);
|
|
618
638
|
}
|
|
619
639
|
function isReactHookCall(node) {
|
|
@@ -712,7 +732,7 @@ function useHookCollector() {
|
|
|
712
732
|
const hooks = /* @__PURE__ */ new Map();
|
|
713
733
|
const functionEntries = [];
|
|
714
734
|
const onFunctionEnter = (node) => {
|
|
715
|
-
const id =
|
|
735
|
+
const id = AST6.getFunctionIdentifier(node);
|
|
716
736
|
const key = getId();
|
|
717
737
|
const name = id?.name;
|
|
718
738
|
if (name != null && isReactHookName(name)) {
|
|
@@ -808,7 +828,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
808
828
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
809
829
|
}
|
|
810
830
|
function getFunctionComponentIdentifier(context, node) {
|
|
811
|
-
const functionId =
|
|
831
|
+
const functionId = AST6.getFunctionIdentifier(node);
|
|
812
832
|
if (functionId != null) {
|
|
813
833
|
return functionId;
|
|
814
834
|
}
|
|
@@ -862,28 +882,28 @@ function isPureComponent(node) {
|
|
|
862
882
|
|
|
863
883
|
// src/component/component-lifecycle.ts
|
|
864
884
|
function isComponentDidMount(node) {
|
|
865
|
-
return
|
|
885
|
+
return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
866
886
|
}
|
|
867
887
|
function isComponentWillUnmount(node) {
|
|
868
|
-
return
|
|
888
|
+
return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
869
889
|
}
|
|
870
890
|
function isComponentDidCatch(node) {
|
|
871
|
-
return
|
|
891
|
+
return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
872
892
|
}
|
|
873
893
|
function isGetDerivedStateFromError(node) {
|
|
874
|
-
return
|
|
894
|
+
return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
875
895
|
}
|
|
876
896
|
function isGetDerivedStateFromProps(node) {
|
|
877
|
-
return
|
|
897
|
+
return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
878
898
|
}
|
|
879
899
|
function isFunctionOfComponentDidMount(node) {
|
|
880
|
-
return
|
|
900
|
+
return AST6.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
881
901
|
}
|
|
882
902
|
function isFunctionOfComponentWillUnmount(node) {
|
|
883
|
-
return
|
|
903
|
+
return AST6.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
884
904
|
}
|
|
885
905
|
function isRenderMethodLike(node) {
|
|
886
|
-
return
|
|
906
|
+
return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
887
907
|
}
|
|
888
908
|
function isFunctionOfRenderMethod(node) {
|
|
889
909
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -892,7 +912,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
892
912
|
return isClassComponent(node.parent.parent.parent);
|
|
893
913
|
}
|
|
894
914
|
function isInsideRenderMethod(node) {
|
|
895
|
-
return
|
|
915
|
+
return AST6.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
896
916
|
}
|
|
897
917
|
|
|
898
918
|
// src/component/hierarchy.ts
|
|
@@ -900,7 +920,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
900
920
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
901
921
|
return false;
|
|
902
922
|
}
|
|
903
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
923
|
+
if (hint & ERComponentHint.SkipMapCallback && AST6.isMapCallLoose(node.parent)) {
|
|
904
924
|
return false;
|
|
905
925
|
}
|
|
906
926
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -912,9 +932,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
912
932
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
913
933
|
return false;
|
|
914
934
|
}
|
|
915
|
-
const boundaryNode =
|
|
935
|
+
const boundaryNode = AST6.findParentNode(
|
|
916
936
|
node,
|
|
917
|
-
|
|
937
|
+
AST6.isOneOf([
|
|
918
938
|
AST_NODE_TYPES.JSXExpressionContainer,
|
|
919
939
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
920
940
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -959,7 +979,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
959
979
|
const entry = functionEntries.at(-1);
|
|
960
980
|
if (entry == null) return;
|
|
961
981
|
if (!entry.isComponent) return functionEntries.pop();
|
|
962
|
-
const shouldDrop =
|
|
982
|
+
const shouldDrop = AST6.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
963
983
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXValue(r.argument, jsxCtx, hint);
|
|
964
984
|
});
|
|
965
985
|
if (shouldDrop) {
|
|
@@ -986,7 +1006,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
986
1006
|
const { body } = entry.node;
|
|
987
1007
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
988
1008
|
if (!isComponent) return;
|
|
989
|
-
const initPath =
|
|
1009
|
+
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
990
1010
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
991
1011
|
const name = getComponentNameFromIdentifier(id);
|
|
992
1012
|
const key = getId();
|
|
@@ -1027,7 +1047,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1027
1047
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1028
1048
|
if (!isComponent) return;
|
|
1029
1049
|
entry.isComponent = true;
|
|
1030
|
-
const initPath =
|
|
1050
|
+
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
1031
1051
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1032
1052
|
const name = getComponentNameFromIdentifier(id);
|
|
1033
1053
|
components.set(entry.key, {
|
|
@@ -1048,10 +1068,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1048
1068
|
}
|
|
1049
1069
|
function getComponentFlag(initPath) {
|
|
1050
1070
|
let flag = ERComponentFlag.None;
|
|
1051
|
-
if (initPath != null &&
|
|
1071
|
+
if (initPath != null && AST6.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1052
1072
|
flag |= ERComponentFlag.Memo;
|
|
1053
1073
|
}
|
|
1054
|
-
if (initPath != null &&
|
|
1074
|
+
if (initPath != null && AST6.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1055
1075
|
flag |= ERComponentFlag.ForwardRef;
|
|
1056
1076
|
}
|
|
1057
1077
|
return flag;
|
|
@@ -1068,7 +1088,7 @@ function useComponentCollectorLegacy() {
|
|
|
1068
1088
|
if (!isClassComponent(node)) {
|
|
1069
1089
|
return;
|
|
1070
1090
|
}
|
|
1071
|
-
const id =
|
|
1091
|
+
const id = AST6.getClassIdentifier(node);
|
|
1072
1092
|
const key = getId();
|
|
1073
1093
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1074
1094
|
components.set(
|
|
@@ -1101,7 +1121,7 @@ var ERPhaseRelevance = birecord({
|
|
|
1101
1121
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1102
1122
|
function isRenderFunctionLoose(context, node) {
|
|
1103
1123
|
const { body, parent } = node;
|
|
1104
|
-
if (
|
|
1124
|
+
if (AST6.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1105
1125
|
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");
|
|
1106
1126
|
}
|
|
1107
1127
|
return JSX3.isJSXValue(
|
|
@@ -1116,7 +1136,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1116
1136
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
1117
1137
|
return false;
|
|
1118
1138
|
}
|
|
1119
|
-
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1139
|
+
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST6.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1120
1140
|
}
|
|
1121
1141
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1122
1142
|
const matching = (node2) => {
|
|
@@ -1128,7 +1148,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1128
1148
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1129
1149
|
return true;
|
|
1130
1150
|
}
|
|
1131
|
-
const parent =
|
|
1151
|
+
const parent = AST6.findParentNode(node, AST6.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1132
1152
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
1133
1153
|
return false;
|
|
1134
1154
|
}
|
|
@@ -1136,7 +1156,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1136
1156
|
}
|
|
1137
1157
|
function isThisSetState(node) {
|
|
1138
1158
|
const { callee } = node;
|
|
1139
|
-
return callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
1159
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && AST6.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1140
1160
|
}
|
|
1141
1161
|
function isFunctionOfUseEffectSetup(node) {
|
|
1142
1162
|
if (node == null) return _;
|
|
@@ -1144,10 +1164,10 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1144
1164
|
}
|
|
1145
1165
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1146
1166
|
if (node == null) return _;
|
|
1147
|
-
const returnStatement =
|
|
1148
|
-
const enclosingFunction =
|
|
1149
|
-
const functionOfReturnStatement =
|
|
1167
|
+
const returnStatement = AST6.findParentNode(node, AST6.is(AST_NODE_TYPES.ReturnStatement));
|
|
1168
|
+
const enclosingFunction = AST6.findParentNode(node, AST6.isFunction);
|
|
1169
|
+
const functionOfReturnStatement = AST6.findParentNode(returnStatement, AST6.isFunction);
|
|
1150
1170
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1151
1171
|
}
|
|
1152
1172
|
|
|
1153
|
-
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, ERComponentFlag, ERComponentHint, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
1173
|
+
export { DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, ERComponentFlag, ERComponentHint, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, getInstanceId, hasNoneOrValidComponentName, hasValidHierarchy, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.28.1-next.
|
|
3
|
+
"version": "1.28.1-next.7",
|
|
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.25.0",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.6.2",
|
|
44
|
-
"@eslint-react/ast": "1.28.1-next.
|
|
45
|
-
"@eslint-react/eff": "1.28.1-next.
|
|
46
|
-
"@eslint-react/jsx": "1.28.1-next.
|
|
47
|
-
"@eslint-react/shared": "1.28.1-next.
|
|
48
|
-
"@eslint-react/var": "1.28.1-next.
|
|
44
|
+
"@eslint-react/ast": "1.28.1-next.7",
|
|
45
|
+
"@eslint-react/eff": "1.28.1-next.7",
|
|
46
|
+
"@eslint-react/jsx": "1.28.1-next.7",
|
|
47
|
+
"@eslint-react/shared": "1.28.1-next.7",
|
|
48
|
+
"@eslint-react/var": "1.28.1-next.7"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.4.0",
|