eslint-plugin-react-x 5.30.0-rc.2 → 5.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +59 -49
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -130,7 +130,7 @@ const rules$6 = {
130
130
  };
131
131
  // package.json
132
132
  var name$6 = "eslint-plugin-react-x";
133
- var version = "5.30.0-rc.2";
133
+ var version = "5.30.0";
134
134
  // src/utils/create-rule.ts
135
135
  function getDocsUrl(ruleName) {
136
136
  return `https://eslint-react.xyz/docs/rules/${ruleName}`;
@@ -1290,7 +1290,8 @@ const KNOWN_MUTATING_HOOKS = /* @__PURE__ */ new Set([
1290
1290
  "useHistory",
1291
1291
  "useNavigate",
1292
1292
  "useNavigation",
1293
- "useRouter"
1293
+ "useRouter",
1294
+ "useWorld"
1294
1295
  ]);
1295
1296
  function isNodeWithin(node, ancestor) {
1296
1297
  let current = node;
@@ -2362,6 +2363,16 @@ function isKeyValueEqual(a, b) {
2362
2363
  if (aValue == null || bValue == null) return false;
2363
2364
  return Compare.isEqual(aValue, bValue);
2364
2365
  }
2366
+ function isRepeatingStaticKey(key) {
2367
+ const { value } = key;
2368
+ if (value == null) return true;
2369
+ if (value.type === AST_NODE_TYPES.Literal) return true;
2370
+ if (value.type !== AST_NODE_TYPES.JSXExpressionContainer) return false;
2371
+ const expr = Extract.unwrap(value.expression);
2372
+ if (expr.type === AST_NODE_TYPES.Literal) return expr.value != null;
2373
+ if (expr.type === AST_NODE_TYPES.TemplateLiteral) return expr.expressions.length === 0;
2374
+ return false;
2375
+ }
2365
2376
  var no_duplicate_key_default = createRule({
2366
2377
  meta: {
2367
2378
  type: "problem",
@@ -2398,7 +2409,7 @@ function create$32(context) {
2398
2409
  }
2399
2410
  function recordMapCallbackKey(call, key) {
2400
2411
  getGroup(call).keys.push({
2401
- duplicate: key.value?.type === AST_NODE_TYPES.Literal,
2412
+ duplicate: isRepeatingStaticKey(key),
2402
2413
  node: key
2403
2414
  });
2404
2415
  }
@@ -6462,15 +6473,14 @@ function last(array) {
6462
6473
  return array[array.length - 1];
6463
6474
  }
6464
6475
  // src/rules/set-state-in-effect/collect.ts
6465
- function createFactCollector$3(additionalStateHooks, additionalEffectHooks) {
6476
+ function createFactCollector$3(additionalHooks) {
6477
+ const [stateHooks, effectHooks] = additionalHooks;
6466
6478
  const facts = {
6467
6479
  calls: [],
6468
6480
  effectRoots: [],
6469
6481
  jsxRefExprs: []
6470
6482
  };
6471
6483
  const functionEntries = [];
6472
- const isUseStateCall = (node) => node.type === AST_NODE_TYPES.CallExpression && core.isUseStateLikeCall(node, additionalStateHooks);
6473
- const isUseEffectCall = (node) => node.type === AST_NODE_TYPES.CallExpression && core.isUseEffectLikeCall(node, additionalEffectHooks);
6474
6484
  return {
6475
6485
  facts,
6476
6486
  visitor: {
@@ -6486,8 +6496,8 @@ function createFactCollector$3(additionalStateHooks, additionalEffectHooks) {
6486
6496
  facts.jsxRefExprs.push(node.value.expression);
6487
6497
  },
6488
6498
  CallExpression(node) {
6489
- if (isUseStateCall(node)) return;
6490
- if (isUseEffectCall(node)) {
6499
+ if (core.isUseStateLikeCall(node, stateHooks)) return;
6500
+ if (core.isUseEffectLikeCall(node, effectHooks)) {
6491
6501
  const setup = node.arguments.at(0);
6492
6502
  if (setup != null) facts.effectRoots.push({
6493
6503
  node,
@@ -6893,7 +6903,7 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
6893
6903
  };
6894
6904
  }
6895
6905
  // src/rules/set-state-in-effect/effects.ts
6896
- function inferViolations$2(context, facts) {
6906
+ function inferViolations$3(context, facts) {
6897
6907
  if (facts.effectRoots.length === 0) return [];
6898
6908
  const resolver = createSetStateResolver$1(context, facts);
6899
6909
  const callsByFunction = /* @__PURE__ */ new Map();
@@ -6970,41 +6980,17 @@ var set_state_in_effect_default = createRule({
6970
6980
  function create$5(context) {
6971
6981
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
6972
6982
  const { additionalEffectHooks, additionalStateHooks } = getSettingsFromContext(context);
6973
- const { facts, visitor } = createFactCollector$3(additionalStateHooks, additionalEffectHooks);
6983
+ const { facts, visitor } = createFactCollector$3([additionalStateHooks, additionalEffectHooks]);
6974
6984
  return merge(visitor, { "Program:exit"() {
6975
- for (const violation of inferViolations$2(context, facts)) context.report({
6985
+ for (const violation of inferViolations$3(context, facts)) context.report({
6976
6986
  data: { name: violation.name },
6977
6987
  messageId: "default",
6978
6988
  node: violation.node
6979
6989
  });
6980
6990
  } });
6981
6991
  }
6982
- // src/rules/set-state-in-render/helpers.ts
6983
- const isComponentOrHookName = or(core.isFunctionComponentName, core.isHookName);
6984
- function isComponentOrHookLikeFunction(context, node) {
6985
- const id = core.getFunctionId(node);
6986
- if (id == null) return core.isFunctionComponentWrapperCallback(context, node);
6987
- if (Check.isIdentifier(id)) return isComponentOrHookName(id.name);
6988
- if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isComponentOrHookName(id.property.name);
6989
- return false;
6990
- }
6991
- function isInsideConditional(node, stopAt) {
6992
- let current = node.parent;
6993
- while (current != null && current !== stopAt) {
6994
- switch (current.type) {
6995
- case AST_NODE_TYPES.IfStatement:
6996
- case AST_NODE_TYPES.ConditionalExpression:
6997
- case AST_NODE_TYPES.LogicalExpression:
6998
- case AST_NODE_TYPES.SwitchStatement:
6999
- case AST_NODE_TYPES.SwitchCase: return true;
7000
- }
7001
- current = current.parent;
7002
- }
7003
- return false;
7004
- }
7005
6992
  // src/rules/set-state-in-render/collect.ts
7006
- function createFactCollector$2(context) {
7007
- const { additionalStateHooks } = getSettingsFromContext(context);
6993
+ function createFactCollector$2(additionalStateHooks, isComponentOrHookLike) {
7008
6994
  const facts = {
7009
6995
  calls: [],
7010
6996
  earlyReturns: []
@@ -7015,7 +7001,7 @@ function createFactCollector$2(context) {
7015
7001
  return node.type === AST_NODE_TYPES.CallExpression && core.isUseStateLikeCall(node, additionalStateHooks);
7016
7002
  }
7017
7003
  function getFunctionKind(node) {
7018
- if (isComponentOrHookLikeFunction(context, node)) return "component";
7004
+ if (isComponentOrHookLike(node)) return "component";
7019
7005
  const parent = Traverse.findParent(node, not(Check.isTypeExpression)) ?? node.parent;
7020
7006
  if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
7021
7007
  return "other";
@@ -7068,6 +7054,29 @@ function createFactCollector$2(context) {
7068
7054
  }
7069
7055
  };
7070
7056
  }
7057
+ // src/rules/set-state-in-render/helpers.ts
7058
+ const isComponentOrHookName = or(core.isFunctionComponentName, core.isHookName);
7059
+ function isComponentOrHookLikeFunction(context, node) {
7060
+ const id = core.getFunctionId(node);
7061
+ if (id == null) return core.isFunctionComponentWrapperCallback(context, node);
7062
+ if (Check.isIdentifier(id)) return isComponentOrHookName(id.name);
7063
+ if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isComponentOrHookName(id.property.name);
7064
+ return false;
7065
+ }
7066
+ function isInsideConditional(node, stopAt) {
7067
+ let current = node.parent;
7068
+ while (current != null && current !== stopAt) {
7069
+ switch (current.type) {
7070
+ case AST_NODE_TYPES.IfStatement:
7071
+ case AST_NODE_TYPES.ConditionalExpression:
7072
+ case AST_NODE_TYPES.LogicalExpression:
7073
+ case AST_NODE_TYPES.SwitchStatement:
7074
+ case AST_NODE_TYPES.SwitchCase: return true;
7075
+ }
7076
+ current = current.parent;
7077
+ }
7078
+ return false;
7079
+ }
7071
7080
  // src/rules/set-state-in-render/origins.ts
7072
7081
  function createSetStateResolver(context) {
7073
7082
  const { additionalStateHooks } = getSettingsFromContext(context);
@@ -7092,7 +7101,7 @@ function createSetStateResolver(context) {
7092
7101
  };
7093
7102
  }
7094
7103
  // src/rules/set-state-in-render/effects.ts
7095
- function inferViolations$1(context, facts) {
7104
+ function inferViolations$2(context, facts) {
7096
7105
  const resolver = createSetStateResolver(context);
7097
7106
  const earlyReturnPositions = /* @__PURE__ */ new Map();
7098
7107
  for (const { componentFunction, node } of facts.earlyReturns) getOrInsertComputed(earlyReturnPositions, componentFunction, () => []).push(node.range[0]);
@@ -7121,9 +7130,10 @@ var set_state_in_render_default = createRule({
7121
7130
  create: create$4
7122
7131
  });
7123
7132
  function create$4(context) {
7124
- const { facts, visitor } = createFactCollector$2(context);
7133
+ const { additionalStateHooks } = getSettingsFromContext(context);
7134
+ const { facts, visitor } = createFactCollector$2(additionalStateHooks, (node) => isComponentOrHookLikeFunction(context, node));
7125
7135
  return merge(visitor, { "Program:exit"() {
7126
- for (const violation of inferViolations$1(context, facts)) context.report({
7136
+ for (const violation of inferViolations$2(context, facts)) context.report({
7127
7137
  data: { name: violation.name },
7128
7138
  messageId: "default",
7129
7139
  node: violation.node
@@ -7343,21 +7353,21 @@ function resolveDynamicMemberOrigin(context, variable, path, isInsideRender, see
7343
7353
  };
7344
7354
  }
7345
7355
  // src/rules/static-components/effects.ts
7346
- function inferCreatedComponents(context, componentUsages, isInsideRender) {
7347
- const effects = [];
7356
+ function inferViolations$1(context, componentUsages, isInsideRender) {
7357
+ const violations = [];
7348
7358
  for (const usage of componentUsages) {
7349
7359
  const variable = findVariable(context.sourceCode.getScope(usage.node), usage.name);
7350
7360
  if (variable == null) continue;
7351
7361
  if (!variable.defs.some((def) => isInsideRender(def.node))) continue;
7352
7362
  const { creationNode, isDynamic } = usage.path.length === 0 ? resolveDynamicComponentOrigin(context, variable, isInsideRender) : resolveDynamicMemberOrigin(context, variable, usage.path, isInsideRender);
7353
7363
  if (!isDynamic) continue;
7354
- effects.push({
7364
+ violations.push({
7355
7365
  name: usage.name,
7356
7366
  creationNode,
7357
7367
  node: usage.node
7358
7368
  });
7359
7369
  }
7360
- return effects;
7370
+ return violations;
7361
7371
  }
7362
7372
  var static_components_default = createRule({
7363
7373
  meta: {
@@ -7380,16 +7390,16 @@ function create$3(context) {
7380
7390
  return merge(fc.visitor, cc.visitor, visitor, { "Program:exit"(program) {
7381
7391
  const isInsideRender = createRenderBoundaryChecker([...fc.api.getAllComponents(program), ...cc.api.getAllComponents(program)].map((component) => component.node));
7382
7392
  const reportedCreations = /* @__PURE__ */ new Set();
7383
- for (const effect of inferCreatedComponents(context, facts.componentUsages, isInsideRender)) {
7393
+ for (const violation of inferViolations$1(context, facts.componentUsages, isInsideRender)) {
7384
7394
  context.report({
7385
7395
  messageId: "default",
7386
- node: effect.node
7396
+ node: violation.node
7387
7397
  });
7388
- if (reportedCreations.has(effect.creationNode)) continue;
7389
- reportedCreations.add(effect.creationNode);
7398
+ if (reportedCreations.has(violation.creationNode)) continue;
7399
+ reportedCreations.add(violation.creationNode);
7390
7400
  context.report({
7391
7401
  messageId: "created-here",
7392
- node: effect.creationNode
7402
+ node: violation.creationNode
7393
7403
  });
7394
7404
  }
7395
7405
  } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.30.0-rc.2",
3
+ "version": "5.30.0",
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.30.0-rc.2",
40
- "@eslint-react/core": "5.30.0-rc.2",
41
- "@eslint-react/eslint": "5.30.0-rc.2",
42
- "@eslint-react/jsx": "5.30.0-rc.2",
43
- "@eslint-react/shared": "5.30.0-rc.2",
44
- "@eslint-react/var": "5.30.0-rc.2",
39
+ "@eslint-react/ast": "5.30.0",
40
+ "@eslint-react/core": "5.30.0",
41
+ "@eslint-react/eslint": "5.30.0",
42
+ "@eslint-react/jsx": "5.30.0",
43
+ "@eslint-react/shared": "5.30.0",
44
+ "@eslint-react/var": "5.30.0",
45
45
  "@typescript-eslint/scope-manager": "^8.72.1",
46
46
  "@typescript-eslint/types": "^8.72.1",
47
47
  "@typescript-eslint/utils": "^8.72.1",