eslint-plugin-react-x 5.26.0 → 5.26.1

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 +73 -73
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -135,7 +135,7 @@ const rules$6 = {
135
135
  //#endregion
136
136
  //#region package.json
137
137
  var name$6 = "eslint-plugin-react-x";
138
- var version = "5.26.0";
138
+ var version = "5.26.1";
139
139
  //#endregion
140
140
  //#region src/utils/create-rule.ts
141
141
  function getDocsUrl(ruleName) {
@@ -1081,15 +1081,6 @@ const MUTATING_ARRAY_METHODS = /* @__PURE__ */ new Set([
1081
1081
  "splice",
1082
1082
  "unshift"
1083
1083
  ]);
1084
- function resolveToFunction(context, node, seen = /* @__PURE__ */ new Set()) {
1085
- const expression = Extract.unwrap(node);
1086
- if (Check.isFunction(expression)) return expression;
1087
- if (!Check.isIdentifier(expression) || seen.has(expression)) return null;
1088
- seen.add(expression);
1089
- const resolved = resolveOrigin(context, expression);
1090
- if (resolved == null) return null;
1091
- return resolveToFunction(context, resolved, seen);
1092
- }
1093
1084
  //#endregion
1094
1085
  //#region src/rules/globals/collect.ts
1095
1086
  function createFactCollector$6() {
@@ -1179,6 +1170,15 @@ function resolveGlobalOrigin(context, node, seen = /* @__PURE__ */ new Set()) {
1179
1170
  if (initializer.type !== AST_NODE_TYPES.Identifier && initializer.type !== AST_NODE_TYPES.MemberExpression) return null;
1180
1171
  return resolveGlobalOrigin(context, initializer, seen);
1181
1172
  }
1173
+ function resolveToFunction(context, node, seen = /* @__PURE__ */ new Set()) {
1174
+ const expression = Extract.unwrap(node);
1175
+ if (Check.isFunction(expression)) return expression;
1176
+ if (!Check.isIdentifier(expression) || seen.has(expression)) return null;
1177
+ seen.add(expression);
1178
+ const resolved = resolveOrigin(context, expression);
1179
+ if (resolved == null) return null;
1180
+ return resolveToFunction(context, resolved, seen);
1181
+ }
1182
1182
  //#endregion
1183
1183
  //#region src/rules/globals/effects.ts
1184
1184
  function inferGlobalMutations(context, facts) {
@@ -1313,39 +1313,6 @@ function isNodeWithin(node, ancestor) {
1313
1313
  }
1314
1314
  return false;
1315
1315
  }
1316
- function isComponentPropsDefinition(def, components) {
1317
- if (def.type !== DefinitionType.Parameter) return false;
1318
- const fn = def.node;
1319
- if (!Check.isFunction(fn)) return false;
1320
- const firstParam = fn.params.at(0);
1321
- if (firstParam == null || !isNodeWithin(def.name, firstParam)) return false;
1322
- return components.includes(fn);
1323
- }
1324
- function getStateHookName(context, init) {
1325
- const { additionalStateHooks } = getSettingsFromContext(context);
1326
- if (core.isUseStateLikeCall(init, additionalStateHooks)) return Extract.getCalleeName(init) ?? "useState";
1327
- if (core.isUseReducerCall(context, init)) return "useReducer";
1328
- return null;
1329
- }
1330
- function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set()) {
1331
- const expr = Extract.unwrap(node);
1332
- if (Check.isFunction(expr)) return expr;
1333
- if (!Check.isIdentifier(expr) || seen.has(expr)) return null;
1334
- seen.add(expr);
1335
- const resolved = resolveOrigin(context, expr);
1336
- return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
1337
- }
1338
- function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__PURE__ */ new Set()) {
1339
- if (seen.has(variable)) return variable;
1340
- seen.add(variable);
1341
- const def = variable.defs.length === 1 ? variable.defs[0] : null;
1342
- if (def?.type !== DefinitionType.Variable || def.node.init == null) return variable;
1343
- if (mode === "binding" && def.node.id.type === AST_NODE_TYPES.Identifier) return variable;
1344
- const init = Extract.unwrap(def.node.init);
1345
- if (!Check.isIdentifier(init)) return variable;
1346
- const source = findVariable(context.sourceCode.getScope(init), init);
1347
- return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
1348
- }
1349
1316
  function isRefLikeName$1(name) {
1350
1317
  return name === "ref" || name.endsWith("Ref");
1351
1318
  }
@@ -1354,30 +1321,6 @@ function hasRefLikeNameInChain(node) {
1354
1321
  if (!Check.isExpression(expr)) return false;
1355
1322
  return Extract.getMemberChain(expr).some((member) => Check.isIdentifier(member) && isRefLikeName$1(member.name));
1356
1323
  }
1357
- function isInitializedFromCall(context, node, isCall) {
1358
- const root = Extract.getMemberChain(node).at(0);
1359
- if (root == null || !Check.isIdentifier(root)) return false;
1360
- const variable = findVariable(context.sourceCode.getScope(root), root);
1361
- if (variable == null) return false;
1362
- const origin = resolveVariableOrigin(context, variable);
1363
- const def = origin.defs.length === 1 ? origin.defs[0] : null;
1364
- if (def?.type !== DefinitionType.Variable || def.node.init == null) return false;
1365
- const init = Extract.unwrap(def.node.init);
1366
- return init.type === AST_NODE_TYPES.CallExpression && isCall(init);
1367
- }
1368
- function isInitializedFromUseRef(context, node) {
1369
- const { additionalRefHooks } = getSettingsFromContext(context);
1370
- return isInitializedFromCall(context, node, (init) => core.isUseRefLikeCall(init, additionalRefHooks));
1371
- }
1372
- function isKnownNonMutatingMethodCall(context, node) {
1373
- const callee = Extract.unwrap(node.callee);
1374
- return Check.isExpression(callee) && isInitializedFromCall(context, callee, (init) => {
1375
- return [...KNOWN_MUTATING_HOOKS].some((hook) => core.isAPICall(hook)(context, init));
1376
- });
1377
- }
1378
- function isRefLikeChain(context, node) {
1379
- return hasRefLikeNameInChain(node) || isInitializedFromUseRef(context, node);
1380
- }
1381
1324
  //#endregion
1382
1325
  //#region src/rules/immutability/collect.ts
1383
1326
  function createFactCollector$5() {
@@ -1468,6 +1411,57 @@ function createFactCollector$5() {
1468
1411
  }
1469
1412
  //#endregion
1470
1413
  //#region src/rules/immutability/origins.ts
1414
+ function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__PURE__ */ new Set()) {
1415
+ if (seen.has(variable)) return variable;
1416
+ seen.add(variable);
1417
+ const def = variable.defs.length === 1 ? variable.defs[0] : null;
1418
+ if (def?.type !== DefinitionType.Variable || def.node.init == null) return variable;
1419
+ if (mode === "binding" && def.node.id.type === AST_NODE_TYPES.Identifier) return variable;
1420
+ const init = Extract.unwrap(def.node.init);
1421
+ if (!Check.isIdentifier(init)) return variable;
1422
+ const source = findVariable(context.sourceCode.getScope(init), init);
1423
+ return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
1424
+ }
1425
+ function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set()) {
1426
+ const expr = Extract.unwrap(node);
1427
+ if (Check.isFunction(expr)) return expr;
1428
+ if (!Check.isIdentifier(expr) || seen.has(expr)) return null;
1429
+ seen.add(expr);
1430
+ const resolved = resolveOrigin(context, expr);
1431
+ return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
1432
+ }
1433
+ function isComponentPropsDefinition(def, components) {
1434
+ if (def.type !== DefinitionType.Parameter) return false;
1435
+ const fn = def.node;
1436
+ if (!Check.isFunction(fn)) return false;
1437
+ const firstParam = fn.params.at(0);
1438
+ if (firstParam == null || !isNodeWithin(def.name, firstParam)) return false;
1439
+ return components.includes(fn);
1440
+ }
1441
+ function getStateHookName(context, init) {
1442
+ const { additionalStateHooks } = getSettingsFromContext(context);
1443
+ if (core.isUseStateLikeCall(init, additionalStateHooks)) return Extract.getCalleeName(init) ?? "useState";
1444
+ if (core.isUseReducerCall(context, init)) return "useReducer";
1445
+ return null;
1446
+ }
1447
+ function isInitializedFromCall(context, node, isCall) {
1448
+ const root = Extract.getMemberChain(node).at(0);
1449
+ if (root == null || !Check.isIdentifier(root)) return false;
1450
+ const variable = findVariable(context.sourceCode.getScope(root), root);
1451
+ if (variable == null) return false;
1452
+ const origin = resolveVariableOrigin(context, variable);
1453
+ const def = origin.defs.length === 1 ? origin.defs[0] : null;
1454
+ if (def?.type !== DefinitionType.Variable || def.node.init == null) return false;
1455
+ const init = Extract.unwrap(def.node.init);
1456
+ return init.type === AST_NODE_TYPES.CallExpression && isCall(init);
1457
+ }
1458
+ function isInitializedFromUseRef(context, node) {
1459
+ const { additionalRefHooks } = getSettingsFromContext(context);
1460
+ return isInitializedFromCall(context, node, (init) => core.isUseRefLikeCall(init, additionalRefHooks));
1461
+ }
1462
+ function isRefLikeChain(context, node) {
1463
+ return hasRefLikeNameInChain(node) || isInitializedFromUseRef(context, node);
1464
+ }
1471
1465
  function classifyFrozenOrigin(context, variable, components, mode = "alias", seen = /* @__PURE__ */ new Set()) {
1472
1466
  if (seen.has(variable)) return null;
1473
1467
  seen.add(variable);
@@ -1537,6 +1531,12 @@ function isRefMutation(context, mutation) {
1537
1531
  if (Check.isIdentifier(mutation.target)) return isRefLikeName$1(mutation.target.name);
1538
1532
  return isRefLikeChain(context, mutation.target);
1539
1533
  }
1534
+ function isKnownNonMutatingMethodCall(context, node) {
1535
+ const callee = Extract.unwrap(node.callee);
1536
+ return Check.isExpression(callee) && isInitializedFromCall(context, callee, (init) => {
1537
+ return [...KNOWN_MUTATING_HOOKS].some((hook) => core.isAPICall(hook)(context, init));
1538
+ });
1539
+ }
1540
1540
  function inferMutableFunctions(context, mutations) {
1541
1541
  const mutableFunctions = /* @__PURE__ */ new Map();
1542
1542
  for (const mutation of mutations) {
@@ -2177,7 +2177,7 @@ var no_context_provider_default = createRule({
2177
2177
  hasSuggestions: true,
2178
2178
  messages: {
2179
2179
  default: "In React 19, you can render '<Context>' as a provider instead of '<Context.Provider>'.",
2180
- replace: "Replace '<Context.Provider>' with '<Context>'."
2180
+ suggest: "Replace '<Context.Provider>' with '<Context>'."
2181
2181
  },
2182
2182
  schema: []
2183
2183
  },
@@ -2206,7 +2206,7 @@ function create$35(context) {
2206
2206
  if (closingElement == null) return fixer.replaceText(openingElement.name, contextFullName);
2207
2207
  return [fixer.replaceText(openingElement.name, contextFullName), fixer.replaceText(closingElement.name, contextFullName)];
2208
2208
  },
2209
- messageId: "replace"
2209
+ messageId: "suggest"
2210
2210
  }]
2211
2211
  });
2212
2212
  } };
@@ -2354,7 +2354,7 @@ var no_forward_ref_default = createRule({
2354
2354
  hasSuggestions: true,
2355
2355
  messages: {
2356
2356
  default: "In React 19, 'forwardRef' is no longer necessary. Pass 'ref' as a prop instead.",
2357
- replace: "Replace 'forwardRef' with passing 'ref' as a prop."
2357
+ suggest: "Replace 'forwardRef' with passing 'ref' as a prop."
2358
2358
  },
2359
2359
  schema: []
2360
2360
  },
@@ -2370,7 +2370,7 @@ function create$31(context) {
2370
2370
  const id = core.getFunctionId(node);
2371
2371
  const suggest = couldFix(context, node) ? [{
2372
2372
  fix: buildFix(context, node),
2373
- messageId: "replace"
2373
+ messageId: "suggest"
2374
2374
  }] : [];
2375
2375
  context.report({
2376
2376
  messageId: "default",
@@ -3609,7 +3609,7 @@ var no_use_context_default = createRule({
3609
3609
  hasSuggestions: true,
3610
3610
  messages: {
3611
3611
  default: "In React 19, 'use' is preferred over 'useContext' because it is more flexible.",
3612
- replace: "Replace 'useContext' with 'use'."
3612
+ suggest: "Replace 'useContext' with 'use'."
3613
3613
  },
3614
3614
  schema: []
3615
3615
  },
@@ -3633,7 +3633,7 @@ function create$8(context) {
3633
3633
  }
3634
3634
  return null;
3635
3635
  },
3636
- messageId: "replace"
3636
+ messageId: "suggest"
3637
3637
  }]
3638
3638
  });
3639
3639
  } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.26.0",
3
+ "version": "5.26.1",
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",
@@ -36,12 +36,12 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.26.0",
40
- "@eslint-react/core": "5.26.0",
41
- "@eslint-react/eslint": "5.26.0",
42
- "@eslint-react/jsx": "5.26.0",
43
- "@eslint-react/shared": "5.26.0",
44
- "@eslint-react/var": "5.26.0",
39
+ "@eslint-react/ast": "5.26.1",
40
+ "@eslint-react/core": "5.26.1",
41
+ "@eslint-react/eslint": "5.26.1",
42
+ "@eslint-react/jsx": "5.26.1",
43
+ "@eslint-react/shared": "5.26.1",
44
+ "@eslint-react/var": "5.26.1",
45
45
  "@typescript-eslint/scope-manager": "^8.71.1",
46
46
  "@typescript-eslint/types": "^8.71.1",
47
47
  "@typescript-eslint/typescript-estree": "^8.71.1",
@@ -64,7 +64,7 @@
64
64
  "react-dom": "^19.3.0",
65
65
  "tsdown": "^0.23.1",
66
66
  "tsl": "^1.0.30",
67
- "tsl-dx": "^0.14.0",
67
+ "tsl-dx": "^0.14.1",
68
68
  "typescript": "6.0.3"
69
69
  },
70
70
  "peerDependencies": {