eslint-plugin-react-x 1.22.2-next.8 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
42
42
 
43
43
  // package.json
44
44
  var name = "eslint-plugin-react-x";
45
- var version = "1.22.2-next.8";
45
+ var version = "1.22.2";
46
46
  var createRule = shared.createRuleForPlugin("x");
47
47
 
48
48
  // src/rules/avoid-shorthand-boolean.ts
@@ -327,12 +327,10 @@ var no_array_index_key_default = createRule({
327
327
  name: RULE_NAME5,
328
328
  create(context) {
329
329
  const indexParamNames = [];
330
+ const isCreateOrCloneElementCall = eff.or(core.isCreateElementCall(context), core.isCloneElementCall(context));
330
331
  function isArrayIndex(node) {
331
332
  return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(eff.O.exists((name2) => name2 === node.name));
332
333
  }
333
- function isCreateOrCloneElementCall(node) {
334
- return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
335
- }
336
334
  function getReportDescriptor(node) {
337
335
  if (isArrayIndex(node)) return [{ messageId: "noArrayIndexKey", node }];
338
336
  if (AST11__namespace.isOneOf([types.AST_NODE_TYPES.TemplateLiteral, types.AST_NODE_TYPES.BinaryExpression])(node)) {
@@ -1728,7 +1726,7 @@ var no_nested_components_default = createRule({
1728
1726
  }
1729
1727
  }
1730
1728
  for (const { name: name2, node: component } of classComponents) {
1731
- if (eff.O.isNone(AST11__namespace.traverseUp(component, (node2) => isClassComponent11(node2) || isFunctionComponent(node2)))) {
1729
+ if (eff.O.isNone(AST11__namespace.traverseUp(component, eff.or(isClassComponent11, isFunctionComponent)))) {
1732
1730
  continue;
1733
1731
  }
1734
1732
  context.report({
@@ -1858,22 +1856,25 @@ var no_set_state_in_component_did_mount_default = createRule({
1858
1856
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
1859
1857
  function getReportDescriptor(node) {
1860
1858
  if (!core.isThisSetState(node)) return eff.O.none();
1861
- const maybeParentClass = AST11__namespace.traverseUp(
1862
- node,
1863
- AST11__namespace.isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression])
1859
+ return eff.F.pipe(
1860
+ eff.O.Do,
1861
+ eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
1862
+ eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidMount)),
1863
+ eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
1864
+ eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
1865
+ eff.O.filter(
1866
+ ({
1867
+ clazz,
1868
+ method,
1869
+ methodScope,
1870
+ upperScope
1871
+ }) => method.parent === clazz.body && upperScope === methodScope
1872
+ ),
1873
+ eff.O.map(() => ({
1874
+ messageId: "noSetStateInComponentDidMount",
1875
+ node
1876
+ }))
1864
1877
  );
1865
- if (eff.O.isNone(maybeParentClass)) return eff.O.none();
1866
- const parentClass = maybeParentClass.value;
1867
- if (!core.isClassComponent(parentClass)) return eff.O.none();
1868
- const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidMount);
1869
- if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
1870
- const parentMethod = maybeParentMethod.value;
1871
- if (parentMethod.parent !== parentClass.body) return eff.O.none();
1872
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
1873
- return eff.O.some({
1874
- messageId: "noSetStateInComponentDidMount",
1875
- node
1876
- });
1877
1878
  }
1878
1879
  return {
1879
1880
  CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
@@ -1905,22 +1906,19 @@ var no_set_state_in_component_did_update_default = createRule({
1905
1906
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
1906
1907
  function getReportDescriptor(node) {
1907
1908
  if (!core.isThisSetState(node)) return eff.O.none();
1908
- const maybeParentClass = AST11__namespace.traverseUp(
1909
- node,
1910
- AST11__namespace.isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression])
1909
+ return eff.F.pipe(
1910
+ eff.O.Do,
1911
+ eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
1912
+ eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidUpdate)),
1913
+ eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
1914
+ eff.O.filter(
1915
+ ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1916
+ ),
1917
+ eff.O.map(() => ({
1918
+ messageId: "noSetStateInComponentDidUpdate",
1919
+ node
1920
+ }))
1911
1921
  );
1912
- if (eff.O.isNone(maybeParentClass)) return eff.O.none();
1913
- const parentClass = maybeParentClass.value;
1914
- if (!core.isClassComponent(parentClass)) return eff.O.none();
1915
- const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidUpdate);
1916
- if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
1917
- const parentMethod = maybeParentMethod.value;
1918
- if (parentMethod.parent !== parentClass.body) return eff.O.none();
1919
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
1920
- return eff.O.some({
1921
- messageId: "noSetStateInComponentDidUpdate",
1922
- node
1923
- });
1924
1922
  }
1925
1923
  return {
1926
1924
  CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
@@ -1952,22 +1950,19 @@ var no_set_state_in_component_will_update_default = createRule({
1952
1950
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
1953
1951
  function getReportDescriptor(node) {
1954
1952
  if (!core.isThisSetState(node)) return eff.O.none();
1955
- const maybeParentClass = AST11__namespace.traverseUp(
1956
- node,
1957
- AST11__namespace.isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression])
1953
+ return eff.F.pipe(
1954
+ eff.O.Do,
1955
+ eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
1956
+ eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentWillUpdate3)),
1957
+ eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
1958
+ eff.O.filter(
1959
+ ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1960
+ ),
1961
+ eff.O.map(() => ({
1962
+ messageId: "noSetStateInComponentWillUpdate",
1963
+ node
1964
+ }))
1958
1965
  );
1959
- if (eff.O.isNone(maybeParentClass)) return eff.O.none();
1960
- const parentClass = maybeParentClass.value;
1961
- if (!core.isClassComponent(parentClass)) return eff.O.none();
1962
- const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentWillUpdate3);
1963
- if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
1964
- const parentMethod = maybeParentMethod.value;
1965
- if (parentMethod.parent !== parentClass.body) return eff.O.none();
1966
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
1967
- return eff.O.some({
1968
- messageId: "noSetStateInComponentWillUpdate",
1969
- node
1970
- });
1971
1966
  }
1972
1967
  return {
1973
1968
  CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
@@ -2165,39 +2160,40 @@ var no_unstable_context_value_default = createRule({
2165
2160
  name: RULE_NAME40,
2166
2161
  create(context) {
2167
2162
  const { ctx, listeners } = core.useComponentCollector(context);
2168
- const possibleValueConstructions = /* @__PURE__ */ new Map();
2163
+ const constructions = /* @__PURE__ */ new Map();
2169
2164
  return {
2170
2165
  ...listeners,
2171
2166
  JSXOpeningElement(node) {
2172
2167
  const openingElementName = node.name;
2173
2168
  if (openingElementName.type !== types.AST_NODE_TYPES.JSXMemberExpression) return;
2174
2169
  if (openingElementName.property.name !== "Provider") return;
2175
- const maybeJSXValueAttribute = eff.O.fromNullable(
2176
- node.attributes.find((attribute) => {
2177
- return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2178
- })
2170
+ const constructionEntry = eff.F.pipe(
2171
+ eff.O.Do,
2172
+ eff.O.bind("function", ctx.getCurrentFunction),
2173
+ eff.O.bind("attribute", () => eff.O.fromNullable(
2174
+ node.attributes.find((attribute) => {
2175
+ return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2176
+ })
2177
+ )),
2178
+ eff.O.bind("value", ({ attribute }) => "value" in attribute ? eff.O.some(attribute.value) : eff.O.none()),
2179
+ eff.O.bind("valueExpression", ({ value }) => value?.type === types.AST_NODE_TYPES.JSXExpressionContainer ? eff.O.some(value.expression) : eff.O.none()),
2180
+ eff.O.bind("construction", ({ valueExpression }) => {
2181
+ const initialScope = context.sourceCode.getScope(valueExpression);
2182
+ return eff.O.some(VAR__namespace.inspectConstruction(valueExpression, initialScope));
2183
+ }),
2184
+ eff.O.filter(({ construction }) => construction._tag !== "None")
2179
2185
  );
2180
- if (eff.O.isNone(maybeJSXValueAttribute) || !("value" in maybeJSXValueAttribute.value)) return;
2181
- const valueNode = maybeJSXValueAttribute.value.value;
2182
- if (valueNode?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
2183
- const valueExpression = valueNode.expression;
2184
- const initialScope = context.sourceCode.getScope(valueExpression);
2185
- const construction = VAR__namespace.inspectConstruction(valueExpression, initialScope);
2186
- if (construction._tag === "None") return;
2187
- eff.O.map(
2188
- ctx.getCurrentFunction(),
2189
- ([_, currentFn]) => possibleValueConstructions.set(currentFn, [
2190
- ...possibleValueConstructions.get(currentFn) ?? [],
2186
+ for (const { construction, function: [_, fNode] } of eff.O.toArray(constructionEntry)) {
2187
+ constructions.set(fNode, [
2188
+ ...constructions.get(fNode) ?? [],
2191
2189
  construction
2192
- ])
2193
- );
2190
+ ]);
2191
+ }
2194
2192
  },
2195
2193
  "Program:exit"(node) {
2196
2194
  const components = ctx.getAllComponents(node).values();
2197
2195
  for (const { node: component } of components) {
2198
- const constructions = possibleValueConstructions.get(component);
2199
- if (!constructions) continue;
2200
- for (const construction of constructions) {
2196
+ for (const construction of constructions.get(component) ?? []) {
2201
2197
  if (construction._tag === "None") continue;
2202
2198
  const { node: constructionNode, _tag } = construction;
2203
2199
  const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
@@ -2234,7 +2230,7 @@ var no_unstable_default_props_default = createRule({
2234
2230
  name: RULE_NAME41,
2235
2231
  create(context) {
2236
2232
  const { ctx, listeners } = core.useComponentCollector(context);
2237
- const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
2233
+ const declarators = /* @__PURE__ */ new WeakMap();
2238
2234
  return {
2239
2235
  ...listeners,
2240
2236
  "Program:exit"(node) {
@@ -2244,10 +2240,7 @@ var no_unstable_default_props_default = createRule({
2244
2240
  const [props] = params;
2245
2241
  if (!props) continue;
2246
2242
  const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2247
- const variableDeclarators = possibleDestructuringDeclarators.get(component);
2248
- if (!variableDeclarators) return [];
2249
- const declarators = variableDeclarators.filter((d) => d.init.name === name2);
2250
- return declarators.flatMap((d) => d.id.properties);
2243
+ return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2251
2244
  }).otherwise(() => []);
2252
2245
  for (const prop of properties) {
2253
2246
  if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) continue;
@@ -2272,13 +2265,10 @@ var no_unstable_default_props_default = createRule({
2272
2265
  }
2273
2266
  },
2274
2267
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2275
- eff.O.map(
2276
- ctx.getCurrentFunction(),
2277
- ([_, currentFn]) => possibleDestructuringDeclarators.set(currentFn, [
2278
- ...possibleDestructuringDeclarators.get(currentFn) ?? [],
2279
- node
2280
- ])
2281
- );
2268
+ for (const [_, currentFn] of eff.O.toArray(ctx.getCurrentFunction())) {
2269
+ const prevDeclarators = declarators.get(currentFn) ?? [];
2270
+ declarators.set(currentFn, [...prevDeclarators, node]);
2271
+ }
2282
2272
  }
2283
2273
  };
2284
2274
  },
@@ -2406,7 +2396,9 @@ var no_unused_class_component_members_default = createRule({
2406
2396
  if (node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
2407
2397
  for (const prop of node.id.properties) {
2408
2398
  if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
2409
- eff.O.map(getName3(prop.key), (name2) => propertyUsages.get(currentClass)?.add(name2));
2399
+ for (const name2 of eff.O.toArray(getName3(prop.key))) {
2400
+ propertyUsages.get(currentClass)?.add(name2);
2401
+ }
2410
2402
  }
2411
2403
  }
2412
2404
  }
@@ -2873,10 +2865,8 @@ var use_jsx_vars_default = createRule({
2873
2865
  meta: {
2874
2866
  type: "problem",
2875
2867
  docs: {
2876
- description: (
2877
- // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2878
- "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
2879
- ),
2868
+ // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2869
+ description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
2880
2870
  [Symbol.for("rule_features")]: RULE_FEATURES49
2881
2871
  },
2882
2872
  messages: {
@@ -2899,9 +2889,9 @@ var use_jsx_vars_default = createRule({
2899
2889
  return {
2900
2890
  JSXOpeningElement(node) {
2901
2891
  if (node.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
2902
- eff.O.map(getName5(node.name), (name2) => {
2892
+ for (const name2 of eff.O.toArray(getName5(node.name))) {
2903
2893
  context.sourceCode.markVariableAsUsed(name2, node);
2904
- });
2894
+ }
2905
2895
  }
2906
2896
  };
2907
2897
  },
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { F, O, isString, isNullable } from '@eslint-react/eff';
1
+ import { F, O, or, isString, isNullable } from '@eslint-react/eff';
2
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, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, 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-next.8";
18
+ var version = "1.22.2";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -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)) {
@@ -1701,7 +1699,7 @@ var no_nested_components_default = createRule({
1701
1699
  }
1702
1700
  }
1703
1701
  for (const { name: name2, node: component } of classComponents) {
1704
- if (O.isNone(AST11.traverseUp(component, (node2) => isClassComponent11(node2) || isFunctionComponent(node2)))) {
1702
+ if (O.isNone(AST11.traverseUp(component, or(isClassComponent11, isFunctionComponent)))) {
1705
1703
  continue;
1706
1704
  }
1707
1705
  context.report({
@@ -1831,22 +1829,25 @@ var no_set_state_in_component_did_mount_default = createRule({
1831
1829
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
1832
1830
  function getReportDescriptor(node) {
1833
1831
  if (!isThisSetState(node)) return O.none();
1834
- const maybeParentClass = AST11.traverseUp(
1835
- node,
1836
- 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
+ }))
1837
1850
  );
1838
- if (O.isNone(maybeParentClass)) return O.none();
1839
- const parentClass = maybeParentClass.value;
1840
- if (!isClassComponent(parentClass)) return O.none();
1841
- const maybeParentMethod = AST11.traverseUp(node, isComponentDidMount);
1842
- if (O.isNone(maybeParentMethod)) return O.none();
1843
- const parentMethod = maybeParentMethod.value;
1844
- if (parentMethod.parent !== parentClass.body) return O.none();
1845
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1846
- return O.some({
1847
- messageId: "noSetStateInComponentDidMount",
1848
- node
1849
- });
1850
1851
  }
1851
1852
  return {
1852
1853
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -1878,22 +1879,19 @@ var no_set_state_in_component_did_update_default = createRule({
1878
1879
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
1879
1880
  function getReportDescriptor(node) {
1880
1881
  if (!isThisSetState(node)) return O.none();
1881
- const maybeParentClass = AST11.traverseUp(
1882
- node,
1883
- 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
+ }))
1884
1894
  );
1885
- if (O.isNone(maybeParentClass)) return O.none();
1886
- const parentClass = maybeParentClass.value;
1887
- if (!isClassComponent(parentClass)) return O.none();
1888
- const maybeParentMethod = AST11.traverseUp(node, isComponentDidUpdate);
1889
- if (O.isNone(maybeParentMethod)) return O.none();
1890
- const parentMethod = maybeParentMethod.value;
1891
- if (parentMethod.parent !== parentClass.body) return O.none();
1892
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1893
- return O.some({
1894
- messageId: "noSetStateInComponentDidUpdate",
1895
- node
1896
- });
1897
1895
  }
1898
1896
  return {
1899
1897
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -1925,22 +1923,19 @@ var no_set_state_in_component_will_update_default = createRule({
1925
1923
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
1926
1924
  function getReportDescriptor(node) {
1927
1925
  if (!isThisSetState(node)) return O.none();
1928
- const maybeParentClass = AST11.traverseUp(
1929
- node,
1930
- 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
+ }))
1931
1938
  );
1932
- if (O.isNone(maybeParentClass)) return O.none();
1933
- const parentClass = maybeParentClass.value;
1934
- if (!isClassComponent(parentClass)) return O.none();
1935
- const maybeParentMethod = AST11.traverseUp(node, isComponentWillUpdate3);
1936
- if (O.isNone(maybeParentMethod)) return O.none();
1937
- const parentMethod = maybeParentMethod.value;
1938
- if (parentMethod.parent !== parentClass.body) return O.none();
1939
- if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
1940
- return O.some({
1941
- messageId: "noSetStateInComponentWillUpdate",
1942
- node
1943
- });
1944
1939
  }
1945
1940
  return {
1946
1941
  CallExpression: F.flow(getReportDescriptor, O.map(context.report))
@@ -2138,39 +2133,40 @@ var no_unstable_context_value_default = createRule({
2138
2133
  name: RULE_NAME40,
2139
2134
  create(context) {
2140
2135
  const { ctx, listeners } = useComponentCollector(context);
2141
- const possibleValueConstructions = /* @__PURE__ */ new Map();
2136
+ const constructions = /* @__PURE__ */ new Map();
2142
2137
  return {
2143
2138
  ...listeners,
2144
2139
  JSXOpeningElement(node) {
2145
2140
  const openingElementName = node.name;
2146
2141
  if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) return;
2147
2142
  if (openingElementName.property.name !== "Provider") return;
2148
- const maybeJSXValueAttribute = O.fromNullable(
2149
- node.attributes.find((attribute) => {
2150
- return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2151
- })
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")
2152
2158
  );
2153
- if (O.isNone(maybeJSXValueAttribute) || !("value" in maybeJSXValueAttribute.value)) return;
2154
- const valueNode = maybeJSXValueAttribute.value.value;
2155
- if (valueNode?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2156
- const valueExpression = valueNode.expression;
2157
- const initialScope = context.sourceCode.getScope(valueExpression);
2158
- const construction = VAR.inspectConstruction(valueExpression, initialScope);
2159
- if (construction._tag === "None") return;
2160
- O.map(
2161
- ctx.getCurrentFunction(),
2162
- ([_, currentFn]) => possibleValueConstructions.set(currentFn, [
2163
- ...possibleValueConstructions.get(currentFn) ?? [],
2159
+ for (const { construction, function: [_, fNode] } of O.toArray(constructionEntry)) {
2160
+ constructions.set(fNode, [
2161
+ ...constructions.get(fNode) ?? [],
2164
2162
  construction
2165
- ])
2166
- );
2163
+ ]);
2164
+ }
2167
2165
  },
2168
2166
  "Program:exit"(node) {
2169
2167
  const components = ctx.getAllComponents(node).values();
2170
2168
  for (const { node: component } of components) {
2171
- const constructions = possibleValueConstructions.get(component);
2172
- if (!constructions) continue;
2173
- for (const construction of constructions) {
2169
+ for (const construction of constructions.get(component) ?? []) {
2174
2170
  if (construction._tag === "None") continue;
2175
2171
  const { node: constructionNode, _tag } = construction;
2176
2172
  const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
@@ -2207,7 +2203,7 @@ var no_unstable_default_props_default = createRule({
2207
2203
  name: RULE_NAME41,
2208
2204
  create(context) {
2209
2205
  const { ctx, listeners } = useComponentCollector(context);
2210
- const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
2206
+ const declarators = /* @__PURE__ */ new WeakMap();
2211
2207
  return {
2212
2208
  ...listeners,
2213
2209
  "Program:exit"(node) {
@@ -2217,10 +2213,7 @@ var no_unstable_default_props_default = createRule({
2217
2213
  const [props] = params;
2218
2214
  if (!props) continue;
2219
2215
  const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2220
- const variableDeclarators = possibleDestructuringDeclarators.get(component);
2221
- if (!variableDeclarators) return [];
2222
- const declarators = variableDeclarators.filter((d) => d.init.name === name2);
2223
- return declarators.flatMap((d) => d.id.properties);
2216
+ return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2224
2217
  }).otherwise(() => []);
2225
2218
  for (const prop of properties) {
2226
2219
  if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
@@ -2245,13 +2238,10 @@ var no_unstable_default_props_default = createRule({
2245
2238
  }
2246
2239
  },
2247
2240
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2248
- O.map(
2249
- ctx.getCurrentFunction(),
2250
- ([_, currentFn]) => possibleDestructuringDeclarators.set(currentFn, [
2251
- ...possibleDestructuringDeclarators.get(currentFn) ?? [],
2252
- node
2253
- ])
2254
- );
2241
+ for (const [_, currentFn] of O.toArray(ctx.getCurrentFunction())) {
2242
+ const prevDeclarators = declarators.get(currentFn) ?? [];
2243
+ declarators.set(currentFn, [...prevDeclarators, node]);
2244
+ }
2255
2245
  }
2256
2246
  };
2257
2247
  },
@@ -2379,7 +2369,9 @@ var no_unused_class_component_members_default = createRule({
2379
2369
  if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2380
2370
  for (const prop of node.id.properties) {
2381
2371
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2382
- 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
+ }
2383
2375
  }
2384
2376
  }
2385
2377
  }
@@ -2846,10 +2838,8 @@ var use_jsx_vars_default = createRule({
2846
2838
  meta: {
2847
2839
  type: "problem",
2848
2840
  docs: {
2849
- description: (
2850
- // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2851
- "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
2852
- ),
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.",
2853
2843
  [Symbol.for("rule_features")]: RULE_FEATURES49
2854
2844
  },
2855
2845
  messages: {
@@ -2872,9 +2862,9 @@ var use_jsx_vars_default = createRule({
2872
2862
  return {
2873
2863
  JSXOpeningElement(node) {
2874
2864
  if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
2875
- O.map(getName5(node.name), (name2) => {
2865
+ for (const name2 of O.toArray(getName5(node.name))) {
2876
2866
  context.sourceCode.markVariableAsUsed(name2, node);
2877
- });
2867
+ }
2878
2868
  }
2879
2869
  };
2880
2870
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.22.2-next.8",
3
+ "version": "1.22.2",
4
4
  "description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
@@ -49,13 +49,13 @@
49
49
  "string-ts": "^2.2.0",
50
50
  "ts-api-utils": "^2.0.0",
51
51
  "ts-pattern": "^5.6.0",
52
- "@eslint-react/ast": "1.22.2-next.8",
53
- "@eslint-react/core": "1.22.2-next.8",
54
- "@eslint-react/jsx": "1.22.2-next.8",
55
- "@eslint-react/eff": "1.22.2-next.8",
56
- "@eslint-react/shared": "1.22.2-next.8",
57
- "@eslint-react/types": "1.22.2-next.8",
58
- "@eslint-react/var": "1.22.2-next.8"
52
+ "@eslint-react/ast": "1.22.2",
53
+ "@eslint-react/core": "1.22.2",
54
+ "@eslint-react/eff": "1.22.2",
55
+ "@eslint-react/jsx": "1.22.2",
56
+ "@eslint-react/types": "1.22.2",
57
+ "@eslint-react/var": "1.22.2",
58
+ "@eslint-react/shared": "1.22.2"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/react": "^19.0.2",