eslint-plugin-react-x 3.0.0-beta.62 → 3.0.0-beta.63

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 +17 -17
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -6,12 +6,12 @@ import { P, isMatching, match } from "ts-pattern";
6
6
  import ts from "typescript";
7
7
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
8
8
  import { constFalse, constTrue, constVoid, flow, getOrElseUpdate, identity, not, unit } from "@eslint-react/eff";
9
- import { findEnclosingAssignmentTarget, findVariable, getObjectType, isAssignmentTargetEqual } from "@eslint-react/var";
10
9
  import { DefinitionType } from "@typescript-eslint/scope-manager";
10
+ import { findVariable, getStaticValue, isIdentifier, isVariableDeclarator } from "@typescript-eslint/utils/ast-utils";
11
11
  import { compare } from "compare-versions";
12
12
  import { getConstrainedTypeAtLocation } from "@typescript-eslint/type-utils";
13
13
  import { unionConstituents } from "ts-api-utils";
14
- import { getStaticValue, isIdentifier, isVariableDeclarator } from "@typescript-eslint/utils/ast-utils";
14
+ import { computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual } from "@eslint-react/var";
15
15
  import { snakeCase } from "string-ts";
16
16
 
17
17
  //#region \0rolldown/runtime.js
@@ -47,10 +47,10 @@ const rules$8 = {
47
47
  "react-x/no-unnecessary-use-callback": "off",
48
48
  "react-x/no-unnecessary-use-memo": "off",
49
49
  "react-x/no-unused-props": "off",
50
- "react-x/unstable-rules-of-props": "off",
51
50
  "react-x/refs": "off",
52
51
  "react-x/rules-of-hooks": "off",
53
- "react-x/set-state-in-render": "off"
52
+ "react-x/set-state-in-render": "off",
53
+ "react-x/unstable-rules-of-props": "off"
54
54
  };
55
55
 
56
56
  //#endregion
@@ -69,7 +69,7 @@ const rules$7 = {
69
69
  //#endregion
70
70
  //#region package.json
71
71
  var name$6 = "eslint-plugin-react-x";
72
- var version = "3.0.0-beta.62";
72
+ var version = "3.0.0-beta.63";
73
73
 
74
74
  //#endregion
75
75
  //#region src/utils/create-rule.ts
@@ -1289,7 +1289,7 @@ function create$61(context) {
1289
1289
  * @returns True if `id` is a state variable, false otherwise.
1290
1290
  */
1291
1291
  function isStateValue(id) {
1292
- const initNode = resolve$4(findVariable(id, context.sourceCode.getScope(id)));
1292
+ const initNode = resolve$4(findVariable(context.sourceCode.getScope(id), id));
1293
1293
  if (initNode == null || initNode.type !== AST_NODE_TYPES.CallExpression) return false;
1294
1294
  if (!isUseStateCall(initNode)) return false;
1295
1295
  const declarator = initNode.parent;
@@ -1313,7 +1313,7 @@ function create$61(context) {
1313
1313
  * @returns True if `id` is a props parameter, false otherwise.
1314
1314
  */
1315
1315
  function isPropsObject(id) {
1316
- const variable = findVariable(id, context.sourceCode.getScope(id));
1316
+ const variable = findVariable(context.sourceCode.getScope(id), id);
1317
1317
  if (variable == null) return false;
1318
1318
  for (const def of variable.defs) {
1319
1319
  if (def.type !== DefinitionType.Parameter) continue;
@@ -2602,7 +2602,7 @@ function create$33(context) {
2602
2602
  }).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
2603
2603
  return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
2604
2604
  }).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
2605
- const variableDefNode = findVariable(n.name, context.sourceCode.getScope(n))?.defs.at(0)?.node;
2605
+ const variableDefNode = findVariable(context.sourceCode.getScope(n), n.name)?.defs.at(0)?.node;
2606
2606
  return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => unit);
2607
2607
  }).otherwise(() => unit);
2608
2608
  }
@@ -3151,7 +3151,7 @@ function create$22(context) {
3151
3151
  const [arg0, arg1] = init.arguments;
3152
3152
  if (arg0 == null || arg1 == null) return;
3153
3153
  if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3154
- const initNode = resolve$3(findVariable(n.name, scope));
3154
+ const initNode = resolve$3(findVariable(scope, n.name));
3155
3155
  if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
3156
3156
  return initNode.elements.length === 0;
3157
3157
  }).otherwise(() => false)) {
@@ -3162,7 +3162,7 @@ function create$22(context) {
3162
3162
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
3163
3163
  return n;
3164
3164
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3165
- const initNode = resolve$3(findVariable(n.name, scope));
3165
+ const initNode = resolve$3(findVariable(scope, n.name));
3166
3166
  if (initNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && initNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
3167
3167
  return initNode;
3168
3168
  }).otherwise(() => null);
@@ -3242,7 +3242,7 @@ function create$21(context) {
3242
3242
  return;
3243
3243
  }
3244
3244
  if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3245
- const initNode = resolve$2(findVariable(n.name, scope));
3245
+ const initNode = resolve$2(findVariable(scope, n.name));
3246
3246
  if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
3247
3247
  return initNode.elements.length === 0;
3248
3248
  }).otherwise(() => false)) {
@@ -3253,7 +3253,7 @@ function create$21(context) {
3253
3253
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
3254
3254
  return n;
3255
3255
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3256
- const variableNode = resolve$2(findVariable(n.name, scope));
3256
+ const variableNode = resolve$2(findVariable(scope, n.name));
3257
3257
  if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
3258
3258
  return variableNode;
3259
3259
  }).otherwise(() => null);
@@ -3452,7 +3452,7 @@ function create$16(context) {
3452
3452
  const value = attribute.value;
3453
3453
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
3454
3454
  const valueExpression = value.expression;
3455
- const construction = getObjectType(valueExpression, context.sourceCode.getScope(valueExpression));
3455
+ const construction = computeObjectType(valueExpression, context.sourceCode.getScope(valueExpression));
3456
3456
  if (construction == null) return;
3457
3457
  if (core.isHookCall(construction.node)) return;
3458
3458
  getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
@@ -3539,7 +3539,7 @@ function create$15(context, [options]) {
3539
3539
  if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
3540
3540
  const { value } = prop;
3541
3541
  const { right } = value;
3542
- const construction = getObjectType(value, context.sourceCode.getScope(value));
3542
+ const construction = computeObjectType(value, context.sourceCode.getScope(value));
3543
3543
  if (construction == null) continue;
3544
3544
  if (core.isHookCall(construction.node)) continue;
3545
3545
  if (safePatterns.length > 0) {
@@ -6566,7 +6566,7 @@ function create$5(context) {
6566
6566
  }
6567
6567
  }
6568
6568
  function isIdFromUseStateCall(id, at) {
6569
- const initNode = resolve$1(findVariable(id, context.sourceCode.getScope(id)));
6569
+ const initNode = resolve$1(findVariable(context.sourceCode.getScope(id), id));
6570
6570
  if (initNode == null) return false;
6571
6571
  if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
6572
6572
  if (!isUseStateCall(initNode)) return false;
@@ -6689,7 +6689,7 @@ function create$5(context) {
6689
6689
  },
6690
6690
  "Program:exit"() {
6691
6691
  const getSetStateCalls = (id, initialScope) => {
6692
- const node = resolve$1(findVariable(id, initialScope));
6692
+ const node = resolve$1(findVariable(initialScope, id));
6693
6693
  switch (node?.type) {
6694
6694
  case AST_NODE_TYPES.ArrowFunctionExpression:
6695
6695
  case AST_NODE_TYPES.FunctionDeclaration:
@@ -6759,7 +6759,7 @@ function create$4(context) {
6759
6759
  return core.isUseStateLikeCall(node, additionalStateHooks);
6760
6760
  }
6761
6761
  function isIdFromUseStateCall(topLevelId, at) {
6762
- const initNode = resolve(findVariable(topLevelId, context.sourceCode.getScope(topLevelId)));
6762
+ const initNode = resolve(findVariable(context.sourceCode.getScope(topLevelId), topLevelId));
6763
6763
  if (initNode == null) return false;
6764
6764
  if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
6765
6765
  if (!isUseStateCall(initNode)) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "3.0.0-beta.62",
3
+ "version": "3.0.0-beta.63",
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,11 +45,11 @@
45
45
  "string-ts": "^2.3.1",
46
46
  "ts-api-utils": "^2.4.0",
47
47
  "ts-pattern": "^5.9.0",
48
- "@eslint-react/ast": "3.0.0-beta.62",
49
- "@eslint-react/eff": "3.0.0-beta.62",
50
- "@eslint-react/core": "3.0.0-beta.62",
51
- "@eslint-react/var": "3.0.0-beta.62",
52
- "@eslint-react/shared": "3.0.0-beta.62"
48
+ "@eslint-react/ast": "3.0.0-beta.63",
49
+ "@eslint-react/eff": "3.0.0-beta.63",
50
+ "@eslint-react/core": "3.0.0-beta.63",
51
+ "@eslint-react/shared": "3.0.0-beta.63",
52
+ "@eslint-react/var": "3.0.0-beta.63"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^19.2.14",