eslint-plugin-react-web-api 5.30.2 → 5.30.4

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 +26 -30
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { Check, Compare, Extract, Traverse } from "@eslint-react/ast";
5
5
  import { getFunctionId, isUseEffectCleanupCallback, isUseEffectSetupCallback, isUseRefLikeCall } from "@eslint-react/core";
6
6
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
7
7
  import { P, isMatching, match } from "ts-pattern";
8
- import { isAssignmentTargetEqual, isInitializedFromReactNative, isProvenanceEqual, resolve, resolveEnclosingAssignmentTarget, resolveOrigin } from "@eslint-react/var";
8
+ import { isAssignmentTargetEqual, isInitializedFromReactNative, isProvenanceEqual, resolve, resolveEnclosingAssignmentTarget, resolveOrigin, resolveOriginChain } from "@eslint-react/var";
9
9
  import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
10
10
  // \0rolldown/runtime.js
11
11
  var __defProp = Object.defineProperty;
@@ -20,7 +20,7 @@ var __exportAll = (all, flags) => {
20
20
  };
21
21
  // package.json
22
22
  var name$1 = "eslint-plugin-react-web-api";
23
- var version = "5.30.2";
23
+ var version = "5.30.4";
24
24
  // src/utils/create-rule.ts
25
25
  function getDocsUrl(ruleName) {
26
26
  return `https://eslint-react.xyz/docs/rules/web-api-${ruleName}`;
@@ -292,6 +292,11 @@ function isSignalPropertyBinding(context, node) {
292
292
  }
293
293
  return false;
294
294
  }
295
+ function isAbortControllerNew(node) {
296
+ if (node?.type !== AST_NODE_TYPES.NewExpression) return false;
297
+ const callee = Extract.unwrap(node.callee);
298
+ return callee.type === AST_NODE_TYPES.Identifier && callee.name === "AbortController";
299
+ }
295
300
  function getSignalValueExpression({ context, node }) {
296
301
  const seen = /* @__PURE__ */ new Set();
297
302
  function visit(node) {
@@ -303,9 +308,8 @@ function getSignalValueExpression({ context, node }) {
303
308
  const resolved = resolveOrigin(context, node);
304
309
  const unwrapped = resolved == null ? null : Extract.unwrap(resolved);
305
310
  if (unwrapped != null && Check.isFunction(unwrapped)) return node;
306
- if (unwrapped != null && unwrapped.type === AST_NODE_TYPES.NewExpression && isSignalPropertyBinding(context, node)) {
307
- const newCallee = Extract.unwrap(unwrapped.callee);
308
- if (newCallee.type === AST_NODE_TYPES.Identifier && newCallee.name === "AbortController") return node;
311
+ if (unwrapped != null && isSignalPropertyBinding(context, node)) {
312
+ if (isAbortControllerNew(unwrapped.type === AST_NODE_TYPES.Identifier ? resolveOriginChain(context, unwrapped) : unwrapped)) return node;
309
313
  }
310
314
  return visit(unwrapped);
311
315
  }
@@ -465,36 +469,28 @@ function resolveToObjectExpression(context, node) {
465
469
  function isGlobalObject(node) {
466
470
  return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
467
471
  }
468
- function isNameBoundInEnclosingScopes(name, node) {
469
- let current = node.parent;
470
- while (current != null) {
471
- if (scopeBindsName(current, name)) return true;
472
- current = current.parent;
473
- }
474
- return false;
475
- }
476
- function scopeBindsName(node, name) {
472
+ function isNameBoundInScope(name, node) {
477
473
  switch (node.type) {
478
474
  case AST_NODE_TYPES.FunctionDeclaration:
479
- case AST_NODE_TYPES.ArrowFunctionExpression: return node.params.some((param) => patternBindsName(param, name));
480
- case AST_NODE_TYPES.FunctionExpression: return node.id?.name === name || node.params.some((param) => patternBindsName(param, name));
481
- case AST_NODE_TYPES.CatchClause: return node.param != null && patternBindsName(node.param, name);
475
+ case AST_NODE_TYPES.ArrowFunctionExpression: return node.params.some((param) => isNameBoundInPattern(name, param));
476
+ case AST_NODE_TYPES.FunctionExpression: return node.id?.name === name || node.params.some((param) => isNameBoundInPattern(name, param));
477
+ case AST_NODE_TYPES.CatchClause: return node.param != null && isNameBoundInPattern(name, node.param);
482
478
  case AST_NODE_TYPES.BlockStatement:
483
479
  case AST_NODE_TYPES.Program:
484
- case AST_NODE_TYPES.StaticBlock: return node.body.some((statement) => statementBindsName(statement, name));
485
- case AST_NODE_TYPES.ForStatement: return node.init?.type === AST_NODE_TYPES.VariableDeclaration && statementBindsName(node.init, name);
480
+ case AST_NODE_TYPES.StaticBlock: return node.body.some((statement) => isNameBoundInStatement(name, statement));
481
+ case AST_NODE_TYPES.ForStatement: return node.init?.type === AST_NODE_TYPES.VariableDeclaration && isNameBoundInStatement(name, node.init);
486
482
  case AST_NODE_TYPES.ForInStatement:
487
- case AST_NODE_TYPES.ForOfStatement: return node.left.type === AST_NODE_TYPES.VariableDeclaration && statementBindsName(node.left, name);
483
+ case AST_NODE_TYPES.ForOfStatement: return node.left.type === AST_NODE_TYPES.VariableDeclaration && isNameBoundInStatement(name, node.left);
488
484
  default: return false;
489
485
  }
490
486
  }
491
- function statementBindsName(statement, name) {
487
+ function isNameBoundInStatement(name, statement) {
492
488
  switch (statement.type) {
493
489
  case AST_NODE_TYPES.FunctionDeclaration:
494
490
  case AST_NODE_TYPES.ClassDeclaration: return statement.id?.name === name;
495
- case AST_NODE_TYPES.VariableDeclaration: return statement.declarations.some((declarator) => patternBindsName(declarator.id, name));
491
+ case AST_NODE_TYPES.VariableDeclaration: return statement.declarations.some((declarator) => isNameBoundInPattern(name, declarator.id));
496
492
  case AST_NODE_TYPES.ImportDeclaration: return statement.specifiers.some((specifier) => specifier.local.name === name);
497
- case AST_NODE_TYPES.ExportNamedDeclaration: return statement.declaration != null && statementBindsName(statement.declaration, name);
493
+ case AST_NODE_TYPES.ExportNamedDeclaration: return statement.declaration != null && isNameBoundInStatement(name, statement.declaration);
498
494
  case AST_NODE_TYPES.ExportDefaultDeclaration: return (statement.declaration.type === AST_NODE_TYPES.FunctionDeclaration || statement.declaration.type === AST_NODE_TYPES.ClassDeclaration) && statement.declaration.id?.name === name;
499
495
  case AST_NODE_TYPES.TSImportEqualsDeclaration:
500
496
  case AST_NODE_TYPES.TSEnumDeclaration: return statement.id.name === name;
@@ -502,14 +498,14 @@ function statementBindsName(statement, name) {
502
498
  default: return false;
503
499
  }
504
500
  }
505
- function patternBindsName(pattern, name) {
501
+ function isNameBoundInPattern(name, pattern) {
506
502
  switch (pattern.type) {
507
503
  case AST_NODE_TYPES.Identifier: return pattern.name === name;
508
- case AST_NODE_TYPES.ArrayPattern: return pattern.elements.some((element) => element != null && patternBindsName(element, name));
509
- case AST_NODE_TYPES.ObjectPattern: return pattern.properties.some((property) => property.type === AST_NODE_TYPES.RestElement ? patternBindsName(property.argument, name) : patternBindsName(property.value, name));
510
- case AST_NODE_TYPES.AssignmentPattern: return patternBindsName(pattern.left, name);
511
- case AST_NODE_TYPES.RestElement: return patternBindsName(pattern.argument, name);
512
- case AST_NODE_TYPES.TSParameterProperty: return patternBindsName(pattern.parameter, name);
504
+ case AST_NODE_TYPES.ArrayPattern: return pattern.elements.some((element) => element != null && isNameBoundInPattern(name, element));
505
+ case AST_NODE_TYPES.ObjectPattern: return pattern.properties.some((property) => property.type === AST_NODE_TYPES.RestElement ? isNameBoundInPattern(name, property.argument) : isNameBoundInPattern(name, property.value));
506
+ case AST_NODE_TYPES.AssignmentPattern: return isNameBoundInPattern(name, pattern.left);
507
+ case AST_NODE_TYPES.RestElement: return isNameBoundInPattern(name, pattern.argument);
508
+ case AST_NODE_TYPES.TSParameterProperty: return isNameBoundInPattern(name, pattern.parameter);
513
509
  default: return false;
514
510
  }
515
511
  }
@@ -576,7 +572,7 @@ const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCal
576
572
  function getCallKind$4(node) {
577
573
  const callee = Extract.unwrap(node.callee);
578
574
  switch (true) {
579
- case Check.isIdentifier(callee, "fetch") && !isNameBoundInEnclosingScopes("fetch", node): return "fetch";
575
+ case Check.isIdentifier(callee, "fetch") && !Traverse.hasParent(node, (n) => isNameBoundInScope("fetch", n)): return "fetch";
580
576
  case callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && Check.isIdentifier(callee.property, "fetch") && isGlobalObject(Extract.unwrap(callee.object)): return "fetch";
581
577
  case Extract.getCalleeName(node) === "abort": return "abort";
582
578
  default: return "other";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "5.30.2",
3
+ "version": "5.30.4",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -37,11 +37,11 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint-react/ast": "5.30.2",
41
- "@eslint-react/core": "5.30.2",
42
- "@eslint-react/eslint": "5.30.2",
43
- "@eslint-react/shared": "5.30.2",
44
- "@eslint-react/var": "5.30.2",
40
+ "@eslint-react/ast": "5.30.4",
41
+ "@eslint-react/core": "5.30.4",
42
+ "@eslint-react/eslint": "5.30.4",
43
+ "@eslint-react/shared": "5.30.4",
44
+ "@eslint-react/var": "5.30.4",
45
45
  "@typescript-eslint/types": "^8.72.2",
46
46
  "@typescript-eslint/utils": "^8.72.2",
47
47
  "ts-pattern": "^5.9.2"
@@ -50,12 +50,12 @@
50
50
  "@local/configs": "0.0.0",
51
51
  "@local/eff": "0.0.0",
52
52
  "@local/testkit": "0.0.0",
53
- "@tsconfig/node20": "^20.1.10",
53
+ "@tsconfig/node20": "^20.1.11",
54
54
  "@types/node": "^20.19.43",
55
55
  "@types/react": "^19.3.0",
56
56
  "@types/react-dom": "^19.3.0",
57
57
  "dedent": "^1.7.2",
58
- "eslint": "^10.14.0",
58
+ "eslint": "^10.15.0",
59
59
  "tsdown": "^0.23.7",
60
60
  "typescript": "6.0.3"
61
61
  },