@eslint-react/core 1.28.1-next.4 → 1.28.1-next.6
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 +54 -31
- package/dist/index.mjs +52 -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);
|
|
@@ -404,6 +404,7 @@ var CustomComponentPropSchema = object({
|
|
|
404
404
|
as: optional(string()),
|
|
405
405
|
/**
|
|
406
406
|
* Whether the prop is controlled or not in the user-defined component.
|
|
407
|
+
* @internal
|
|
407
408
|
* @example
|
|
408
409
|
* `true`
|
|
409
410
|
*/
|
|
@@ -523,6 +524,20 @@ var ESLintReactSettingsSchema = object({
|
|
|
523
524
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
524
525
|
...parse(ESLintReactSettingsSchema, {}),
|
|
525
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
|
+
}
|
|
526
541
|
function getRequireExpressionArguments(node) {
|
|
527
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._);
|
|
528
543
|
}
|
|
@@ -541,7 +556,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
541
556
|
}
|
|
542
557
|
const args = getRequireExpressionArguments(init);
|
|
543
558
|
const arg0 = args?.[0];
|
|
544
|
-
if (arg0 == null || !
|
|
559
|
+
if (arg0 == null || !AST6__namespace.isKindOfLiteral(arg0, "string")) {
|
|
545
560
|
return false;
|
|
546
561
|
}
|
|
547
562
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -605,6 +620,12 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
605
620
|
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
606
621
|
});
|
|
607
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
|
+
}
|
|
608
629
|
|
|
609
630
|
// src/utils/is-react-api.ts
|
|
610
631
|
function isReactAPI(arg0, arg1) {
|
|
@@ -639,7 +660,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
639
660
|
// src/hook/is.ts
|
|
640
661
|
function isReactHook(node) {
|
|
641
662
|
if (node == null) return eff._;
|
|
642
|
-
const id =
|
|
663
|
+
const id = AST6__namespace.getFunctionIdentifier(node);
|
|
643
664
|
return id?.name != null && isReactHookName(id.name);
|
|
644
665
|
}
|
|
645
666
|
function isReactHookCall(node) {
|
|
@@ -738,7 +759,7 @@ function useHookCollector() {
|
|
|
738
759
|
const hooks = /* @__PURE__ */ new Map();
|
|
739
760
|
const functionEntries = [];
|
|
740
761
|
const onFunctionEnter = (node) => {
|
|
741
|
-
const id =
|
|
762
|
+
const id = AST6__namespace.getFunctionIdentifier(node);
|
|
742
763
|
const key = shared.getId();
|
|
743
764
|
const name = id?.name;
|
|
744
765
|
if (name != null && isReactHookName(name)) {
|
|
@@ -834,7 +855,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
834
855
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
835
856
|
}
|
|
836
857
|
function getFunctionComponentIdentifier(context, node) {
|
|
837
|
-
const functionId =
|
|
858
|
+
const functionId = AST6__namespace.getFunctionIdentifier(node);
|
|
838
859
|
if (functionId != null) {
|
|
839
860
|
return functionId;
|
|
840
861
|
}
|
|
@@ -888,28 +909,28 @@ function isPureComponent(node) {
|
|
|
888
909
|
|
|
889
910
|
// src/component/component-lifecycle.ts
|
|
890
911
|
function isComponentDidMount(node) {
|
|
891
|
-
return
|
|
912
|
+
return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
892
913
|
}
|
|
893
914
|
function isComponentWillUnmount(node) {
|
|
894
|
-
return
|
|
915
|
+
return AST6__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
895
916
|
}
|
|
896
917
|
function isComponentDidCatch(node) {
|
|
897
|
-
return
|
|
918
|
+
return AST6__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
898
919
|
}
|
|
899
920
|
function isGetDerivedStateFromError(node) {
|
|
900
|
-
return
|
|
921
|
+
return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
901
922
|
}
|
|
902
923
|
function isGetDerivedStateFromProps(node) {
|
|
903
|
-
return
|
|
924
|
+
return AST6__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
904
925
|
}
|
|
905
926
|
function isFunctionOfComponentDidMount(node) {
|
|
906
|
-
return
|
|
927
|
+
return AST6__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
907
928
|
}
|
|
908
929
|
function isFunctionOfComponentWillUnmount(node) {
|
|
909
|
-
return
|
|
930
|
+
return AST6__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
910
931
|
}
|
|
911
932
|
function isRenderMethodLike(node) {
|
|
912
|
-
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;
|
|
913
934
|
}
|
|
914
935
|
function isFunctionOfRenderMethod(node) {
|
|
915
936
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -918,7 +939,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
918
939
|
return isClassComponent(node.parent.parent.parent);
|
|
919
940
|
}
|
|
920
941
|
function isInsideRenderMethod(node) {
|
|
921
|
-
return
|
|
942
|
+
return AST6__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
922
943
|
}
|
|
923
944
|
|
|
924
945
|
// src/component/hierarchy.ts
|
|
@@ -926,7 +947,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
926
947
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
927
948
|
return false;
|
|
928
949
|
}
|
|
929
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
950
|
+
if (hint & ERComponentHint.SkipMapCallback && AST6__namespace.isMapCallLoose(node.parent)) {
|
|
930
951
|
return false;
|
|
931
952
|
}
|
|
932
953
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -938,9 +959,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
938
959
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
939
960
|
return false;
|
|
940
961
|
}
|
|
941
|
-
const boundaryNode =
|
|
962
|
+
const boundaryNode = AST6__namespace.findParentNode(
|
|
942
963
|
node,
|
|
943
|
-
|
|
964
|
+
AST6__namespace.isOneOf([
|
|
944
965
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
945
966
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
946
967
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -985,7 +1006,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
985
1006
|
const entry = functionEntries.at(-1);
|
|
986
1007
|
if (entry == null) return;
|
|
987
1008
|
if (!entry.isComponent) return functionEntries.pop();
|
|
988
|
-
const shouldDrop =
|
|
1009
|
+
const shouldDrop = AST6__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
989
1010
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
990
1011
|
});
|
|
991
1012
|
if (shouldDrop) {
|
|
@@ -1012,7 +1033,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1012
1033
|
const { body } = entry.node;
|
|
1013
1034
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1014
1035
|
if (!isComponent) return;
|
|
1015
|
-
const initPath =
|
|
1036
|
+
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
1016
1037
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1017
1038
|
const name = getComponentNameFromIdentifier(id);
|
|
1018
1039
|
const key = shared.getId();
|
|
@@ -1053,7 +1074,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1053
1074
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1054
1075
|
if (!isComponent) return;
|
|
1055
1076
|
entry.isComponent = true;
|
|
1056
|
-
const initPath =
|
|
1077
|
+
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
1057
1078
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1058
1079
|
const name = getComponentNameFromIdentifier(id);
|
|
1059
1080
|
components.set(entry.key, {
|
|
@@ -1074,10 +1095,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1074
1095
|
}
|
|
1075
1096
|
function getComponentFlag(initPath) {
|
|
1076
1097
|
let flag = ERComponentFlag.None;
|
|
1077
|
-
if (initPath != null &&
|
|
1098
|
+
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1078
1099
|
flag |= ERComponentFlag.Memo;
|
|
1079
1100
|
}
|
|
1080
|
-
if (initPath != null &&
|
|
1101
|
+
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1081
1102
|
flag |= ERComponentFlag.ForwardRef;
|
|
1082
1103
|
}
|
|
1083
1104
|
return flag;
|
|
@@ -1094,7 +1115,7 @@ function useComponentCollectorLegacy() {
|
|
|
1094
1115
|
if (!isClassComponent(node)) {
|
|
1095
1116
|
return;
|
|
1096
1117
|
}
|
|
1097
|
-
const id =
|
|
1118
|
+
const id = AST6__namespace.getClassIdentifier(node);
|
|
1098
1119
|
const key = shared.getId();
|
|
1099
1120
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1100
1121
|
components.set(
|
|
@@ -1127,7 +1148,7 @@ var ERPhaseRelevance = birecord__default.default({
|
|
|
1127
1148
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1128
1149
|
function isRenderFunctionLoose(context, node) {
|
|
1129
1150
|
const { body, parent } = node;
|
|
1130
|
-
if (
|
|
1151
|
+
if (AST6__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1131
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");
|
|
1132
1153
|
}
|
|
1133
1154
|
return JSX3__namespace.isJSXValue(
|
|
@@ -1142,7 +1163,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1142
1163
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1143
1164
|
return false;
|
|
1144
1165
|
}
|
|
1145
|
-
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);
|
|
1146
1167
|
}
|
|
1147
1168
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1148
1169
|
const matching = (node2) => {
|
|
@@ -1154,7 +1175,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1154
1175
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1155
1176
|
return true;
|
|
1156
1177
|
}
|
|
1157
|
-
const parent =
|
|
1178
|
+
const parent = AST6__namespace.findParentNode(node, AST6__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1158
1179
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
1159
1180
|
return false;
|
|
1160
1181
|
}
|
|
@@ -1162,7 +1183,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1162
1183
|
}
|
|
1163
1184
|
function isThisSetState(node) {
|
|
1164
1185
|
const { callee } = node;
|
|
1165
|
-
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";
|
|
1166
1187
|
}
|
|
1167
1188
|
function isFunctionOfUseEffectSetup(node) {
|
|
1168
1189
|
if (node == null) return eff._;
|
|
@@ -1170,9 +1191,9 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1170
1191
|
}
|
|
1171
1192
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1172
1193
|
if (node == null) return eff._;
|
|
1173
|
-
const returnStatement =
|
|
1174
|
-
const enclosingFunction =
|
|
1175
|
-
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);
|
|
1176
1197
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1177
1198
|
}
|
|
1178
1199
|
|
|
@@ -1185,6 +1206,7 @@ exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
|
1185
1206
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
1186
1207
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
1187
1208
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
1209
|
+
exports.getInstanceId = getInstanceId;
|
|
1188
1210
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
1189
1211
|
exports.hasValidHierarchy = hasValidHierarchy;
|
|
1190
1212
|
exports.isCallFromReact = isCallFromReact;
|
|
@@ -1229,6 +1251,7 @@ exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
|
|
|
1229
1251
|
exports.isGetDerivedStateFromProps = isGetDerivedStateFromProps;
|
|
1230
1252
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
1231
1253
|
exports.isInsideRenderMethod = isInsideRenderMethod;
|
|
1254
|
+
exports.isInstanceIdEqual = isInstanceIdEqual;
|
|
1232
1255
|
exports.isInversePhase = isInversePhase;
|
|
1233
1256
|
exports.isMemo = isMemo;
|
|
1234
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';
|
|
@@ -377,6 +377,7 @@ var CustomComponentPropSchema = object({
|
|
|
377
377
|
as: optional(string()),
|
|
378
378
|
/**
|
|
379
379
|
* Whether the prop is controlled or not in the user-defined component.
|
|
380
|
+
* @internal
|
|
380
381
|
* @example
|
|
381
382
|
* `true`
|
|
382
383
|
*/
|
|
@@ -496,6 +497,20 @@ var ESLintReactSettingsSchema = object({
|
|
|
496
497
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
497
498
|
...parse(ESLintReactSettingsSchema, {}),
|
|
498
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
|
+
}
|
|
499
514
|
function getRequireExpressionArguments(node) {
|
|
500
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(() => _);
|
|
501
516
|
}
|
|
@@ -514,7 +529,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
514
529
|
}
|
|
515
530
|
const args = getRequireExpressionArguments(init);
|
|
516
531
|
const arg0 = args?.[0];
|
|
517
|
-
if (arg0 == null || !
|
|
532
|
+
if (arg0 == null || !AST6.isKindOfLiteral(arg0, "string")) {
|
|
518
533
|
return false;
|
|
519
534
|
}
|
|
520
535
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -578,6 +593,12 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
578
593
|
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
579
594
|
});
|
|
580
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
|
+
}
|
|
581
602
|
|
|
582
603
|
// src/utils/is-react-api.ts
|
|
583
604
|
function isReactAPI(arg0, arg1) {
|
|
@@ -612,7 +633,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
612
633
|
// src/hook/is.ts
|
|
613
634
|
function isReactHook(node) {
|
|
614
635
|
if (node == null) return _;
|
|
615
|
-
const id =
|
|
636
|
+
const id = AST6.getFunctionIdentifier(node);
|
|
616
637
|
return id?.name != null && isReactHookName(id.name);
|
|
617
638
|
}
|
|
618
639
|
function isReactHookCall(node) {
|
|
@@ -711,7 +732,7 @@ function useHookCollector() {
|
|
|
711
732
|
const hooks = /* @__PURE__ */ new Map();
|
|
712
733
|
const functionEntries = [];
|
|
713
734
|
const onFunctionEnter = (node) => {
|
|
714
|
-
const id =
|
|
735
|
+
const id = AST6.getFunctionIdentifier(node);
|
|
715
736
|
const key = getId();
|
|
716
737
|
const name = id?.name;
|
|
717
738
|
if (name != null && isReactHookName(name)) {
|
|
@@ -807,7 +828,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
807
828
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
808
829
|
}
|
|
809
830
|
function getFunctionComponentIdentifier(context, node) {
|
|
810
|
-
const functionId =
|
|
831
|
+
const functionId = AST6.getFunctionIdentifier(node);
|
|
811
832
|
if (functionId != null) {
|
|
812
833
|
return functionId;
|
|
813
834
|
}
|
|
@@ -861,28 +882,28 @@ function isPureComponent(node) {
|
|
|
861
882
|
|
|
862
883
|
// src/component/component-lifecycle.ts
|
|
863
884
|
function isComponentDidMount(node) {
|
|
864
|
-
return
|
|
885
|
+
return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
865
886
|
}
|
|
866
887
|
function isComponentWillUnmount(node) {
|
|
867
|
-
return
|
|
888
|
+
return AST6.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
868
889
|
}
|
|
869
890
|
function isComponentDidCatch(node) {
|
|
870
|
-
return
|
|
891
|
+
return AST6.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
871
892
|
}
|
|
872
893
|
function isGetDerivedStateFromError(node) {
|
|
873
|
-
return
|
|
894
|
+
return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
874
895
|
}
|
|
875
896
|
function isGetDerivedStateFromProps(node) {
|
|
876
|
-
return
|
|
897
|
+
return AST6.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
877
898
|
}
|
|
878
899
|
function isFunctionOfComponentDidMount(node) {
|
|
879
|
-
return
|
|
900
|
+
return AST6.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
880
901
|
}
|
|
881
902
|
function isFunctionOfComponentWillUnmount(node) {
|
|
882
|
-
return
|
|
903
|
+
return AST6.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
883
904
|
}
|
|
884
905
|
function isRenderMethodLike(node) {
|
|
885
|
-
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;
|
|
886
907
|
}
|
|
887
908
|
function isFunctionOfRenderMethod(node) {
|
|
888
909
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -891,7 +912,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
891
912
|
return isClassComponent(node.parent.parent.parent);
|
|
892
913
|
}
|
|
893
914
|
function isInsideRenderMethod(node) {
|
|
894
|
-
return
|
|
915
|
+
return AST6.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
895
916
|
}
|
|
896
917
|
|
|
897
918
|
// src/component/hierarchy.ts
|
|
@@ -899,7 +920,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
899
920
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
900
921
|
return false;
|
|
901
922
|
}
|
|
902
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
923
|
+
if (hint & ERComponentHint.SkipMapCallback && AST6.isMapCallLoose(node.parent)) {
|
|
903
924
|
return false;
|
|
904
925
|
}
|
|
905
926
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -911,9 +932,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
911
932
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
912
933
|
return false;
|
|
913
934
|
}
|
|
914
|
-
const boundaryNode =
|
|
935
|
+
const boundaryNode = AST6.findParentNode(
|
|
915
936
|
node,
|
|
916
|
-
|
|
937
|
+
AST6.isOneOf([
|
|
917
938
|
AST_NODE_TYPES.JSXExpressionContainer,
|
|
918
939
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
919
940
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -958,7 +979,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
958
979
|
const entry = functionEntries.at(-1);
|
|
959
980
|
if (entry == null) return;
|
|
960
981
|
if (!entry.isComponent) return functionEntries.pop();
|
|
961
|
-
const shouldDrop =
|
|
982
|
+
const shouldDrop = AST6.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
962
983
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXValue(r.argument, jsxCtx, hint);
|
|
963
984
|
});
|
|
964
985
|
if (shouldDrop) {
|
|
@@ -985,7 +1006,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
985
1006
|
const { body } = entry.node;
|
|
986
1007
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
987
1008
|
if (!isComponent) return;
|
|
988
|
-
const initPath =
|
|
1009
|
+
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
989
1010
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
990
1011
|
const name = getComponentNameFromIdentifier(id);
|
|
991
1012
|
const key = getId();
|
|
@@ -1026,7 +1047,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1026
1047
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1027
1048
|
if (!isComponent) return;
|
|
1028
1049
|
entry.isComponent = true;
|
|
1029
|
-
const initPath =
|
|
1050
|
+
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
1030
1051
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1031
1052
|
const name = getComponentNameFromIdentifier(id);
|
|
1032
1053
|
components.set(entry.key, {
|
|
@@ -1047,10 +1068,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1047
1068
|
}
|
|
1048
1069
|
function getComponentFlag(initPath) {
|
|
1049
1070
|
let flag = ERComponentFlag.None;
|
|
1050
|
-
if (initPath != null &&
|
|
1071
|
+
if (initPath != null && AST6.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1051
1072
|
flag |= ERComponentFlag.Memo;
|
|
1052
1073
|
}
|
|
1053
|
-
if (initPath != null &&
|
|
1074
|
+
if (initPath != null && AST6.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1054
1075
|
flag |= ERComponentFlag.ForwardRef;
|
|
1055
1076
|
}
|
|
1056
1077
|
return flag;
|
|
@@ -1067,7 +1088,7 @@ function useComponentCollectorLegacy() {
|
|
|
1067
1088
|
if (!isClassComponent(node)) {
|
|
1068
1089
|
return;
|
|
1069
1090
|
}
|
|
1070
|
-
const id =
|
|
1091
|
+
const id = AST6.getClassIdentifier(node);
|
|
1071
1092
|
const key = getId();
|
|
1072
1093
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1073
1094
|
components.set(
|
|
@@ -1100,7 +1121,7 @@ var ERPhaseRelevance = birecord({
|
|
|
1100
1121
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1101
1122
|
function isRenderFunctionLoose(context, node) {
|
|
1102
1123
|
const { body, parent } = node;
|
|
1103
|
-
if (
|
|
1124
|
+
if (AST6.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1104
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");
|
|
1105
1126
|
}
|
|
1106
1127
|
return JSX3.isJSXValue(
|
|
@@ -1115,7 +1136,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1115
1136
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
1116
1137
|
return false;
|
|
1117
1138
|
}
|
|
1118
|
-
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);
|
|
1119
1140
|
}
|
|
1120
1141
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1121
1142
|
const matching = (node2) => {
|
|
@@ -1127,7 +1148,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1127
1148
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1128
1149
|
return true;
|
|
1129
1150
|
}
|
|
1130
|
-
const parent =
|
|
1151
|
+
const parent = AST6.findParentNode(node, AST6.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1131
1152
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
1132
1153
|
return false;
|
|
1133
1154
|
}
|
|
@@ -1135,7 +1156,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1135
1156
|
}
|
|
1136
1157
|
function isThisSetState(node) {
|
|
1137
1158
|
const { callee } = node;
|
|
1138
|
-
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";
|
|
1139
1160
|
}
|
|
1140
1161
|
function isFunctionOfUseEffectSetup(node) {
|
|
1141
1162
|
if (node == null) return _;
|
|
@@ -1143,10 +1164,10 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1143
1164
|
}
|
|
1144
1165
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1145
1166
|
if (node == null) return _;
|
|
1146
|
-
const returnStatement =
|
|
1147
|
-
const enclosingFunction =
|
|
1148
|
-
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);
|
|
1149
1170
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1150
1171
|
}
|
|
1151
1172
|
|
|
1152
|
-
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.6",
|
|
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.6",
|
|
45
|
+
"@eslint-react/eff": "1.28.1-next.6",
|
|
46
|
+
"@eslint-react/jsx": "1.28.1-next.6",
|
|
47
|
+
"@eslint-react/shared": "1.28.1-next.6",
|
|
48
|
+
"@eslint-react/var": "1.28.1-next.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.4.0",
|