eslint-plugin-react-x 1.22.2-beta.0 → 1.22.2-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +152 -216
  2. package/dist/index.mjs +153 -217
  3. package/package.json +13 -13
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { F, O, isString, MutRef, isNullable } from '@eslint-react/eff';
2
- import * as JSX8 from '@eslint-react/jsx';
1
+ import { F, O, or, isString, isNullable } from '@eslint-react/eff';
2
+ import * as JSX7 from '@eslint-react/jsx';
3
3
  import { createRuleForPlugin, normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
4
4
  import * as AST11 from '@eslint-react/ast';
5
- import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, isChildrenToArrayCall, useComponentCollector, ERFunctionComponentFlag, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isFragmentElement, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
5
+ import { isForwardRefCall, isThisSetState, isClassComponent, isCreateElementCall, isCloneElementCall, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isFragmentElement, isInitializedFromReact } from '@eslint-react/core';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
7
7
  import { isMatching, P, match } 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.22.2-beta.0";
18
+ var version = "1.22.2-beta.11";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -43,7 +43,7 @@ var avoid_shorthand_boolean_default = createRule({
43
43
  messageId: "avoidShorthandBoolean",
44
44
  node,
45
45
  data: {
46
- propName: JSX8.getPropName(node)
46
+ propName: JSX7.getPropName(node)
47
47
  },
48
48
  fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
49
49
  });
@@ -124,7 +124,7 @@ var RULE_FEATURES4 = [
124
124
  "CHK"
125
125
  ];
126
126
  function getName(node) {
127
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
127
+ if (AST11.isTypeExpression(node)) {
128
128
  return getName(node.expression);
129
129
  }
130
130
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
@@ -300,12 +300,10 @@ var no_array_index_key_default = createRule({
300
300
  name: RULE_NAME5,
301
301
  create(context) {
302
302
  const indexParamNames = [];
303
+ const isCreateOrCloneElementCall = or(isCreateElementCall(context), isCloneElementCall(context));
303
304
  function isArrayIndex(node) {
304
305
  return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
305
306
  }
306
- function isCreateOrCloneElementCall(node) {
307
- return isCreateElementCall(node, context) || isCloneElementCall(node, context);
308
- }
309
307
  function getReportDescriptor(node) {
310
308
  if (isArrayIndex(node)) return [{ messageId: "noArrayIndexKey", node }];
311
309
  if (AST11.isOneOf([AST_NODE_TYPES.TemplateLiteral, AST_NODE_TYPES.BinaryExpression])(node)) {
@@ -510,7 +508,7 @@ var no_children_prop_default = createRule({
510
508
  return {
511
509
  JSXElement(node) {
512
510
  const initialScope = context.sourceCode.getScope(node);
513
- const prop = JSX8.getProp(node.openingElement.attributes, "children", initialScope);
511
+ const prop = JSX7.getProp(node.openingElement.attributes, "children", initialScope);
514
512
  const reportDescriptor = O.map(prop, (prop2) => ({ messageId: "noChildrenProp", node: prop2 }));
515
513
  O.map(reportDescriptor, context.report);
516
514
  }
@@ -885,7 +883,7 @@ var no_context_provider_default = createRule({
885
883
  if (compare(version2, "19.0.0", "<")) return {};
886
884
  return {
887
885
  JSXElement(node) {
888
- const elementName = JSX8.getElementName(node.openingElement);
886
+ const elementName = JSX7.getElementName(node.openingElement);
889
887
  if (!elementName.endsWith(".Provider")) return;
890
888
  context.report({
891
889
  messageId: "noContextProvider",
@@ -982,7 +980,7 @@ var RULE_FEATURES22 = [
982
980
  "CHK"
983
981
  ];
984
982
  function getName2(node) {
985
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
983
+ if (AST11.isTypeExpression(node)) {
986
984
  return getName2(node.expression);
987
985
  }
988
986
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
@@ -1096,116 +1094,61 @@ var no_duplicate_key_default = createRule({
1096
1094
  },
1097
1095
  name: RULE_NAME24,
1098
1096
  create(context) {
1099
- const isWithinChildrenToArrayRef = MutRef.make(false);
1100
- function isKeyEqual(a, b) {
1101
- return VAR.isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
1102
- }
1103
- function checkIteratorElement(node) {
1104
- if (node.type !== AST_NODE_TYPES.JSXElement) return O.none();
1105
- const initialScope = context.sourceCode.getScope(node);
1106
- return F.pipe(
1107
- JSX8.findPropInAttributes(node.openingElement.attributes, initialScope)("key"),
1108
- O.flatMap((k) => "value" in k ? O.fromNullable(k.value) : O.none()),
1109
- O.flatMap((v) => {
1110
- return isKeyEqual(v, v) ? O.some({
1111
- messageId: "noDuplicateKey",
1112
- node: v,
1113
- data: {
1114
- value: context.sourceCode.getText(v)
1115
- }
1116
- }) : O.none();
1117
- })
1118
- );
1119
- }
1120
- function checkExpression(node) {
1121
- switch (node.type) {
1122
- case AST_NODE_TYPES.ConditionalExpression:
1123
- if (!("consequent" in node)) return O.none();
1124
- return F.pipe(
1125
- checkIteratorElement(node.consequent),
1126
- O.orElse(() => checkIteratorElement(node.alternate))
1127
- );
1128
- case AST_NODE_TYPES.JSXElement:
1129
- case AST_NODE_TYPES.JSXFragment:
1130
- return checkIteratorElement(node);
1131
- case AST_NODE_TYPES.LogicalExpression:
1132
- if (!("left" in node)) return O.none();
1133
- return F.pipe(
1134
- checkIteratorElement(node.left),
1135
- O.orElse(() => checkIteratorElement(node.right))
1136
- );
1137
- default:
1138
- return O.none();
1139
- }
1140
- }
1141
- function checkBlockStatement(node) {
1142
- return AST11.getNestedReturnStatements(node).reduce((acc, statement) => {
1143
- if (!statement.argument) return acc;
1144
- const maybeDescriptor = checkIteratorElement(statement.argument);
1145
- if (O.isNone(maybeDescriptor)) return acc;
1146
- const descriptor = maybeDescriptor.value;
1147
- return [...acc, descriptor];
1148
- }, []);
1097
+ if (!context.sourceCode.getText().includes("key=")) return {};
1098
+ const keyedEntries = /* @__PURE__ */ new Map();
1099
+ function isKeyValueEqual(a, b) {
1100
+ const aValue = a.value;
1101
+ const bValue = b.value;
1102
+ if (aValue === null || bValue === null) return false;
1103
+ return AST11.isNodeEqual(aValue, bValue);
1149
1104
  }
1150
- const seen = /* @__PURE__ */ new WeakSet();
1151
1105
  return {
1152
- "ArrayExpression, JSXElement > JSXElement"(node) {
1153
- if (MutRef.get(isWithinChildrenToArrayRef)) return;
1154
- const elements = match(node).with({ type: AST_NODE_TYPES.ArrayExpression }, ({ elements: elements2 }) => elements2).with({ type: AST_NODE_TYPES.JSXElement }, ({ parent }) => "children" in parent ? parent.children : []).otherwise(() => []).filter(AST11.is(AST_NODE_TYPES.JSXElement)).filter((element) => !seen.has(element));
1155
- const keys = elements.reduce(
1156
- (acc, element) => {
1157
- const attr = element.openingElement.attributes.findLast((attr2) => {
1158
- if (attr2.type !== AST_NODE_TYPES.JSXAttribute) return false;
1159
- return attr2.name.name === "key";
1106
+ "JSXAttribute[name.name='key']"(node) {
1107
+ const jsxElement = node.parent.parent;
1108
+ switch (jsxElement.parent.type) {
1109
+ case AST_NODE_TYPES.ArrayExpression:
1110
+ case AST_NODE_TYPES.JSXElement:
1111
+ case AST_NODE_TYPES.JSXFragment: {
1112
+ const root = jsxElement.parent;
1113
+ const prevKeys = keyedEntries.get(root)?.keys ?? [];
1114
+ keyedEntries.set(root, {
1115
+ hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, node)),
1116
+ keys: [...prevKeys, node],
1117
+ root: jsxElement.parent
1160
1118
  });
1161
- if (!attr || !("value" in attr) || attr.value === null) return acc;
1162
- const { value } = attr;
1163
- if (acc.length === 0) return [[element, attr, value]];
1164
- if (acc.some(([_, _1, v]) => isKeyEqual(v, value))) {
1165
- return [...acc, [element, attr, value]];
1166
- }
1167
- return acc;
1168
- },
1169
- []
1170
- );
1171
- if (keys.length < 2) return;
1172
- for (const [element, attr, value] of keys) {
1173
- seen.add(element);
1174
- context.report({
1175
- messageId: "noDuplicateKey",
1176
- node: attr,
1177
- data: {
1178
- value: context.sourceCode.getText(value)
1119
+ break;
1120
+ }
1121
+ default: {
1122
+ const entry = F.pipe(
1123
+ O.Do,
1124
+ O.bind("call", () => AST11.traverseUpGuard(jsxElement, AST11.isMapCallLoose)),
1125
+ O.bind("iter", ({ call }) => AST11.traverseUpStop(jsxElement, call, AST11.isFunction)),
1126
+ O.bind("arg0", ({ call }) => O.fromNullable(call.arguments[0]))
1127
+ );
1128
+ for (const { arg0, call, iter } of O.toArray(entry)) {
1129
+ if (AST11.unwrapTypeExpression(arg0) !== iter) continue;
1130
+ keyedEntries.set(call, {
1131
+ hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
1132
+ keys: [node],
1133
+ root: call
1134
+ });
1179
1135
  }
1180
- });
1136
+ }
1181
1137
  }
1182
1138
  },
1183
- CallExpression(node) {
1184
- if (isChildrenToArrayCall(node, context)) MutRef.set(isWithinChildrenToArrayRef, true);
1185
- const isMapCall = AST11.isMapCallLoose(node);
1186
- const isArrayFromCall = isMatching({
1187
- type: AST_NODE_TYPES.CallExpression,
1188
- callee: {
1189
- type: AST_NODE_TYPES.MemberExpression,
1190
- property: {
1191
- name: "from"
1192
- }
1193
- }
1194
- }, node);
1195
- if (!isMapCall && !isArrayFromCall) return;
1196
- if (MutRef.get(isWithinChildrenToArrayRef)) return;
1197
- const fn = node.arguments[isMapCall ? 0 : 1];
1198
- if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) return;
1199
- if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
1200
- for (const descriptor of checkBlockStatement(fn.body)) {
1201
- context.report(descriptor);
1139
+ "Program:exit"() {
1140
+ for (const { hasDuplicate, keys } of keyedEntries.values()) {
1141
+ if (!hasDuplicate) continue;
1142
+ for (const key of keys) {
1143
+ context.report({
1144
+ messageId: "noDuplicateKey",
1145
+ node: key,
1146
+ data: {
1147
+ value: context.sourceCode.getText(key)
1148
+ }
1149
+ });
1202
1150
  }
1203
- return;
1204
1151
  }
1205
- O.map(checkExpression(fn.body), context.report);
1206
- },
1207
- "CallExpression:exit"(node) {
1208
- if (isChildrenToArrayCall(node, context)) MutRef.set(isWithinChildrenToArrayRef, false);
1209
1152
  }
1210
1153
  };
1211
1154
  },
@@ -1328,7 +1271,7 @@ var no_implicit_key_default = createRule({
1328
1271
  create(context) {
1329
1272
  function getReportDescriptor(node) {
1330
1273
  const initialScope = context.sourceCode.getScope(node);
1331
- const keyPropFound = JSX8.findPropInAttributes(node.attributes, initialScope)("key");
1274
+ const keyPropFound = JSX7.findPropInAttributes(node.attributes, initialScope)("key");
1332
1275
  const keyPropOnElement = node.attributes.some(
1333
1276
  (n) => AST11.is(AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key"
1334
1277
  );
@@ -1568,12 +1511,12 @@ var no_missing_key_default = createRule({
1568
1511
  },
1569
1512
  name: RULE_NAME29,
1570
1513
  create(context) {
1571
- const isWithinChildrenToArrayRef = MutRef.make(false);
1514
+ const state = { isWithinChildrenToArray: false };
1572
1515
  function checkIteratorElement(node) {
1573
1516
  switch (node.type) {
1574
1517
  case AST_NODE_TYPES.JSXElement: {
1575
1518
  const initialScope = context.sourceCode.getScope(node);
1576
- if (!JSX8.hasProp(node.openingElement.attributes, "key", initialScope)) {
1519
+ if (!JSX7.hasProp(node.openingElement.attributes, "key", initialScope)) {
1577
1520
  return O.some({
1578
1521
  messageId: "noMissingKey",
1579
1522
  node
@@ -1617,12 +1560,12 @@ var no_missing_key_default = createRule({
1617
1560
  }
1618
1561
  return {
1619
1562
  ArrayExpression(node) {
1620
- if (MutRef.get(isWithinChildrenToArrayRef)) return;
1563
+ if (state.isWithinChildrenToArray) return;
1621
1564
  const elements = node.elements.filter(AST11.is(AST_NODE_TYPES.JSXElement));
1622
1565
  if (elements.length === 0) return;
1623
1566
  const initialScope = context.sourceCode.getScope(node);
1624
1567
  for (const element of elements) {
1625
- if (!JSX8.hasProp(element.openingElement.attributes, "key", initialScope)) {
1568
+ if (!JSX7.hasProp(element.openingElement.attributes, "key", initialScope)) {
1626
1569
  context.report({
1627
1570
  messageId: "noMissingKey",
1628
1571
  node: element
@@ -1631,7 +1574,8 @@ var no_missing_key_default = createRule({
1631
1574
  }
1632
1575
  },
1633
1576
  CallExpression(node) {
1634
- if (isChildrenToArrayCall(node, context)) MutRef.set(isWithinChildrenToArrayRef, true);
1577
+ state.isWithinChildrenToArray ||= isChildrenToArrayCall(node, context);
1578
+ if (state.isWithinChildrenToArray) return;
1635
1579
  const isMapCall = AST11.isMapCallLoose(node);
1636
1580
  const isArrayFromCall = isMatching({
1637
1581
  type: AST_NODE_TYPES.CallExpression,
@@ -1643,7 +1587,6 @@ var no_missing_key_default = createRule({
1643
1587
  }
1644
1588
  }, node);
1645
1589
  if (!isMapCall && !isArrayFromCall) return;
1646
- if (MutRef.get(isWithinChildrenToArrayRef)) return;
1647
1590
  const fn = node.arguments[isMapCall ? 0 : 1];
1648
1591
  if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) return;
1649
1592
  if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
@@ -1655,10 +1598,11 @@ var no_missing_key_default = createRule({
1655
1598
  O.map(checkExpression(fn.body), context.report);
1656
1599
  },
1657
1600
  "CallExpression:exit"(node) {
1658
- if (isChildrenToArrayCall(node, context)) MutRef.set(isWithinChildrenToArrayRef, false);
1601
+ if (!isChildrenToArrayCall(node, context)) return;
1602
+ state.isWithinChildrenToArray = false;
1659
1603
  },
1660
1604
  JSXFragment(node) {
1661
- if (MutRef.get(isWithinChildrenToArrayRef)) return;
1605
+ if (state.isWithinChildrenToArray) return;
1662
1606
  if (node.parent.type === AST_NODE_TYPES.ArrayExpression) {
1663
1607
  context.report({
1664
1608
  messageId: "noMissingKeyWithFragment",
@@ -1709,7 +1653,7 @@ var no_nested_components_default = createRule({
1709
1653
  if (O.isNone(componentName)) continue;
1710
1654
  const name2 = componentName.value;
1711
1655
  const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
1712
- const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX8.traverseUpProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
1656
+ const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX7.traverseUpProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
1713
1657
  if (isInsideJSXPropValue) {
1714
1658
  if (!isDeclaredInRenderPropLoose(component)) {
1715
1659
  context.report({
@@ -1755,7 +1699,7 @@ var no_nested_components_default = createRule({
1755
1699
  }
1756
1700
  }
1757
1701
  for (const { name: name2, node: component } of classComponents) {
1758
- if (O.isNone(AST11.traverseUp(component, (node2) => isClassComponent11(node2) || isFunctionComponent(node2)))) {
1702
+ if (O.isNone(AST11.traverseUp(component, or(isClassComponent11, isFunctionComponent)))) {
1759
1703
  continue;
1760
1704
  }
1761
1705
  context.report({
@@ -1885,22 +1829,25 @@ var no_set_state_in_component_did_mount_default = createRule({
1885
1829
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
1886
1830
  function getReportDescriptor(node) {
1887
1831
  if (!isThisSetState(node)) return O.none();
1888
- const maybeParentClass = AST11.traverseUp(
1889
- node,
1890
- AST11.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression])
1832
+ return F.pipe(
1833
+ O.Do,
1834
+ O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
1835
+ O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentDidMount)),
1836
+ O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
1837
+ O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
1838
+ O.filter(
1839
+ ({
1840
+ clazz,
1841
+ method,
1842
+ methodScope,
1843
+ upperScope
1844
+ }) => method.parent === clazz.body && upperScope === methodScope
1845
+ ),
1846
+ O.map(() => ({
1847
+ messageId: "noSetStateInComponentDidMount",
1848
+ node
1849
+ }))
1891
1850
  );
1892
- if (O.isNone(maybeParentClass)) return O.none();
1893
- const parentClass = maybeParentClass.value;
1894
- if (!isClassComponent(parentClass)) return O.none();
1895
- const maybeParentMethod = AST11.traverseUp(node, isComponentDidMount);
1896
- if (O.isNone(maybeParentMethod)) return O.none();
1897
- const parentMethod = maybeParentMethod.value;
1898
- if (parentMethod.parent !== parentClass.body) return O.none();
1899
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1900
- return O.some({
1901
- messageId: "noSetStateInComponentDidMount",
1902
- node
1903
- });
1904
1851
  }
1905
1852
  return {
1906
1853
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -1932,22 +1879,19 @@ var no_set_state_in_component_did_update_default = createRule({
1932
1879
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
1933
1880
  function getReportDescriptor(node) {
1934
1881
  if (!isThisSetState(node)) return O.none();
1935
- const maybeParentClass = AST11.traverseUp(
1936
- node,
1937
- AST11.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression])
1882
+ return F.pipe(
1883
+ O.Do,
1884
+ O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
1885
+ O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentDidUpdate)),
1886
+ O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
1887
+ O.filter(
1888
+ ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1889
+ ),
1890
+ O.map(() => ({
1891
+ messageId: "noSetStateInComponentDidUpdate",
1892
+ node
1893
+ }))
1938
1894
  );
1939
- if (O.isNone(maybeParentClass)) return O.none();
1940
- const parentClass = maybeParentClass.value;
1941
- if (!isClassComponent(parentClass)) return O.none();
1942
- const maybeParentMethod = AST11.traverseUp(node, isComponentDidUpdate);
1943
- if (O.isNone(maybeParentMethod)) return O.none();
1944
- const parentMethod = maybeParentMethod.value;
1945
- if (parentMethod.parent !== parentClass.body) return O.none();
1946
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1947
- return O.some({
1948
- messageId: "noSetStateInComponentDidUpdate",
1949
- node
1950
- });
1951
1895
  }
1952
1896
  return {
1953
1897
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -1979,22 +1923,19 @@ var no_set_state_in_component_will_update_default = createRule({
1979
1923
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
1980
1924
  function getReportDescriptor(node) {
1981
1925
  if (!isThisSetState(node)) return O.none();
1982
- const maybeParentClass = AST11.traverseUp(
1983
- node,
1984
- AST11.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression])
1926
+ return F.pipe(
1927
+ O.Do,
1928
+ O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
1929
+ O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentWillUpdate3)),
1930
+ O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
1931
+ O.filter(
1932
+ ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1933
+ ),
1934
+ O.map(() => ({
1935
+ messageId: "noSetStateInComponentWillUpdate",
1936
+ node
1937
+ }))
1985
1938
  );
1986
- if (O.isNone(maybeParentClass)) return O.none();
1987
- const parentClass = maybeParentClass.value;
1988
- if (!isClassComponent(parentClass)) return O.none();
1989
- const maybeParentMethod = AST11.traverseUp(node, isComponentWillUpdate3);
1990
- if (O.isNone(maybeParentMethod)) return O.none();
1991
- const parentMethod = maybeParentMethod.value;
1992
- if (parentMethod.parent !== parentClass.body) return O.none();
1993
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1994
- return O.some({
1995
- messageId: "noSetStateInComponentWillUpdate",
1996
- node
1997
- });
1998
1939
  }
1999
1940
  return {
2000
1941
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -2192,39 +2133,40 @@ var no_unstable_context_value_default = createRule({
2192
2133
  name: RULE_NAME40,
2193
2134
  create(context) {
2194
2135
  const { ctx, listeners } = useComponentCollector(context);
2195
- const possibleValueConstructions = /* @__PURE__ */ new Map();
2136
+ const constructions = /* @__PURE__ */ new Map();
2196
2137
  return {
2197
2138
  ...listeners,
2198
2139
  JSXOpeningElement(node) {
2199
2140
  const openingElementName = node.name;
2200
2141
  if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) return;
2201
2142
  if (openingElementName.property.name !== "Provider") return;
2202
- const maybeJSXValueAttribute = O.fromNullable(
2203
- node.attributes.find((attribute) => {
2204
- return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2205
- })
2143
+ const constructionEntry = F.pipe(
2144
+ O.Do,
2145
+ O.bind("function", ctx.getCurrentFunction),
2146
+ O.bind("attribute", () => O.fromNullable(
2147
+ node.attributes.find((attribute) => {
2148
+ return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2149
+ })
2150
+ )),
2151
+ O.bind("value", ({ attribute }) => "value" in attribute ? O.some(attribute.value) : O.none()),
2152
+ O.bind("valueExpression", ({ value }) => value?.type === AST_NODE_TYPES.JSXExpressionContainer ? O.some(value.expression) : O.none()),
2153
+ O.bind("construction", ({ valueExpression }) => {
2154
+ const initialScope = context.sourceCode.getScope(valueExpression);
2155
+ return O.some(VAR.inspectConstruction(valueExpression, initialScope));
2156
+ }),
2157
+ O.filter(({ construction }) => construction._tag !== "None")
2206
2158
  );
2207
- if (O.isNone(maybeJSXValueAttribute) || !("value" in maybeJSXValueAttribute.value)) return;
2208
- const valueNode = maybeJSXValueAttribute.value.value;
2209
- if (valueNode?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2210
- const valueExpression = valueNode.expression;
2211
- const initialScope = context.sourceCode.getScope(valueExpression);
2212
- const construction = VAR.inspectConstruction(valueExpression, initialScope);
2213
- if (construction._tag === "None") return;
2214
- O.map(
2215
- ctx.getCurrentFunction(),
2216
- ([_, currentFn]) => possibleValueConstructions.set(currentFn, [
2217
- ...possibleValueConstructions.get(currentFn) ?? [],
2159
+ for (const { construction, function: [_, fNode] } of O.toArray(constructionEntry)) {
2160
+ constructions.set(fNode, [
2161
+ ...constructions.get(fNode) ?? [],
2218
2162
  construction
2219
- ])
2220
- );
2163
+ ]);
2164
+ }
2221
2165
  },
2222
2166
  "Program:exit"(node) {
2223
2167
  const components = ctx.getAllComponents(node).values();
2224
2168
  for (const { node: component } of components) {
2225
- const constructions = possibleValueConstructions.get(component);
2226
- if (!constructions) continue;
2227
- for (const construction of constructions) {
2169
+ for (const construction of constructions.get(component) ?? []) {
2228
2170
  if (construction._tag === "None") continue;
2229
2171
  const { node: constructionNode, _tag } = construction;
2230
2172
  const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
@@ -2261,7 +2203,7 @@ var no_unstable_default_props_default = createRule({
2261
2203
  name: RULE_NAME41,
2262
2204
  create(context) {
2263
2205
  const { ctx, listeners } = useComponentCollector(context);
2264
- const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
2206
+ const declarators = /* @__PURE__ */ new WeakMap();
2265
2207
  return {
2266
2208
  ...listeners,
2267
2209
  "Program:exit"(node) {
@@ -2271,10 +2213,7 @@ var no_unstable_default_props_default = createRule({
2271
2213
  const [props] = params;
2272
2214
  if (!props) continue;
2273
2215
  const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2274
- const variableDeclarators = possibleDestructuringDeclarators.get(component);
2275
- if (!variableDeclarators) return [];
2276
- const declarators = variableDeclarators.filter((d) => d.init.name === name2);
2277
- return declarators.flatMap((d) => d.id.properties);
2216
+ return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2278
2217
  }).otherwise(() => []);
2279
2218
  for (const prop of properties) {
2280
2219
  if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
@@ -2299,13 +2238,10 @@ var no_unstable_default_props_default = createRule({
2299
2238
  }
2300
2239
  },
2301
2240
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2302
- O.map(
2303
- ctx.getCurrentFunction(),
2304
- ([_, currentFn]) => possibleDestructuringDeclarators.set(currentFn, [
2305
- ...possibleDestructuringDeclarators.get(currentFn) ?? [],
2306
- node
2307
- ])
2308
- );
2241
+ for (const [_, currentFn] of O.toArray(ctx.getCurrentFunction())) {
2242
+ const prevDeclarators = declarators.get(currentFn) ?? [];
2243
+ declarators.set(currentFn, [...prevDeclarators, node]);
2244
+ }
2309
2245
  }
2310
2246
  };
2311
2247
  },
@@ -2333,7 +2269,7 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
2333
2269
  "UNSAFE_componentWillUpdate"
2334
2270
  ]);
2335
2271
  function getName3(node) {
2336
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
2272
+ if (AST11.isTypeExpression(node)) {
2337
2273
  return getName3(node.expression);
2338
2274
  }
2339
2275
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
@@ -2433,7 +2369,9 @@ var no_unused_class_component_members_default = createRule({
2433
2369
  if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2434
2370
  for (const prop of node.id.properties) {
2435
2371
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2436
- O.map(getName3(prop.key), (name2) => propertyUsages.get(currentClass)?.add(name2));
2372
+ for (const name2 of O.toArray(getName3(prop.key))) {
2373
+ propertyUsages.get(currentClass)?.add(name2);
2374
+ }
2437
2375
  }
2438
2376
  }
2439
2377
  }
@@ -2447,7 +2385,7 @@ var RULE_FEATURES43 = [
2447
2385
  "CHK"
2448
2386
  ];
2449
2387
  function getName4(node) {
2450
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
2388
+ if (AST11.isTypeExpression(node)) {
2451
2389
  return getName4(node.expression);
2452
2390
  }
2453
2391
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
@@ -2590,18 +2528,18 @@ var no_unused_state_default = createRule({
2590
2528
  var RULE_NAME44 = "no-useless-fragment";
2591
2529
  function check(node, context, allowExpressions) {
2592
2530
  const initialScope = context.sourceCode.getScope(node);
2593
- if (JSX8.isKeyedElement(node, initialScope)) return;
2594
- if (JSX8.isBuiltInElement(node.parent)) context.report({ messageId: "noUselessFragmentInBuiltIn", node });
2531
+ if (JSX7.isKeyedElement(node, initialScope)) return;
2532
+ if (JSX7.isBuiltInElement(node.parent)) context.report({ messageId: "noUselessFragmentInBuiltIn", node });
2595
2533
  if (node.children.length === 0) return context.report({ messageId: "noUselessFragment", node });
2596
2534
  const isChildren = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
2597
2535
  const [firstChildren] = node.children;
2598
- if (allowExpressions && node.children.length === 1 && JSX8.isLiteral(firstChildren) && !isChildren) return;
2536
+ if (allowExpressions && node.children.length === 1 && JSX7.isLiteral(firstChildren) && !isChildren) return;
2599
2537
  if (!allowExpressions && isChildren) {
2600
2538
  return context.report({ messageId: "noUselessFragment", node });
2601
2539
  } else if (!allowExpressions && !isChildren && node.children.length === 1) {
2602
2540
  return context.report({ messageId: "noUselessFragment", node });
2603
2541
  }
2604
- const nonPaddingChildren = node.children.filter((child) => !JSX8.isPaddingSpaces(child));
2542
+ const nonPaddingChildren = node.children.filter((child) => !JSX7.isPaddingSpaces(child));
2605
2543
  if (nonPaddingChildren.length > 1) return;
2606
2544
  if (nonPaddingChildren.length === 0) return context.report({ messageId: "noUselessFragment", node });
2607
2545
  const [first] = nonPaddingChildren;
@@ -2843,7 +2781,7 @@ var prefer_shorthand_boolean_default = createRule({
2843
2781
  create(context) {
2844
2782
  function getReportDescriptor(node) {
2845
2783
  const { value } = node;
2846
- const propName = JSX8.getPropName(node);
2784
+ const propName = JSX7.getPropName(node);
2847
2785
  const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
2848
2786
  if (!hasValueTrue) return O.none();
2849
2787
  return O.some({
@@ -2900,10 +2838,8 @@ var use_jsx_vars_default = createRule({
2900
2838
  meta: {
2901
2839
  type: "problem",
2902
2840
  docs: {
2903
- description: (
2904
- // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2905
- "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
2906
- ),
2841
+ // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2842
+ description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
2907
2843
  [Symbol.for("rule_features")]: RULE_FEATURES49
2908
2844
  },
2909
2845
  messages: {
@@ -2926,9 +2862,9 @@ var use_jsx_vars_default = createRule({
2926
2862
  return {
2927
2863
  JSXOpeningElement(node) {
2928
2864
  if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
2929
- O.map(getName5(node.name), (name2) => {
2865
+ for (const name2 of O.toArray(getName5(node.name))) {
2930
2866
  context.sourceCode.markVariableAsUsed(name2, node);
2931
- });
2867
+ }
2932
2868
  }
2933
2869
  };
2934
2870
  },