eslint-plugin-react-x 5.12.0 → 5.12.1

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 +23 -45
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -144,7 +144,7 @@ const rules$6 = {
144
144
  //#endregion
145
145
  //#region package.json
146
146
  var name$6 = "eslint-plugin-react-x";
147
- var version = "5.12.0";
147
+ var version = "5.12.1";
148
148
 
149
149
  //#endregion
150
150
  //#region src/utils/create-rule.ts
@@ -1751,17 +1751,6 @@ function create$47(context) {
1751
1751
  //#endregion
1752
1752
  //#region src/rules/no-array-index-key/lib.ts
1753
1753
  /**
1754
- * Creates a report function for the given rule context.
1755
- * @param context The ESLint rule context.
1756
- * @returns A function that can be used to report violations.
1757
- */
1758
- function report$2(context) {
1759
- return (descriptor) => {
1760
- if (descriptor == null) return;
1761
- context.report(descriptor);
1762
- };
1763
- }
1764
- /**
1765
1754
  * Iterator-like methods that pass the item's index to their callback,
1766
1755
  * mapped to the position of the index parameter in the callback's parameter list.
1767
1756
  * `map` and `forEach` also cover `Children.map` and `Children.forEach`,
@@ -1858,7 +1847,7 @@ function create$46(context) {
1858
1847
  * @param node The key value expression to check.
1859
1848
  * @returns The report descriptors for the violations found.
1860
1849
  */
1861
- function checkKeyExpression(node) {
1850
+ function visitKeyExpression(node) {
1862
1851
  switch (node.type) {
1863
1852
  case AST_NODE_TYPES.Identifier: return isArrayIndex(node) ? [{
1864
1853
  messageId: "default",
@@ -1872,8 +1861,8 @@ function create$46(context) {
1872
1861
  messageId: "default",
1873
1862
  node: identifier
1874
1863
  }));
1875
- case AST_NODE_TYPES.ConditionalExpression: return [...checkKeyExpression(node.consequent), ...checkKeyExpression(node.alternate)];
1876
- case AST_NODE_TYPES.LogicalExpression: return [...checkKeyExpression(node.left), ...checkKeyExpression(node.right)];
1864
+ case AST_NODE_TYPES.ConditionalExpression: return [...visitKeyExpression(node.consequent), ...visitKeyExpression(node.alternate)];
1865
+ case AST_NODE_TYPES.LogicalExpression: return [...visitKeyExpression(node.left), ...visitKeyExpression(node.right)];
1877
1866
  case AST_NODE_TYPES.CallExpression: {
1878
1867
  const callee = Extract.unwrap(node.callee);
1879
1868
  if (callee.type === AST_NODE_TYPES.MemberExpression && Extract.getPropertyName(callee.property) === "toString" && isArrayIndex(callee.object)) return [{
@@ -1898,12 +1887,12 @@ function create$46(context) {
1898
1887
  for (const property of props.properties) {
1899
1888
  const value = getKeyPropValue(property);
1900
1889
  if (value == null) continue;
1901
- checkKeyExpression(value).forEach(report$2(context));
1890
+ for (const desc of visitKeyExpression(value)) context.report(desc);
1902
1891
  }
1903
1892
  },
1904
1893
  "JSXAttribute[name.name='key']"(node) {
1905
1894
  if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
1906
- checkKeyExpression(node.value.expression).forEach(report$2(context));
1895
+ for (const desc of visitKeyExpression(node.value.expression)) context.report(desc);
1907
1896
  }
1908
1897
  };
1909
1898
  }
@@ -2599,7 +2588,7 @@ function create$28(context) {
2599
2588
  * @param context The ESLint rule context.
2600
2589
  * @returns A function that can be used to report violations.
2601
2590
  */
2602
- function report$1(context) {
2591
+ function report(context) {
2603
2592
  return (descriptor) => {
2604
2593
  if (descriptor == null) return;
2605
2594
  context.report(descriptor);
@@ -2643,16 +2632,16 @@ function create$27(context) {
2643
2632
  * @param seen A set of visited identifier names to prevent infinite recursion.
2644
2633
  * @returns A report descriptor if a problem is found, otherwise `null`
2645
2634
  */
2646
- function getReportDescriptor(node, seen = /* @__PURE__ */ new Set()) {
2635
+ function visit(node, seen = /* @__PURE__ */ new Set()) {
2647
2636
  if (node == null) return null;
2648
- if (Check.is(AST_NODE_TYPES.JSXExpressionContainer)(node)) return getReportDescriptor(node.expression, seen);
2637
+ if (Check.is(AST_NODE_TYPES.JSXExpressionContainer)(node)) return visit(node.expression, seen);
2649
2638
  if (Check.isJSX(node)) return null;
2650
- if (Check.isTypeExpression(node)) return getReportDescriptor(node.expression, seen);
2639
+ if (Check.isTypeExpression(node)) return visit(node.expression, seen);
2651
2640
  return match(node).with({
2652
2641
  type: AST_NODE_TYPES.LogicalExpression,
2653
2642
  operator: "&&"
2654
2643
  }, ({ left, right }) => {
2655
- if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!") return getReportDescriptor(right, seen);
2644
+ if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!") return visit(right, seen);
2656
2645
  const initialScope = context.sourceCode.getScope(left);
2657
2646
  if (Check.isIdentifier(left, "NaN") || getStaticValue(left, initialScope)?.value === "NaN") return {
2658
2647
  data: { value: context.sourceCode.getText(left) },
@@ -2661,22 +2650,22 @@ function create$27(context) {
2661
2650
  };
2662
2651
  const leftType = getConstrainedTypeAtLocation(services, left);
2663
2652
  const leftTypeVariants = core.getTypeVariants(unionConstituents(leftType));
2664
- if (Array.from(leftTypeVariants.values()).every((t) => allowedTypeVariants.some((a) => a === t))) return getReportDescriptor(right, seen);
2653
+ if (Array.from(leftTypeVariants.values()).every((t) => allowedTypeVariants.some((a) => a === t))) return visit(right, seen);
2665
2654
  return {
2666
2655
  data: { value: context.sourceCode.getText(left) },
2667
2656
  messageId: "default",
2668
2657
  node: left
2669
2658
  };
2670
2659
  }).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
2671
- return getReportDescriptor(consequent, seen) ?? getReportDescriptor(alternate, seen);
2660
+ return visit(consequent, seen) ?? visit(alternate, seen);
2672
2661
  }).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2673
2662
  if (seen.has(n.name)) return null;
2674
2663
  seen.add(n.name);
2675
2664
  const variableDefNode = findVariable(context.sourceCode.getScope(n), n.name)?.defs.at(0)?.node;
2676
- return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, (init) => getReportDescriptor(init, seen)).otherwise(() => null);
2665
+ return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, (init) => visit(init, seen)).otherwise(() => null);
2677
2666
  }).otherwise(() => null);
2678
2667
  }
2679
- return { JSXExpressionContainer: flow(getReportDescriptor, report$1(context)) };
2668
+ return { JSXExpressionContainer: flow(visit, report(context)) };
2680
2669
  }
2681
2670
 
2682
2671
  //#endregion
@@ -2791,17 +2780,6 @@ const INDEX_PARAM_POSITIONS = /* @__PURE__ */ new Map([
2791
2780
  ["map", 0]
2792
2781
  ]);
2793
2782
  /**
2794
- * Creates a report function for the given rule context.
2795
- * @param context The ESLint rule context.
2796
- * @returns A function that can be used to report violations.
2797
- */
2798
- function report(context) {
2799
- return (descriptor) => {
2800
- if (descriptor == null) return;
2801
- context.report(descriptor);
2802
- };
2803
- }
2804
- /**
2805
2783
  * Gets the nested return statements in the node that are within the same function
2806
2784
  * @param node The AST node
2807
2785
  * @returns The nested return statements in the node
@@ -2857,7 +2835,7 @@ function create$24(context) {
2857
2835
  * @param node The expression to check.
2858
2836
  * @returns The report descriptors for the violations found.
2859
2837
  */
2860
- function checkItemExpression(node) {
2838
+ function visitItemExpression(node) {
2861
2839
  switch (node.type) {
2862
2840
  case AST_NODE_TYPES.JSXElement: return hasAttribute(context, node, "key") ? [] : [{
2863
2841
  messageId: "default",
@@ -2867,8 +2845,8 @@ function create$24(context) {
2867
2845
  messageId: "unexpectedFragmentSyntax",
2868
2846
  node
2869
2847
  }];
2870
- case AST_NODE_TYPES.ConditionalExpression: return [...checkItemExpression(node.consequent), ...checkItemExpression(node.alternate)];
2871
- case AST_NODE_TYPES.LogicalExpression: return [...checkItemExpression(node.left), ...checkItemExpression(node.right)];
2848
+ case AST_NODE_TYPES.ConditionalExpression: return [...visitItemExpression(node.consequent), ...visitItemExpression(node.alternate)];
2849
+ case AST_NODE_TYPES.LogicalExpression: return [...visitItemExpression(node.left), ...visitItemExpression(node.right)];
2872
2850
  default: return [];
2873
2851
  }
2874
2852
  }
@@ -2878,16 +2856,16 @@ function create$24(context) {
2878
2856
  * @param node The callback function to check.
2879
2857
  * @returns The report descriptors for the violations found.
2880
2858
  */
2881
- function checkIteratorCallback(node) {
2882
- if (node.body.type !== AST_NODE_TYPES.BlockStatement) return checkItemExpression(node.body);
2883
- return getNestedReturnStatements$1(node.body).flatMap((stmt) => stmt.argument == null ? [] : checkItemExpression(stmt.argument));
2859
+ function visitIteratorCallback(node) {
2860
+ if (node.body.type !== AST_NODE_TYPES.BlockStatement) return visitItemExpression(node.body);
2861
+ return getNestedReturnStatements$1(node.body).flatMap((stmt) => stmt.argument == null ? [] : visitItemExpression(stmt.argument));
2884
2862
  }
2885
2863
  return {
2886
2864
  ArrayExpression(node) {
2887
2865
  if (childrenToArrayDepth > 0) return;
2888
2866
  for (const element of node.elements) {
2889
2867
  if (element == null || element.type === AST_NODE_TYPES.SpreadElement) continue;
2890
- checkItemExpression(element).forEach(report(context));
2868
+ for (const desc of visitItemExpression(element)) context.report(desc);
2891
2869
  }
2892
2870
  },
2893
2871
  CallExpression(node) {
@@ -2898,7 +2876,7 @@ function create$24(context) {
2898
2876
  if (childrenToArrayDepth > 0) return;
2899
2877
  const callback = getIteratorCallback(node);
2900
2878
  if (callback == null) return;
2901
- checkIteratorCallback(callback).forEach(report(context));
2879
+ for (const desc of visitIteratorCallback(callback)) context.report(desc);
2902
2880
  },
2903
2881
  "CallExpression:exit"(node) {
2904
2882
  if (core.isChildrenToArrayCall(context, node)) childrenToArrayDepth -= 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.12.0",
3
+ "version": "5.12.1",
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",
@@ -45,12 +45,12 @@
45
45
  "string-ts": "^2.3.1",
46
46
  "ts-api-utils": "^2.5.0",
47
47
  "ts-pattern": "^5.9.0",
48
- "@eslint-react/ast": "5.12.0",
49
- "@eslint-react/core": "5.12.0",
50
- "@eslint-react/eslint": "5.12.0",
51
- "@eslint-react/jsx": "5.12.0",
52
- "@eslint-react/shared": "5.12.0",
53
- "@eslint-react/var": "5.12.0"
48
+ "@eslint-react/ast": "5.12.1",
49
+ "@eslint-react/jsx": "5.12.1",
50
+ "@eslint-react/core": "5.12.1",
51
+ "@eslint-react/var": "5.12.1",
52
+ "@eslint-react/shared": "5.12.1",
53
+ "@eslint-react/eslint": "5.12.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.17",