eslint-plugin-react-x 2.0.1-beta.4 → 2.0.1-next.0

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 +146 -145
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ import { isFalseLiteralType, isTrueLiteralType, isTypeFlagSet, unionConstituents
5
5
  import { P, isMatching, match } from "ts-pattern";
6
6
  import ts from "typescript";
7
7
  import * as AST from "@eslint-react/ast";
8
- import { ConstructionDetectionHint, findVariable, getChildScopes, getConstruction, getVariableDefinitionNode } from "@eslint-react/var";
9
- import { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, JsxEmit, findParentAttribute, getAttribute, getAttributeName, getElementType, getInstanceId, getJsxConfigFromAnnotation, getJsxConfigFromContext, hasAttribute, isAssignmentToThisState, isCaptureOwnerStackCall, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUpdate, isCreateContextCall, isCreateElementCall, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRefCall, isFragmentElement, isGetDerivedStateFromError, isGetDerivedStateFromProps, isHostElement, isInitializedFromReact, isInstanceIdEqual, isJsxText, isLazyCall, isReactHookCall, isReactHookName, isRenderMethodLike, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseCall, isUseCallbackCall, isUseContextCall, isUseMemoCall, isUseStateCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector } from "@eslint-react/core";
8
+ import * as VAR from "@eslint-react/var";
9
+ import * as ER from "@eslint-react/core";
10
10
  import { report, toRegExp } from "@eslint-react/kit";
11
11
  import { constFalse, constTrue, flow, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
12
12
  import { compare } from "compare-versions";
@@ -115,7 +115,7 @@ const settings = { ...settings$1 };
115
115
  //#endregion
116
116
  //#region package.json
117
117
  var name = "eslint-plugin-react-x";
118
- var version = "2.0.1-beta.4";
118
+ var version = "2.0.1-next.0";
119
119
 
120
120
  //#endregion
121
121
  //#region src/utils/create-rule.ts
@@ -373,7 +373,7 @@ function create$57(context) {
373
373
  if (name$4 == null) return;
374
374
  if (name$4 === "this") return;
375
375
  if (/^[a-z]/u.test(name$4)) return;
376
- if (findVariable(name$4, context.sourceCode.getScope(node)) == null) context.report({
376
+ if (VAR.findVariable(name$4, context.sourceCode.getScope(node)) == null) context.report({
377
377
  messageId: "jsxNoUndef",
378
378
  node,
379
379
  data: { name: name$4 }
@@ -409,7 +409,7 @@ function create$56(context) {
409
409
  const policy = context.options[0] ?? defaultOptions$3[0];
410
410
  return { JSXAttribute(node) {
411
411
  const { value } = node;
412
- const propName = getAttributeName(context, node);
412
+ const propName = ER.getAttributeName(context, node);
413
413
  switch (true) {
414
414
  case policy === 1 && value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true:
415
415
  context.report({
@@ -458,11 +458,11 @@ var jsx_shorthand_fragment_default = createRule({
458
458
  function create$55(context) {
459
459
  const policy = context.options[0] ?? defaultOptions$2[0];
460
460
  const { jsxFragmentFactory } = {
461
- ...getJsxConfigFromContext(context),
462
- ...getJsxConfigFromAnnotation(context)
461
+ ...ER.getJsxConfigFromContext(context),
462
+ ...ER.getJsxConfigFromAnnotation(context)
463
463
  };
464
464
  return match(policy).with(1, () => ({ JSXElement(node) {
465
- if (!isFragmentElement(context, node)) return;
465
+ if (!ER.isFragmentElement(context, node)) return;
466
466
  if (node.openingElement.attributes.length > 0) return;
467
467
  context.report({
468
468
  messageId: "jsxShorthandFragment",
@@ -481,7 +481,7 @@ function create$55(context) {
481
481
  data: { message: "Use 'Fragment' component instead of fragment shorthand syntax." },
482
482
  fix: (fixer) => {
483
483
  const { closingFragment, openingFragment } = node;
484
- return [fixer.replaceTextRange([openingFragment.range[0], openingFragment.range[1]], `<${jsxFragmentFactory}>`), fixer.replaceTextRange([closingFragment.range[0], closingFragment.range[1]], `</${jsxFragmentFactory}>`)];
484
+ return [fixer.replaceTextRange([openingFragment.range[0], openingFragment.range[1]], "<" + jsxFragmentFactory + ">"), fixer.replaceTextRange([closingFragment.range[0], closingFragment.range[1]], "</" + jsxFragmentFactory + ">")];
485
485
  }
486
486
  });
487
487
  } })).otherwise(() => ({}));
@@ -489,6 +489,7 @@ function create$55(context) {
489
489
 
490
490
  //#endregion
491
491
  //#region src/rules/jsx-uses-react.ts
492
+ const JsxEmit = ER.JsxEmit;
492
493
  const RULE_NAME$54 = "jsx-uses-react";
493
494
  const RULE_FEATURES$52 = [];
494
495
  var jsx_uses_react_default = createRule({
@@ -507,8 +508,8 @@ var jsx_uses_react_default = createRule({
507
508
  });
508
509
  function create$54(context) {
509
510
  const { jsx, jsxFactory, jsxFragmentFactory } = {
510
- ...getJsxConfigFromContext(context),
511
- ...getJsxConfigFromAnnotation(context)
511
+ ...ER.getJsxConfigFromContext(context),
512
+ ...ER.getJsxConfigFromAnnotation(context)
512
513
  };
513
514
  if (jsx === JsxEmit.ReactJSX || jsx === JsxEmit.ReactJSXDev) return {};
514
515
  function handleJsxElement(node) {
@@ -599,21 +600,21 @@ function create$52(context) {
599
600
  const setStateEntries = [];
600
601
  return {
601
602
  CallExpression(node) {
602
- if (!isThisSetState(node)) return;
603
+ if (!ER.isThisSetState(node)) return;
603
604
  setStateEntries.push([node, false]);
604
605
  },
605
606
  "CallExpression:exit"(node) {
606
- if (!isThisSetState(node)) return;
607
+ if (!ER.isThisSetState(node)) return;
607
608
  setStateEntries.pop();
608
609
  },
609
610
  ClassDeclaration(node) {
610
- classEntries.push([node, isClassComponent(node)]);
611
+ classEntries.push([node, ER.isClassComponent(node)]);
611
612
  },
612
613
  "ClassDeclaration:exit"() {
613
614
  classEntries.pop();
614
615
  },
615
616
  ClassExpression(node) {
616
- classEntries.push([node, isClassComponent(node)]);
617
+ classEntries.push([node, ER.isClassComponent(node)]);
617
618
  },
618
619
  "ClassExpression:exit"() {
619
620
  classEntries.pop();
@@ -676,7 +677,7 @@ function isUsingReactChildren(context, node) {
676
677
  if (!isReactChildrenMethod(callee.property.name)) return false;
677
678
  const initialScope = context.sourceCode.getScope(node);
678
679
  if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children") return true;
679
- if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) return isInitializedFromReact(callee.object.object.name, importSource, initialScope);
680
+ if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) return ER.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
680
681
  return false;
681
682
  }
682
683
  function getMapIndexParamName(context, node) {
@@ -719,7 +720,7 @@ function create$51(context) {
719
720
  return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name$4) => name$4 != null && name$4 === node.name);
720
721
  }
721
722
  function isCreateOrCloneElementCall(node) {
722
- return isCreateElementCall(context, node) || isCloneElementCall(context, node);
723
+ return ER.isCreateElementCall(context, node) || ER.isCloneElementCall(context, node);
723
724
  }
724
725
  function getReportDescriptors(node) {
725
726
  switch (node.type) {
@@ -797,7 +798,7 @@ var no_children_count_default = createRule({
797
798
  });
798
799
  function create$50(context) {
799
800
  return { MemberExpression(node) {
800
- if (isChildrenCount(context, node)) context.report({
801
+ if (ER.isChildrenCount(context, node)) context.report({
801
802
  messageId: "noChildrenCount",
802
803
  node: node.property
803
804
  });
@@ -824,7 +825,7 @@ var no_children_for_each_default = createRule({
824
825
  });
825
826
  function create$49(context) {
826
827
  return { MemberExpression(node) {
827
- if (isChildrenForEach(context, node)) context.report({
828
+ if (ER.isChildrenForEach(context, node)) context.report({
828
829
  messageId: "noChildrenForEach",
829
830
  node: node.property
830
831
  });
@@ -851,7 +852,7 @@ var no_children_map_default = createRule({
851
852
  });
852
853
  function create$48(context) {
853
854
  return { MemberExpression(node) {
854
- if (isChildrenMap(context, node)) context.report({
855
+ if (ER.isChildrenMap(context, node)) context.report({
855
856
  messageId: "noChildrenMap",
856
857
  node: node.property
857
858
  });
@@ -878,7 +879,7 @@ var no_children_only_default = createRule({
878
879
  });
879
880
  function create$47(context) {
880
881
  return { MemberExpression(node) {
881
- if (isChildrenOnly(context, node)) context.report({
882
+ if (ER.isChildrenOnly(context, node)) context.report({
882
883
  messageId: "noChildrenOnly",
883
884
  node: node.property
884
885
  });
@@ -905,7 +906,7 @@ var no_children_prop_default = createRule({
905
906
  });
906
907
  function create$46(context) {
907
908
  return { JSXElement(node) {
908
- const childrenProp = getAttribute(context, node.openingElement.attributes, context.sourceCode.getScope(node))("children");
909
+ const childrenProp = ER.getAttribute(context, node.openingElement.attributes, context.sourceCode.getScope(node))("children");
909
910
  if (childrenProp != null) context.report({
910
911
  messageId: "noChildrenProp",
911
912
  node: childrenProp
@@ -933,7 +934,7 @@ var no_children_to_array_default = createRule({
933
934
  });
934
935
  function create$45(context) {
935
936
  return { MemberExpression(node) {
936
- if (isChildrenToArray(context, node)) context.report({
937
+ if (ER.isChildrenToArray(context, node)) context.report({
937
938
  messageId: "noChildrenToArray",
938
939
  node: node.property
939
940
  });
@@ -960,13 +961,13 @@ var no_class_component_default = createRule({
960
961
  });
961
962
  function create$44(context) {
962
963
  if (!context.sourceCode.text.includes("Component")) return {};
963
- const { ctx, listeners } = useComponentCollectorLegacy();
964
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
964
965
  return {
965
966
  ...listeners,
966
967
  "Program:exit"(program) {
967
968
  const components = ctx.getAllComponents(program);
968
969
  for (const { name: name$4 = "anonymous", node: component } of components.values()) {
969
- if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) continue;
970
+ if (component.body.body.some((m) => ER.isComponentDidCatch(m) || ER.isGetDerivedStateFromError(m))) continue;
970
971
  context.report({
971
972
  messageId: "noClassComponent",
972
973
  node: component,
@@ -997,7 +998,7 @@ var no_clone_element_default = createRule({
997
998
  });
998
999
  function create$43(context) {
999
1000
  return { CallExpression(node) {
1000
- if (isCloneElementCall(context, node)) context.report({
1001
+ if (ER.isCloneElementCall(context, node)) context.report({
1001
1002
  messageId: "noCloneElement",
1002
1003
  node
1003
1004
  });
@@ -1025,14 +1026,14 @@ var no_component_will_mount_default = createRule({
1025
1026
  });
1026
1027
  function create$42(context) {
1027
1028
  if (!context.sourceCode.text.includes("componentWillMount")) return {};
1028
- const { ctx, listeners } = useComponentCollectorLegacy();
1029
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
1029
1030
  return {
1030
1031
  ...listeners,
1031
1032
  "Program:exit"(program) {
1032
1033
  const components = ctx.getAllComponents(program);
1033
1034
  for (const { node: component } of components.values()) {
1034
1035
  const { body } = component.body;
1035
- for (const member of body) if (isComponentWillMount(member)) context.report({
1036
+ for (const member of body) if (ER.isComponentWillMount(member)) context.report({
1036
1037
  messageId: "noComponentWillMount",
1037
1038
  node: member,
1038
1039
  fix(fixer) {
@@ -1066,14 +1067,14 @@ var no_component_will_receive_props_default = createRule({
1066
1067
  });
1067
1068
  function create$41(context) {
1068
1069
  if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
1069
- const { ctx, listeners } = useComponentCollectorLegacy();
1070
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
1070
1071
  return {
1071
1072
  ...listeners,
1072
1073
  "Program:exit"(program) {
1073
1074
  const components = ctx.getAllComponents(program);
1074
1075
  for (const { node: component } of components.values()) {
1075
1076
  const { body } = component.body;
1076
- for (const member of body) if (isComponentWillReceiveProps(member)) context.report({
1077
+ for (const member of body) if (ER.isComponentWillReceiveProps(member)) context.report({
1077
1078
  messageId: "noComponentWillReceiveProps",
1078
1079
  node: member,
1079
1080
  fix(fixer) {
@@ -1107,14 +1108,14 @@ var no_component_will_update_default = createRule({
1107
1108
  });
1108
1109
  function create$40(context) {
1109
1110
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
1110
- const { ctx, listeners } = useComponentCollectorLegacy();
1111
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
1111
1112
  return {
1112
1113
  ...listeners,
1113
1114
  "Program:exit"(program) {
1114
1115
  const components = ctx.getAllComponents(program);
1115
1116
  for (const { node: component } of components.values()) {
1116
1117
  const { body } = component.body;
1117
- for (const member of body) if (isComponentWillUpdate(member)) context.report({
1118
+ for (const member of body) if (ER.isComponentWillUpdate(member)) context.report({
1118
1119
  messageId: "noComponentWillUpdate",
1119
1120
  node: member,
1120
1121
  fix(fixer) {
@@ -1151,7 +1152,7 @@ function create$39(context) {
1151
1152
  const { version: version$1 } = getSettingsFromContext(context);
1152
1153
  if (compare(version$1, "19.0.0", "<")) return {};
1153
1154
  return { JSXElement(node) {
1154
- const parts = getElementType(context, node).split(".");
1155
+ const parts = ER.getElementType(context, node).split(".");
1155
1156
  const selfName = parts.pop();
1156
1157
  const contextFullName = parts.join(".");
1157
1158
  const contextSelfName = parts.pop();
@@ -1161,7 +1162,7 @@ function create$39(context) {
1161
1162
  messageId: "noContextProvider",
1162
1163
  node,
1163
1164
  fix(fixer) {
1164
- if (!isComponentNameLoose(contextSelfName)) return null;
1165
+ if (!ER.isComponentNameLoose(contextSelfName)) return null;
1165
1166
  const openingElement = node.openingElement;
1166
1167
  const closingElement = node.closingElement;
1167
1168
  if (closingElement == null) return fixer.replaceText(openingElement.name, contextFullName);
@@ -1191,7 +1192,7 @@ var no_create_ref_default = createRule({
1191
1192
  });
1192
1193
  function create$38(context) {
1193
1194
  return { CallExpression(node) {
1194
- if (isCreateRefCall(context, node) && AST.findParentNode(node, isClassComponent) == null) context.report({
1195
+ if (ER.isCreateRefCall(context, node) && AST.findParentNode(node, ER.isClassComponent) == null) context.report({
1195
1196
  messageId: "noCreateRef",
1196
1197
  node
1197
1198
  });
@@ -1223,9 +1224,9 @@ function create$37(context) {
1223
1224
  const { object, property } = node.left;
1224
1225
  if (object.type !== AST_NODE_TYPES.Identifier) return;
1225
1226
  if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") return;
1226
- if (!isComponentNameLoose(object.name)) return;
1227
- const variable = findVariable(object.name, context.sourceCode.getScope(node));
1228
- const variableNode = getVariableDefinitionNode(variable, 0);
1227
+ if (!ER.isComponentNameLoose(object.name)) return;
1228
+ const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1229
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
1229
1230
  if (variableNode == null) return;
1230
1231
  if (!AST.isFunction(variableNode)) return;
1231
1232
  context.report({
@@ -1258,10 +1259,10 @@ var no_direct_mutation_state_default = createRule({
1258
1259
  });
1259
1260
  function create$36(context) {
1260
1261
  return { AssignmentExpression(node) {
1261
- if (!isAssignmentToThisState(node)) return;
1262
+ if (!ER.isAssignmentToThisState(node)) return;
1262
1263
  const parentClass = AST.findParentNode(node, AST.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
1263
1264
  if (parentClass == null) return;
1264
- if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST.findParentNode(node, isConstructorFunction)) context.report({
1265
+ if (ER.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST.findParentNode(node, isConstructorFunction)) context.report({
1265
1266
  messageId: "noDirectMutationState",
1266
1267
  node
1267
1268
  });
@@ -1440,7 +1441,7 @@ function create$33(context) {
1440
1441
  const { version: version$1 } = getSettingsFromContext(context);
1441
1442
  if (compare(version$1, "19.0.0", "<")) return {};
1442
1443
  return { CallExpression(node) {
1443
- if (!isForwardRefCall(context, node)) return;
1444
+ if (!ER.isForwardRefCall(context, node)) return;
1444
1445
  const id = AST.getFunctionId(node);
1445
1446
  const fix = canFix$1(context, node) ? getFix$1(context, node) : null;
1446
1447
  context.report({
@@ -1462,8 +1463,8 @@ function canFix$1(context, node) {
1462
1463
  const { importSource } = getSettingsFromContext(context);
1463
1464
  const initialScope = context.sourceCode.getScope(node);
1464
1465
  switch (node.callee.type) {
1465
- case AST_NODE_TYPES.Identifier: return isInitializedFromReact(node.callee.name, importSource, initialScope);
1466
- case AST_NODE_TYPES.MemberExpression: return node.callee.object.type === AST_NODE_TYPES.Identifier && isInitializedFromReact(node.callee.object.name, importSource, initialScope);
1466
+ case AST_NODE_TYPES.Identifier: return ER.isInitializedFromReact(node.callee.name, importSource, initialScope);
1467
+ case AST_NODE_TYPES.MemberExpression: return node.callee.object.type === AST_NODE_TYPES.Identifier && ER.isInitializedFromReact(node.callee.object.name, importSource, initialScope);
1467
1468
  default: return false;
1468
1469
  }
1469
1470
  }
@@ -1535,7 +1536,7 @@ var no_implicit_key_default = createRule({
1535
1536
  function create$32(context) {
1536
1537
  return { JSXOpeningElement(node) {
1537
1538
  const initialScope = context.sourceCode.getScope(node);
1538
- const keyProp = getAttribute(context, node.attributes, initialScope)("key");
1539
+ const keyProp = ER.getAttribute(context, node.attributes, initialScope)("key");
1539
1540
  const isKeyPropOnElement = node.attributes.some((n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key");
1540
1541
  if (keyProp != null && !isKeyPropOnElement) context.report({
1541
1542
  messageId: "noImplicitKey",
@@ -1605,7 +1606,7 @@ function create$31(context) {
1605
1606
  }).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
1606
1607
  return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
1607
1608
  }).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
1608
- const variableDefNode = findVariable(n.name, context.sourceCode.getScope(n))?.defs.at(0)?.node;
1609
+ const variableDefNode = VAR.findVariable(n.name, context.sourceCode.getScope(n))?.defs.at(0)?.node;
1609
1610
  return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => unit);
1610
1611
  }).otherwise(() => unit);
1611
1612
  }
@@ -1632,17 +1633,17 @@ var no_missing_component_display_name_default = createRule({
1632
1633
  });
1633
1634
  function create$30(context) {
1634
1635
  if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
1635
- const { ctx, listeners } = useComponentCollector(context, {
1636
+ const { ctx, listeners } = ER.useComponentCollector(context, {
1636
1637
  collectDisplayName: true,
1637
1638
  collectHookCalls: false,
1638
- hint: DEFAULT_COMPONENT_DETECTION_HINT
1639
+ hint: ER.DEFAULT_COMPONENT_DETECTION_HINT
1639
1640
  });
1640
1641
  return {
1641
1642
  ...listeners,
1642
1643
  "Program:exit"(program) {
1643
1644
  const components = ctx.getAllComponents(program);
1644
1645
  for (const { node, displayName, flag } of components.values()) {
1645
- const isMemoOrForwardRef = (flag & (ComponentFlag.ForwardRef | ComponentFlag.Memo)) > 0n;
1646
+ const isMemoOrForwardRef = (flag & (ER.ComponentFlag.ForwardRef | ER.ComponentFlag.Memo)) > 0n;
1646
1647
  if (AST.getFunctionId(node) != null) continue;
1647
1648
  if (!isMemoOrForwardRef) continue;
1648
1649
  if (displayName == null) {
@@ -1685,12 +1686,12 @@ function create$29(context) {
1685
1686
  displayNameAssignments.push(node);
1686
1687
  },
1687
1688
  CallExpression(node) {
1688
- if (!isCreateContextCall(context, node)) return;
1689
+ if (!ER.isCreateContextCall(context, node)) return;
1689
1690
  createCalls.push(node);
1690
1691
  },
1691
1692
  "Program:exit"() {
1692
1693
  for (const call of createCalls) {
1693
- const id = getInstanceId(call);
1694
+ const id = ER.getInstanceId(call);
1694
1695
  if (id == null) {
1695
1696
  context.report({
1696
1697
  messageId: "noMissingContextDisplayName",
@@ -1702,7 +1703,7 @@ function create$29(context) {
1702
1703
  const left = node.left;
1703
1704
  if (left.type !== AST_NODE_TYPES.MemberExpression) return false;
1704
1705
  const object = left.object;
1705
- return isInstanceIdEqual(context, id, object);
1706
+ return ER.isInstanceIdEqual(context, id, object);
1706
1707
  })) context.report({
1707
1708
  messageId: "noMissingContextDisplayName",
1708
1709
  node: id,
@@ -1753,7 +1754,7 @@ function create$28(context) {
1753
1754
  switch (node.type) {
1754
1755
  case AST_NODE_TYPES.JSXElement: {
1755
1756
  const initialScope = context.sourceCode.getScope(node);
1756
- if (!hasAttribute(context, "key", node.openingElement.attributes, initialScope)) return {
1757
+ if (!ER.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) return {
1757
1758
  messageId: "missingKey",
1758
1759
  node
1759
1760
  };
@@ -1794,13 +1795,13 @@ function create$28(context) {
1794
1795
  const elements = node.elements.filter(AST.is(AST_NODE_TYPES.JSXElement));
1795
1796
  if (elements.length === 0) return;
1796
1797
  const initialScope = context.sourceCode.getScope(node);
1797
- for (const element of elements) if (!hasAttribute(context, "key", element.openingElement.attributes, initialScope)) context.report({
1798
+ for (const element of elements) if (!ER.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) context.report({
1798
1799
  messageId: "missingKey",
1799
1800
  node: element
1800
1801
  });
1801
1802
  },
1802
1803
  CallExpression(node) {
1803
- state.isWithinChildrenToArray ||= isChildrenToArrayCall(context, node);
1804
+ state.isWithinChildrenToArray ||= ER.isChildrenToArrayCall(context, node);
1804
1805
  if (state.isWithinChildrenToArray) return;
1805
1806
  const callback = match(node).when(AST.isArrayMapCall, (n) => n.arguments[0]).when(AST.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
1806
1807
  if (!AST.isFunction(callback)) return;
@@ -1812,7 +1813,7 @@ function create$28(context) {
1812
1813
  report(context)(checkExpression(body));
1813
1814
  },
1814
1815
  "CallExpression:exit"(node) {
1815
- if (!isChildrenToArrayCall(context, node)) return;
1816
+ if (!ER.isChildrenToArrayCall(context, node)) return;
1816
1817
  state.isWithinChildrenToArray = false;
1817
1818
  },
1818
1819
  JSXFragment(node) {
@@ -1852,7 +1853,7 @@ function create$27(context) {
1852
1853
  const { importSource } = getSettingsFromContext(context);
1853
1854
  return {
1854
1855
  CallExpression(node) {
1855
- if (!isCaptureOwnerStackCall(context, node)) return;
1856
+ if (!ER.isCaptureOwnerStackCall(context, node)) return;
1856
1857
  if (AST.findParentNode(node, isDevelopmentOnlyCheck) == null) context.report({
1857
1858
  messageId: "missingDevelopmentOnlyCheck",
1858
1859
  node
@@ -1896,9 +1897,9 @@ var no_nested_component_definitions_default = createRule({
1896
1897
  defaultOptions: []
1897
1898
  });
1898
1899
  function create$26(context) {
1899
- const hint = ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNullLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.StrictLogical | ComponentDetectionHint.StrictConditional;
1900
- const collector = useComponentCollector(context, { hint });
1901
- const collectorLegacy = useComponentCollectorLegacy();
1900
+ const hint = ER.ComponentDetectionHint.SkipArrayMapArgument | ER.ComponentDetectionHint.SkipNullLiteral | ER.ComponentDetectionHint.SkipUndefined | ER.ComponentDetectionHint.SkipBooleanLiteral | ER.ComponentDetectionHint.SkipStringLiteral | ER.ComponentDetectionHint.SkipNumberLiteral | ER.ComponentDetectionHint.StrictLogical | ER.ComponentDetectionHint.StrictConditional;
1901
+ const collector = ER.useComponentCollector(context, { hint });
1902
+ const collectorLegacy = ER.useComponentCollectorLegacy();
1902
1903
  return {
1903
1904
  ...collector.listeners,
1904
1905
  ...collectorLegacy.listeners,
@@ -1908,14 +1909,14 @@ function create$26(context) {
1908
1909
  const isFunctionComponent = (node) => {
1909
1910
  return AST.isFunction(node) && functionComponents.some((component) => component.node === node);
1910
1911
  };
1911
- const isClassComponent$1 = (node) => {
1912
+ const isClassComponent = (node) => {
1912
1913
  return AST.isClass(node) && classComponents.some((component) => component.node === node);
1913
1914
  };
1914
1915
  for (const { name: name$4, node: component } of functionComponents) {
1915
1916
  if (name$4 == null) continue;
1916
- if (isDirectValueOfRenderPropertyLoose(component)) continue;
1917
+ if (ER.isDirectValueOfRenderPropertyLoose(component)) continue;
1917
1918
  if (isInsideJSXAttributeValue(component)) {
1918
- if (!isDeclaredInRenderPropLoose(component)) context.report({
1919
+ if (!ER.isDeclaredInRenderPropLoose(component)) context.report({
1919
1920
  messageId: "noNestedComponentDefinitions",
1920
1921
  node: component,
1921
1922
  data: {
@@ -1937,7 +1938,7 @@ function create$26(context) {
1937
1938
  continue;
1938
1939
  }
1939
1940
  const parentComponent = AST.findParentNode(component, isFunctionComponent);
1940
- if (parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent)) {
1941
+ if (parentComponent != null && !ER.isDirectValueOfRenderPropertyLoose(parentComponent)) {
1941
1942
  context.report({
1942
1943
  messageId: "noNestedComponentDefinitions",
1943
1944
  node: component,
@@ -1958,7 +1959,7 @@ function create$26(context) {
1958
1959
  });
1959
1960
  }
1960
1961
  for (const { name: name$4 = "unknown", node: component } of classComponents) {
1961
- if (AST.findParentNode(component, (n) => isClassComponent$1(n) || isFunctionComponent(n)) == null) continue;
1962
+ if (AST.findParentNode(component, (n) => isClassComponent(n) || isFunctionComponent(n)) == null) continue;
1962
1963
  context.report({
1963
1964
  messageId: "noNestedComponentDefinitions",
1964
1965
  node: component,
@@ -1977,7 +1978,7 @@ function create$26(context) {
1977
1978
  * @returns `true` if the node is inside JSX attribute value
1978
1979
  */
1979
1980
  function isInsideJSXAttributeValue(node) {
1980
- return node.parent.type === AST_NODE_TYPES.JSXAttribute || findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
1981
+ return node.parent.type === AST_NODE_TYPES.JSXAttribute || ER.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
1981
1982
  }
1982
1983
  /**
1983
1984
  * Check whether given node is declared inside class component's render block
@@ -1995,7 +1996,7 @@ function isInsideJSXAttributeValue(node) {
1995
1996
  * @returns `true` if node is inside class component's render block, `false` if not
1996
1997
  */
1997
1998
  function isInsideRenderMethod(node) {
1998
- return AST.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
1999
+ return AST.findParentNode(node, (n) => ER.isRenderMethodLike(n) && ER.isClassComponent(n.parent.parent)) != null;
1999
2000
  }
2000
2001
  /**
2001
2002
  * Determines whether inside `createElement`'s props.
@@ -2004,7 +2005,7 @@ function isInsideRenderMethod(node) {
2004
2005
  * @returns `true` if the node is inside createElement's props
2005
2006
  */
2006
2007
  function isInsideCreateElementProps(context, node) {
2007
- const call = AST.findParentNode(node, isCreateElementCall(context));
2008
+ const call = AST.findParentNode(node, ER.isCreateElementCall(context));
2008
2009
  if (call == null) return false;
2009
2010
  const prop = AST.findParentNode(node, AST.is(AST_NODE_TYPES.ObjectExpression));
2010
2011
  if (prop == null) return false;
@@ -2030,15 +2031,15 @@ var no_nested_lazy_component_declarations_default = createRule({
2030
2031
  defaultOptions: []
2031
2032
  });
2032
2033
  function create$25(context) {
2033
- const hint = ComponentDetectionHint.None;
2034
- const collector = useComponentCollector(context, { hint });
2035
- const collectorLegacy = useComponentCollectorLegacy();
2034
+ const hint = ER.ComponentDetectionHint.None;
2035
+ const collector = ER.useComponentCollector(context, { hint });
2036
+ const collectorLegacy = ER.useComponentCollectorLegacy();
2036
2037
  const lazyComponentDeclarations = /* @__PURE__ */ new Set();
2037
2038
  return {
2038
2039
  ...collector.listeners,
2039
2040
  ...collectorLegacy.listeners,
2040
2041
  ImportExpression(node) {
2041
- const lazyCall = AST.findParentNode(node, (n) => isLazyCall(context, n));
2042
+ const lazyCall = AST.findParentNode(node, (n) => ER.isLazyCall(context, n));
2042
2043
  if (lazyCall != null) lazyComponentDeclarations.add(lazyCall);
2043
2044
  },
2044
2045
  "Program:exit"(program) {
@@ -2046,7 +2047,7 @@ function create$25(context) {
2046
2047
  const classComponents = [...collectorLegacy.ctx.getAllComponents(program).values()];
2047
2048
  for (const lazy of lazyComponentDeclarations) if (AST.findParentNode(lazy, (n) => {
2048
2049
  if (AST.isJSX(n)) return true;
2049
- if (n.type === AST_NODE_TYPES.CallExpression) return isReactHookCall(n) || isCreateElementCall(context, n) || isCreateContextCall(context, n);
2050
+ if (n.type === AST_NODE_TYPES.CallExpression) return ER.isReactHookCall(n) || ER.isCreateElementCall(context, n) || ER.isCreateContextCall(context, n);
2050
2051
  if (AST.isFunction(n)) return functionComponents.some((c) => c.node === n);
2051
2052
  if (AST.isClass(n)) return classComponents.some((c) => c.node === n);
2052
2053
  return false;
@@ -2084,16 +2085,16 @@ function create$24(context) {
2084
2085
  const { object, property } = node.left;
2085
2086
  if (object.type !== AST_NODE_TYPES.Identifier) return;
2086
2087
  if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") return;
2087
- if (!isComponentNameLoose(object.name)) return;
2088
- const variable = findVariable(object.name, context.sourceCode.getScope(node));
2089
- const variableNode = getVariableDefinitionNode(variable, 0);
2090
- if (variableNode != null && (AST.isFunction(variableNode) || isClassComponent(variableNode))) context.report({
2088
+ if (!ER.isComponentNameLoose(object.name)) return;
2089
+ const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
2090
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
2091
+ if (variableNode != null && (AST.isFunction(variableNode) || ER.isClassComponent(variableNode))) context.report({
2091
2092
  messageId: "noPropTypes",
2092
2093
  node: property
2093
2094
  });
2094
2095
  },
2095
2096
  PropertyDefinition(node) {
2096
- if (!isClassComponent(node.parent.parent)) return;
2097
+ if (!ER.isClassComponent(node.parent.parent)) return;
2097
2098
  if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") return;
2098
2099
  context.report({
2099
2100
  messageId: "noPropTypes",
@@ -2126,13 +2127,13 @@ var no_redundant_should_component_update_default = createRule({
2126
2127
  });
2127
2128
  function create$23(context) {
2128
2129
  if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
2129
- const { ctx, listeners } = useComponentCollectorLegacy();
2130
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
2130
2131
  return {
2131
2132
  ...listeners,
2132
2133
  "Program:exit"(program) {
2133
2134
  const components = ctx.getAllComponents(program);
2134
2135
  for (const { name: name$4 = "PureComponent", node: component, flag } of components.values()) {
2135
- if ((flag & ComponentFlag.PureComponent) === 0n) continue;
2136
+ if ((flag & ER.ComponentFlag.PureComponent) === 0n) continue;
2136
2137
  const { body } = component.body;
2137
2138
  for (const member of body) if (isShouldComponentUpdate(member)) context.report({
2138
2139
  messageId: "noRedundantShouldComponentUpdate",
@@ -2165,9 +2166,9 @@ var no_set_state_in_component_did_mount_default = createRule({
2165
2166
  function create$22(context) {
2166
2167
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
2167
2168
  return { CallExpression(node) {
2168
- if (!isThisSetState(node)) return;
2169
- const clazz = AST.findParentNode(node, isClassComponent);
2170
- const method = AST.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2169
+ if (!ER.isThisSetState(node)) return;
2170
+ const clazz = AST.findParentNode(node, ER.isClassComponent);
2171
+ const method = AST.findParentNode(node, (n) => n === clazz || ER.isComponentDidMount(n));
2171
2172
  if (clazz == null || method == null || method === clazz) return;
2172
2173
  const methodScope = context.sourceCode.getScope(method);
2173
2174
  const upperScope = context.sourceCode.getScope(node).upper;
@@ -2199,9 +2200,9 @@ var no_set_state_in_component_did_update_default = createRule({
2199
2200
  function create$21(context) {
2200
2201
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
2201
2202
  return { CallExpression(node) {
2202
- if (!isThisSetState(node)) return;
2203
- const clazz = AST.findParentNode(node, isClassComponent);
2204
- const method = AST.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2203
+ if (!ER.isThisSetState(node)) return;
2204
+ const clazz = AST.findParentNode(node, ER.isClassComponent);
2205
+ const method = AST.findParentNode(node, (n) => n === clazz || ER.isComponentDidUpdate(n));
2205
2206
  if (clazz == null || method == null || method === clazz) return;
2206
2207
  const methodScope = context.sourceCode.getScope(method);
2207
2208
  const upperScope = context.sourceCode.getScope(node).upper;
@@ -2233,9 +2234,9 @@ var no_set_state_in_component_will_update_default = createRule({
2233
2234
  function create$20(context) {
2234
2235
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
2235
2236
  return { CallExpression(node) {
2236
- if (!isThisSetState(node)) return;
2237
- const clazz = AST.findParentNode(node, isClassComponent);
2238
- const method = AST.findParentNode(node, (n) => n === clazz || isComponentWillUpdate(n));
2237
+ if (!ER.isThisSetState(node)) return;
2238
+ const clazz = AST.findParentNode(node, ER.isClassComponent);
2239
+ const method = AST.findParentNode(node, (n) => n === clazz || ER.isComponentWillUpdate(n));
2239
2240
  if (clazz == null || method == null || method === clazz) return;
2240
2241
  const methodScope = context.sourceCode.getScope(method);
2241
2242
  const upperScope = context.sourceCode.getScope(node).upper;
@@ -2268,7 +2269,7 @@ var no_string_refs_default = createRule({
2268
2269
  function create$19(context) {
2269
2270
  const state = { isWithinClassComponent: false };
2270
2271
  function onClassBodyEnter(node) {
2271
- if (isClassComponent(node.parent)) state.isWithinClassComponent = true;
2272
+ if (ER.isClassComponent(node.parent)) state.isWithinClassComponent = true;
2272
2273
  }
2273
2274
  function onClassBodyExit() {
2274
2275
  state.isWithinClassComponent = false;
@@ -2366,15 +2367,15 @@ var no_unnecessary_use_callback_default = createRule({
2366
2367
  function create$17(context) {
2367
2368
  if (!context.sourceCode.text.includes("useCallback")) return {};
2368
2369
  return { CallExpression(node) {
2369
- if (!isUseCallbackCall(node)) return;
2370
+ if (!ER.isUseCallbackCall(node)) return;
2370
2371
  const initialScope = context.sourceCode.getScope(node);
2371
2372
  const component = context.sourceCode.getScope(node).block;
2372
2373
  if (!AST.isFunction(component)) return;
2373
2374
  const [arg0, arg1] = node.arguments;
2374
2375
  if (arg0 == null || arg1 == null) return;
2375
2376
  if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2376
- const variable = findVariable(n.name, initialScope);
2377
- const variableNode = getVariableDefinitionNode(variable, 0);
2377
+ const variable = VAR.findVariable(n.name, initialScope);
2378
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
2378
2379
  if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
2379
2380
  return variableNode.elements.length === 0;
2380
2381
  }).otherwise(() => false)) return;
@@ -2382,14 +2383,14 @@ function create$17(context) {
2382
2383
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
2383
2384
  return n;
2384
2385
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2385
- const variable = findVariable(n.name, initialScope);
2386
- const variableNode = getVariableDefinitionNode(variable, 0);
2386
+ const variable = VAR.findVariable(n.name, initialScope);
2387
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
2387
2388
  if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
2388
2389
  return variableNode;
2389
2390
  }).otherwise(() => null);
2390
2391
  if (arg0Node == null) return;
2391
2392
  const arg0NodeScope = context.sourceCode.getScope(arg0Node);
2392
- if (!getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
2393
+ if (!VAR.getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
2393
2394
  messageId: "noUnnecessaryUseCallback",
2394
2395
  node
2395
2396
  });
@@ -2418,15 +2419,15 @@ function create$16(context) {
2418
2419
  if (!context.sourceCode.text.includes("useMemo")) return {};
2419
2420
  return { CallExpression(node) {
2420
2421
  const initialScope = context.sourceCode.getScope(node);
2421
- if (!isUseMemoCall(node)) return;
2422
+ if (!ER.isUseMemoCall(node)) return;
2422
2423
  const component = context.sourceCode.getScope(node).block;
2423
2424
  if (!AST.isFunction(component)) return;
2424
2425
  const [arg0, arg1] = node.arguments;
2425
2426
  if (arg0 == null || arg1 == null) return;
2426
2427
  if (AST.isFunction(arg0) && [...AST.getNestedCallExpressions(arg0.body), ...AST.getNestedNewExpressions(arg0.body)].length > 0) return;
2427
2428
  if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2428
- const variable = findVariable(n.name, initialScope);
2429
- const variableNode = getVariableDefinitionNode(variable, 0);
2429
+ const variable = VAR.findVariable(n.name, initialScope);
2430
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
2430
2431
  if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
2431
2432
  return variableNode.elements.length === 0;
2432
2433
  }).otherwise(() => false)) return;
@@ -2434,14 +2435,14 @@ function create$16(context) {
2434
2435
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
2435
2436
  return n;
2436
2437
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2437
- const variable = findVariable(n.name, initialScope);
2438
- const variableNode = getVariableDefinitionNode(variable, 0);
2438
+ const variable = VAR.findVariable(n.name, initialScope);
2439
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
2439
2440
  if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
2440
2441
  return variableNode;
2441
2442
  }).otherwise(() => null);
2442
2443
  if (arg0Node == null) return;
2443
2444
  const arg0NodeScope = context.sourceCode.getScope(arg0Node);
2444
- if (!getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
2445
+ if (!VAR.getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
2445
2446
  messageId: "noUnnecessaryUseMemo",
2446
2447
  node
2447
2448
  });
@@ -2471,7 +2472,7 @@ var no_unnecessary_use_prefix_default = createRule({
2471
2472
  defaultOptions: []
2472
2473
  });
2473
2474
  function create$15(context) {
2474
- const { ctx, listeners } = useHookCollector();
2475
+ const { ctx, listeners } = ER.useHookCollector();
2475
2476
  return {
2476
2477
  ...listeners,
2477
2478
  "Program:exit"(program) {
@@ -2512,14 +2513,14 @@ var no_unsafe_component_will_mount_default = createRule({
2512
2513
  });
2513
2514
  function create$14(context) {
2514
2515
  if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
2515
- const { ctx, listeners } = useComponentCollectorLegacy();
2516
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
2516
2517
  return {
2517
2518
  ...listeners,
2518
2519
  "Program:exit"(program) {
2519
2520
  const components = ctx.getAllComponents(program);
2520
2521
  for (const { node: component } of components.values()) {
2521
2522
  const { body } = component.body;
2522
- for (const member of body) if (isUnsafeComponentWillMount(member)) context.report({
2523
+ for (const member of body) if (ER.isUnsafeComponentWillMount(member)) context.report({
2523
2524
  messageId: "noUnsafeComponentWillMount",
2524
2525
  node: member
2525
2526
  });
@@ -2548,14 +2549,14 @@ var no_unsafe_component_will_receive_props_default = createRule({
2548
2549
  });
2549
2550
  function create$13(context) {
2550
2551
  if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
2551
- const { ctx, listeners } = useComponentCollectorLegacy();
2552
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
2552
2553
  return {
2553
2554
  ...listeners,
2554
2555
  "Program:exit"(program) {
2555
2556
  const components = ctx.getAllComponents(program);
2556
2557
  for (const { node: component } of components.values()) {
2557
2558
  const { body } = component.body;
2558
- for (const member of body) if (isUnsafeComponentWillReceiveProps(member)) context.report({
2559
+ for (const member of body) if (ER.isUnsafeComponentWillReceiveProps(member)) context.report({
2559
2560
  messageId: "noUnsafeComponentWillReceiveProps",
2560
2561
  node: member
2561
2562
  });
@@ -2584,14 +2585,14 @@ var no_unsafe_component_will_update_default = createRule({
2584
2585
  });
2585
2586
  function create$12(context) {
2586
2587
  if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
2587
- const { ctx, listeners } = useComponentCollectorLegacy();
2588
+ const { ctx, listeners } = ER.useComponentCollectorLegacy();
2588
2589
  return {
2589
2590
  ...listeners,
2590
2591
  "Program:exit"(program) {
2591
2592
  const components = ctx.getAllComponents(program);
2592
2593
  for (const { node: component } of components.values()) {
2593
2594
  const { body } = component.body;
2594
- for (const member of body) if (isUnsafeComponentWillUpdate(member)) context.report({
2595
+ for (const member of body) if (ER.isUnsafeComponentWillUpdate(member)) context.report({
2595
2596
  messageId: "noUnsafeComponentWillUpdate",
2596
2597
  node: member
2597
2598
  });
@@ -2621,12 +2622,12 @@ var no_unstable_context_value_default = createRule({
2621
2622
  function create$11(context) {
2622
2623
  const { version: version$1 } = getSettingsFromContext(context);
2623
2624
  const isReact18OrBelow = compare(version$1, "19.0.0", "<");
2624
- const { ctx, listeners } = useComponentCollector(context);
2625
+ const { ctx, listeners } = ER.useComponentCollector(context);
2625
2626
  const constructions = /* @__PURE__ */ new WeakMap();
2626
2627
  return {
2627
2628
  ...listeners,
2628
2629
  JSXOpeningElement(node) {
2629
- const selfName = getElementType(context, node.parent).split(".").at(-1);
2630
+ const selfName = ER.getElementType(context, node.parent).split(".").at(-1);
2630
2631
  if (selfName == null) return;
2631
2632
  if (!isContextName(selfName, isReact18OrBelow)) return;
2632
2633
  const functionEntry = ctx.getCurrentEntry();
@@ -2637,9 +2638,9 @@ function create$11(context) {
2637
2638
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2638
2639
  const valueExpression = value.expression;
2639
2640
  const initialScope = context.sourceCode.getScope(valueExpression);
2640
- const construction = getConstruction(valueExpression, initialScope);
2641
+ const construction = VAR.getConstruction(valueExpression, initialScope);
2641
2642
  if (construction == null) return;
2642
- if (isReactHookCall(construction.node)) return;
2643
+ if (ER.isReactHookCall(construction.node)) return;
2643
2644
  getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
2644
2645
  },
2645
2646
  "Program:exit"(program) {
@@ -2684,7 +2685,7 @@ var no_unstable_default_props_default = createRule({
2684
2685
  defaultOptions: []
2685
2686
  });
2686
2687
  function create$10(context) {
2687
- const { ctx, listeners } = useComponentCollector(context);
2688
+ const { ctx, listeners } = ER.useComponentCollector(context);
2688
2689
  const declarators = /* @__PURE__ */ new WeakMap();
2689
2690
  return {
2690
2691
  ...listeners,
@@ -2707,9 +2708,9 @@ function create$10(context) {
2707
2708
  const { value } = prop;
2708
2709
  const { right } = value;
2709
2710
  const initialScope = context.sourceCode.getScope(value);
2710
- const construction = getConstruction(value, initialScope, ConstructionDetectionHint.StrictCallExpression);
2711
+ const construction = VAR.getConstruction(value, initialScope, VAR.ConstructionDetectionHint.StrictCallExpression);
2711
2712
  if (construction == null) continue;
2712
- if (isReactHookCall(construction.node)) continue;
2713
+ if (ER.isReactHookCall(construction.node)) continue;
2713
2714
  const forbiddenType = AST.toDelimiterFormat(right);
2714
2715
  context.report({
2715
2716
  messageId: "noUnstableDefaultProps",
@@ -2770,13 +2771,13 @@ function create$9(context) {
2770
2771
  const propertyUsages = /* @__PURE__ */ new WeakMap();
2771
2772
  function classEnter(node) {
2772
2773
  classEntries.push(node);
2773
- if (!isClassComponent(node)) return;
2774
+ if (!ER.isClassComponent(node)) return;
2774
2775
  propertyDefs.set(node, /* @__PURE__ */ new Set());
2775
2776
  propertyUsages.set(node, /* @__PURE__ */ new Set());
2776
2777
  }
2777
2778
  function classExit() {
2778
2779
  const currentClass = classEntries.pop();
2779
- if (currentClass == null || !isClassComponent(currentClass)) return;
2780
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
2780
2781
  const className = AST.getClassId(currentClass)?.name;
2781
2782
  const defs = propertyDefs.get(currentClass);
2782
2783
  const usages = propertyUsages.get(currentClass);
@@ -2798,7 +2799,7 @@ function create$9(context) {
2798
2799
  function methodEnter(node) {
2799
2800
  methodEntries.push(node);
2800
2801
  const currentClass = classEntries.at(-1);
2801
- if (currentClass == null || !isClassComponent(currentClass)) return;
2802
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
2802
2803
  if (node.static) return;
2803
2804
  if (isKeyLiteral$1(node, node.key)) propertyDefs.get(currentClass)?.add(node.key);
2804
2805
  }
@@ -2814,7 +2815,7 @@ function create$9(context) {
2814
2815
  const currentClass = classEntries.at(-1);
2815
2816
  const currentMethod = methodEntries.at(-1);
2816
2817
  if (currentClass == null || currentMethod == null) return;
2817
- if (!isClassComponent(currentClass) || currentMethod.static) return;
2818
+ if (!ER.isClassComponent(currentClass) || currentMethod.static) return;
2818
2819
  if (!AST.isThisExpression(node.object) || !isKeyLiteral$1(node, node.property)) return;
2819
2820
  if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
2820
2821
  propertyDefs.get(currentClass)?.add(node.property);
@@ -2831,7 +2832,7 @@ function create$9(context) {
2831
2832
  const currentClass = classEntries.at(-1);
2832
2833
  const currentMethod = methodEntries.at(-1);
2833
2834
  if (currentClass == null || currentMethod == null) return;
2834
- if (!isClassComponent(currentClass) || currentMethod.static) return;
2835
+ if (!ER.isClassComponent(currentClass) || currentMethod.static) return;
2835
2836
  if (node.init != null && AST.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2836
2837
  for (const prop of node.id.properties) if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral$1(prop, prop.key)) {
2837
2838
  const keyName = AST.getPropertyName(prop.key);
@@ -2862,7 +2863,7 @@ var no_unused_props_default = createRule({
2862
2863
  });
2863
2864
  function create$8(context) {
2864
2865
  const services = ESLintUtils.getParserServices(context, false);
2865
- const { ctx, listeners } = useComponentCollector(context);
2866
+ const { ctx, listeners } = ER.useComponentCollector(context);
2866
2867
  return {
2867
2868
  ...listeners,
2868
2869
  "Program:exit"(program) {
@@ -2994,7 +2995,7 @@ function create$7(context) {
2994
2995
  }
2995
2996
  function classExit() {
2996
2997
  const currentClass = classEntries.pop();
2997
- if (currentClass == null || !isClassComponent(currentClass)) return;
2998
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
2998
2999
  const className = AST.getClassId(currentClass)?.name;
2999
3000
  const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
3000
3001
  if (defNode == null || isUsed) return;
@@ -3007,9 +3008,9 @@ function create$7(context) {
3007
3008
  function methodEnter(node) {
3008
3009
  methodEntries.push(node);
3009
3010
  const currentClass = classEntries.at(-1);
3010
- if (currentClass == null || !isClassComponent(currentClass)) return;
3011
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
3011
3012
  if (node.static) {
3012
- if (isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
3013
+ if (ER.isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
3013
3014
  const defNode = stateDefs.get(currentClass)?.node;
3014
3015
  stateDefs.set(currentClass, {
3015
3016
  node: defNode,
@@ -3034,9 +3035,9 @@ function create$7(context) {
3034
3035
  }
3035
3036
  return {
3036
3037
  AssignmentExpression(node) {
3037
- if (!isAssignmentToThisState(node)) return;
3038
+ if (!ER.isAssignmentToThisState(node)) return;
3038
3039
  const currentClass = classEntries.at(-1);
3039
- if (currentClass == null || !isClassComponent(currentClass)) return;
3040
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
3040
3041
  const currentConstructor = constructorEntries.at(-1);
3041
3042
  if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) return;
3042
3043
  const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
@@ -3053,7 +3054,7 @@ function create$7(context) {
3053
3054
  if (!AST.isThisExpression(node.object)) return;
3054
3055
  if (AST.getPropertyName(node.property) !== "state") return;
3055
3056
  const currentClass = classEntries.at(-1);
3056
- if (currentClass == null || !isClassComponent(currentClass)) return;
3057
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
3057
3058
  const currentMethod = methodEntries.at(-1);
3058
3059
  if (currentMethod == null || currentMethod.static) return;
3059
3060
  if (currentMethod === constructorEntries.at(-1)) return;
@@ -3072,7 +3073,7 @@ function create$7(context) {
3072
3073
  "PropertyDefinition:exit": methodExit,
3073
3074
  VariableDeclarator(node) {
3074
3075
  const currentClass = classEntries.at(-1);
3075
- if (currentClass == null || !isClassComponent(currentClass)) return;
3076
+ if (currentClass == null || !ER.isClassComponent(currentClass)) return;
3076
3077
  const currentMethod = methodEntries.at(-1);
3077
3078
  if (currentMethod == null || currentMethod.static) return;
3078
3079
  if (currentMethod === constructorEntries.at(-1)) return;
@@ -3117,7 +3118,7 @@ function create$6(context) {
3117
3118
  const hookCalls = /* @__PURE__ */ new Set();
3118
3119
  return {
3119
3120
  CallExpression(node) {
3120
- if (!isReactHookCall(node)) return;
3121
+ if (!ER.isReactHookCall(node)) return;
3121
3122
  hookCalls.add(node);
3122
3123
  },
3123
3124
  ImportDeclaration(node) {
@@ -3148,7 +3149,7 @@ function create$6(context) {
3148
3149
  },
3149
3150
  "Program:exit"() {
3150
3151
  for (const node of hookCalls) {
3151
- if (!isUseContextCall(node)) continue;
3152
+ if (!ER.isUseContextCall(node)) continue;
3152
3153
  context.report({
3153
3154
  messageId: "noUseContext",
3154
3155
  node: node.callee,
@@ -3193,7 +3194,7 @@ var no_useless_forward_ref_default = createRule({
3193
3194
  });
3194
3195
  function create$5(context) {
3195
3196
  return { CallExpression(node) {
3196
- if (!isForwardRefCall(context, node)) return;
3197
+ if (!ER.isForwardRefCall(context, node)) return;
3197
3198
  const [component] = node.arguments;
3198
3199
  if (component == null || !AST.isFunction(component)) return;
3199
3200
  if (component.params[1] != null) return;
@@ -3232,7 +3233,7 @@ function create$4(context, [option]) {
3232
3233
  const { allowExpressions = true } = option;
3233
3234
  return {
3234
3235
  JSXElement(node) {
3235
- if (!isFragmentElement(context, node)) return;
3236
+ if (!ER.isFragmentElement(context, node)) return;
3236
3237
  checkNode(context, node, allowExpressions);
3237
3238
  },
3238
3239
  JSXFragment(node) {
@@ -3250,7 +3251,7 @@ function isWhiteSpace(node) {
3250
3251
  * Check if a node is padding spaces (whitespace with line breaks)
3251
3252
  */
3252
3253
  function isPaddingSpaces(node) {
3253
- return isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
3254
+ return ER.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
3254
3255
  }
3255
3256
  /**
3256
3257
  * Trim whitespace like React would in JSX
@@ -3267,8 +3268,8 @@ function trimLikeReact(text) {
3267
3268
  */
3268
3269
  function checkNode(context, node, allowExpressions) {
3269
3270
  const initialScope = context.sourceCode.getScope(node);
3270
- if (node.type === AST_NODE_TYPES.JSXElement && hasAttribute(context, "key", node.openingElement.attributes, initialScope)) return;
3271
- if (isHostElement(context, node.parent)) context.report({
3271
+ if (node.type === AST_NODE_TYPES.JSXElement && ER.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) return;
3272
+ if (ER.isHostElement(context, node.parent)) context.report({
3272
3273
  messageId: "uselessFragment",
3273
3274
  node,
3274
3275
  data: { reason: "placed inside a host component" },
@@ -3285,7 +3286,7 @@ function checkNode(context, node, allowExpressions) {
3285
3286
  }
3286
3287
  const isChildElement = AST.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
3287
3288
  switch (true) {
3288
- case allowExpressions && !isChildElement && node.children.length === 1 && isJsxText(node.children.at(0)): return;
3289
+ case allowExpressions && !isChildElement && node.children.length === 1 && ER.isJsxText(node.children.at(0)): return;
3289
3290
  case !allowExpressions && isChildElement:
3290
3291
  context.report({
3291
3292
  messageId: "uselessFragment",
@@ -3328,9 +3329,9 @@ function getFix(context, node) {
3328
3329
  * Check if it's safe to automatically fix the fragment
3329
3330
  */
3330
3331
  function canFix(context, node) {
3331
- if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) return isHostElement(context, node.parent);
3332
+ if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) return ER.isHostElement(context, node.parent);
3332
3333
  if (node.children.length === 0) return false;
3333
- return !node.children.some((child) => isJsxText(child) && !isWhiteSpace(child) || AST.is(AST_NODE_TYPES.JSXExpressionContainer)(child));
3334
+ return !node.children.some((child) => ER.isJsxText(child) && !isWhiteSpace(child) || AST.is(AST_NODE_TYPES.JSXExpressionContainer)(child));
3334
3335
  }
3335
3336
 
3336
3337
  //#endregion
@@ -3355,7 +3356,7 @@ var prefer_destructuring_assignment_default = createRule({
3355
3356
  defaultOptions: []
3356
3357
  });
3357
3358
  function create$3(context) {
3358
- const { ctx, listeners } = useComponentCollector(context);
3359
+ const { ctx, listeners } = ER.useComponentCollector(context);
3359
3360
  const memberExpressionWithNames = [];
3360
3361
  return {
3361
3362
  ...listeners,
@@ -3370,7 +3371,7 @@ function create$3(context) {
3370
3371
  function isFunctionComponent(block) {
3371
3372
  if (!AST.isFunction(block)) return false;
3372
3373
  const id = AST.getFunctionId(block);
3373
- return id != null && isComponentNameLoose(id.name) && components.some((component) => component.node === block);
3374
+ return id != null && ER.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
3374
3375
  }
3375
3376
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
3376
3377
  let scope = initialScope;
@@ -3460,7 +3461,7 @@ var prefer_read_only_props_default = createRule({
3460
3461
  });
3461
3462
  function create$1(context) {
3462
3463
  const services = ESLintUtils.getParserServices(context, false);
3463
- const { ctx, listeners } = useComponentCollector(context);
3464
+ const { ctx, listeners } = ER.useComponentCollector(context);
3464
3465
  return {
3465
3466
  ...listeners,
3466
3467
  "Program:exit"(program) {
@@ -3515,13 +3516,13 @@ var prefer_use_state_lazy_initialization_default = createRule({
3515
3516
  });
3516
3517
  function create(context) {
3517
3518
  return { CallExpression(node) {
3518
- if (!isUseStateCall(node)) return;
3519
+ if (!ER.isUseStateCall(node)) return;
3519
3520
  const [useStateInput] = node.arguments;
3520
3521
  if (useStateInput == null) return;
3521
3522
  for (const expr of AST.getNestedNewExpressions(useStateInput)) {
3522
3523
  if (!("name" in expr.callee)) continue;
3523
3524
  if (ALLOW_LIST.includes(expr.callee.name)) continue;
3524
- if (AST.findParentNode(expr, isUseCall) != null) continue;
3525
+ if (AST.findParentNode(expr, ER.isUseCall) != null) continue;
3525
3526
  context.report({
3526
3527
  messageId: "preferUseStateLazyInitialization",
3527
3528
  node: expr
@@ -3529,9 +3530,9 @@ function create(context) {
3529
3530
  }
3530
3531
  for (const expr of AST.getNestedCallExpressions(useStateInput)) {
3531
3532
  if (!("name" in expr.callee)) continue;
3532
- if (isReactHookName(expr.callee.name)) continue;
3533
+ if (ER.isReactHookName(expr.callee.name)) continue;
3533
3534
  if (ALLOW_LIST.includes(expr.callee.name)) continue;
3534
- if (AST.findParentNode(expr, isUseCall) != null) continue;
3535
+ if (AST.findParentNode(expr, ER.isUseCall) != null) continue;
3535
3536
  context.report({
3536
3537
  messageId: "preferUseStateLazyInitialization",
3537
3538
  node: expr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "2.0.1-beta.4",
3
+ "version": "2.0.1-next.0",
4
4
  "description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
@@ -42,15 +42,15 @@
42
42
  "is-immutable-type": "^5.0.1",
43
43
  "string-ts": "^2.2.1",
44
44
  "ts-pattern": "^5.8.0",
45
- "@eslint-react/ast": "2.0.1-beta.4",
46
- "@eslint-react/eff": "2.0.1-beta.4",
47
- "@eslint-react/kit": "2.0.1-beta.4",
48
- "@eslint-react/core": "2.0.1-beta.4",
49
- "@eslint-react/shared": "2.0.1-beta.4",
50
- "@eslint-react/var": "2.0.1-beta.4"
45
+ "@eslint-react/ast": "2.0.1-next.0",
46
+ "@eslint-react/core": "2.0.1-next.0",
47
+ "@eslint-react/eff": "2.0.1-next.0",
48
+ "@eslint-react/kit": "2.0.1-next.0",
49
+ "@eslint-react/shared": "2.0.1-next.0",
50
+ "@eslint-react/var": "2.0.1-next.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@types/react": "^19.1.14",
53
+ "@types/react": "^19.1.13",
54
54
  "@types/react-dom": "^19.1.9",
55
55
  "ts-api-utils": "^2.1.0",
56
56
  "tsdown": "^0.15.4",