eslint-plugin-react-x 1.24.0-next.0 → 1.24.0-next.11

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 (3) hide show
  1. package/dist/index.js +73 -75
  2. package/dist/index.mjs +74 -76
  3. package/package.json +13 -14
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
42
42
 
43
43
  // package.json
44
44
  var name = "eslint-plugin-react-x";
45
- var version = "1.24.0-next.0";
45
+ var version = "1.24.0-next.11";
46
46
  var createRule = shared.createRuleForPlugin("x");
47
47
 
48
48
  // src/rules/avoid-shorthand-boolean.ts
@@ -72,7 +72,7 @@ var avoid_shorthand_boolean_default = createRule({
72
72
  messageId: "avoidShorthandBoolean",
73
73
  node,
74
74
  data: {
75
- propName: JSX7__namespace.getPropName(node)
75
+ propName: JSX7__namespace.getAttributeName(node)
76
76
  },
77
77
  fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
78
78
  });
@@ -221,15 +221,15 @@ var no_access_state_in_setstate_default = createRule({
221
221
  if (!AST11__namespace.isThisExpression(node.object)) {
222
222
  return;
223
223
  }
224
- const [currClass, isComponent] = classEntries.at(-1) ?? [];
224
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
225
225
  if (currClass == null || !isComponent) {
226
226
  return;
227
227
  }
228
- const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
228
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
229
229
  if (currMethod == null || isStatic) {
230
230
  return;
231
231
  }
232
- const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
232
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
233
233
  if (setState == null || hasThisState) {
234
234
  return;
235
235
  }
@@ -251,15 +251,15 @@ var no_access_state_in_setstate_default = createRule({
251
251
  methodEntries.pop();
252
252
  },
253
253
  VariableDeclarator(node) {
254
- const [currClass, isComponent] = classEntries.at(-1) ?? [];
254
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
255
255
  if (currClass == null || !isComponent) {
256
256
  return;
257
257
  }
258
- const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
258
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
259
259
  if (currMethod == null || isStatic) {
260
260
  return;
261
261
  }
262
- const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
262
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
263
263
  if (setState == null || hasThisState) {
264
264
  return;
265
265
  }
@@ -610,15 +610,15 @@ var no_children_prop_default = createRule({
610
610
  create(context) {
611
611
  return {
612
612
  JSXElement(node) {
613
- const prop = JSX7__namespace.getProp(
613
+ const attribute = JSX7__namespace.getAttributeNode(
614
614
  "children",
615
615
  context.sourceCode.getScope(node),
616
616
  node.openingElement.attributes
617
617
  );
618
- if (prop) {
618
+ if (attribute != null) {
619
619
  context.report({
620
620
  messageId: "noChildrenProp",
621
- node: prop
621
+ node: attribute
622
622
  });
623
623
  }
624
624
  }
@@ -661,12 +661,6 @@ var RULE_NAME12 = "no-class-component";
661
661
  var RULE_FEATURES12 = [
662
662
  "CHK"
663
663
  ];
664
- function isComponentDidCatch(node) {
665
- return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
666
- }
667
- function isGetDerivedStateFromError(node) {
668
- return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
669
- }
670
664
  var no_class_component_default = createRule({
671
665
  meta: {
672
666
  type: "problem",
@@ -690,7 +684,7 @@ var no_class_component_default = createRule({
690
684
  "Program:exit"(node) {
691
685
  const components = ctx.getAllComponents(node);
692
686
  for (const { name: name2 = "anonymous", node: component } of components.values()) {
693
- if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
687
+ if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) {
694
688
  continue;
695
689
  }
696
690
  context.report({
@@ -1063,7 +1057,7 @@ var no_create_ref_default = createRule({
1063
1057
  create(context) {
1064
1058
  return {
1065
1059
  CallExpression(node) {
1066
- if (core.isCreateRefCall(node, context) && !AST11__namespace.findParentNode(node, core.isClassComponent)) {
1060
+ if (core.isCreateRefCall(node, context) && AST11__namespace.findParentNode(node, core.isClassComponent) == null) {
1067
1061
  context.report({ messageId: "noCreateRef", node });
1068
1062
  }
1069
1063
  }
@@ -1109,7 +1103,7 @@ var no_default_props_default = createRule({
1109
1103
  }
1110
1104
  const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
1111
1105
  const variableNode = VAR__namespace.getVariableNode(variable, 0);
1112
- if (variableNode === eff._) return;
1106
+ if (variableNode == null) return;
1113
1107
  if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
1114
1108
  context.report({ messageId: "noDefaultProps", node: property });
1115
1109
  },
@@ -1171,15 +1165,15 @@ var no_direct_mutation_state_default = createRule({
1171
1165
  if (!isAssignmentToThisState(node)) {
1172
1166
  return;
1173
1167
  }
1174
- const parentClass = AST11__namespace.findParentNodeGuard(
1168
+ const parentClass = AST11__namespace.findParentNode(
1175
1169
  node,
1176
1170
  AST11__namespace.isOneOf([
1177
1171
  types.AST_NODE_TYPES.ClassDeclaration,
1178
1172
  types.AST_NODE_TYPES.ClassExpression
1179
1173
  ])
1180
1174
  );
1181
- if (!parentClass) return;
1182
- if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNodeGuard(node, isConstructorFunction)) {
1175
+ if (parentClass == null) return;
1176
+ if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
1183
1177
  context.report({
1184
1178
  messageId: "noDirectMutationState",
1185
1179
  node
@@ -1280,10 +1274,11 @@ var no_duplicate_key_default = createRule({
1280
1274
  break;
1281
1275
  }
1282
1276
  default: {
1283
- const call = AST11__namespace.findParentNodeGuard(jsxElement, AST11__namespace.isMapCallLoose);
1284
- const iter = call && AST11__namespace.findParentNodeStop(jsxElement, call, AST11__namespace.isFunction);
1277
+ const call = AST11__namespace.findParentNode(jsxElement, AST11__namespace.isMapCallLoose);
1278
+ const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
1279
+ if (!AST11__namespace.isFunction(iter)) return;
1285
1280
  const arg0 = call?.arguments[0];
1286
- if (!call || !iter || !arg0) return;
1281
+ if (call == null || arg0 == null) return;
1287
1282
  if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) {
1288
1283
  return;
1289
1284
  }
@@ -1443,11 +1438,11 @@ var no_implicit_key_default = createRule({
1443
1438
  return {
1444
1439
  JSXOpeningElement(node) {
1445
1440
  const initialScope = context.sourceCode.getScope(node);
1446
- const keyPropFound = JSX7__namespace.findPropInAttributes("key", initialScope, node.attributes);
1441
+ const keyPropFound = JSX7__namespace.getAttributeNode("key", initialScope, node.attributes);
1447
1442
  const keyPropOnElement = node.attributes.some(
1448
1443
  (n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1449
1444
  );
1450
- if (keyPropFound && !keyPropOnElement) {
1445
+ if (keyPropFound != null && !keyPropOnElement) {
1451
1446
  context.report({ messageId: "noImplicitKey", node: keyPropFound });
1452
1447
  }
1453
1448
  }
@@ -1544,7 +1539,7 @@ function isInitExpression(node) {
1544
1539
  }
1545
1540
  function getVariableInitExpression(variable, at) {
1546
1541
  const def = variable?.defs[at];
1547
- if (def?.node === eff._ || !("init" in def.node)) {
1542
+ if (def?.node == null || !("init" in def.node)) {
1548
1543
  return eff._;
1549
1544
  }
1550
1545
  return isInitExpression(def.node.init) ? def.node.init : eff._;
@@ -1581,7 +1576,7 @@ var no_leaked_conditional_rendering_default = createRule({
1581
1576
  ];
1582
1577
  const services = utils.ESLintUtils.getParserServices(context, false);
1583
1578
  function getReportDescriptor(node) {
1584
- if (node === eff._) return eff._;
1579
+ if (node == null) return eff._;
1585
1580
  return tsPattern.match(node).when(AST11__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1586
1581
  const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
1587
1582
  if (isLeftUnaryNot) {
@@ -1617,7 +1612,7 @@ var no_leaked_conditional_rendering_default = createRule({
1617
1612
  }
1618
1613
  const visitorFunction = (node) => {
1619
1614
  const descriptor = getReportDescriptor(node);
1620
- if (descriptor === eff._) return;
1615
+ if (descriptor == null) return;
1621
1616
  context.report(descriptor);
1622
1617
  };
1623
1618
  return {
@@ -1648,20 +1643,30 @@ var no_missing_component_display_name_default = createRule({
1648
1643
  if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
1649
1644
  return {};
1650
1645
  }
1651
- const { ctx, listeners } = core.useComponentCollector(context);
1646
+ const {
1647
+ ctx,
1648
+ listeners
1649
+ } = core.useComponentCollector(
1650
+ context,
1651
+ core.DEFAULT_COMPONENT_HINT,
1652
+ {
1653
+ collectDisplayName: true,
1654
+ collectHookCalls: false
1655
+ }
1656
+ );
1652
1657
  return {
1653
1658
  ...listeners,
1654
1659
  "Program:exit"(node) {
1655
1660
  const components = ctx.getAllComponents(node);
1656
1661
  for (const { node: node2, displayName, flag } of components.values()) {
1657
1662
  const isMemoOrForwardRef = (flag & (core.ERFunctionComponentFlag.ForwardRef | core.ERFunctionComponentFlag.Memo)) > 0n;
1658
- if (AST11__namespace.getFunctionIdentifier(node2)) {
1663
+ if (AST11__namespace.getFunctionIdentifier(node2) != null) {
1659
1664
  continue;
1660
1665
  }
1661
1666
  if (!isMemoOrForwardRef) {
1662
1667
  continue;
1663
1668
  }
1664
- if (!displayName) {
1669
+ if (displayName == null) {
1665
1670
  context.report({
1666
1671
  messageId: "noMissingComponentDisplayName",
1667
1672
  node: node2
@@ -1697,7 +1702,7 @@ var no_missing_key_default = createRule({
1697
1702
  switch (node.type) {
1698
1703
  case types.AST_NODE_TYPES.JSXElement: {
1699
1704
  const initialScope = context.sourceCode.getScope(node);
1700
- if (!JSX7__namespace.hasProp("key", initialScope, node.openingElement.attributes)) {
1705
+ if (!JSX7__namespace.hasAttribute("key", initialScope, node.openingElement.attributes)) {
1701
1706
  return {
1702
1707
  messageId: "noMissingKey",
1703
1708
  node
@@ -1758,7 +1763,7 @@ var no_missing_key_default = createRule({
1758
1763
  }
1759
1764
  const initialScope = context.sourceCode.getScope(node);
1760
1765
  for (const element of elements) {
1761
- if (!JSX7__namespace.hasProp("key", initialScope, element.openingElement.attributes)) {
1766
+ if (!JSX7__namespace.hasAttribute("key", initialScope, element.openingElement.attributes)) {
1762
1767
  context.report({
1763
1768
  messageId: "noMissingKey",
1764
1769
  node: element
@@ -1860,7 +1865,7 @@ var no_nested_components_default = createRule({
1860
1865
  continue;
1861
1866
  }
1862
1867
  const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
1863
- const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || !!JSX7__namespace.findParentProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer);
1868
+ const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.findParentAttributeNode(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
1864
1869
  if (isInsideJSXPropValue) {
1865
1870
  if (!core.isDeclaredInRenderPropLoose(component)) {
1866
1871
  context.report({
@@ -1883,8 +1888,8 @@ var no_nested_components_default = createRule({
1883
1888
  });
1884
1889
  continue;
1885
1890
  }
1886
- const parentComponent = AST11__namespace.findParentNodeGuard(component, isFunctionComponent);
1887
- const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
1891
+ const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
1892
+ const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
1888
1893
  if (isParnetComponentNotDirectValueOfRenderProperty) {
1889
1894
  context.report({
1890
1895
  messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
@@ -1906,7 +1911,7 @@ var no_nested_components_default = createRule({
1906
1911
  }
1907
1912
  }
1908
1913
  for (const { name: name2 = "unknown", node: component } of classComponents) {
1909
- if (!AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
1914
+ if (AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
1910
1915
  continue;
1911
1916
  }
1912
1917
  context.report({
@@ -1959,8 +1964,8 @@ var no_prop_types_default = createRule({
1959
1964
  return;
1960
1965
  }
1961
1966
  const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
1962
- const variableNode = variable && VAR__namespace.getVariableNode(variable, 0);
1963
- if (variableNode && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
1967
+ const variableNode = VAR__namespace.getVariableNode(variable, 0);
1968
+ if (variableNode != null && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
1964
1969
  context.report({ messageId: "noPropTypes", node: property });
1965
1970
  }
1966
1971
  },
@@ -2057,11 +2062,12 @@ var no_set_state_in_component_did_mount_default = createRule({
2057
2062
  if (!core.isThisSetState(node)) {
2058
2063
  return;
2059
2064
  }
2060
- const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
2061
- const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentDidMount);
2062
- const methodScope = method && context.sourceCode.getScope(method);
2065
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2066
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2067
+ if (clazz == null || method == null || method === clazz) return;
2068
+ const methodScope = context.sourceCode.getScope(method);
2063
2069
  const upperScope = context.sourceCode.getScope(node).upper;
2064
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2070
+ if (method.parent === clazz.body && upperScope === methodScope) {
2065
2071
  context.report({
2066
2072
  messageId: "noSetStateInComponentDidMount",
2067
2073
  node
@@ -2101,11 +2107,12 @@ var no_set_state_in_component_did_update_default = createRule({
2101
2107
  if (!core.isThisSetState(node)) {
2102
2108
  return;
2103
2109
  }
2104
- const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
2105
- const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentDidUpdate);
2106
- const methodScope = method && context.sourceCode.getScope(method);
2110
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2111
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2112
+ if (clazz == null || method == null || method === clazz) return;
2113
+ const methodScope = context.sourceCode.getScope(method);
2107
2114
  const upperScope = context.sourceCode.getScope(node).upper;
2108
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2115
+ if (method.parent === clazz.body && upperScope === methodScope) {
2109
2116
  context.report({
2110
2117
  messageId: "noSetStateInComponentDidUpdate",
2111
2118
  node
@@ -2145,11 +2152,12 @@ var no_set_state_in_component_will_update_default = createRule({
2145
2152
  if (!core.isThisSetState(node)) {
2146
2153
  return;
2147
2154
  }
2148
- const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
2149
- const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentWillUpdate3);
2150
- const methodScope = method && context.sourceCode.getScope(method);
2155
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2156
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
2157
+ if (clazz == null || method == null || method === clazz) return;
2158
+ const methodScope = context.sourceCode.getScope(method);
2151
2159
  const upperScope = context.sourceCode.getScope(node).upper;
2152
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2160
+ if (method.parent === clazz.body && upperScope === methodScope) {
2153
2161
  context.report({
2154
2162
  messageId: "noSetStateInComponentWillUpdate",
2155
2163
  node
@@ -2374,22 +2382,21 @@ var no_unstable_context_value_default = createRule({
2374
2382
  return;
2375
2383
  }
2376
2384
  const functionEntry = ctx.getCurrentEntry();
2377
- if (functionEntry === eff._) return;
2385
+ if (functionEntry == null) return;
2378
2386
  const attribute = node.attributes.find(
2379
2387
  (attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
2380
2388
  );
2381
- if (attribute === eff._ || !("value" in attribute)) return;
2389
+ if (attribute == null || !("value" in attribute)) return;
2382
2390
  const value = attribute.value;
2383
2391
  if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
2384
2392
  const valueExpression = value.expression;
2385
2393
  const initialScope = context.sourceCode.getScope(valueExpression);
2386
2394
  const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
2387
- if (construction === eff._) return;
2395
+ if (construction == null) return;
2388
2396
  if (core.isReactHookCall(construction.node)) {
2389
2397
  return;
2390
2398
  }
2391
- const prevs = constructions.get(functionEntry.node) ?? [];
2392
- constructions.set(functionEntry.node, [...prevs, construction]);
2399
+ eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
2393
2400
  },
2394
2401
  "Program:exit"(node) {
2395
2402
  const components = ctx.getAllComponents(node).values();
@@ -2456,7 +2463,7 @@ var no_unstable_default_props_default = createRule({
2456
2463
  initialScope,
2457
2464
  VAR__namespace.ValueConstructionHint.StrictCallExpression
2458
2465
  );
2459
- if (construction === eff._) {
2466
+ if (construction == null) {
2460
2467
  continue;
2461
2468
  }
2462
2469
  if (core.isReactHookCall(construction.node)) {
@@ -2475,7 +2482,7 @@ var no_unstable_default_props_default = createRule({
2475
2482
  },
2476
2483
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2477
2484
  const functionEntry = ctx.getCurrentEntry();
2478
- if (!functionEntry) return;
2485
+ if (functionEntry == null) return;
2479
2486
  const prevs = declarators.get(functionEntry.node) ?? [];
2480
2487
  declarators.set(functionEntry.node, [...prevs, node]);
2481
2488
  }
@@ -2667,15 +2674,6 @@ function isAssignmentToThisState2(node) {
2667
2674
  const { left } = node;
2668
2675
  return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
2669
2676
  }
2670
- var isGetDerivedStateFromProps = tsPattern.isMatching({
2671
- key: {
2672
- name: "getDerivedStateFromProps"
2673
- },
2674
- static: true,
2675
- value: {
2676
- params: tsPattern.P.array()
2677
- }
2678
- });
2679
2677
  var no_unused_state_default = createRule({
2680
2678
  meta: {
2681
2679
  type: "problem",
@@ -2703,8 +2701,8 @@ var no_unused_state_default = createRule({
2703
2701
  return;
2704
2702
  }
2705
2703
  const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
2706
- const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
2707
- if (!defNode || isUsed) {
2704
+ const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
2705
+ if (defNode == null || isUsed) {
2708
2706
  return;
2709
2707
  }
2710
2708
  context.report({
@@ -2722,7 +2720,7 @@ var no_unused_state_default = createRule({
2722
2720
  return;
2723
2721
  }
2724
2722
  if (node.static) {
2725
- if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
2723
+ if (core.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
2726
2724
  const defNode = stateDefs.get(currentClass)?.node;
2727
2725
  stateDefs.set(currentClass, { node: defNode, isUsed: true });
2728
2726
  }
@@ -2947,7 +2945,7 @@ var prefer_destructuring_assignment_default = createRule({
2947
2945
  return false;
2948
2946
  }
2949
2947
  const id = AST11__namespace.getFunctionIdentifier(block);
2950
- return !!id && core.isComponentName(id.name) && components.some((component) => component.node === block);
2948
+ return id != null && core.isComponentName(id.name) && components.some((component) => component.node === block);
2951
2949
  }
2952
2950
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
2953
2951
  let scope = initialScope;
@@ -3115,7 +3113,7 @@ var prefer_shorthand_boolean_default = createRule({
3115
3113
  return {
3116
3114
  JSXAttribute(node) {
3117
3115
  const { value } = node;
3118
- const propName = JSX7__namespace.getPropName(node);
3116
+ const propName = JSX7__namespace.getAttributeName(node);
3119
3117
  const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
3120
3118
  if (!hasValueTrue) {
3121
3119
  return;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as JSX7 from '@eslint-react/jsx';
2
2
  import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
3
3
  import * as AST11 from '@eslint-react/ast';
4
- import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
5
- import { _ } from '@eslint-react/eff';
4
+ import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
5
+ import { _, getOrUpdate } from '@eslint-react/eff';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
7
7
  import { isMatching, match, P } from 'ts-pattern';
8
8
  import { compare } from 'compare-versions';
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
15
15
 
16
16
  // package.json
17
17
  var name = "eslint-plugin-react-x";
18
- var version = "1.24.0-next.0";
18
+ var version = "1.24.0-next.11";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -45,7 +45,7 @@ var avoid_shorthand_boolean_default = createRule({
45
45
  messageId: "avoidShorthandBoolean",
46
46
  node,
47
47
  data: {
48
- propName: JSX7.getPropName(node)
48
+ propName: JSX7.getAttributeName(node)
49
49
  },
50
50
  fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
51
51
  });
@@ -194,15 +194,15 @@ var no_access_state_in_setstate_default = createRule({
194
194
  if (!AST11.isThisExpression(node.object)) {
195
195
  return;
196
196
  }
197
- const [currClass, isComponent] = classEntries.at(-1) ?? [];
197
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
198
198
  if (currClass == null || !isComponent) {
199
199
  return;
200
200
  }
201
- const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
201
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
202
202
  if (currMethod == null || isStatic) {
203
203
  return;
204
204
  }
205
- const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
205
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
206
206
  if (setState == null || hasThisState) {
207
207
  return;
208
208
  }
@@ -224,15 +224,15 @@ var no_access_state_in_setstate_default = createRule({
224
224
  methodEntries.pop();
225
225
  },
226
226
  VariableDeclarator(node) {
227
- const [currClass, isComponent] = classEntries.at(-1) ?? [];
227
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
228
228
  if (currClass == null || !isComponent) {
229
229
  return;
230
230
  }
231
- const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
231
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
232
232
  if (currMethod == null || isStatic) {
233
233
  return;
234
234
  }
235
- const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
235
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
236
236
  if (setState == null || hasThisState) {
237
237
  return;
238
238
  }
@@ -583,15 +583,15 @@ var no_children_prop_default = createRule({
583
583
  create(context) {
584
584
  return {
585
585
  JSXElement(node) {
586
- const prop = JSX7.getProp(
586
+ const attribute = JSX7.getAttributeNode(
587
587
  "children",
588
588
  context.sourceCode.getScope(node),
589
589
  node.openingElement.attributes
590
590
  );
591
- if (prop) {
591
+ if (attribute != null) {
592
592
  context.report({
593
593
  messageId: "noChildrenProp",
594
- node: prop
594
+ node: attribute
595
595
  });
596
596
  }
597
597
  }
@@ -634,12 +634,6 @@ var RULE_NAME12 = "no-class-component";
634
634
  var RULE_FEATURES12 = [
635
635
  "CHK"
636
636
  ];
637
- function isComponentDidCatch(node) {
638
- return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
639
- }
640
- function isGetDerivedStateFromError(node) {
641
- return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
642
- }
643
637
  var no_class_component_default = createRule({
644
638
  meta: {
645
639
  type: "problem",
@@ -1036,7 +1030,7 @@ var no_create_ref_default = createRule({
1036
1030
  create(context) {
1037
1031
  return {
1038
1032
  CallExpression(node) {
1039
- if (isCreateRefCall(node, context) && !AST11.findParentNode(node, isClassComponent)) {
1033
+ if (isCreateRefCall(node, context) && AST11.findParentNode(node, isClassComponent) == null) {
1040
1034
  context.report({ messageId: "noCreateRef", node });
1041
1035
  }
1042
1036
  }
@@ -1082,7 +1076,7 @@ var no_default_props_default = createRule({
1082
1076
  }
1083
1077
  const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1084
1078
  const variableNode = VAR.getVariableNode(variable, 0);
1085
- if (variableNode === _) return;
1079
+ if (variableNode == null) return;
1086
1080
  if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
1087
1081
  context.report({ messageId: "noDefaultProps", node: property });
1088
1082
  },
@@ -1144,15 +1138,15 @@ var no_direct_mutation_state_default = createRule({
1144
1138
  if (!isAssignmentToThisState(node)) {
1145
1139
  return;
1146
1140
  }
1147
- const parentClass = AST11.findParentNodeGuard(
1141
+ const parentClass = AST11.findParentNode(
1148
1142
  node,
1149
1143
  AST11.isOneOf([
1150
1144
  AST_NODE_TYPES.ClassDeclaration,
1151
1145
  AST_NODE_TYPES.ClassExpression
1152
1146
  ])
1153
1147
  );
1154
- if (!parentClass) return;
1155
- if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNodeGuard(node, isConstructorFunction)) {
1148
+ if (parentClass == null) return;
1149
+ if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNode(node, isConstructorFunction)) {
1156
1150
  context.report({
1157
1151
  messageId: "noDirectMutationState",
1158
1152
  node
@@ -1253,10 +1247,11 @@ var no_duplicate_key_default = createRule({
1253
1247
  break;
1254
1248
  }
1255
1249
  default: {
1256
- const call = AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose);
1257
- const iter = call && AST11.findParentNodeStop(jsxElement, call, AST11.isFunction);
1250
+ const call = AST11.findParentNode(jsxElement, AST11.isMapCallLoose);
1251
+ const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
1252
+ if (!AST11.isFunction(iter)) return;
1258
1253
  const arg0 = call?.arguments[0];
1259
- if (!call || !iter || !arg0) return;
1254
+ if (call == null || arg0 == null) return;
1260
1255
  if (AST11.unwrapTypeExpression(arg0) !== iter) {
1261
1256
  return;
1262
1257
  }
@@ -1416,11 +1411,11 @@ var no_implicit_key_default = createRule({
1416
1411
  return {
1417
1412
  JSXOpeningElement(node) {
1418
1413
  const initialScope = context.sourceCode.getScope(node);
1419
- const keyPropFound = JSX7.findPropInAttributes("key", initialScope, node.attributes);
1414
+ const keyPropFound = JSX7.getAttributeNode("key", initialScope, node.attributes);
1420
1415
  const keyPropOnElement = node.attributes.some(
1421
1416
  (n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1422
1417
  );
1423
- if (keyPropFound && !keyPropOnElement) {
1418
+ if (keyPropFound != null && !keyPropOnElement) {
1424
1419
  context.report({ messageId: "noImplicitKey", node: keyPropFound });
1425
1420
  }
1426
1421
  }
@@ -1517,7 +1512,7 @@ function isInitExpression(node) {
1517
1512
  }
1518
1513
  function getVariableInitExpression(variable, at) {
1519
1514
  const def = variable?.defs[at];
1520
- if (def?.node === _ || !("init" in def.node)) {
1515
+ if (def?.node == null || !("init" in def.node)) {
1521
1516
  return _;
1522
1517
  }
1523
1518
  return isInitExpression(def.node.init) ? def.node.init : _;
@@ -1554,7 +1549,7 @@ var no_leaked_conditional_rendering_default = createRule({
1554
1549
  ];
1555
1550
  const services = ESLintUtils.getParserServices(context, false);
1556
1551
  function getReportDescriptor(node) {
1557
- if (node === _) return _;
1552
+ if (node == null) return _;
1558
1553
  return match(node).when(AST11.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1559
1554
  const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
1560
1555
  if (isLeftUnaryNot) {
@@ -1590,7 +1585,7 @@ var no_leaked_conditional_rendering_default = createRule({
1590
1585
  }
1591
1586
  const visitorFunction = (node) => {
1592
1587
  const descriptor = getReportDescriptor(node);
1593
- if (descriptor === _) return;
1588
+ if (descriptor == null) return;
1594
1589
  context.report(descriptor);
1595
1590
  };
1596
1591
  return {
@@ -1621,20 +1616,30 @@ var no_missing_component_display_name_default = createRule({
1621
1616
  if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
1622
1617
  return {};
1623
1618
  }
1624
- const { ctx, listeners } = useComponentCollector(context);
1619
+ const {
1620
+ ctx,
1621
+ listeners
1622
+ } = useComponentCollector(
1623
+ context,
1624
+ DEFAULT_COMPONENT_HINT,
1625
+ {
1626
+ collectDisplayName: true,
1627
+ collectHookCalls: false
1628
+ }
1629
+ );
1625
1630
  return {
1626
1631
  ...listeners,
1627
1632
  "Program:exit"(node) {
1628
1633
  const components = ctx.getAllComponents(node);
1629
1634
  for (const { node: node2, displayName, flag } of components.values()) {
1630
1635
  const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
1631
- if (AST11.getFunctionIdentifier(node2)) {
1636
+ if (AST11.getFunctionIdentifier(node2) != null) {
1632
1637
  continue;
1633
1638
  }
1634
1639
  if (!isMemoOrForwardRef) {
1635
1640
  continue;
1636
1641
  }
1637
- if (!displayName) {
1642
+ if (displayName == null) {
1638
1643
  context.report({
1639
1644
  messageId: "noMissingComponentDisplayName",
1640
1645
  node: node2
@@ -1670,7 +1675,7 @@ var no_missing_key_default = createRule({
1670
1675
  switch (node.type) {
1671
1676
  case AST_NODE_TYPES.JSXElement: {
1672
1677
  const initialScope = context.sourceCode.getScope(node);
1673
- if (!JSX7.hasProp("key", initialScope, node.openingElement.attributes)) {
1678
+ if (!JSX7.hasAttribute("key", initialScope, node.openingElement.attributes)) {
1674
1679
  return {
1675
1680
  messageId: "noMissingKey",
1676
1681
  node
@@ -1731,7 +1736,7 @@ var no_missing_key_default = createRule({
1731
1736
  }
1732
1737
  const initialScope = context.sourceCode.getScope(node);
1733
1738
  for (const element of elements) {
1734
- if (!JSX7.hasProp("key", initialScope, element.openingElement.attributes)) {
1739
+ if (!JSX7.hasAttribute("key", initialScope, element.openingElement.attributes)) {
1735
1740
  context.report({
1736
1741
  messageId: "noMissingKey",
1737
1742
  node: element
@@ -1833,7 +1838,7 @@ var no_nested_components_default = createRule({
1833
1838
  continue;
1834
1839
  }
1835
1840
  const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
1836
- const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || !!JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer);
1841
+ const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentAttributeNode(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
1837
1842
  if (isInsideJSXPropValue) {
1838
1843
  if (!isDeclaredInRenderPropLoose(component)) {
1839
1844
  context.report({
@@ -1856,8 +1861,8 @@ var no_nested_components_default = createRule({
1856
1861
  });
1857
1862
  continue;
1858
1863
  }
1859
- const parentComponent = AST11.findParentNodeGuard(component, isFunctionComponent);
1860
- const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !isDirectValueOfRenderPropertyLoose(parentComponent);
1864
+ const parentComponent = AST11.findParentNode(component, isFunctionComponent);
1865
+ const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
1861
1866
  if (isParnetComponentNotDirectValueOfRenderProperty) {
1862
1867
  context.report({
1863
1868
  messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
@@ -1879,7 +1884,7 @@ var no_nested_components_default = createRule({
1879
1884
  }
1880
1885
  }
1881
1886
  for (const { name: name2 = "unknown", node: component } of classComponents) {
1882
- if (!AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
1887
+ if (AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
1883
1888
  continue;
1884
1889
  }
1885
1890
  context.report({
@@ -1932,8 +1937,8 @@ var no_prop_types_default = createRule({
1932
1937
  return;
1933
1938
  }
1934
1939
  const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1935
- const variableNode = variable && VAR.getVariableNode(variable, 0);
1936
- if (variableNode && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
1940
+ const variableNode = VAR.getVariableNode(variable, 0);
1941
+ if (variableNode != null && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
1937
1942
  context.report({ messageId: "noPropTypes", node: property });
1938
1943
  }
1939
1944
  },
@@ -2030,11 +2035,12 @@ var no_set_state_in_component_did_mount_default = createRule({
2030
2035
  if (!isThisSetState(node)) {
2031
2036
  return;
2032
2037
  }
2033
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2034
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidMount);
2035
- const methodScope = method && context.sourceCode.getScope(method);
2038
+ const clazz = AST11.findParentNode(node, isClassComponent);
2039
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2040
+ if (clazz == null || method == null || method === clazz) return;
2041
+ const methodScope = context.sourceCode.getScope(method);
2036
2042
  const upperScope = context.sourceCode.getScope(node).upper;
2037
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2043
+ if (method.parent === clazz.body && upperScope === methodScope) {
2038
2044
  context.report({
2039
2045
  messageId: "noSetStateInComponentDidMount",
2040
2046
  node
@@ -2074,11 +2080,12 @@ var no_set_state_in_component_did_update_default = createRule({
2074
2080
  if (!isThisSetState(node)) {
2075
2081
  return;
2076
2082
  }
2077
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2078
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidUpdate);
2079
- const methodScope = method && context.sourceCode.getScope(method);
2083
+ const clazz = AST11.findParentNode(node, isClassComponent);
2084
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2085
+ if (clazz == null || method == null || method === clazz) return;
2086
+ const methodScope = context.sourceCode.getScope(method);
2080
2087
  const upperScope = context.sourceCode.getScope(node).upper;
2081
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2088
+ if (method.parent === clazz.body && upperScope === methodScope) {
2082
2089
  context.report({
2083
2090
  messageId: "noSetStateInComponentDidUpdate",
2084
2091
  node
@@ -2118,11 +2125,12 @@ var no_set_state_in_component_will_update_default = createRule({
2118
2125
  if (!isThisSetState(node)) {
2119
2126
  return;
2120
2127
  }
2121
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2122
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentWillUpdate3);
2123
- const methodScope = method && context.sourceCode.getScope(method);
2128
+ const clazz = AST11.findParentNode(node, isClassComponent);
2129
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
2130
+ if (clazz == null || method == null || method === clazz) return;
2131
+ const methodScope = context.sourceCode.getScope(method);
2124
2132
  const upperScope = context.sourceCode.getScope(node).upper;
2125
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2133
+ if (method.parent === clazz.body && upperScope === methodScope) {
2126
2134
  context.report({
2127
2135
  messageId: "noSetStateInComponentWillUpdate",
2128
2136
  node
@@ -2347,22 +2355,21 @@ var no_unstable_context_value_default = createRule({
2347
2355
  return;
2348
2356
  }
2349
2357
  const functionEntry = ctx.getCurrentEntry();
2350
- if (functionEntry === _) return;
2358
+ if (functionEntry == null) return;
2351
2359
  const attribute = node.attributes.find(
2352
2360
  (attribute2) => attribute2.type === AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
2353
2361
  );
2354
- if (attribute === _ || !("value" in attribute)) return;
2362
+ if (attribute == null || !("value" in attribute)) return;
2355
2363
  const value = attribute.value;
2356
2364
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2357
2365
  const valueExpression = value.expression;
2358
2366
  const initialScope = context.sourceCode.getScope(valueExpression);
2359
2367
  const construction = VAR.getValueConstruction(valueExpression, initialScope);
2360
- if (construction === _) return;
2368
+ if (construction == null) return;
2361
2369
  if (isReactHookCall(construction.node)) {
2362
2370
  return;
2363
2371
  }
2364
- const prevs = constructions.get(functionEntry.node) ?? [];
2365
- constructions.set(functionEntry.node, [...prevs, construction]);
2372
+ getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
2366
2373
  },
2367
2374
  "Program:exit"(node) {
2368
2375
  const components = ctx.getAllComponents(node).values();
@@ -2429,7 +2436,7 @@ var no_unstable_default_props_default = createRule({
2429
2436
  initialScope,
2430
2437
  VAR.ValueConstructionHint.StrictCallExpression
2431
2438
  );
2432
- if (construction === _) {
2439
+ if (construction == null) {
2433
2440
  continue;
2434
2441
  }
2435
2442
  if (isReactHookCall(construction.node)) {
@@ -2448,7 +2455,7 @@ var no_unstable_default_props_default = createRule({
2448
2455
  },
2449
2456
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2450
2457
  const functionEntry = ctx.getCurrentEntry();
2451
- if (!functionEntry) return;
2458
+ if (functionEntry == null) return;
2452
2459
  const prevs = declarators.get(functionEntry.node) ?? [];
2453
2460
  declarators.set(functionEntry.node, [...prevs, node]);
2454
2461
  }
@@ -2640,15 +2647,6 @@ function isAssignmentToThisState2(node) {
2640
2647
  const { left } = node;
2641
2648
  return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
2642
2649
  }
2643
- var isGetDerivedStateFromProps = isMatching({
2644
- key: {
2645
- name: "getDerivedStateFromProps"
2646
- },
2647
- static: true,
2648
- value: {
2649
- params: P.array()
2650
- }
2651
- });
2652
2650
  var no_unused_state_default = createRule({
2653
2651
  meta: {
2654
2652
  type: "problem",
@@ -2676,8 +2674,8 @@ var no_unused_state_default = createRule({
2676
2674
  return;
2677
2675
  }
2678
2676
  const className = AST11.getClassIdentifier(currentClass)?.name;
2679
- const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
2680
- if (!defNode || isUsed) {
2677
+ const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
2678
+ if (defNode == null || isUsed) {
2681
2679
  return;
2682
2680
  }
2683
2681
  context.report({
@@ -2695,7 +2693,7 @@ var no_unused_state_default = createRule({
2695
2693
  return;
2696
2694
  }
2697
2695
  if (node.static) {
2698
- if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
2696
+ if (isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
2699
2697
  const defNode = stateDefs.get(currentClass)?.node;
2700
2698
  stateDefs.set(currentClass, { node: defNode, isUsed: true });
2701
2699
  }
@@ -2920,7 +2918,7 @@ var prefer_destructuring_assignment_default = createRule({
2920
2918
  return false;
2921
2919
  }
2922
2920
  const id = AST11.getFunctionIdentifier(block);
2923
- return !!id && isComponentName(id.name) && components.some((component) => component.node === block);
2921
+ return id != null && isComponentName(id.name) && components.some((component) => component.node === block);
2924
2922
  }
2925
2923
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
2926
2924
  let scope = initialScope;
@@ -3088,7 +3086,7 @@ var prefer_shorthand_boolean_default = createRule({
3088
3086
  return {
3089
3087
  JSXAttribute(node) {
3090
3088
  const { value } = node;
3091
- const propName = JSX7.getPropName(node);
3089
+ const propName = JSX7.getAttributeName(node);
3092
3090
  const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
3093
3091
  if (!hasValueTrue) {
3094
3092
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.24.0-next.0",
3
+ "version": "1.24.0-next.11",
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",
@@ -40,25 +40,24 @@
40
40
  "./package.json"
41
41
  ],
42
42
  "dependencies": {
43
- "@typescript-eslint/scope-manager": "^8.19.1",
44
- "@typescript-eslint/type-utils": "^8.19.1",
45
- "@typescript-eslint/types": "^8.19.1",
46
- "@typescript-eslint/utils": "^8.19.1",
43
+ "@typescript-eslint/scope-manager": "^8.20.0",
44
+ "@typescript-eslint/type-utils": "^8.20.0",
45
+ "@typescript-eslint/types": "^8.20.0",
46
+ "@typescript-eslint/utils": "^8.20.0",
47
47
  "compare-versions": "^6.1.1",
48
48
  "is-immutable-type": "^5.0.1",
49
49
  "string-ts": "^2.2.0",
50
50
  "ts-pattern": "^5.6.0",
51
- "@eslint-react/ast": "1.24.0-next.0",
52
- "@eslint-react/core": "1.24.0-next.0",
53
- "@eslint-react/eff": "1.24.0-next.0",
54
- "@eslint-react/shared": "1.24.0-next.0",
55
- "@eslint-react/jsx": "1.24.0-next.0",
56
- "@eslint-react/types": "1.24.0-next.0",
57
- "@eslint-react/var": "1.24.0-next.0"
51
+ "@eslint-react/ast": "1.24.0-next.11",
52
+ "@eslint-react/eff": "1.24.0-next.11",
53
+ "@eslint-react/jsx": "1.24.0-next.11",
54
+ "@eslint-react/core": "1.24.0-next.11",
55
+ "@eslint-react/shared": "1.24.0-next.11",
56
+ "@eslint-react/var": "1.24.0-next.11"
58
57
  },
59
58
  "devDependencies": {
60
- "@types/react": "^19.0.4",
61
- "@types/react-dom": "^19.0.2",
59
+ "@types/react": "^19.0.7",
60
+ "@types/react-dom": "^19.0.3",
62
61
  "ts-api-utils": "^2.0.0",
63
62
  "tsup": "^8.3.5",
64
63
  "@workspace/configs": "0.0.0"