eslint-plugin-react-x 5.8.4-next.0 → 5.8.4-next.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 +23 -22
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -4,9 +4,9 @@ import { Check, Compare, Extract, Traverse, is, isOneOf } from "@eslint-react/as
4
4
  import * as core from "@eslint-react/core";
5
5
  import { merge } from "@eslint-react/eslint";
6
6
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
7
+ import { DefinitionType, ScopeType } from "@typescript-eslint/scope-manager";
7
8
  import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
8
9
  import { computeObjectType, isAssignmentTargetEqual, resolve, resolveEnclosingAssignmentTarget } from "@eslint-react/var";
9
- import { DefinitionType } from "@typescript-eslint/scope-manager";
10
10
  import { P, isMatching, match } from "ts-pattern";
11
11
  import { findParentAttribute, getElementFullType, hasAttribute } from "@eslint-react/jsx";
12
12
  import { compare } from "compare-versions";
@@ -143,7 +143,7 @@ const rules$6 = {
143
143
  //#endregion
144
144
  //#region package.json
145
145
  var name$6 = "eslint-plugin-react-x";
146
- var version = "5.8.4-next.0";
146
+ var version = "5.8.4-next.1";
147
147
 
148
148
  //#endregion
149
149
  //#region src/utils/create-rule.ts
@@ -185,7 +185,7 @@ function getEnclosingTryBlock(node) {
185
185
  n = n.parent;
186
186
  }
187
187
  }
188
- if (current.type === "Program") return null;
188
+ if (current.type === AST_NODE_TYPES.Program) return null;
189
189
  current = current.parent;
190
190
  }
191
191
  return null;
@@ -1188,7 +1188,7 @@ function create$49(context) {
1188
1188
  if (variable == null) return true;
1189
1189
  if (variable.defs.length === 0) return true;
1190
1190
  const scopeType = variable.scope.type;
1191
- return scopeType === "global" || scopeType === "module";
1191
+ return scopeType === ScopeType.global || scopeType === ScopeType.module;
1192
1192
  }
1193
1193
  /**
1194
1194
  * Return the nearest enclosing function for `node`.
@@ -1731,13 +1731,13 @@ function create$47(context) {
1731
1731
  setStateStack.pop();
1732
1732
  },
1733
1733
  ClassDeclaration(node) {
1734
- classStack.push([node, core.isClassComponent(node)]);
1734
+ classStack.push([node, core.isClassComponent(context, node)]);
1735
1735
  },
1736
1736
  "ClassDeclaration:exit"() {
1737
1737
  classStack.pop();
1738
1738
  },
1739
1739
  ClassExpression(node) {
1740
- classStack.push([node, core.isClassComponent(node)]);
1740
+ classStack.push([node, core.isClassComponent(context, node)]);
1741
1741
  },
1742
1742
  "ClassExpression:exit"() {
1743
1743
  classStack.pop();
@@ -1795,7 +1795,7 @@ function create$47(context) {
1795
1795
  function report$2(context) {
1796
1796
  return (descriptor) => {
1797
1797
  if (descriptor == null) return;
1798
- return context.report(descriptor);
1798
+ context.report(descriptor);
1799
1799
  };
1800
1800
  }
1801
1801
  function getIndexParamPosition(methodName) {
@@ -2246,7 +2246,7 @@ var no_create_ref_default = createRule({
2246
2246
  });
2247
2247
  function create$34(context) {
2248
2248
  return merge({ CallExpression(node) {
2249
- if (core.isCreateRefCall(context, node) && Traverse.findParent(node, core.isClassComponent) == null) context.report({
2249
+ if (core.isCreateRefCall(context, node) && Traverse.findParent(node, (n) => core.isClassComponent(context, n)) == null) context.report({
2250
2250
  messageId: "default",
2251
2251
  node
2252
2252
  });
@@ -2275,7 +2275,7 @@ function create$33(context) {
2275
2275
  if (!core.isAssignmentToThisState(node)) return;
2276
2276
  const parentClass = Traverse.findParent(node, isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
2277
2277
  if (parentClass == null) return;
2278
- if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== Traverse.findParent(node, isConstructorFunction)) context.report({
2278
+ if (core.isClassComponent(context, parentClass) && context.sourceCode.getScope(node).block !== Traverse.findParent(node, isConstructorFunction)) context.report({
2279
2279
  messageId: "default",
2280
2280
  node
2281
2281
  });
@@ -2595,7 +2595,7 @@ function create$28(context) {
2595
2595
  function report$1(context) {
2596
2596
  return (descriptor) => {
2597
2597
  if (descriptor == null) return;
2598
- return context.report(descriptor);
2598
+ context.report(descriptor);
2599
2599
  };
2600
2600
  }
2601
2601
 
@@ -2780,7 +2780,7 @@ function create$25(context) {
2780
2780
  function report(context) {
2781
2781
  return (descriptor) => {
2782
2782
  if (descriptor == null) return;
2783
- return context.report(descriptor);
2783
+ context.report(descriptor);
2784
2784
  };
2785
2785
  }
2786
2786
  /**
@@ -2971,11 +2971,12 @@ function isInsideJSXAttributeValue(node) {
2971
2971
  /**
2972
2972
  * Check whether a given node is declared inside a class component's render block
2973
2973
  * Ex: class C extends React.Component { render() { const Nested = () => <div />; } }
2974
+ * @param context The rule context
2974
2975
  * @param node The AST node being checked
2975
2976
  * @returns `true` if the node is inside a class component's render block
2976
2977
  */
2977
- function isInsideRenderMethod(node) {
2978
- return Traverse.findParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(n.parent.parent)) != null;
2978
+ function isInsideRenderMethod(context, node) {
2979
+ return Traverse.findParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(context, n.parent.parent)) != null;
2979
2980
  }
2980
2981
  /**
2981
2982
  * Determine whether the node is inside `createElement`'s props argument
@@ -3054,7 +3055,7 @@ function create$22(context) {
3054
3055
  });
3055
3056
  continue;
3056
3057
  }
3057
- if (isInsideRenderMethod(component)) context.report({
3058
+ if (isInsideRenderMethod(context, component)) context.report({
3058
3059
  data: {
3059
3060
  name,
3060
3061
  suggestion: "Move it to the top level."
@@ -3133,7 +3134,7 @@ function create$20(context) {
3133
3134
  if (!context.sourceCode.text.includes("componentDidMount")) return {};
3134
3135
  return merge({ CallExpression(node) {
3135
3136
  if (!core.isThisSetStateCall(node)) return;
3136
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3137
+ const enclosingClassNode = Traverse.findParent(node, (n) => core.isClassComponent(context, n));
3137
3138
  const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidMount(n));
3138
3139
  if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3139
3140
  const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
@@ -3163,7 +3164,7 @@ function create$19(context) {
3163
3164
  if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
3164
3165
  return merge({ CallExpression(node) {
3165
3166
  if (!core.isThisSetStateCall(node)) return;
3166
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3167
+ const enclosingClassNode = Traverse.findParent(node, (n) => core.isClassComponent(context, n));
3167
3168
  const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidUpdate(n));
3168
3169
  if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3169
3170
  const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
@@ -3193,7 +3194,7 @@ function create$18(context) {
3193
3194
  if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
3194
3195
  return merge({ CallExpression(node) {
3195
3196
  if (!core.isThisSetStateCall(node)) return;
3196
- const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
3197
+ const enclosingClassNode = Traverse.findParent(node, (n) => core.isClassComponent(context, n));
3197
3198
  const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentWillUpdate(n));
3198
3199
  if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
3199
3200
  const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
@@ -3539,13 +3540,13 @@ function create$11(context) {
3539
3540
  const propertyUsages = /* @__PURE__ */ new WeakMap();
3540
3541
  function classEnter(node) {
3541
3542
  classStack.push(node);
3542
- if (!core.isClassComponent(node)) return;
3543
+ if (!core.isClassComponent(context, node)) return;
3543
3544
  propertyDefs.set(node, /* @__PURE__ */ new Set());
3544
3545
  propertyUsages.set(node, /* @__PURE__ */ new Set());
3545
3546
  }
3546
3547
  function classExit() {
3547
3548
  const currentClass = classStack.pop();
3548
- if (currentClass == null || !core.isClassComponent(currentClass)) return;
3549
+ if (currentClass == null || !core.isClassComponent(context, currentClass)) return;
3549
3550
  const id = core.getClassId(currentClass);
3550
3551
  const defs = propertyDefs.get(currentClass);
3551
3552
  const usages = propertyUsages.get(currentClass);
@@ -3568,7 +3569,7 @@ function create$11(context) {
3568
3569
  function methodEnter(node) {
3569
3570
  methodStack.push(node);
3570
3571
  const currentClass = classStack.at(-1);
3571
- if (currentClass == null || !core.isClassComponent(currentClass)) return;
3572
+ if (currentClass == null || !core.isClassComponent(context, currentClass)) return;
3572
3573
  if (node.static) return;
3573
3574
  if (isKeyLiteral(node, node.key)) propertyDefs.get(currentClass)?.add(node.key);
3574
3575
  }
@@ -3584,7 +3585,7 @@ function create$11(context) {
3584
3585
  const currentClass = classStack.at(-1);
3585
3586
  const currentMethod = methodStack.at(-1);
3586
3587
  if (currentClass == null || currentMethod == null) return;
3587
- if (!core.isClassComponent(currentClass) || currentMethod.static) return;
3588
+ if (!core.isClassComponent(context, currentClass) || currentMethod.static) return;
3588
3589
  if (node.object.type !== AST_NODE_TYPES.ThisExpression || !isKeyLiteral(node, node.property)) return;
3589
3590
  if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
3590
3591
  propertyDefs.get(currentClass)?.add(node.property);
@@ -3601,7 +3602,7 @@ function create$11(context) {
3601
3602
  const currentClass = classStack.at(-1);
3602
3603
  const currentMethod = methodStack.at(-1);
3603
3604
  if (currentClass == null || currentMethod == null) return;
3604
- if (!core.isClassComponent(currentClass) || currentMethod.static) return;
3605
+ if (!core.isClassComponent(context, currentClass) || currentMethod.static) return;
3605
3606
  if (node.init != null && node.init.type === AST_NODE_TYPES.ThisExpression && node.id.type === AST_NODE_TYPES.ObjectPattern) {
3606
3607
  for (const prop of node.id.properties) if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key)) {
3607
3608
  const keyName = Extract.getPropertyName(prop.key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.8.4-next.0",
3
+ "version": "5.8.4-next.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",
@@ -45,12 +45,12 @@
45
45
  "string-ts": "^2.3.1",
46
46
  "ts-api-utils": "^2.5.0",
47
47
  "ts-pattern": "^5.9.0",
48
- "@eslint-react/ast": "5.8.4-next.0",
49
- "@eslint-react/core": "5.8.4-next.0",
50
- "@eslint-react/jsx": "5.8.4-next.0",
51
- "@eslint-react/shared": "5.8.4-next.0",
52
- "@eslint-react/eslint": "5.8.4-next.0",
53
- "@eslint-react/var": "5.8.4-next.0"
48
+ "@eslint-react/ast": "5.8.4-next.1",
49
+ "@eslint-react/core": "5.8.4-next.1",
50
+ "@eslint-react/eslint": "5.8.4-next.1",
51
+ "@eslint-react/jsx": "5.8.4-next.1",
52
+ "@eslint-react/shared": "5.8.4-next.1",
53
+ "@eslint-react/var": "5.8.4-next.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.14",
@@ -63,8 +63,8 @@
63
63
  "tsl": "^1.0.30",
64
64
  "tsl-dx": "^0.12.1",
65
65
  "typescript": "^6.0.3",
66
- "@local/eff": "3.0.0-beta.72",
67
- "@local/configs": "0.0.0"
66
+ "@local/configs": "0.0.0",
67
+ "@local/eff": "3.0.0-beta.72"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "eslint": "^10.3.0",
@@ -77,7 +77,7 @@
77
77
  "@local/eff": "workspace:*"
78
78
  },
79
79
  "scripts": {
80
- "build": "tsdown --dts-resolve",
80
+ "build": "tsdown",
81
81
  "lint:publish": "publint",
82
82
  "lint:ts": "tsl"
83
83
  }