eslint-plugin-react-x 5.24.6 → 5.24.8

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 +22 -21
  2. package/package.json +11 -11
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.24.6";
138
+ var version = "5.24.8";
139
139
  //#endregion
140
140
  //#region src/utils/create-rule.ts
141
141
  function getDocsUrl(ruleName) {
@@ -1335,15 +1335,16 @@ function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set())
1335
1335
  const resolved = resolveOrigin(context, expr);
1336
1336
  return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
1337
1337
  }
1338
- function resolveVariableOrigin(context, variable, seen = /* @__PURE__ */ new Set()) {
1338
+ function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__PURE__ */ new Set()) {
1339
1339
  if (seen.has(variable)) return variable;
1340
1340
  seen.add(variable);
1341
1341
  const def = variable.defs.length === 1 ? variable.defs[0] : null;
1342
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;
1343
1344
  const init = Extract.unwrap(def.node.init);
1344
1345
  if (!Check.isIdentifier(init)) return variable;
1345
1346
  const source = findVariable(context.sourceCode.getScope(init), init);
1346
- return source == null ? variable : resolveVariableOrigin(context, source, seen);
1347
+ return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
1347
1348
  }
1348
1349
  function isRefLikeName$1(name) {
1349
1350
  return name === "ref" || name.endsWith("Ref");
@@ -1467,10 +1468,10 @@ function createFactCollector$5() {
1467
1468
  }
1468
1469
  //#endregion
1469
1470
  //#region src/rules/immutability/origins.ts
1470
- function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__ */ new Set()) {
1471
+ function classifyFrozenOrigin(context, variable, components, mode = "alias", seen = /* @__PURE__ */ new Set()) {
1471
1472
  if (seen.has(variable)) return null;
1472
1473
  seen.add(variable);
1473
- const origin = resolveVariableOrigin(context, variable);
1474
+ const origin = resolveVariableOrigin(context, variable, mode);
1474
1475
  const def = origin.defs.length === 1 ? origin.defs[0] : null;
1475
1476
  if (def == null) return null;
1476
1477
  if (isComponentPropsDefinition(def, components)) return {
@@ -1485,7 +1486,7 @@ function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__
1485
1486
  if (root == null || !Check.isIdentifier(root)) return null;
1486
1487
  const source = findVariable(context.sourceCode.getScope(root), root);
1487
1488
  if (source == null) return null;
1488
- const inner = classifyFrozenOrigin(context, source, components, seen);
1489
+ const inner = classifyFrozenOrigin(context, source, components, mode, seen);
1489
1490
  return inner == null ? null : {
1490
1491
  kind: "iterator",
1491
1492
  name: origin.name,
@@ -1515,7 +1516,7 @@ function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__
1515
1516
  if (!Check.isIdentifier(argument)) continue;
1516
1517
  const source = findVariable(context.sourceCode.getScope(argument), argument);
1517
1518
  if (source == null) continue;
1518
- const inner = classifyFrozenOrigin(context, source, components, seen);
1519
+ const inner = classifyFrozenOrigin(context, source, components, mode, seen);
1519
1520
  if (inner != null) return {
1520
1521
  kind: "shallow-copy",
1521
1522
  name: origin.name,
@@ -1570,7 +1571,7 @@ function inferDirectMutations(context, mutations, components) {
1570
1571
  if (isRefMutation(context, mutation)) continue;
1571
1572
  const variable = findVariable(context.sourceCode.getScope(mutation.root), mutation.root);
1572
1573
  if (variable == null) continue;
1573
- const origin = classifyFrozenOrigin(context, variable, components);
1574
+ const origin = classifyFrozenOrigin(context, variable, components, mutation.kind === "binding" ? "binding" : "alias");
1574
1575
  if (origin == null) continue;
1575
1576
  if (mutation.kind === "binding") {
1576
1577
  switch (origin.kind) {
@@ -4875,7 +4876,7 @@ var ForkContext = class ForkContext {
4875
4876
  makeNext(begin, end) {
4876
4877
  return makeSegments(this, begin, end, CodePathSegment.newNext);
4877
4878
  }
4878
- makeUnreachable(begin, end) {
4879
+ makeUnreachable(begin = NaN, end = NaN) {
4879
4880
  return makeSegments(this, begin, end, CodePathSegment.newUnreachable);
4880
4881
  }
4881
4882
  makeDisconnected(begin, end) {
@@ -5253,7 +5254,7 @@ var CodePathState = class {
5253
5254
  if (returned && !returned.empty) getReturnContext(this).returnedForkContext.add(leavingSegments);
5254
5255
  if (!thrown.empty) getThrowContext(this).thrownForkContext.add(leavingSegments);
5255
5256
  this.forkContext.replaceHead(normalSegments);
5256
- if (!context.lastOfTryIsReachable && !context.lastOfCatchIsReachable) this.forkContext.makeUnreachable(-1, -1);
5257
+ if (!context.lastOfTryIsReachable && !context.lastOfCatchIsReachable) this.forkContext.makeUnreachable();
5257
5258
  }
5258
5259
  makeCatchBlock() {
5259
5260
  const context = this.tryContext;
@@ -6765,9 +6766,9 @@ function create$5(context) {
6765
6766
  //#endregion
6766
6767
  //#region src/rules/set-state-in-render/helpers.ts
6767
6768
  const isComponentOrHookName = or(core.isFunctionComponentName, core.isHookName);
6768
- function isComponentOrHookLikeFunction(node) {
6769
+ function isComponentOrHookLikeFunction(context, node) {
6769
6770
  const id = core.getFunctionId(node);
6770
- if (id == null) return false;
6771
+ if (id == null) return core.isFunctionComponentWrapperCallback(context, node);
6771
6772
  if (Check.isIdentifier(id)) return isComponentOrHookName(id.name);
6772
6773
  if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isComponentOrHookName(id.property.name);
6773
6774
  return false;
@@ -6788,18 +6789,19 @@ function isInsideConditional(node, stopAt) {
6788
6789
  }
6789
6790
  //#endregion
6790
6791
  //#region src/rules/set-state-in-render/collect.ts
6791
- function createFactCollector$2(additionalStateHooks) {
6792
+ function createFactCollector$2(context) {
6793
+ const { additionalStateHooks } = getSettingsFromContext(context);
6792
6794
  const facts = {
6793
6795
  calls: [],
6794
6796
  earlyReturns: []
6795
6797
  };
6796
6798
  const functionEntries = [];
6797
- const componentFnRef = { current: null };
6799
+ const componentFnStack = [];
6798
6800
  function isUseStateCall(node) {
6799
6801
  return core.isUseStateLikeCall(node, additionalStateHooks);
6800
6802
  }
6801
6803
  function getFunctionKind(node) {
6802
- if (isComponentOrHookLikeFunction(node)) return "component";
6804
+ if (isComponentOrHookLikeFunction(context, node)) return "component";
6803
6805
  const parent = Traverse.findParent(node, not(Check.isTypeExpression)) ?? node.parent;
6804
6806
  if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
6805
6807
  return "other";
@@ -6813,10 +6815,10 @@ function createFactCollector$2(additionalStateHooks) {
6813
6815
  kind,
6814
6816
  node
6815
6817
  });
6816
- if (kind === "component") componentFnRef.current = node;
6818
+ if (kind === "component") componentFnStack.push(node);
6817
6819
  },
6818
6820
  ":function:exit"(node) {
6819
- if (functionEntries.at(-1)?.kind === "component" && componentFnRef.current === node) componentFnRef.current = null;
6821
+ if (functionEntries.at(-1)?.kind === "component" && componentFnStack.at(-1) === node) componentFnStack.pop();
6820
6822
  functionEntries.pop();
6821
6823
  },
6822
6824
  CallExpression(node) {
@@ -6824,14 +6826,14 @@ function createFactCollector$2(additionalStateHooks) {
6824
6826
  if (entry == null) return;
6825
6827
  if (isUseStateCall(node)) return;
6826
6828
  facts.calls.push({
6827
- componentFunction: componentFnRef.current,
6829
+ componentFunction: componentFnStack.at(-1) ?? null,
6828
6830
  enclosingFunction: entry.node,
6829
6831
  enclosingFunctionKind: entry.kind,
6830
6832
  node
6831
6833
  });
6832
6834
  },
6833
6835
  ReturnStatement(node) {
6834
- const componentFn = componentFnRef.current;
6836
+ const componentFn = componentFnStack.at(-1);
6835
6837
  if (componentFn == null) return;
6836
6838
  const entry = functionEntries.at(-1);
6837
6839
  if (entry == null || entry.node !== componentFn) return;
@@ -6930,8 +6932,7 @@ var set_state_in_render_default = createRule({
6930
6932
  create: create$4
6931
6933
  });
6932
6934
  function create$4(context) {
6933
- const { additionalStateHooks } = getSettingsFromContext(context);
6934
- const facts = createFactCollector$2(additionalStateHooks);
6935
+ const facts = createFactCollector$2(context);
6935
6936
  return merge(facts.visitor, { "Program:exit"() {
6936
6937
  for (const violation of inferViolations$1(context, facts.facts)) context.report({
6937
6938
  data: { name: violation.name },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.24.6",
3
+ "version": "5.24.8",
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,16 +36,16 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.24.6",
40
- "@eslint-react/core": "5.24.6",
41
- "@eslint-react/eslint": "5.24.6",
42
- "@eslint-react/jsx": "5.24.6",
43
- "@eslint-react/shared": "5.24.6",
44
- "@eslint-react/var": "5.24.6",
45
- "@typescript-eslint/scope-manager": "^8.71.0",
46
- "@typescript-eslint/types": "^8.71.0",
47
- "@typescript-eslint/typescript-estree": "^8.71.0",
48
- "@typescript-eslint/utils": "^8.71.0",
39
+ "@eslint-react/ast": "5.24.8",
40
+ "@eslint-react/core": "5.24.8",
41
+ "@eslint-react/eslint": "5.24.8",
42
+ "@eslint-react/jsx": "5.24.8",
43
+ "@eslint-react/shared": "5.24.8",
44
+ "@eslint-react/var": "5.24.8",
45
+ "@typescript-eslint/scope-manager": "^8.71.1",
46
+ "@typescript-eslint/types": "^8.71.1",
47
+ "@typescript-eslint/typescript-estree": "^8.71.1",
48
+ "@typescript-eslint/utils": "^8.71.1",
49
49
  "compare-versions": "^6.1.1",
50
50
  "string-ts": "^2.3.1",
51
51
  "ts-api-utils": "^2.5.0",