@eslint-react/core 2.7.1-next.1 → 2.7.1-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -117,6 +117,10 @@ interface FunctionComponent extends SemanticNode {
117
117
  * The initialization path of the function
118
118
  */
119
119
  initPath: unit | AST.FunctionInitPath;
120
+ /**
121
+ * Indicates if the component is exported as default
122
+ */
123
+ isExportDefault: boolean;
120
124
  /**
121
125
  * List of hook calls within the component
122
126
  */
@@ -170,6 +174,8 @@ type FunctionEntry$1 = {
170
174
  node: AST.TSESTreeFunction;
171
175
  hookCalls: TSESTree.CallExpression[];
172
176
  isComponent: boolean;
177
+ isComponentDefinition: boolean;
178
+ isExportDefault: boolean;
173
179
  rets: TSESTree.ReturnStatement["argument"][];
174
180
  };
175
181
  declare namespace useComponentCollector {
@@ -420,7 +426,7 @@ declare function isComponentWrapperCallbackLoose(context: RuleContext, node: TSE
420
426
  * @param node The starting node
421
427
  * @returns The enclosing assignment target node, or undefined if not found
422
428
  */
423
- declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
429
+ declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.JSXElement | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | TSESTree.PrivateIdentifier | undefined;
424
430
  /**
425
431
  * Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
426
432
  */
@@ -434,7 +440,7 @@ type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null
434
440
  * @param test Optional test function to customize component or hook identification
435
441
  * @returns The enclosing component or hook node, or `null` if none is found
436
442
  */
437
- declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
443
+ declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | undefined;
438
444
  //#endregion
439
445
  //#region src/hierarchy/is-inside-component-or-hook.d.ts
440
446
  /**
@@ -613,7 +619,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
613
619
  readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
614
620
  } | {
615
621
  readonly kind: "expression";
616
- readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
622
+ readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
617
623
  readonly toStatic: () => unknown;
618
624
  } | {
619
625
  readonly kind: "element";
@@ -621,7 +627,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
621
627
  readonly toStatic: () => undefined;
622
628
  } | {
623
629
  readonly kind: "spreadChild";
624
- readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
630
+ readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
625
631
  readonly toStatic: () => undefined;
626
632
  } | {
627
633
  readonly kind: "spreadProps";
package/dist/index.js CHANGED
@@ -822,13 +822,18 @@ function isComponentDefinition(context, node, hint) {
822
822
  if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) return false;
823
823
  if (shouldExcludeBasedOnHint(node, hint)) return false;
824
824
  const significantParent = AST.findParentNode(node, AST.isOneOf([
825
+ AST_NODE_TYPES.ArrayPattern,
826
+ AST_NODE_TYPES.ArrayExpression,
825
827
  AST_NODE_TYPES.JSXExpressionContainer,
826
828
  AST_NODE_TYPES.ArrowFunctionExpression,
827
829
  AST_NODE_TYPES.FunctionExpression,
828
830
  AST_NODE_TYPES.Property,
829
831
  AST_NODE_TYPES.ClassBody
830
832
  ]));
831
- return significantParent == null || significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
833
+ if (significantParent == null) return true;
834
+ if (significantParent.type === AST_NODE_TYPES.JSXExpressionContainer) return false;
835
+ if (significantParent.type === AST_NODE_TYPES.ArrayPattern || significantParent.type === AST_NODE_TYPES.ArrayExpression) return false;
836
+ return true;
832
837
  }
833
838
 
834
839
  //#endregion
@@ -960,6 +965,8 @@ function useComponentCollector(context, options = {}) {
960
965
  node,
961
966
  hookCalls: [],
962
967
  isComponent: false,
968
+ isComponentDefinition: isComponentDefinition(context, node, hint),
969
+ isExportDefault: AST.findParentNode(node, (n) => n.type === AST_NODE_TYPES.ExportDefaultDeclaration) != null,
963
970
  rets: []
964
971
  });
965
972
  };
@@ -982,9 +989,10 @@ function useComponentCollector(context, options = {}) {
982
989
  "ArrowFunctionExpression[body.type!='BlockStatement']"() {
983
990
  const entry = getCurrentEntry();
984
991
  if (entry == null) return;
992
+ if (!entry.isComponentDefinition) return;
985
993
  const { body } = entry.node;
986
994
  if (body.type === AST_NODE_TYPES.BlockStatement) return;
987
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isComponentDefinition(context, entry.node, hint))) return;
995
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint))) return;
988
996
  const initPath = AST.getFunctionInitPath(entry.node);
989
997
  const id = getFunctionComponentId(context, entry.node);
990
998
  const key = entry.key;
@@ -1000,6 +1008,7 @@ function useComponentCollector(context, options = {}) {
1000
1008
  hint,
1001
1009
  hookCalls: entry.hookCalls,
1002
1010
  initPath,
1011
+ isExportDefault: entry.isExportDefault,
1003
1012
  rets: [body]
1004
1013
  });
1005
1014
  },
@@ -1020,8 +1029,10 @@ function useComponentCollector(context, options = {}) {
1020
1029
  "ReturnStatement[type]"(node) {
1021
1030
  const entry = getCurrentEntry();
1022
1031
  if (entry == null) return;
1023
- entry.rets.push(node.argument);
1024
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isComponentDefinition(context, entry.node, hint))) return;
1032
+ if (!entry.isComponentDefinition) return;
1033
+ const { argument } = node;
1034
+ entry.rets.push(argument);
1035
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, argument, hint))) return;
1025
1036
  entry.isComponent = true;
1026
1037
  const initPath = AST.getFunctionInitPath(entry.node);
1027
1038
  const id = getFunctionComponentId(context, entry.node);
@@ -1038,6 +1049,7 @@ function useComponentCollector(context, options = {}) {
1038
1049
  hint,
1039
1050
  hookCalls: entry.hookCalls,
1040
1051
  initPath,
1052
+ isExportDefault: entry.isExportDefault,
1041
1053
  rets: entry.rets
1042
1054
  });
1043
1055
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.7.1-next.1",
3
+ "version": "2.7.1-next.3",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -35,10 +35,10 @@
35
35
  "@typescript-eslint/utils": "^8.53.0",
36
36
  "birecord": "^0.1.1",
37
37
  "ts-pattern": "^5.9.0",
38
- "@eslint-react/ast": "2.7.1-next.1",
39
- "@eslint-react/eff": "2.7.1-next.1",
40
- "@eslint-react/shared": "2.7.1-next.1",
41
- "@eslint-react/var": "2.7.1-next.1"
38
+ "@eslint-react/ast": "2.7.1-next.3",
39
+ "@eslint-react/eff": "2.7.1-next.3",
40
+ "@eslint-react/var": "2.7.1-next.3",
41
+ "@eslint-react/shared": "2.7.1-next.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsdown": "^0.20.0-beta.3",