eslint-plugin-react-x 5.27.0 → 5.27.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.
Files changed (2) hide show
  1. package/dist/index.js +28 -35
  2. package/package.json +9 -7
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.27.0";
138
+ var version = "5.27.2";
139
139
  //#endregion
140
140
  //#region src/utils/create-rule.ts
141
141
  function getDocsUrl(ruleName) {
@@ -1547,9 +1547,10 @@ function inferMutableFunctions(context, mutations) {
1547
1547
  const origin = mutation.kind === "binding" ? variable : resolveVariableOrigin(context, variable);
1548
1548
  if (isGlobalOrModuleVariable(origin)) continue;
1549
1549
  const declaration = origin.identifiers.at(0) ?? null;
1550
+ const declarationFn = declaration == null ? null : Traverse.findParent(declaration, Check.isFunction);
1550
1551
  let current = mutation.enclosingFunction;
1551
1552
  while (current != null) {
1552
- if (declaration != null && Traverse.findParent(declaration, Check.isFunction) === current) break;
1553
+ if (declarationFn === current) break;
1553
1554
  if (!mutableFunctions.has(current)) mutableFunctions.set(current, {
1554
1555
  name: origin.name,
1555
1556
  node: mutation.node
@@ -2005,7 +2006,7 @@ cast(absurd);
2005
2006
  function not(predicate) {
2006
2007
  return (data) => !predicate(data);
2007
2008
  }
2008
- dual(2, (a, b) => (data) => a(data) && b(data));
2009
+ const and = dual(2, (a, b) => (data) => a(data) && b(data));
2009
2010
  const or = dual(2, (a, b) => (data) => a(data) || b(data));
2010
2011
  dual(2, (a, b) => (data) => a(data) !== b(data));
2011
2012
  dual(2, (a, b) => (data) => a(data) === b(data));
@@ -2322,10 +2323,11 @@ function create$32(context) {
2322
2323
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
2323
2324
  return Check.isIdentifier(callee.property, "map");
2324
2325
  });
2326
+ if (call == null) return;
2325
2327
  const iter = Traverse.findParent(jsxElement, Check.isFunction, (n) => n === call);
2326
- if (!Check.isFunction(iter)) return;
2327
- const arg0 = call?.arguments[0];
2328
- if (call == null || arg0 == null) return;
2328
+ if (iter == null) return;
2329
+ const arg0 = call.arguments[0];
2330
+ if (arg0 == null) return;
2329
2331
  if (Extract.unwrap(arg0) !== iter) return;
2330
2332
  keyedEntries.set(call, {
2331
2333
  hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
@@ -3023,12 +3025,12 @@ function create$20(context) {
3023
3025
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
3024
3026
  return { CallExpression(node) {
3025
3027
  if (!core.isThisSetStateCall(node)) return;
3026
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3027
- const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidMount(n));
3028
- if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3029
- const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
3030
- const setStateCallParentScope = context.sourceCode.getScope(node).upper;
3031
- if (enclosingMethodNode.parent === enclosingClassNode.body && setStateCallParentScope === enclosingMethodScope) context.report({
3028
+ const component = Traverse.findParent(node, core.isClassComponent);
3029
+ if (component == null) return;
3030
+ const method = Traverse.findParent(node, core.isComponentDidMount, (n) => n === component);
3031
+ if (method == null) return;
3032
+ const lifecycleFunction = method.value == null ? null : Extract.unwrap(method.value);
3033
+ if (method.parent === component.body && lifecycleFunction != null && lifecycleFunction === Traverse.findParent(node, Check.isFunctionOrClass)) context.report({
3032
3034
  messageId: "default",
3033
3035
  node
3034
3036
  });
@@ -3048,12 +3050,12 @@ function create$19(context) {
3048
3050
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
3049
3051
  return { CallExpression(node) {
3050
3052
  if (!core.isThisSetStateCall(node)) return;
3051
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3052
- const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidUpdate(n));
3053
- if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3054
- const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
3055
- const setStateCallParentScope = context.sourceCode.getScope(node).upper;
3056
- if (enclosingMethodNode.parent === enclosingClassNode.body && setStateCallParentScope === enclosingMethodScope) context.report({
3053
+ const component = Traverse.findParent(node, core.isClassComponent);
3054
+ if (component == null) return;
3055
+ const method = Traverse.findParent(node, core.isComponentDidUpdate, (n) => n === component);
3056
+ if (method == null) return;
3057
+ const lifecycleFunction = method.value == null ? null : Extract.unwrap(method.value);
3058
+ if (method.parent === component.body && lifecycleFunction != null && lifecycleFunction === Traverse.findParent(node, Check.isFunctionOrClass)) context.report({
3057
3059
  messageId: "default",
3058
3060
  node
3059
3061
  });
@@ -3073,12 +3075,12 @@ function create$18(context) {
3073
3075
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
3074
3076
  return { CallExpression(node) {
3075
3077
  if (!core.isThisSetStateCall(node)) return;
3076
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3077
- const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentWillUpdate(n));
3078
- if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3079
- const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
3080
- const setStateCallParentScope = context.sourceCode.getScope(node).upper;
3081
- if (enclosingMethodNode.parent === enclosingClassNode.body && setStateCallParentScope === enclosingMethodScope) context.report({
3078
+ const component = Traverse.findParent(node, core.isClassComponent);
3079
+ if (component == null) return;
3080
+ const method = Traverse.findParent(node, core.isComponentWillUpdate, (n) => n === component);
3081
+ if (method == null) return;
3082
+ const lifecycleFunction = method.value == null ? null : Extract.unwrap(method.value);
3083
+ if (method.parent === component.body && lifecycleFunction != null && lifecycleFunction === Traverse.findParent(node, Check.isFunctionOrClass)) context.report({
3082
3084
  messageId: "default",
3083
3085
  node
3084
3086
  });
@@ -6589,20 +6591,11 @@ function isInitializedFromRef(context, id, refParams, seen = /* @__PURE__ */ new
6589
6591
  const writeExpr = reference.writeExpr == null ? null : Extract.unwrap(reference.writeExpr);
6590
6592
  if (writeExpr == null) continue;
6591
6593
  if (writeExpr.range[1] > id.range[0]) continue;
6592
- const writeFn = Traverse.findParent(writeExpr, Check.isFunction);
6593
- if (writeFn != null && !isSelfOrAncestorFunction(writeFn, id)) continue;
6594
+ if (Traverse.hasParent(writeExpr, and(Check.isFunction, (n) => !Traverse.hasParent(id, (m) => m === n)))) continue;
6594
6595
  if (isExpressionFromRef(context, writeExpr, refParams, seen)) return true;
6595
6596
  }
6596
6597
  return false;
6597
6598
  }
6598
- function isSelfOrAncestorFunction(fn, node) {
6599
- let current = Traverse.findParent(node, Check.isFunction);
6600
- while (current != null) {
6601
- if (current === fn) return true;
6602
- current = Traverse.findParent(current, Check.isFunction);
6603
- }
6604
- return false;
6605
- }
6606
6599
  function isExpressionFromRef(context, init, refParams, seen) {
6607
6600
  const { additionalRefHooks } = getSettingsFromContext(context);
6608
6601
  switch (true) {
@@ -7041,7 +7034,7 @@ const KNOWN_DYNAMIC_EXPRESSION_TYPES = /* @__PURE__ */ new Set([
7041
7034
  ]);
7042
7035
  function createRenderBoundaryChecker(componentNodes) {
7043
7036
  const components = new Set(componentNodes);
7044
- return (node) => Traverse.hasParent(node, (n) => (Check.isFunction(n) || Check.isClass(n)) && components.has(n));
7037
+ return (node) => Traverse.hasParent(node, (n) => Check.isFunctionOrClass(n) && components.has(n));
7045
7038
  }
7046
7039
  //#endregion
7047
7040
  //#region src/rules/static-components/origins.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.27.0",
3
+ "version": "5.27.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",
@@ -36,12 +36,12 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.27.0",
40
- "@eslint-react/core": "5.27.0",
41
- "@eslint-react/eslint": "5.27.0",
42
- "@eslint-react/jsx": "5.27.0",
43
- "@eslint-react/shared": "5.27.0",
44
- "@eslint-react/var": "5.27.0",
39
+ "@eslint-react/ast": "5.27.2",
40
+ "@eslint-react/core": "5.27.2",
41
+ "@eslint-react/eslint": "5.27.2",
42
+ "@eslint-react/jsx": "5.27.2",
43
+ "@eslint-react/shared": "5.27.2",
44
+ "@eslint-react/var": "5.27.2",
45
45
  "@typescript-eslint/scope-manager": "^8.71.2",
46
46
  "@typescript-eslint/types": "^8.71.2",
47
47
  "@typescript-eslint/typescript-estree": "^8.71.2",
@@ -56,6 +56,8 @@
56
56
  "@local/eff": "0.0.0",
57
57
  "@local/testkit": "0.0.0",
58
58
  "@rbxts/react": "17.3.7-ts.2",
59
+ "@tsconfig/node20": "^20.1.10",
60
+ "@types/node": "^20.19.43",
59
61
  "@types/react": "^19.3.0",
60
62
  "@types/react-dom": "^19.3.0",
61
63
  "dedent": "^1.7.2",