eslint-plugin-react-web-api 5.30.0 → 5.30.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 +133 -80
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -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.0";
23
+ var version = "5.30.2";
24
24
  // src/utils/create-rule.ts
25
25
  function getDocsUrl(ruleName) {
26
26
  return `https://eslint-react.xyz/docs/rules/web-api-${ruleName}`;
@@ -140,14 +140,14 @@ function getCallKind$5(node) {
140
140
  if (name != null && isMatching(P.union("addEventListener", "removeEventListener"))(name)) return name;
141
141
  return "other";
142
142
  }
143
- function isGlobalObject(node) {
143
+ function isGlobalObject$1(node) {
144
144
  return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
145
145
  }
146
146
  function isSameObject(a, b, isEqual = Compare.isEqual) {
147
147
  switch (true) {
148
148
  case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isEqual(a.object, b.object);
149
- case a.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(a.object);
150
- case b.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(b.object);
149
+ case a.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject$1(a.object);
150
+ case b.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject$1(b.object);
151
151
  default: return true;
152
152
  }
153
153
  }
@@ -462,84 +462,56 @@ function resolveToObjectExpression(context, node) {
462
462
  default: return null;
463
463
  }
464
464
  }
465
- // src/rules/no-leaked-fetch/no-leaked-fetch.ts
466
- const RULE_NAME$4 = "no-leaked-fetch";
467
- const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
468
- function getCallKind$4(node) {
469
- const name = Extract.getCalleeName(node);
470
- if (name != null && isMatching(P.union("fetch", "abort"))(name)) return name;
471
- return "other";
465
+ function isGlobalObject(node) {
466
+ return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
472
467
  }
473
- function getControllerFromSignal(context, node, seen = /* @__PURE__ */ new Set()) {
474
- node = Extract.unwrap(node);
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) {
475
477
  switch (node.type) {
476
- case AST_NODE_TYPES.MemberExpression: return {
477
- controller: node.object,
478
- isParamSignal: false
479
- };
480
- case AST_NODE_TYPES.Identifier: {
481
- if (seen.has(node)) return {
482
- controller: null,
483
- isParamSignal: false
484
- };
485
- seen.add(node);
486
- const resolved = resolveOrigin(context, node);
487
- const resolvedUnwrapped = resolved == null ? null : Extract.unwrap(resolved);
488
- if (resolvedUnwrapped?.type === AST_NODE_TYPES.MemberExpression) return {
489
- controller: resolvedUnwrapped.object,
490
- isParamSignal: false
491
- };
492
- if (resolved != null && Check.isFunction(resolved)) return {
493
- controller: node,
494
- isParamSignal: true
495
- };
496
- if (resolvedUnwrapped != null) return getControllerFromSignal(context, resolvedUnwrapped, seen);
497
- return {
498
- controller: null,
499
- isParamSignal: false
500
- };
501
- }
502
- default: return {
503
- controller: null,
504
- isParamSignal: false
505
- };
478
+ 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);
482
+ case AST_NODE_TYPES.BlockStatement:
483
+ 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);
486
+ case AST_NODE_TYPES.ForInStatement:
487
+ case AST_NODE_TYPES.ForOfStatement: return node.left.type === AST_NODE_TYPES.VariableDeclaration && statementBindsName(node.left, name);
488
+ default: return false;
506
489
  }
507
490
  }
508
- function getFetchController(context, node) {
509
- const [, optionsArg] = node.arguments;
510
- if (optionsArg == null) return {
511
- controller: null,
512
- isParamSignal: false
513
- };
514
- const options = resolveToObjectExpression(context, optionsArg);
515
- if (options == null) return {
516
- controller: null,
517
- isParamSignal: false
518
- };
519
- const findSignal = (properties) => {
520
- for (const property of properties) {
521
- if (property.type === AST_NODE_TYPES.Property) {
522
- const key = Extract.unwrap(property.key);
523
- if ((!property.computed && Check.isIdentifier(key) ? key.name : key.type === AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0 ? key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null : null) === "signal") return property;
524
- }
525
- if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
526
- const found = findSignal(property.argument.properties);
527
- if (found != null) return found;
528
- }
529
- }
530
- return null;
531
- };
532
- const signalProp = findSignal(options.properties);
533
- if (signalProp?.type !== AST_NODE_TYPES.Property) return {
534
- controller: null,
535
- isParamSignal: false
536
- };
537
- return getControllerFromSignal(context, signalProp.value);
491
+ function statementBindsName(statement, name) {
492
+ switch (statement.type) {
493
+ case AST_NODE_TYPES.FunctionDeclaration:
494
+ 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));
496
+ 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);
498
+ 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
+ case AST_NODE_TYPES.TSImportEqualsDeclaration:
500
+ case AST_NODE_TYPES.TSEnumDeclaration: return statement.id.name === name;
501
+ case AST_NODE_TYPES.TSModuleDeclaration: return statement.id.type === AST_NODE_TYPES.Identifier && statement.id.name === name;
502
+ default: return false;
503
+ }
538
504
  }
539
- function getAbortController(node) {
540
- const callee = Extract.unwrap(node.callee);
541
- if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.object;
542
- return null;
505
+ function patternBindsName(pattern, name) {
506
+ switch (pattern.type) {
507
+ 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);
513
+ default: return false;
514
+ }
543
515
  }
544
516
  var no_leaked_fetch_default = createRule({
545
517
  meta: {
@@ -551,7 +523,7 @@ var no_leaked_fetch_default = createRule({
551
523
  },
552
524
  schema: []
553
525
  },
554
- name: RULE_NAME$4,
526
+ name: "no-leaked-fetch",
555
527
  create: create$4
556
528
  });
557
529
  function create$4(context) {
@@ -560,7 +532,7 @@ function create$4(context) {
560
532
  const fetchEntries = [];
561
533
  const abortEntries = [];
562
534
  return {
563
- ["CallExpression"](node) {
535
+ CallExpression(node) {
564
536
  match(getCallKind$4(node)).with("fetch", () => {
565
537
  const fn = Traverse.findParent(node, Check.isFunction);
566
538
  if (fn == null || !isUseEffectSetupCallback(fn)) return;
@@ -581,7 +553,7 @@ function create$4(context) {
581
553
  });
582
554
  }).otherwise(() => null);
583
555
  },
584
- ["Program:exit"]() {
556
+ "Program:exit"() {
585
557
  for (const fEntry of fetchEntries) {
586
558
  const controller = fEntry.controller;
587
559
  if (controller == null) {
@@ -600,6 +572,87 @@ function create$4(context) {
600
572
  }
601
573
  };
602
574
  }
575
+ const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
576
+ function getCallKind$4(node) {
577
+ const callee = Extract.unwrap(node.callee);
578
+ switch (true) {
579
+ case Check.isIdentifier(callee, "fetch") && !isNameBoundInEnclosingScopes("fetch", node): return "fetch";
580
+ case callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && Check.isIdentifier(callee.property, "fetch") && isGlobalObject(Extract.unwrap(callee.object)): return "fetch";
581
+ case Extract.getCalleeName(node) === "abort": return "abort";
582
+ default: return "other";
583
+ }
584
+ }
585
+ function getFetchController(context, node) {
586
+ const [, optionsArg] = node.arguments;
587
+ if (optionsArg == null) return {
588
+ controller: null,
589
+ isParamSignal: false
590
+ };
591
+ const options = resolveToObjectExpression(context, optionsArg);
592
+ if (options == null) return {
593
+ controller: null,
594
+ isParamSignal: false
595
+ };
596
+ const signalProp = findSignalProperty(options.properties);
597
+ if (signalProp?.type !== AST_NODE_TYPES.Property) return {
598
+ controller: null,
599
+ isParamSignal: false
600
+ };
601
+ return getControllerFromSignal(context, signalProp.value);
602
+ }
603
+ function getControllerFromSignal(context, node, seen = /* @__PURE__ */ new Set()) {
604
+ node = Extract.unwrap(node);
605
+ switch (node.type) {
606
+ case AST_NODE_TYPES.MemberExpression: return {
607
+ controller: node.object,
608
+ isParamSignal: false
609
+ };
610
+ case AST_NODE_TYPES.Identifier: {
611
+ if (seen.has(node)) return {
612
+ controller: null,
613
+ isParamSignal: false
614
+ };
615
+ seen.add(node);
616
+ const resolved = resolveOrigin(context, node);
617
+ const resolvedUnwrapped = resolved == null ? null : Extract.unwrap(resolved);
618
+ if (resolvedUnwrapped?.type === AST_NODE_TYPES.MemberExpression) return {
619
+ controller: resolvedUnwrapped.object,
620
+ isParamSignal: false
621
+ };
622
+ if (resolved != null && Check.isFunction(resolved)) return {
623
+ controller: node,
624
+ isParamSignal: true
625
+ };
626
+ if (resolvedUnwrapped != null) return getControllerFromSignal(context, resolvedUnwrapped, seen);
627
+ return {
628
+ controller: null,
629
+ isParamSignal: false
630
+ };
631
+ }
632
+ default: return {
633
+ controller: null,
634
+ isParamSignal: false
635
+ };
636
+ }
637
+ }
638
+ function findSignalProperty(properties) {
639
+ for (const property of properties) {
640
+ if (property.type === AST_NODE_TYPES.Property) {
641
+ const key = Extract.unwrap(property.key);
642
+ if ((!property.computed && Check.isIdentifier(key) ? key.name : key.type === AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0 ? key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null : null) === "signal") return property;
643
+ }
644
+ if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
645
+ const found = findSignalProperty(property.argument.properties);
646
+ if (found != null) return found;
647
+ }
648
+ }
649
+ return null;
650
+ }
651
+ function getAbortController(node) {
652
+ const callee = Extract.unwrap(node.callee);
653
+ if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.object;
654
+ return null;
655
+ }
603
656
  // src/rules/no-leaked-intersection-observer/lib.ts
604
657
  function isNewObserver$1(node, name) {
605
658
  if (node?.type !== AST_NODE_TYPES.NewExpression) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "5.30.0",
3
+ "version": "5.30.2",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -37,13 +37,13 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint-react/ast": "5.30.0",
41
- "@eslint-react/core": "5.30.0",
42
- "@eslint-react/eslint": "5.30.0",
43
- "@eslint-react/shared": "5.30.0",
44
- "@eslint-react/var": "5.30.0",
45
- "@typescript-eslint/types": "^8.72.1",
46
- "@typescript-eslint/utils": "^8.72.1",
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",
45
+ "@typescript-eslint/types": "^8.72.2",
46
+ "@typescript-eslint/utils": "^8.72.2",
47
47
  "ts-pattern": "^5.9.2"
48
48
  },
49
49
  "devDependencies": {