eslint-plugin-react-x 1.22.2-beta.9 → 1.22.2-next.10

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-beta.9";
45
+ var version = "1.22.2-next.10";
46
46
  var createRule = shared.createRuleForPlugin("x");
47
47
 
48
48
  // src/rules/avoid-shorthand-boolean.ts
@@ -1862,9 +1862,15 @@ var no_set_state_in_component_did_mount_default = createRule({
1862
1862
  eff.O.Do,
1863
1863
  eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
1864
1864
  eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidMount)),
1865
+ eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
1865
1866
  eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
1866
1867
  eff.O.filter(
1867
- ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1868
+ ({
1869
+ clazz,
1870
+ method,
1871
+ methodScope,
1872
+ upperScope
1873
+ }) => method.parent === clazz.body && upperScope === methodScope
1868
1874
  ),
1869
1875
  eff.O.map(() => ({
1870
1876
  messageId: "noSetStateInComponentDidMount",
@@ -2156,39 +2162,40 @@ var no_unstable_context_value_default = createRule({
2156
2162
  name: RULE_NAME40,
2157
2163
  create(context) {
2158
2164
  const { ctx, listeners } = core.useComponentCollector(context);
2159
- const possibleValueConstructions = /* @__PURE__ */ new Map();
2165
+ const constructions = /* @__PURE__ */ new Map();
2160
2166
  return {
2161
2167
  ...listeners,
2162
2168
  JSXOpeningElement(node) {
2163
2169
  const openingElementName = node.name;
2164
2170
  if (openingElementName.type !== types.AST_NODE_TYPES.JSXMemberExpression) return;
2165
2171
  if (openingElementName.property.name !== "Provider") return;
2166
- const maybeJSXValueAttribute = eff.O.fromNullable(
2167
- node.attributes.find((attribute) => {
2168
- return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2169
- })
2172
+ const constructionEntry = eff.F.pipe(
2173
+ eff.O.Do,
2174
+ eff.O.bind("function", ctx.getCurrentFunction),
2175
+ eff.O.bind("attribute", () => eff.O.fromNullable(
2176
+ node.attributes.find((attribute) => {
2177
+ return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2178
+ })
2179
+ )),
2180
+ eff.O.bind("value", ({ attribute }) => "value" in attribute ? eff.O.some(attribute.value) : eff.O.none()),
2181
+ eff.O.bind("valueExpression", ({ value }) => value?.type === types.AST_NODE_TYPES.JSXExpressionContainer ? eff.O.some(value.expression) : eff.O.none()),
2182
+ eff.O.bind("construction", ({ valueExpression }) => {
2183
+ const initialScope = context.sourceCode.getScope(valueExpression);
2184
+ return eff.O.some(VAR__namespace.inspectConstruction(valueExpression, initialScope));
2185
+ }),
2186
+ eff.O.filter(({ construction }) => construction._tag !== "None")
2170
2187
  );
2171
- if (eff.O.isNone(maybeJSXValueAttribute) || !("value" in maybeJSXValueAttribute.value)) return;
2172
- const valueNode = maybeJSXValueAttribute.value.value;
2173
- if (valueNode?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
2174
- const valueExpression = valueNode.expression;
2175
- const initialScope = context.sourceCode.getScope(valueExpression);
2176
- const construction = VAR__namespace.inspectConstruction(valueExpression, initialScope);
2177
- if (construction._tag === "None") return;
2178
- eff.O.map(
2179
- ctx.getCurrentFunction(),
2180
- ([_, currentFn]) => possibleValueConstructions.set(currentFn, [
2181
- ...possibleValueConstructions.get(currentFn) ?? [],
2188
+ for (const { construction, function: [_, fNode] } of eff.O.toArray(constructionEntry)) {
2189
+ constructions.set(fNode, [
2190
+ ...constructions.get(fNode) ?? [],
2182
2191
  construction
2183
- ])
2184
- );
2192
+ ]);
2193
+ }
2185
2194
  },
2186
2195
  "Program:exit"(node) {
2187
2196
  const components = ctx.getAllComponents(node).values();
2188
2197
  for (const { node: component } of components) {
2189
- const constructions = possibleValueConstructions.get(component);
2190
- if (!constructions) continue;
2191
- for (const construction of constructions) {
2198
+ for (const construction of constructions.get(component) ?? []) {
2192
2199
  if (construction._tag === "None") continue;
2193
2200
  const { node: constructionNode, _tag } = construction;
2194
2201
  const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
@@ -2225,7 +2232,7 @@ var no_unstable_default_props_default = createRule({
2225
2232
  name: RULE_NAME41,
2226
2233
  create(context) {
2227
2234
  const { ctx, listeners } = core.useComponentCollector(context);
2228
- const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
2235
+ const declarators = /* @__PURE__ */ new WeakMap();
2229
2236
  return {
2230
2237
  ...listeners,
2231
2238
  "Program:exit"(node) {
@@ -2235,10 +2242,7 @@ var no_unstable_default_props_default = createRule({
2235
2242
  const [props] = params;
2236
2243
  if (!props) continue;
2237
2244
  const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2238
- const variableDeclarators = possibleDestructuringDeclarators.get(component);
2239
- if (!variableDeclarators) return [];
2240
- const declarators = variableDeclarators.filter((d) => d.init.name === name2);
2241
- return declarators.flatMap((d) => d.id.properties);
2245
+ return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2242
2246
  }).otherwise(() => []);
2243
2247
  for (const prop of properties) {
2244
2248
  if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) continue;
@@ -2263,13 +2267,10 @@ var no_unstable_default_props_default = createRule({
2263
2267
  }
2264
2268
  },
2265
2269
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2266
- eff.O.map(
2267
- ctx.getCurrentFunction(),
2268
- ([_, currentFn]) => possibleDestructuringDeclarators.set(currentFn, [
2269
- ...possibleDestructuringDeclarators.get(currentFn) ?? [],
2270
- node
2271
- ])
2272
- );
2270
+ for (const [_, currentFn] of eff.O.toArray(ctx.getCurrentFunction())) {
2271
+ const prevDeclarators = declarators.get(currentFn) ?? [];
2272
+ declarators.set(currentFn, [...prevDeclarators, node]);
2273
+ }
2273
2274
  }
2274
2275
  };
2275
2276
  },
@@ -2397,7 +2398,9 @@ var no_unused_class_component_members_default = createRule({
2397
2398
  if (node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
2398
2399
  for (const prop of node.id.properties) {
2399
2400
  if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
2400
- eff.O.map(getName3(prop.key), (name2) => propertyUsages.get(currentClass)?.add(name2));
2401
+ for (const name2 of eff.O.toArray(getName3(prop.key))) {
2402
+ propertyUsages.get(currentClass)?.add(name2);
2403
+ }
2401
2404
  }
2402
2405
  }
2403
2406
  }
@@ -2864,10 +2867,8 @@ var use_jsx_vars_default = createRule({
2864
2867
  meta: {
2865
2868
  type: "problem",
2866
2869
  docs: {
2867
- description: (
2868
- // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2869
- "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
2870
- ),
2870
+ // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2871
+ description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
2871
2872
  [Symbol.for("rule_features")]: RULE_FEATURES49
2872
2873
  },
2873
2874
  messages: {
@@ -2890,9 +2891,9 @@ var use_jsx_vars_default = createRule({
2890
2891
  return {
2891
2892
  JSXOpeningElement(node) {
2892
2893
  if (node.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
2893
- eff.O.map(getName5(node.name), (name2) => {
2894
+ for (const name2 of eff.O.toArray(getName5(node.name))) {
2894
2895
  context.sourceCode.markVariableAsUsed(name2, node);
2895
- });
2896
+ }
2896
2897
  }
2897
2898
  };
2898
2899
  },
package/dist/index.mjs CHANGED
@@ -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.9";
18
+ var version = "1.22.2-next.10";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -1835,9 +1835,15 @@ var no_set_state_in_component_did_mount_default = createRule({
1835
1835
  O.Do,
1836
1836
  O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
1837
1837
  O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentDidMount)),
1838
+ O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
1838
1839
  O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
1839
1840
  O.filter(
1840
- ({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
1841
+ ({
1842
+ clazz,
1843
+ method,
1844
+ methodScope,
1845
+ upperScope
1846
+ }) => method.parent === clazz.body && upperScope === methodScope
1841
1847
  ),
1842
1848
  O.map(() => ({
1843
1849
  messageId: "noSetStateInComponentDidMount",
@@ -2129,39 +2135,40 @@ var no_unstable_context_value_default = createRule({
2129
2135
  name: RULE_NAME40,
2130
2136
  create(context) {
2131
2137
  const { ctx, listeners } = useComponentCollector(context);
2132
- const possibleValueConstructions = /* @__PURE__ */ new Map();
2138
+ const constructions = /* @__PURE__ */ new Map();
2133
2139
  return {
2134
2140
  ...listeners,
2135
2141
  JSXOpeningElement(node) {
2136
2142
  const openingElementName = node.name;
2137
2143
  if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) return;
2138
2144
  if (openingElementName.property.name !== "Provider") return;
2139
- const maybeJSXValueAttribute = O.fromNullable(
2140
- node.attributes.find((attribute) => {
2141
- return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2142
- })
2145
+ const constructionEntry = F.pipe(
2146
+ O.Do,
2147
+ O.bind("function", ctx.getCurrentFunction),
2148
+ O.bind("attribute", () => O.fromNullable(
2149
+ node.attributes.find((attribute) => {
2150
+ return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2151
+ })
2152
+ )),
2153
+ O.bind("value", ({ attribute }) => "value" in attribute ? O.some(attribute.value) : O.none()),
2154
+ O.bind("valueExpression", ({ value }) => value?.type === AST_NODE_TYPES.JSXExpressionContainer ? O.some(value.expression) : O.none()),
2155
+ O.bind("construction", ({ valueExpression }) => {
2156
+ const initialScope = context.sourceCode.getScope(valueExpression);
2157
+ return O.some(VAR.inspectConstruction(valueExpression, initialScope));
2158
+ }),
2159
+ O.filter(({ construction }) => construction._tag !== "None")
2143
2160
  );
2144
- if (O.isNone(maybeJSXValueAttribute) || !("value" in maybeJSXValueAttribute.value)) return;
2145
- const valueNode = maybeJSXValueAttribute.value.value;
2146
- if (valueNode?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2147
- const valueExpression = valueNode.expression;
2148
- const initialScope = context.sourceCode.getScope(valueExpression);
2149
- const construction = VAR.inspectConstruction(valueExpression, initialScope);
2150
- if (construction._tag === "None") return;
2151
- O.map(
2152
- ctx.getCurrentFunction(),
2153
- ([_, currentFn]) => possibleValueConstructions.set(currentFn, [
2154
- ...possibleValueConstructions.get(currentFn) ?? [],
2161
+ for (const { construction, function: [_, fNode] } of O.toArray(constructionEntry)) {
2162
+ constructions.set(fNode, [
2163
+ ...constructions.get(fNode) ?? [],
2155
2164
  construction
2156
- ])
2157
- );
2165
+ ]);
2166
+ }
2158
2167
  },
2159
2168
  "Program:exit"(node) {
2160
2169
  const components = ctx.getAllComponents(node).values();
2161
2170
  for (const { node: component } of components) {
2162
- const constructions = possibleValueConstructions.get(component);
2163
- if (!constructions) continue;
2164
- for (const construction of constructions) {
2171
+ for (const construction of constructions.get(component) ?? []) {
2165
2172
  if (construction._tag === "None") continue;
2166
2173
  const { node: constructionNode, _tag } = construction;
2167
2174
  const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
@@ -2198,7 +2205,7 @@ var no_unstable_default_props_default = createRule({
2198
2205
  name: RULE_NAME41,
2199
2206
  create(context) {
2200
2207
  const { ctx, listeners } = useComponentCollector(context);
2201
- const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
2208
+ const declarators = /* @__PURE__ */ new WeakMap();
2202
2209
  return {
2203
2210
  ...listeners,
2204
2211
  "Program:exit"(node) {
@@ -2208,10 +2215,7 @@ var no_unstable_default_props_default = createRule({
2208
2215
  const [props] = params;
2209
2216
  if (!props) continue;
2210
2217
  const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2211
- const variableDeclarators = possibleDestructuringDeclarators.get(component);
2212
- if (!variableDeclarators) return [];
2213
- const declarators = variableDeclarators.filter((d) => d.init.name === name2);
2214
- return declarators.flatMap((d) => d.id.properties);
2218
+ return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2215
2219
  }).otherwise(() => []);
2216
2220
  for (const prop of properties) {
2217
2221
  if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
@@ -2236,13 +2240,10 @@ var no_unstable_default_props_default = createRule({
2236
2240
  }
2237
2241
  },
2238
2242
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2239
- O.map(
2240
- ctx.getCurrentFunction(),
2241
- ([_, currentFn]) => possibleDestructuringDeclarators.set(currentFn, [
2242
- ...possibleDestructuringDeclarators.get(currentFn) ?? [],
2243
- node
2244
- ])
2245
- );
2243
+ for (const [_, currentFn] of O.toArray(ctx.getCurrentFunction())) {
2244
+ const prevDeclarators = declarators.get(currentFn) ?? [];
2245
+ declarators.set(currentFn, [...prevDeclarators, node]);
2246
+ }
2246
2247
  }
2247
2248
  };
2248
2249
  },
@@ -2370,7 +2371,9 @@ var no_unused_class_component_members_default = createRule({
2370
2371
  if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2371
2372
  for (const prop of node.id.properties) {
2372
2373
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2373
- O.map(getName3(prop.key), (name2) => propertyUsages.get(currentClass)?.add(name2));
2374
+ for (const name2 of O.toArray(getName3(prop.key))) {
2375
+ propertyUsages.get(currentClass)?.add(name2);
2376
+ }
2374
2377
  }
2375
2378
  }
2376
2379
  }
@@ -2837,10 +2840,8 @@ var use_jsx_vars_default = createRule({
2837
2840
  meta: {
2838
2841
  type: "problem",
2839
2842
  docs: {
2840
- description: (
2841
- // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2842
- "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
2843
- ),
2843
+ // eslint-disable-next-line eslint-plugin/require-meta-docs-description
2844
+ description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
2844
2845
  [Symbol.for("rule_features")]: RULE_FEATURES49
2845
2846
  },
2846
2847
  messages: {
@@ -2863,9 +2864,9 @@ var use_jsx_vars_default = createRule({
2863
2864
  return {
2864
2865
  JSXOpeningElement(node) {
2865
2866
  if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
2866
- O.map(getName5(node.name), (name2) => {
2867
+ for (const name2 of O.toArray(getName5(node.name))) {
2867
2868
  context.sourceCode.markVariableAsUsed(name2, node);
2868
- });
2869
+ }
2869
2870
  }
2870
2871
  };
2871
2872
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.22.2-beta.9",
3
+ "version": "1.22.2-next.10",
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-beta.9",
53
- "@eslint-react/core": "1.22.2-beta.9",
54
- "@eslint-react/eff": "1.22.2-beta.9",
55
- "@eslint-react/jsx": "1.22.2-beta.9",
56
- "@eslint-react/types": "1.22.2-beta.9",
57
- "@eslint-react/shared": "1.22.2-beta.9",
58
- "@eslint-react/var": "1.22.2-beta.9"
52
+ "@eslint-react/ast": "1.22.2-next.10",
53
+ "@eslint-react/core": "1.22.2-next.10",
54
+ "@eslint-react/eff": "1.22.2-next.10",
55
+ "@eslint-react/jsx": "1.22.2-next.10",
56
+ "@eslint-react/shared": "1.22.2-next.10",
57
+ "@eslint-react/types": "1.22.2-next.10",
58
+ "@eslint-react/var": "1.22.2-next.10"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/react": "^19.0.2",