eslint-plugin-react-x 5.5.6-next.0 → 5.6.0-beta.2

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 +72 -51
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -142,7 +142,7 @@ const rules$6 = {
142
142
  //#endregion
143
143
  //#region package.json
144
144
  var name$6 = "eslint-plugin-react-x";
145
- var version = "5.5.6-next.0";
145
+ var version = "5.6.0-beta.2";
146
146
 
147
147
  //#endregion
148
148
  //#region src/utils/create-rule.ts
@@ -1830,15 +1830,18 @@ function create$45(context) {
1830
1830
  });
1831
1831
  return descriptors;
1832
1832
  }
1833
- case AST_NODE_TYPES.CallExpression: switch (true) {
1834
- case node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object): return [{
1835
- messageId: "default",
1836
- node: node.callee.object
1837
- }];
1838
- case node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0]): return [{
1839
- messageId: "default",
1840
- node: node.arguments[0]
1841
- }];
1833
+ case AST_NODE_TYPES.CallExpression: {
1834
+ const callee = Extract.unwrap(node.callee);
1835
+ switch (true) {
1836
+ case callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "toString" && isArrayIndex(callee.object): return [{
1837
+ messageId: "default",
1838
+ node: callee.object
1839
+ }];
1840
+ case callee.type === AST_NODE_TYPES.Identifier && callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0]): return [{
1841
+ messageId: "default",
1842
+ node: node.arguments[0]
1843
+ }];
1844
+ }
1842
1845
  }
1843
1846
  }
1844
1847
  return [];
@@ -2273,7 +2276,11 @@ function create$31(context) {
2273
2276
  break;
2274
2277
  }
2275
2278
  default: {
2276
- const call = Traverse.findParent(jsxElement, (n) => n.type === AST_NODE_TYPES.CallExpression && n.callee.type === AST_NODE_TYPES.MemberExpression && n.callee.property.type === AST_NODE_TYPES.Identifier && n.callee.property.name === "map");
2279
+ const call = Traverse.findParent(jsxElement, (n) => {
2280
+ if (n.type !== AST_NODE_TYPES.CallExpression) return false;
2281
+ const callee = Extract.unwrap(n.callee);
2282
+ return callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "map";
2283
+ });
2277
2284
  const iter = Traverse.findParent(jsxElement, (n) => n === call || Check.isFunction(n));
2278
2285
  if (!Check.isFunction(iter)) return;
2279
2286
  const arg0 = call?.arguments[0];
@@ -2348,9 +2355,10 @@ function create$30(context) {
2348
2355
  function canFix(context, node) {
2349
2356
  const { importSource } = getSettingsFromContext(context);
2350
2357
  const initialScope = context.sourceCode.getScope(node);
2351
- switch (node.callee.type) {
2352
- case AST_NODE_TYPES.Identifier: return core.isAPIFromReact(node.callee.name, initialScope, importSource);
2353
- case AST_NODE_TYPES.MemberExpression: return node.callee.object.type === AST_NODE_TYPES.Identifier && core.isAPIFromReact(node.callee.object.name, initialScope, importSource);
2358
+ const callee = Extract.unwrap(node.callee);
2359
+ switch (callee.type) {
2360
+ case AST_NODE_TYPES.Identifier: return core.isAPIFromReact(callee.name, initialScope, importSource);
2361
+ case AST_NODE_TYPES.MemberExpression: return callee.object.type === AST_NODE_TYPES.Identifier && core.isAPIFromReact(callee.object.name, initialScope, importSource);
2354
2362
  default: return false;
2355
2363
  }
2356
2364
  }
@@ -2805,9 +2813,10 @@ function create$23(context) {
2805
2813
  CallExpression(node) {
2806
2814
  inChildrenToArray ||= core.isChildrenToArrayCall(context, node);
2807
2815
  if (inChildrenToArray) return;
2808
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
2809
- if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return;
2810
- const name = node.callee.property.name;
2816
+ const callee = Extract.unwrap(node.callee);
2817
+ if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
2818
+ if (callee.property.type !== AST_NODE_TYPES.Identifier) return;
2819
+ const name = callee.property.name;
2811
2820
  const idx = name === "from" ? 1 : name === "map" ? 0 : -1;
2812
2821
  if (idx < 0) return;
2813
2822
  const cb = node.arguments[idx];
@@ -3376,10 +3385,17 @@ var no_unstable_default_props_default = createRule({
3376
3385
  defaultOptions: defaultOptions$1
3377
3386
  });
3378
3387
  function extractIdentifier(node) {
3379
- if (node.type === AST_NODE_TYPES.NewExpression && node.callee.type === AST_NODE_TYPES.Identifier) return node.callee.name;
3380
- if (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression) {
3381
- const { object } = node.callee;
3382
- if (object.type === AST_NODE_TYPES.Identifier) return object.name;
3388
+ if (node.type === AST_NODE_TYPES.NewExpression) {
3389
+ const callee = Extract.unwrap(node.callee);
3390
+ if (callee.type === AST_NODE_TYPES.Identifier) return callee.name;
3391
+ }
3392
+ if (node.type === AST_NODE_TYPES.CallExpression) {
3393
+ const callee = Extract.unwrap(node.callee);
3394
+ if (callee.type === AST_NODE_TYPES.Identifier) return callee.name;
3395
+ if (callee.type === AST_NODE_TYPES.MemberExpression) {
3396
+ const { object } = callee;
3397
+ if (object.type === AST_NODE_TYPES.Identifier) return object.name;
3398
+ }
3383
3399
  }
3384
3400
  return null;
3385
3401
  }
@@ -6570,9 +6586,10 @@ function isHookDecl(node) {
6570
6586
  if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
6571
6587
  const init = node.init;
6572
6588
  if (init == null || init.type !== AST_NODE_TYPES.CallExpression) return false;
6573
- switch (init.callee.type) {
6574
- case AST_NODE_TYPES.Identifier: return core.isHookName(init.callee.name);
6575
- case AST_NODE_TYPES.MemberExpression: return init.callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(init.callee.property.name);
6589
+ const callee = Extract.unwrap(init.callee);
6590
+ switch (callee.type) {
6591
+ case AST_NODE_TYPES.Identifier: return core.isHookName(callee.name);
6592
+ case AST_NODE_TYPES.MemberExpression: return callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(callee.property.name);
6576
6593
  default: return false;
6577
6594
  }
6578
6595
  }
@@ -6657,7 +6674,8 @@ function create$5(context) {
6657
6674
  if (setupFnRef.current === node) setupFnRef.current = null;
6658
6675
  };
6659
6676
  function isThenCall(node) {
6660
- return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
6677
+ const callee = Extract.unwrap(node.callee);
6678
+ return callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "then";
6661
6679
  }
6662
6680
  function isUseStateCall(node) {
6663
6681
  return core.isUseStateLikeCall(node, additionalStateHooks);
@@ -6695,21 +6713,22 @@ function create$5(context) {
6695
6713
  return variableNodeParent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === id.name) === at;
6696
6714
  }
6697
6715
  function isSetStateCall(node) {
6698
- switch (node.callee.type) {
6716
+ const callee = Extract.unwrap(node.callee);
6717
+ switch (callee.type) {
6699
6718
  case AST_NODE_TYPES.CallExpression: {
6700
- const { callee } = node.callee;
6701
- if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
6702
- if (!("name" in callee.object)) return false;
6703
- const isAt = callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "at";
6704
- const [index] = node.callee.arguments;
6719
+ const innerCallee = Extract.unwrap(callee.callee);
6720
+ if (innerCallee.type !== AST_NODE_TYPES.MemberExpression) return false;
6721
+ if (!("name" in innerCallee.object)) return false;
6722
+ const isAt = innerCallee.property.type === AST_NODE_TYPES.Identifier && innerCallee.property.name === "at";
6723
+ const [index] = callee.arguments;
6705
6724
  if (!isAt || index == null) return false;
6706
- return getStaticValue(index, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(callee.object);
6725
+ return getStaticValue(index, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(innerCallee.object);
6707
6726
  }
6708
- case AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(node.callee, 1);
6727
+ case AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(callee, 1);
6709
6728
  case AST_NODE_TYPES.MemberExpression: {
6710
- if (!("name" in node.callee.object)) return false;
6711
- const property = node.callee.property;
6712
- return getStaticValue(property, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(node.callee.object, 1);
6729
+ if (!("name" in callee.object)) return false;
6730
+ const property = callee.property;
6731
+ return getStaticValue(property, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(callee.object, 1);
6713
6732
  }
6714
6733
  default: return false;
6715
6734
  }
@@ -6762,7 +6781,7 @@ function create$5(context) {
6762
6781
  if (isArgumentUsingRefValue(context, args0)) return;
6763
6782
  if (isRefGatedContext(context, node)) return;
6764
6783
  context.report({
6765
- data: { name: context.sourceCode.getText(node.callee) },
6784
+ data: { name: context.sourceCode.getText(Extract.unwrap(node.callee)) },
6766
6785
  messageId: "default",
6767
6786
  node
6768
6787
  });
@@ -6824,8 +6843,9 @@ function create$5(context) {
6824
6843
  });
6825
6844
  }
6826
6845
  for (const { callee } of trackedFnCalls) {
6827
- if (!("name" in callee)) continue;
6828
- const setStateCalls = getSetStateCalls(context, callee);
6846
+ const unwrappedCallee = Extract.unwrap(callee);
6847
+ if (unwrappedCallee.type !== AST_NODE_TYPES.Identifier) continue;
6848
+ const setStateCalls = getSetStateCalls(context, unwrappedCallee);
6829
6849
  for (const setStateCall of setStateCalls) {
6830
6850
  if (isRefGatedContext(context, getSetStateCallExpression(setStateCall))) continue;
6831
6851
  context.report({
@@ -6915,21 +6935,22 @@ function create$4(context) {
6915
6935
  return initNodeParent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === topLevelId.name) === at;
6916
6936
  }
6917
6937
  function isSetStateCall(node) {
6918
- switch (node.callee.type) {
6938
+ const callee = Extract.unwrap(node.callee);
6939
+ switch (callee.type) {
6919
6940
  case AST_NODE_TYPES.CallExpression: {
6920
- const { callee } = node.callee;
6921
- if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
6922
- if (!("name" in callee.object)) return false;
6923
- const isAt = callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "at";
6924
- const [index] = node.callee.arguments;
6941
+ const innerCallee = Extract.unwrap(callee.callee);
6942
+ if (innerCallee.type !== AST_NODE_TYPES.MemberExpression) return false;
6943
+ if (!("name" in innerCallee.object)) return false;
6944
+ const isAt = innerCallee.property.type === AST_NODE_TYPES.Identifier && innerCallee.property.name === "at";
6945
+ const [index] = callee.arguments;
6925
6946
  if (!isAt || index == null) return false;
6926
- return getStaticValue(index, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(callee.object);
6947
+ return getStaticValue(index, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(innerCallee.object);
6927
6948
  }
6928
- case AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(node.callee, 1);
6949
+ case AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(callee, 1);
6929
6950
  case AST_NODE_TYPES.MemberExpression: {
6930
- if (!("name" in node.callee.object)) return false;
6931
- const property = node.callee.property;
6932
- return getStaticValue(property, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(node.callee.object, 1);
6951
+ if (!("name" in callee.object)) return false;
6952
+ const property = callee.property;
6953
+ return getStaticValue(property, context.sourceCode.getScope(node))?.value === 1 && isIdFromUseStateCall(callee.object, 1);
6933
6954
  }
6934
6955
  default: return false;
6935
6956
  }
@@ -6967,7 +6988,7 @@ function create$4(context) {
6967
6988
  if (isInsideConditional(node, componentFn)) return;
6968
6989
  if (componentHasEarlyReturn.current) return;
6969
6990
  context.report({
6970
- data: { name: context.sourceCode.getText(node.callee) },
6991
+ data: { name: context.sourceCode.getText(Extract.unwrap(node.callee)) },
6971
6992
  messageId: "default",
6972
6993
  node
6973
6994
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.5.6-next.0",
3
+ "version": "5.6.0-beta.2",
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.5.6-next.0",
49
- "@eslint-react/core": "5.5.6-next.0",
50
- "@eslint-react/jsx": "5.5.6-next.0",
51
- "@eslint-react/shared": "5.5.6-next.0",
52
- "@eslint-react/var": "5.5.6-next.0",
53
- "@eslint-react/eslint": "5.5.6-next.0"
48
+ "@eslint-react/ast": "5.6.0-beta.2",
49
+ "@eslint-react/eslint": "5.6.0-beta.2",
50
+ "@eslint-react/jsx": "5.6.0-beta.2",
51
+ "@eslint-react/core": "5.6.0-beta.2",
52
+ "@eslint-react/shared": "5.6.0-beta.2",
53
+ "@eslint-react/var": "5.6.0-beta.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.14",