eslint-plugin-react-x 5.20.2 → 5.20.4

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -27
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -145,7 +145,7 @@ const rules$6 = {
145
145
  //#endregion
146
146
  //#region package.json
147
147
  var name$6 = "eslint-plugin-react-x";
148
- var version = "5.20.2";
148
+ var version = "5.20.4";
149
149
 
150
150
  //#endregion
151
151
  //#region src/utils/create-rule.ts
@@ -1462,13 +1462,13 @@ function isRefLikeName$1(name) {
1462
1462
  return name === "ref" || name.endsWith("Ref");
1463
1463
  }
1464
1464
  function hasRefLikeNameInChain(node) {
1465
- if (Check.isIdentifier(node)) return isRefLikeName$1(node.name);
1466
- if (node.type !== AST_NODE_TYPES.MemberExpression) return false;
1467
- return Check.isIdentifier(node.property) ? isRefLikeName$1(node.property.name) || hasRefLikeNameInChain(node.object) : hasRefLikeNameInChain(node.object);
1465
+ const unwrapped = Extract.unwrap(node);
1466
+ if (!Check.isExpression(unwrapped)) return false;
1467
+ return Extract.getMemberChain(unwrapped).some((member) => Check.isIdentifier(member) && isRefLikeName$1(member.name));
1468
1468
  }
1469
1469
  function isInitializedFromCall(context, node, isCall) {
1470
- const root = Check.isIdentifier(node) ? node : Extract.getIdentifierAt(node, 0);
1471
- if (root == null) return false;
1470
+ const root = Extract.getMemberChain(node).at(0);
1471
+ if (root == null || !Check.isIdentifier(root)) return false;
1472
1472
  const variable = findVariable(context.sourceCode.getScope(root), root);
1473
1473
  if (variable == null) return false;
1474
1474
  const origin = resolveVariableOrigin(context, variable);
@@ -1509,6 +1509,11 @@ function createFactCollector$1() {
1509
1509
  target
1510
1510
  });
1511
1511
  }
1512
+ function pushMemberMutation(node, target) {
1513
+ const root = Extract.getMemberChain(target).at(0);
1514
+ if (root == null || !Check.isIdentifier(root)) return;
1515
+ pushMutation("value", node, target, root);
1516
+ }
1512
1517
  return {
1513
1518
  facts,
1514
1519
  visitor: {
@@ -1518,21 +1523,16 @@ function createFactCollector$1() {
1518
1523
  case AST_NODE_TYPES.Identifier:
1519
1524
  pushMutation("binding", node, target, target);
1520
1525
  return;
1521
- case AST_NODE_TYPES.MemberExpression: {
1522
- const root = Extract.getIdentifierAt(target, 0);
1523
- if (root != null) pushMutation("value", node, target, root);
1526
+ case AST_NODE_TYPES.MemberExpression:
1527
+ pushMemberMutation(node, target);
1524
1528
  return;
1525
- }
1526
1529
  }
1527
1530
  },
1528
1531
  CallExpression(node) {
1529
1532
  const callee = Extract.unwrap(node.callee);
1530
1533
  if (callee.type === AST_NODE_TYPES.MemberExpression) {
1531
1534
  const method = Extract.getCalleeName(node);
1532
- if (method != null && KNOWN_MUTATING_METHODS.has(method)) {
1533
- const root = Extract.getIdentifierAt(callee.object, 0);
1534
- if (root != null) pushMutation("value", node, callee.object, root);
1535
- }
1535
+ if (method != null && KNOWN_MUTATING_METHODS.has(method)) pushMemberMutation(node, callee.object);
1536
1536
  }
1537
1537
  if (!core.isHookCall(node)) return;
1538
1538
  for (const argument of node.arguments) {
@@ -1556,8 +1556,7 @@ function createFactCollector$1() {
1556
1556
  if (node.operator !== "delete") return;
1557
1557
  const target = Extract.unwrap(node.argument);
1558
1558
  if (target.type !== AST_NODE_TYPES.MemberExpression) return;
1559
- const root = Extract.getIdentifierAt(target, 0);
1560
- if (root != null) pushMutation("value", node, target, root);
1559
+ pushMemberMutation(node, target);
1561
1560
  },
1562
1561
  UpdateExpression(node) {
1563
1562
  const target = Extract.unwrap(node.argument);
@@ -1565,11 +1564,9 @@ function createFactCollector$1() {
1565
1564
  case AST_NODE_TYPES.Identifier:
1566
1565
  pushMutation("binding", node, target, target);
1567
1566
  return;
1568
- case AST_NODE_TYPES.MemberExpression: {
1569
- const root = Extract.getIdentifierAt(target, 0);
1570
- if (root != null) pushMutation("value", node, target, root);
1567
+ case AST_NODE_TYPES.MemberExpression:
1568
+ pushMemberMutation(node, target);
1571
1569
  return;
1572
- }
1573
1570
  }
1574
1571
  }
1575
1572
  }
@@ -1603,8 +1600,8 @@ function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__
1603
1600
  if (def.node.init == null) {
1604
1601
  const loop = def.node.parent.parent;
1605
1602
  if (loop.type !== AST_NODE_TYPES.ForOfStatement || loop.left !== def.node.parent) return null;
1606
- const root = Extract.getIdentifierAt(loop.right, 0);
1607
- if (root == null) return null;
1603
+ const root = Extract.getMemberChain(loop.right).at(0);
1604
+ if (root == null || !Check.isIdentifier(root)) return null;
1608
1605
  const source = findVariable(context.sourceCode.getScope(root), root);
1609
1606
  if (source == null) return null;
1610
1607
  const inner = classifyFrozenOrigin(context, source, components, seen);
@@ -3679,7 +3676,7 @@ const isWithStateCall = core.isAPICall("withState");
3679
3676
  */
3680
3677
  function isComponentWrapperCall(context, call, arg) {
3681
3678
  if (Extract.unwrap(call.callee) === arg) return false;
3682
- call = Extract.getInnermostCall(call);
3679
+ call = getInnermostCall(call);
3683
3680
  if (isConnectCall(context, call)) return true;
3684
3681
  if (isCreateFragmentContainerCall(context, call)) return true;
3685
3682
  if (isCreatePaginationContainerCall(context, call)) return true;
@@ -3698,6 +3695,21 @@ function isComponentWrapperCall(context, call, arg) {
3698
3695
  return false;
3699
3696
  }
3700
3697
  /**
3698
+ * Unwrap curried call wrappers like `connect(...)(Component)` to get the innermost call expression.
3699
+ * Type expressions and chain expressions around each callee are unwrapped along the way.
3700
+ * @param node The outermost call expression to inspect.
3701
+ * @returns The innermost call expression, whose callee is not itself a call expression.
3702
+ */
3703
+ function getInnermostCall(node) {
3704
+ let call = node;
3705
+ let callee = Extract.unwrap(call.callee);
3706
+ while (callee.type === AST_NODE_TYPES.CallExpression) {
3707
+ call = callee;
3708
+ callee = Extract.unwrap(call.callee);
3709
+ }
3710
+ return call;
3711
+ }
3712
+ /**
3701
3713
  * Resolve the name a function is bound to through wrapping calls (e.g. `const C = useCallback(...)` → `C`).
3702
3714
  * @param context The rule context
3703
3715
  * @param node The function node to resolve the bound name for
@@ -4880,8 +4892,8 @@ function resolveBuiltinObjectName(context, node, seen = /* @__PURE__ */ new Set(
4880
4892
  const init = Extract.unwrap(def.node.init);
4881
4893
  if (Check.isIdentifier(init)) return resolveBuiltinObjectName(context, init, seen);
4882
4894
  if (init.type === AST_NODE_TYPES.MemberExpression) {
4883
- const rootId = Extract.getIdentifierAt(init, 0);
4884
- if (rootId != null) return resolveBuiltinObjectName(context, rootId, seen);
4895
+ const rootId = Extract.getMemberChain(init).at(0);
4896
+ if (rootId != null && Check.isIdentifier(rootId)) return resolveBuiltinObjectName(context, rootId, seen);
4885
4897
  }
4886
4898
  }
4887
4899
  return null;
@@ -4924,8 +4936,8 @@ function create$7(context) {
4924
4936
  break;
4925
4937
  }
4926
4938
  case expr.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(expr.property): {
4927
- const rootId = Extract.getIdentifierAt(expr.object, 0);
4928
- if (rootId == null) return;
4939
+ const rootId = Extract.getMemberChain(expr.object).at(0);
4940
+ if (rootId == null || !Check.isIdentifier(rootId)) return;
4929
4941
  const objectName = resolveBuiltinObjectName(context, rootId);
4930
4942
  if (objectName == null) return;
4931
4943
  const propertyName = expr.property.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.20.2",
3
+ "version": "5.20.4",
4
4
  "description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
@@ -36,12 +36,12 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.20.2",
40
- "@eslint-react/core": "5.20.2",
41
- "@eslint-react/eslint": "5.20.2",
42
- "@eslint-react/jsx": "5.20.2",
43
- "@eslint-react/shared": "5.20.2",
44
- "@eslint-react/var": "5.20.2",
39
+ "@eslint-react/ast": "5.20.4",
40
+ "@eslint-react/core": "5.20.4",
41
+ "@eslint-react/eslint": "5.20.4",
42
+ "@eslint-react/jsx": "5.20.4",
43
+ "@eslint-react/shared": "5.20.4",
44
+ "@eslint-react/var": "5.20.4",
45
45
  "@typescript-eslint/scope-manager": "^8.70.0",
46
46
  "@typescript-eslint/type-utils": "^8.70.0",
47
47
  "@typescript-eslint/types": "^8.70.0",