eslint-plugin-react-x 3.0.0-next.61 → 3.0.0-next.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 +56 -93
  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-next.61";
72
+ var version = "3.0.0-next.63";
73
73
 
74
74
  //#endregion
75
75
  //#region src/utils/create-rule.ts
@@ -1289,14 +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
- function resolve(v) {
1293
- if (v == null) return unit;
1294
- const def = v.defs.at(0);
1295
- if (def == null) return unit;
1296
- if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
1297
- return def.node;
1298
- }
1299
- const initNode = resolve(findVariable(id, context.sourceCode.getScope(id)));
1292
+ const initNode = resolve$4(findVariable(context.sourceCode.getScope(id), id));
1300
1293
  if (initNode == null || initNode.type !== AST_NODE_TYPES.CallExpression) return false;
1301
1294
  if (!isUseStateCall(initNode)) return false;
1302
1295
  const declarator = initNode.parent;
@@ -1320,7 +1313,7 @@ function create$61(context) {
1320
1313
  * @returns True if `id` is a props parameter, false otherwise.
1321
1314
  */
1322
1315
  function isPropsObject(id) {
1323
- const variable = findVariable(id, context.sourceCode.getScope(id));
1316
+ const variable = findVariable(context.sourceCode.getScope(id), id);
1324
1317
  if (variable == null) return false;
1325
1318
  for (const def of variable.defs) {
1326
1319
  if (def.type !== DefinitionType.Parameter) continue;
@@ -1395,6 +1388,13 @@ function create$61(context) {
1395
1388
  }
1396
1389
  });
1397
1390
  }
1391
+ function resolve$4(v) {
1392
+ if (v == null) return unit;
1393
+ const def = v.defs.at(0);
1394
+ if (def == null) return unit;
1395
+ if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
1396
+ return def.node;
1397
+ }
1398
1398
 
1399
1399
  //#endregion
1400
1400
  //#region src/rules/jsx-dollar/jsx-dollar.ts
@@ -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,19 +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 variable = findVariable(n.name, scope);
3155
- function resolve(v) {
3156
- if (v == null) return unit;
3157
- const def = v.defs.at(0);
3158
- if (def == null) return unit;
3159
- switch (true) {
3160
- case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
3161
- case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
3162
- case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
3163
- default: return unit;
3164
- }
3165
- }
3166
- const initNode = resolve(variable);
3154
+ const initNode = resolve$3(findVariable(scope, n.name));
3167
3155
  if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
3168
3156
  return initNode.elements.length === 0;
3169
3157
  }).otherwise(() => false)) {
@@ -3174,19 +3162,7 @@ function create$22(context) {
3174
3162
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
3175
3163
  return n;
3176
3164
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3177
- const variable = findVariable(n.name, scope);
3178
- function resolve(v) {
3179
- if (v == null) return unit;
3180
- const def = v.defs.at(0);
3181
- if (def == null) return unit;
3182
- switch (true) {
3183
- case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
3184
- case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
3185
- case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
3186
- default: return unit;
3187
- }
3188
- }
3189
- const initNode = resolve(variable);
3165
+ const initNode = resolve$3(findVariable(scope, n.name));
3190
3166
  if (initNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && initNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
3191
3167
  return initNode;
3192
3168
  }).otherwise(() => null);
@@ -3223,6 +3199,13 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
3223
3199
  node
3224
3200
  };
3225
3201
  }
3202
+ function resolve$3(v) {
3203
+ if (v == null) return unit;
3204
+ const def = v.defs.at(0);
3205
+ if (def == null) return unit;
3206
+ if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
3207
+ return def.node;
3208
+ }
3226
3209
 
3227
3210
  //#endregion
3228
3211
  //#region src/rules/no-unnecessary-use-memo/no-unnecessary-use-memo.ts
@@ -3259,19 +3242,7 @@ function create$21(context) {
3259
3242
  return;
3260
3243
  }
3261
3244
  if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3262
- const variable = findVariable(n.name, scope);
3263
- function resolve(v) {
3264
- if (v == null) return unit;
3265
- const def = v.defs.at(0);
3266
- if (def == null) return unit;
3267
- switch (true) {
3268
- case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
3269
- case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
3270
- case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
3271
- default: return unit;
3272
- }
3273
- }
3274
- const initNode = resolve(variable);
3245
+ const initNode = resolve$2(findVariable(scope, n.name));
3275
3246
  if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
3276
3247
  return initNode.elements.length === 0;
3277
3248
  }).otherwise(() => false)) {
@@ -3282,14 +3253,7 @@ function create$21(context) {
3282
3253
  if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
3283
3254
  return n;
3284
3255
  }).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
3285
- function resolve(v) {
3286
- if (v == null) return unit;
3287
- const def = v.defs.at(0);
3288
- if (def == null) return unit;
3289
- if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
3290
- return def.node;
3291
- }
3292
- const variableNode = resolve(findVariable(n.name, scope));
3256
+ const variableNode = resolve$2(findVariable(scope, n.name));
3293
3257
  if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
3294
3258
  return variableNode;
3295
3259
  }).otherwise(() => null);
@@ -3326,6 +3290,13 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
3326
3290
  node
3327
3291
  };
3328
3292
  }
3293
+ function resolve$2(v) {
3294
+ if (v == null) return unit;
3295
+ const def = v.defs.at(0);
3296
+ if (def == null) return unit;
3297
+ if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
3298
+ return def.node;
3299
+ }
3329
3300
 
3330
3301
  //#endregion
3331
3302
  //#region src/rules/no-unnecessary-use-prefix/no-unnecessary-use-prefix.ts
@@ -3481,7 +3452,7 @@ function create$16(context) {
3481
3452
  const value = attribute.value;
3482
3453
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
3483
3454
  const valueExpression = value.expression;
3484
- const construction = getObjectType(valueExpression, context.sourceCode.getScope(valueExpression));
3455
+ const construction = computeObjectType(valueExpression, context.sourceCode.getScope(valueExpression));
3485
3456
  if (construction == null) return;
3486
3457
  if (core.isHookCall(construction.node)) return;
3487
3458
  getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
@@ -3568,7 +3539,7 @@ function create$15(context, [options]) {
3568
3539
  if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
3569
3540
  const { value } = prop;
3570
3541
  const { right } = value;
3571
- const construction = getObjectType(value, context.sourceCode.getScope(value));
3542
+ const construction = computeObjectType(value, context.sourceCode.getScope(value));
3572
3543
  if (construction == null) continue;
3573
3544
  if (core.isHookCall(construction.node)) continue;
3574
3545
  if (safePatterns.length > 0) {
@@ -6595,19 +6566,7 @@ function create$5(context) {
6595
6566
  }
6596
6567
  }
6597
6568
  function isIdFromUseStateCall(id, at) {
6598
- const variable = findVariable(id, context.sourceCode.getScope(id));
6599
- function resolve(v) {
6600
- if (v == null) return unit;
6601
- const def = v.defs.at(0);
6602
- if (def == null) return unit;
6603
- switch (true) {
6604
- case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
6605
- case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
6606
- case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
6607
- default: return unit;
6608
- }
6609
- }
6610
- const initNode = resolve(variable);
6569
+ const initNode = resolve$1(findVariable(context.sourceCode.getScope(id), id));
6611
6570
  if (initNode == null) return false;
6612
6571
  if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
6613
6572
  if (!isUseStateCall(initNode)) return false;
@@ -6730,14 +6689,7 @@ function create$5(context) {
6730
6689
  },
6731
6690
  "Program:exit"() {
6732
6691
  const getSetStateCalls = (id, initialScope) => {
6733
- function resolve(v) {
6734
- if (v == null) return unit;
6735
- const def = v.defs.at(0);
6736
- if (def == null) return unit;
6737
- if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
6738
- return def.node;
6739
- }
6740
- const node = resolve(findVariable(id, initialScope));
6692
+ const node = resolve$1(findVariable(initialScope, id));
6741
6693
  switch (node?.type) {
6742
6694
  case AST_NODE_TYPES.ArrowFunctionExpression:
6743
6695
  case AST_NODE_TYPES.FunctionDeclaration:
@@ -6772,6 +6724,17 @@ function create$5(context) {
6772
6724
  }
6773
6725
  });
6774
6726
  }
6727
+ function resolve$1(v) {
6728
+ if (v == null) return unit;
6729
+ const def = v.defs.at(0);
6730
+ if (def == null) return unit;
6731
+ switch (true) {
6732
+ case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
6733
+ case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
6734
+ case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
6735
+ default: return unit;
6736
+ }
6737
+ }
6775
6738
 
6776
6739
  //#endregion
6777
6740
  //#region src/rules/set-state-in-render/set-state-in-render.ts
@@ -6796,14 +6759,7 @@ function create$4(context) {
6796
6759
  return core.isUseStateLikeCall(node, additionalStateHooks);
6797
6760
  }
6798
6761
  function isIdFromUseStateCall(topLevelId, at) {
6799
- function resolve(v) {
6800
- if (v == null) return unit;
6801
- const def = v.defs.at(0);
6802
- if (def == null) return unit;
6803
- if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
6804
- return def.node;
6805
- }
6806
- const initNode = resolve(findVariable(topLevelId, context.sourceCode.getScope(topLevelId)));
6762
+ const initNode = resolve(findVariable(context.sourceCode.getScope(topLevelId), topLevelId));
6807
6763
  if (initNode == null) return false;
6808
6764
  if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
6809
6765
  if (!isUseStateCall(initNode)) return false;
@@ -6916,6 +6872,13 @@ function create$4(context) {
6916
6872
  }
6917
6873
  });
6918
6874
  }
6875
+ function resolve(v) {
6876
+ if (v == null) return unit;
6877
+ const def = v.defs.at(0);
6878
+ if (def == null) return unit;
6879
+ if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
6880
+ return def.node;
6881
+ }
6919
6882
 
6920
6883
  //#endregion
6921
6884
  //#region src/rules/unsupported-syntax/unsupported-syntax.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "3.0.0-next.61",
3
+ "version": "3.0.0-next.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-next.61",
49
- "@eslint-react/core": "3.0.0-next.61",
50
- "@eslint-react/eff": "3.0.0-next.61",
51
- "@eslint-react/shared": "3.0.0-next.61",
52
- "@eslint-react/var": "3.0.0-next.61"
48
+ "@eslint-react/ast": "3.0.0-next.63",
49
+ "@eslint-react/core": "3.0.0-next.63",
50
+ "@eslint-react/shared": "3.0.0-next.63",
51
+ "@eslint-react/var": "3.0.0-next.63",
52
+ "@eslint-react/eff": "3.0.0-next.63"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^19.2.14",