eslint-plugin-react-x 1.24.0-beta.0 → 1.24.0-beta.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.
Files changed (3) hide show
  1. package/dist/index.js +64 -51
  2. package/dist/index.mjs +66 -53
  3. package/package.json +10 -10
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-beta.0";
45
+ var version = "1.24.0-beta.3";
46
46
  var createRule = shared.createRuleForPlugin("x");
47
47
 
48
48
  // src/rules/avoid-shorthand-boolean.ts
@@ -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
  }
@@ -615,7 +615,7 @@ var no_children_prop_default = createRule({
615
615
  context.sourceCode.getScope(node),
616
616
  node.openingElement.attributes
617
617
  );
618
- if (prop) {
618
+ if (prop != null) {
619
619
  context.report({
620
620
  messageId: "noChildrenProp",
621
621
  node: prop
@@ -1063,7 +1063,7 @@ var no_create_ref_default = createRule({
1063
1063
  create(context) {
1064
1064
  return {
1065
1065
  CallExpression(node) {
1066
- if (core.isCreateRefCall(node, context) && !AST11__namespace.findParentNode(node, core.isClassComponent)) {
1066
+ if (core.isCreateRefCall(node, context) && AST11__namespace.findParentNode(node, core.isClassComponent) == null) {
1067
1067
  context.report({ messageId: "noCreateRef", node });
1068
1068
  }
1069
1069
  }
@@ -1109,7 +1109,7 @@ var no_default_props_default = createRule({
1109
1109
  }
1110
1110
  const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
1111
1111
  const variableNode = VAR__namespace.getVariableNode(variable, 0);
1112
- if (variableNode === eff._) return;
1112
+ if (variableNode == null) return;
1113
1113
  if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
1114
1114
  context.report({ messageId: "noDefaultProps", node: property });
1115
1115
  },
@@ -1171,15 +1171,15 @@ var no_direct_mutation_state_default = createRule({
1171
1171
  if (!isAssignmentToThisState(node)) {
1172
1172
  return;
1173
1173
  }
1174
- const parentClass = AST11__namespace.findParentNodeGuard(
1174
+ const parentClass = AST11__namespace.findParentNode(
1175
1175
  node,
1176
1176
  AST11__namespace.isOneOf([
1177
1177
  types.AST_NODE_TYPES.ClassDeclaration,
1178
1178
  types.AST_NODE_TYPES.ClassExpression
1179
1179
  ])
1180
1180
  );
1181
- if (!parentClass) return;
1182
- if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNodeGuard(node, isConstructorFunction)) {
1181
+ if (parentClass == null) return;
1182
+ if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
1183
1183
  context.report({
1184
1184
  messageId: "noDirectMutationState",
1185
1185
  node
@@ -1280,10 +1280,11 @@ var no_duplicate_key_default = createRule({
1280
1280
  break;
1281
1281
  }
1282
1282
  default: {
1283
- const call = AST11__namespace.findParentNodeGuard(jsxElement, AST11__namespace.isMapCallLoose);
1284
- const iter = call && AST11__namespace.findParentNodeStop(jsxElement, call, AST11__namespace.isFunction);
1283
+ const call = AST11__namespace.findParentNode(jsxElement, AST11__namespace.isMapCallLoose);
1284
+ const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
1285
+ if (!AST11__namespace.isFunction(iter)) return;
1285
1286
  const arg0 = call?.arguments[0];
1286
- if (!call || !iter || !arg0) return;
1287
+ if (call == null || arg0 == null) return;
1287
1288
  if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) {
1288
1289
  return;
1289
1290
  }
@@ -1447,7 +1448,7 @@ var no_implicit_key_default = createRule({
1447
1448
  const keyPropOnElement = node.attributes.some(
1448
1449
  (n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1449
1450
  );
1450
- if (keyPropFound && !keyPropOnElement) {
1451
+ if (keyPropFound != null && !keyPropOnElement) {
1451
1452
  context.report({ messageId: "noImplicitKey", node: keyPropFound });
1452
1453
  }
1453
1454
  }
@@ -1544,7 +1545,7 @@ function isInitExpression(node) {
1544
1545
  }
1545
1546
  function getVariableInitExpression(variable, at) {
1546
1547
  const def = variable?.defs[at];
1547
- if (def?.node === eff._ || !("init" in def.node)) {
1548
+ if (def?.node == null || !("init" in def.node)) {
1548
1549
  return eff._;
1549
1550
  }
1550
1551
  return isInitExpression(def.node.init) ? def.node.init : eff._;
@@ -1581,7 +1582,7 @@ var no_leaked_conditional_rendering_default = createRule({
1581
1582
  ];
1582
1583
  const services = utils.ESLintUtils.getParserServices(context, false);
1583
1584
  function getReportDescriptor(node) {
1584
- if (node === eff._) return eff._;
1585
+ if (node == null) return eff._;
1585
1586
  return tsPattern.match(node).when(AST11__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1586
1587
  const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
1587
1588
  if (isLeftUnaryNot) {
@@ -1617,7 +1618,7 @@ var no_leaked_conditional_rendering_default = createRule({
1617
1618
  }
1618
1619
  const visitorFunction = (node) => {
1619
1620
  const descriptor = getReportDescriptor(node);
1620
- if (descriptor === eff._) return;
1621
+ if (descriptor == null) return;
1621
1622
  context.report(descriptor);
1622
1623
  };
1623
1624
  return {
@@ -1648,20 +1649,30 @@ var no_missing_component_display_name_default = createRule({
1648
1649
  if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
1649
1650
  return {};
1650
1651
  }
1651
- const { ctx, listeners } = core.useComponentCollector(context);
1652
+ const {
1653
+ ctx,
1654
+ listeners
1655
+ } = core.useComponentCollector(
1656
+ context,
1657
+ core.DEFAULT_COMPONENT_HINT,
1658
+ {
1659
+ collectDisplayName: true,
1660
+ collectHookCalls: false
1661
+ }
1662
+ );
1652
1663
  return {
1653
1664
  ...listeners,
1654
1665
  "Program:exit"(node) {
1655
1666
  const components = ctx.getAllComponents(node);
1656
1667
  for (const { node: node2, displayName, flag } of components.values()) {
1657
1668
  const isMemoOrForwardRef = (flag & (core.ERFunctionComponentFlag.ForwardRef | core.ERFunctionComponentFlag.Memo)) > 0n;
1658
- if (AST11__namespace.getFunctionIdentifier(node2)) {
1669
+ if (AST11__namespace.getFunctionIdentifier(node2) != null) {
1659
1670
  continue;
1660
1671
  }
1661
1672
  if (!isMemoOrForwardRef) {
1662
1673
  continue;
1663
1674
  }
1664
- if (!displayName) {
1675
+ if (displayName == null) {
1665
1676
  context.report({
1666
1677
  messageId: "noMissingComponentDisplayName",
1667
1678
  node: node2
@@ -1860,7 +1871,7 @@ var no_nested_components_default = createRule({
1860
1871
  continue;
1861
1872
  }
1862
1873
  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);
1874
+ const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.findParentProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
1864
1875
  if (isInsideJSXPropValue) {
1865
1876
  if (!core.isDeclaredInRenderPropLoose(component)) {
1866
1877
  context.report({
@@ -1883,8 +1894,8 @@ var no_nested_components_default = createRule({
1883
1894
  });
1884
1895
  continue;
1885
1896
  }
1886
- const parentComponent = AST11__namespace.findParentNodeGuard(component, isFunctionComponent);
1887
- const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
1897
+ const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
1898
+ const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
1888
1899
  if (isParnetComponentNotDirectValueOfRenderProperty) {
1889
1900
  context.report({
1890
1901
  messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
@@ -1906,7 +1917,7 @@ var no_nested_components_default = createRule({
1906
1917
  }
1907
1918
  }
1908
1919
  for (const { name: name2 = "unknown", node: component } of classComponents) {
1909
- if (!AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
1920
+ if (AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
1910
1921
  continue;
1911
1922
  }
1912
1923
  context.report({
@@ -1959,8 +1970,8 @@ var no_prop_types_default = createRule({
1959
1970
  return;
1960
1971
  }
1961
1972
  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))) {
1973
+ const variableNode = VAR__namespace.getVariableNode(variable, 0);
1974
+ if (variableNode != null && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
1964
1975
  context.report({ messageId: "noPropTypes", node: property });
1965
1976
  }
1966
1977
  },
@@ -2057,11 +2068,12 @@ var no_set_state_in_component_did_mount_default = createRule({
2057
2068
  if (!core.isThisSetState(node)) {
2058
2069
  return;
2059
2070
  }
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);
2071
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2072
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2073
+ if (clazz == null || method == null || method === clazz) return;
2074
+ const methodScope = context.sourceCode.getScope(method);
2063
2075
  const upperScope = context.sourceCode.getScope(node).upper;
2064
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2076
+ if (method.parent === clazz.body && upperScope === methodScope) {
2065
2077
  context.report({
2066
2078
  messageId: "noSetStateInComponentDidMount",
2067
2079
  node
@@ -2101,11 +2113,12 @@ var no_set_state_in_component_did_update_default = createRule({
2101
2113
  if (!core.isThisSetState(node)) {
2102
2114
  return;
2103
2115
  }
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);
2116
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2117
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2118
+ if (clazz == null || method == null || method === clazz) return;
2119
+ const methodScope = context.sourceCode.getScope(method);
2107
2120
  const upperScope = context.sourceCode.getScope(node).upper;
2108
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2121
+ if (method.parent === clazz.body && upperScope === methodScope) {
2109
2122
  context.report({
2110
2123
  messageId: "noSetStateInComponentDidUpdate",
2111
2124
  node
@@ -2145,11 +2158,12 @@ var no_set_state_in_component_will_update_default = createRule({
2145
2158
  if (!core.isThisSetState(node)) {
2146
2159
  return;
2147
2160
  }
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);
2161
+ const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
2162
+ const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
2163
+ if (clazz == null || method == null || method === clazz) return;
2164
+ const methodScope = context.sourceCode.getScope(method);
2151
2165
  const upperScope = context.sourceCode.getScope(node).upper;
2152
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2166
+ if (method.parent === clazz.body && upperScope === methodScope) {
2153
2167
  context.report({
2154
2168
  messageId: "noSetStateInComponentWillUpdate",
2155
2169
  node
@@ -2374,22 +2388,21 @@ var no_unstable_context_value_default = createRule({
2374
2388
  return;
2375
2389
  }
2376
2390
  const functionEntry = ctx.getCurrentEntry();
2377
- if (functionEntry === eff._) return;
2391
+ if (functionEntry == null) return;
2378
2392
  const attribute = node.attributes.find(
2379
2393
  (attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
2380
2394
  );
2381
- if (attribute === eff._ || !("value" in attribute)) return;
2395
+ if (attribute == null || !("value" in attribute)) return;
2382
2396
  const value = attribute.value;
2383
2397
  if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
2384
2398
  const valueExpression = value.expression;
2385
2399
  const initialScope = context.sourceCode.getScope(valueExpression);
2386
2400
  const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
2387
- if (construction === eff._) return;
2401
+ if (construction == null) return;
2388
2402
  if (core.isReactHookCall(construction.node)) {
2389
2403
  return;
2390
2404
  }
2391
- const prevs = constructions.get(functionEntry.node) ?? [];
2392
- constructions.set(functionEntry.node, [...prevs, construction]);
2405
+ eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
2393
2406
  },
2394
2407
  "Program:exit"(node) {
2395
2408
  const components = ctx.getAllComponents(node).values();
@@ -2456,7 +2469,7 @@ var no_unstable_default_props_default = createRule({
2456
2469
  initialScope,
2457
2470
  VAR__namespace.ValueConstructionHint.StrictCallExpression
2458
2471
  );
2459
- if (construction === eff._) {
2472
+ if (construction == null) {
2460
2473
  continue;
2461
2474
  }
2462
2475
  if (core.isReactHookCall(construction.node)) {
@@ -2475,7 +2488,7 @@ var no_unstable_default_props_default = createRule({
2475
2488
  },
2476
2489
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2477
2490
  const functionEntry = ctx.getCurrentEntry();
2478
- if (!functionEntry) return;
2491
+ if (functionEntry == null) return;
2479
2492
  const prevs = declarators.get(functionEntry.node) ?? [];
2480
2493
  declarators.set(functionEntry.node, [...prevs, node]);
2481
2494
  }
@@ -2703,8 +2716,8 @@ var no_unused_state_default = createRule({
2703
2716
  return;
2704
2717
  }
2705
2718
  const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
2706
- const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
2707
- if (!defNode || isUsed) {
2719
+ const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
2720
+ if (defNode == null || isUsed) {
2708
2721
  return;
2709
2722
  }
2710
2723
  context.report({
@@ -2947,7 +2960,7 @@ var prefer_destructuring_assignment_default = createRule({
2947
2960
  return false;
2948
2961
  }
2949
2962
  const id = AST11__namespace.getFunctionIdentifier(block);
2950
- return !!id && core.isComponentName(id.name) && components.some((component) => component.node === block);
2963
+ return id != null && core.isComponentName(id.name) && components.some((component) => component.node === block);
2951
2964
  }
2952
2965
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
2953
2966
  let scope = initialScope;
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, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, 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-beta.0";
18
+ var version = "1.24.0-beta.3";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -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
  }
@@ -588,7 +588,7 @@ var no_children_prop_default = createRule({
588
588
  context.sourceCode.getScope(node),
589
589
  node.openingElement.attributes
590
590
  );
591
- if (prop) {
591
+ if (prop != null) {
592
592
  context.report({
593
593
  messageId: "noChildrenProp",
594
594
  node: prop
@@ -1036,7 +1036,7 @@ var no_create_ref_default = createRule({
1036
1036
  create(context) {
1037
1037
  return {
1038
1038
  CallExpression(node) {
1039
- if (isCreateRefCall(node, context) && !AST11.findParentNode(node, isClassComponent)) {
1039
+ if (isCreateRefCall(node, context) && AST11.findParentNode(node, isClassComponent) == null) {
1040
1040
  context.report({ messageId: "noCreateRef", node });
1041
1041
  }
1042
1042
  }
@@ -1082,7 +1082,7 @@ var no_default_props_default = createRule({
1082
1082
  }
1083
1083
  const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1084
1084
  const variableNode = VAR.getVariableNode(variable, 0);
1085
- if (variableNode === _) return;
1085
+ if (variableNode == null) return;
1086
1086
  if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
1087
1087
  context.report({ messageId: "noDefaultProps", node: property });
1088
1088
  },
@@ -1144,15 +1144,15 @@ var no_direct_mutation_state_default = createRule({
1144
1144
  if (!isAssignmentToThisState(node)) {
1145
1145
  return;
1146
1146
  }
1147
- const parentClass = AST11.findParentNodeGuard(
1147
+ const parentClass = AST11.findParentNode(
1148
1148
  node,
1149
1149
  AST11.isOneOf([
1150
1150
  AST_NODE_TYPES.ClassDeclaration,
1151
1151
  AST_NODE_TYPES.ClassExpression
1152
1152
  ])
1153
1153
  );
1154
- if (!parentClass) return;
1155
- if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNodeGuard(node, isConstructorFunction)) {
1154
+ if (parentClass == null) return;
1155
+ if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNode(node, isConstructorFunction)) {
1156
1156
  context.report({
1157
1157
  messageId: "noDirectMutationState",
1158
1158
  node
@@ -1253,10 +1253,11 @@ var no_duplicate_key_default = createRule({
1253
1253
  break;
1254
1254
  }
1255
1255
  default: {
1256
- const call = AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose);
1257
- const iter = call && AST11.findParentNodeStop(jsxElement, call, AST11.isFunction);
1256
+ const call = AST11.findParentNode(jsxElement, AST11.isMapCallLoose);
1257
+ const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
1258
+ if (!AST11.isFunction(iter)) return;
1258
1259
  const arg0 = call?.arguments[0];
1259
- if (!call || !iter || !arg0) return;
1260
+ if (call == null || arg0 == null) return;
1260
1261
  if (AST11.unwrapTypeExpression(arg0) !== iter) {
1261
1262
  return;
1262
1263
  }
@@ -1420,7 +1421,7 @@ var no_implicit_key_default = createRule({
1420
1421
  const keyPropOnElement = node.attributes.some(
1421
1422
  (n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1422
1423
  );
1423
- if (keyPropFound && !keyPropOnElement) {
1424
+ if (keyPropFound != null && !keyPropOnElement) {
1424
1425
  context.report({ messageId: "noImplicitKey", node: keyPropFound });
1425
1426
  }
1426
1427
  }
@@ -1517,7 +1518,7 @@ function isInitExpression(node) {
1517
1518
  }
1518
1519
  function getVariableInitExpression(variable, at) {
1519
1520
  const def = variable?.defs[at];
1520
- if (def?.node === _ || !("init" in def.node)) {
1521
+ if (def?.node == null || !("init" in def.node)) {
1521
1522
  return _;
1522
1523
  }
1523
1524
  return isInitExpression(def.node.init) ? def.node.init : _;
@@ -1554,7 +1555,7 @@ var no_leaked_conditional_rendering_default = createRule({
1554
1555
  ];
1555
1556
  const services = ESLintUtils.getParserServices(context, false);
1556
1557
  function getReportDescriptor(node) {
1557
- if (node === _) return _;
1558
+ if (node == null) return _;
1558
1559
  return match(node).when(AST11.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1559
1560
  const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
1560
1561
  if (isLeftUnaryNot) {
@@ -1590,7 +1591,7 @@ var no_leaked_conditional_rendering_default = createRule({
1590
1591
  }
1591
1592
  const visitorFunction = (node) => {
1592
1593
  const descriptor = getReportDescriptor(node);
1593
- if (descriptor === _) return;
1594
+ if (descriptor == null) return;
1594
1595
  context.report(descriptor);
1595
1596
  };
1596
1597
  return {
@@ -1621,20 +1622,30 @@ var no_missing_component_display_name_default = createRule({
1621
1622
  if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
1622
1623
  return {};
1623
1624
  }
1624
- const { ctx, listeners } = useComponentCollector(context);
1625
+ const {
1626
+ ctx,
1627
+ listeners
1628
+ } = useComponentCollector(
1629
+ context,
1630
+ DEFAULT_COMPONENT_HINT,
1631
+ {
1632
+ collectDisplayName: true,
1633
+ collectHookCalls: false
1634
+ }
1635
+ );
1625
1636
  return {
1626
1637
  ...listeners,
1627
1638
  "Program:exit"(node) {
1628
1639
  const components = ctx.getAllComponents(node);
1629
1640
  for (const { node: node2, displayName, flag } of components.values()) {
1630
1641
  const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
1631
- if (AST11.getFunctionIdentifier(node2)) {
1642
+ if (AST11.getFunctionIdentifier(node2) != null) {
1632
1643
  continue;
1633
1644
  }
1634
1645
  if (!isMemoOrForwardRef) {
1635
1646
  continue;
1636
1647
  }
1637
- if (!displayName) {
1648
+ if (displayName == null) {
1638
1649
  context.report({
1639
1650
  messageId: "noMissingComponentDisplayName",
1640
1651
  node: node2
@@ -1833,7 +1844,7 @@ var no_nested_components_default = createRule({
1833
1844
  continue;
1834
1845
  }
1835
1846
  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);
1847
+ const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
1837
1848
  if (isInsideJSXPropValue) {
1838
1849
  if (!isDeclaredInRenderPropLoose(component)) {
1839
1850
  context.report({
@@ -1856,8 +1867,8 @@ var no_nested_components_default = createRule({
1856
1867
  });
1857
1868
  continue;
1858
1869
  }
1859
- const parentComponent = AST11.findParentNodeGuard(component, isFunctionComponent);
1860
- const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !isDirectValueOfRenderPropertyLoose(parentComponent);
1870
+ const parentComponent = AST11.findParentNode(component, isFunctionComponent);
1871
+ const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
1861
1872
  if (isParnetComponentNotDirectValueOfRenderProperty) {
1862
1873
  context.report({
1863
1874
  messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
@@ -1879,7 +1890,7 @@ var no_nested_components_default = createRule({
1879
1890
  }
1880
1891
  }
1881
1892
  for (const { name: name2 = "unknown", node: component } of classComponents) {
1882
- if (!AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
1893
+ if (AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
1883
1894
  continue;
1884
1895
  }
1885
1896
  context.report({
@@ -1932,8 +1943,8 @@ var no_prop_types_default = createRule({
1932
1943
  return;
1933
1944
  }
1934
1945
  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))) {
1946
+ const variableNode = VAR.getVariableNode(variable, 0);
1947
+ if (variableNode != null && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
1937
1948
  context.report({ messageId: "noPropTypes", node: property });
1938
1949
  }
1939
1950
  },
@@ -2030,11 +2041,12 @@ var no_set_state_in_component_did_mount_default = createRule({
2030
2041
  if (!isThisSetState(node)) {
2031
2042
  return;
2032
2043
  }
2033
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2034
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidMount);
2035
- const methodScope = method && context.sourceCode.getScope(method);
2044
+ const clazz = AST11.findParentNode(node, isClassComponent);
2045
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2046
+ if (clazz == null || method == null || method === clazz) return;
2047
+ const methodScope = context.sourceCode.getScope(method);
2036
2048
  const upperScope = context.sourceCode.getScope(node).upper;
2037
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2049
+ if (method.parent === clazz.body && upperScope === methodScope) {
2038
2050
  context.report({
2039
2051
  messageId: "noSetStateInComponentDidMount",
2040
2052
  node
@@ -2074,11 +2086,12 @@ var no_set_state_in_component_did_update_default = createRule({
2074
2086
  if (!isThisSetState(node)) {
2075
2087
  return;
2076
2088
  }
2077
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2078
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidUpdate);
2079
- const methodScope = method && context.sourceCode.getScope(method);
2089
+ const clazz = AST11.findParentNode(node, isClassComponent);
2090
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2091
+ if (clazz == null || method == null || method === clazz) return;
2092
+ const methodScope = context.sourceCode.getScope(method);
2080
2093
  const upperScope = context.sourceCode.getScope(node).upper;
2081
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2094
+ if (method.parent === clazz.body && upperScope === methodScope) {
2082
2095
  context.report({
2083
2096
  messageId: "noSetStateInComponentDidUpdate",
2084
2097
  node
@@ -2118,11 +2131,12 @@ var no_set_state_in_component_will_update_default = createRule({
2118
2131
  if (!isThisSetState(node)) {
2119
2132
  return;
2120
2133
  }
2121
- const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2122
- const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentWillUpdate3);
2123
- const methodScope = method && context.sourceCode.getScope(method);
2134
+ const clazz = AST11.findParentNode(node, isClassComponent);
2135
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
2136
+ if (clazz == null || method == null || method === clazz) return;
2137
+ const methodScope = context.sourceCode.getScope(method);
2124
2138
  const upperScope = context.sourceCode.getScope(node).upper;
2125
- if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
2139
+ if (method.parent === clazz.body && upperScope === methodScope) {
2126
2140
  context.report({
2127
2141
  messageId: "noSetStateInComponentWillUpdate",
2128
2142
  node
@@ -2347,22 +2361,21 @@ var no_unstable_context_value_default = createRule({
2347
2361
  return;
2348
2362
  }
2349
2363
  const functionEntry = ctx.getCurrentEntry();
2350
- if (functionEntry === _) return;
2364
+ if (functionEntry == null) return;
2351
2365
  const attribute = node.attributes.find(
2352
2366
  (attribute2) => attribute2.type === AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
2353
2367
  );
2354
- if (attribute === _ || !("value" in attribute)) return;
2368
+ if (attribute == null || !("value" in attribute)) return;
2355
2369
  const value = attribute.value;
2356
2370
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2357
2371
  const valueExpression = value.expression;
2358
2372
  const initialScope = context.sourceCode.getScope(valueExpression);
2359
2373
  const construction = VAR.getValueConstruction(valueExpression, initialScope);
2360
- if (construction === _) return;
2374
+ if (construction == null) return;
2361
2375
  if (isReactHookCall(construction.node)) {
2362
2376
  return;
2363
2377
  }
2364
- const prevs = constructions.get(functionEntry.node) ?? [];
2365
- constructions.set(functionEntry.node, [...prevs, construction]);
2378
+ getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
2366
2379
  },
2367
2380
  "Program:exit"(node) {
2368
2381
  const components = ctx.getAllComponents(node).values();
@@ -2429,7 +2442,7 @@ var no_unstable_default_props_default = createRule({
2429
2442
  initialScope,
2430
2443
  VAR.ValueConstructionHint.StrictCallExpression
2431
2444
  );
2432
- if (construction === _) {
2445
+ if (construction == null) {
2433
2446
  continue;
2434
2447
  }
2435
2448
  if (isReactHookCall(construction.node)) {
@@ -2448,7 +2461,7 @@ var no_unstable_default_props_default = createRule({
2448
2461
  },
2449
2462
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2450
2463
  const functionEntry = ctx.getCurrentEntry();
2451
- if (!functionEntry) return;
2464
+ if (functionEntry == null) return;
2452
2465
  const prevs = declarators.get(functionEntry.node) ?? [];
2453
2466
  declarators.set(functionEntry.node, [...prevs, node]);
2454
2467
  }
@@ -2676,8 +2689,8 @@ var no_unused_state_default = createRule({
2676
2689
  return;
2677
2690
  }
2678
2691
  const className = AST11.getClassIdentifier(currentClass)?.name;
2679
- const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
2680
- if (!defNode || isUsed) {
2692
+ const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
2693
+ if (defNode == null || isUsed) {
2681
2694
  return;
2682
2695
  }
2683
2696
  context.report({
@@ -2920,7 +2933,7 @@ var prefer_destructuring_assignment_default = createRule({
2920
2933
  return false;
2921
2934
  }
2922
2935
  const id = AST11.getFunctionIdentifier(block);
2923
- return !!id && isComponentName(id.name) && components.some((component) => component.node === block);
2936
+ return id != null && isComponentName(id.name) && components.some((component) => component.node === block);
2924
2937
  }
2925
2938
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
2926
2939
  let scope = initialScope;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.24.0-beta.0",
3
+ "version": "1.24.0-beta.3",
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",
@@ -48,17 +48,17 @@
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/core": "1.24.0-beta.0",
52
- "@eslint-react/jsx": "1.24.0-beta.0",
53
- "@eslint-react/ast": "1.24.0-beta.0",
54
- "@eslint-react/types": "1.24.0-beta.0",
55
- "@eslint-react/shared": "1.24.0-beta.0",
56
- "@eslint-react/var": "1.24.0-beta.0",
57
- "@eslint-react/eff": "1.24.0-beta.0"
51
+ "@eslint-react/ast": "1.24.0-beta.3",
52
+ "@eslint-react/core": "1.24.0-beta.3",
53
+ "@eslint-react/eff": "1.24.0-beta.3",
54
+ "@eslint-react/jsx": "1.24.0-beta.3",
55
+ "@eslint-react/shared": "1.24.0-beta.3",
56
+ "@eslint-react/types": "1.24.0-beta.3",
57
+ "@eslint-react/var": "1.24.0-beta.3"
58
58
  },
59
59
  "devDependencies": {
60
- "@types/react": "^19.0.4",
61
- "@types/react-dom": "^19.0.2",
60
+ "@types/react": "^19.0.6",
61
+ "@types/react-dom": "^19.0.3",
62
62
  "ts-api-utils": "^2.0.0",
63
63
  "tsup": "^8.3.5",
64
64
  "@workspace/configs": "0.0.0"