eslint-plugin-react-web-api 1.52.3-beta.12 → 1.52.3-beta.13

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.
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ var eff = require('@eslint-react/eff');
7
7
  var VAR = require('@eslint-react/var');
8
8
  var utils = require('@typescript-eslint/utils');
9
9
  var tsPattern = require('ts-pattern');
10
+ var types = require('@typescript-eslint/types');
10
11
 
11
12
  function _interopNamespace(e) {
12
13
  if (e && e.__esModule) return e;
@@ -56,11 +57,25 @@ var settings = {
56
57
 
57
58
  // package.json
58
59
  var name2 = "eslint-plugin-react-web-api";
59
- var version = "1.52.3-beta.12";
60
+ var version = "1.52.3-beta.13";
60
61
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("web-api"));
61
62
  function getPhaseKindOfFunction(node) {
62
63
  return tsPattern.match(node).when(ER4__namespace.isFunctionOfUseEffectSetup, () => "setup").when(ER4__namespace.isFunctionOfUseEffectCleanup, () => "cleanup").when(ER4__namespace.isFunctionOfComponentDidMount, () => "mount").when(ER4__namespace.isFunctionOfComponentWillUnmount, () => "unmount").otherwise(() => null);
63
64
  }
65
+ var isControlFlow = eff.or(
66
+ AST__namespace.isLoop,
67
+ AST__namespace.isOneOf([
68
+ types.AST_NODE_TYPES.IfStatement,
69
+ types.AST_NODE_TYPES.SwitchStatement
70
+ ])
71
+ );
72
+ var isConditional = eff.or(
73
+ isControlFlow,
74
+ AST__namespace.isOneOf([
75
+ types.AST_NODE_TYPES.LogicalExpression,
76
+ types.AST_NODE_TYPES.ConditionalExpression
77
+ ])
78
+ );
64
79
 
65
80
  // src/rules/no-leaked-event-listener.ts
66
81
  var RULE_NAME = "no-leaked-event-listener";
@@ -565,7 +580,7 @@ function create3(context) {
565
580
  }
566
581
  const oentries = oEntries.filter((e) => ER4__namespace.isInstanceIdEqual(context, e.observer, id));
567
582
  const uentries = uEntries.filter((e) => ER4__namespace.isInstanceIdEqual(context, e.observer, id));
568
- const isDynamic = (node2) => node2?.type === utils.AST_NODE_TYPES.CallExpression || AST__namespace.isConditional(node2);
583
+ const isDynamic = (node2) => node2?.type === utils.AST_NODE_TYPES.CallExpression || isConditional(node2);
569
584
  const isPhaseNode = (node2) => node2 === phaseNode;
570
585
  const hasDynamicallyAdded = oentries.some((e) => !isPhaseNode(AST__namespace.findParentNode(e.node, eff.or(isDynamic, isPhaseNode))));
571
586
  if (hasDynamicallyAdded) {
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import { getDocsUrl, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
2
2
  import * as AST from '@eslint-react/ast';
3
3
  import * as ER4 from '@eslint-react/core';
4
- import { unit, or } from '@eslint-react/eff';
4
+ import { or, unit } from '@eslint-react/eff';
5
5
  import * as VAR from '@eslint-react/var';
6
- import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
6
+ import { ESLintUtils, AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/utils';
7
7
  import { match, isMatching, P } from 'ts-pattern';
8
+ import { AST_NODE_TYPES } from '@typescript-eslint/types';
8
9
 
9
10
  var __defProp = Object.defineProperty;
10
11
  var __export = (target, all) => {
@@ -32,11 +33,25 @@ var settings = {
32
33
 
33
34
  // package.json
34
35
  var name2 = "eslint-plugin-react-web-api";
35
- var version = "1.52.3-beta.12";
36
+ var version = "1.52.3-beta.13";
36
37
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("web-api"));
37
38
  function getPhaseKindOfFunction(node) {
38
39
  return match(node).when(ER4.isFunctionOfUseEffectSetup, () => "setup").when(ER4.isFunctionOfUseEffectCleanup, () => "cleanup").when(ER4.isFunctionOfComponentDidMount, () => "mount").when(ER4.isFunctionOfComponentWillUnmount, () => "unmount").otherwise(() => null);
39
40
  }
41
+ var isControlFlow = or(
42
+ AST.isLoop,
43
+ AST.isOneOf([
44
+ AST_NODE_TYPES.IfStatement,
45
+ AST_NODE_TYPES.SwitchStatement
46
+ ])
47
+ );
48
+ var isConditional = or(
49
+ isControlFlow,
50
+ AST.isOneOf([
51
+ AST_NODE_TYPES.LogicalExpression,
52
+ AST_NODE_TYPES.ConditionalExpression
53
+ ])
54
+ );
40
55
 
41
56
  // src/rules/no-leaked-event-listener.ts
42
57
  var RULE_NAME = "no-leaked-event-listener";
@@ -48,9 +63,9 @@ var defaultOptions = {
48
63
  };
49
64
  function getCallKind(node) {
50
65
  switch (true) {
51
- case (node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("addEventListener", "removeEventListener", "abort"))(node.callee.name)):
66
+ case (node.callee.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("addEventListener", "removeEventListener", "abort"))(node.callee.name)):
52
67
  return node.callee.name;
53
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && isMatching(P.union("addEventListener", "removeEventListener", "abort"))(node.callee.property.name)):
68
+ case (node.callee.type === AST_NODE_TYPES$1.MemberExpression && node.callee.property.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("addEventListener", "removeEventListener", "abort"))(node.callee.property.name)):
54
69
  return node.callee.property.name;
55
70
  default:
56
71
  return "other";
@@ -62,10 +77,10 @@ function getFunctionKind(node) {
62
77
  function getSignalValueExpression(node, initialScope) {
63
78
  if (node == null) return unit;
64
79
  switch (node.type) {
65
- case AST_NODE_TYPES.Identifier: {
80
+ case AST_NODE_TYPES$1.Identifier: {
66
81
  return getSignalValueExpression(VAR.getVariableInitNode(VAR.findVariable(node, initialScope), 0), initialScope);
67
82
  }
68
- case AST_NODE_TYPES.MemberExpression:
83
+ case AST_NODE_TYPES$1.MemberExpression:
69
84
  return node;
70
85
  default:
71
86
  return unit;
@@ -76,11 +91,11 @@ function getOptions(node, initialScope) {
76
91
  return VAR.findPropertyInProperties(propName, properties, initialScope);
77
92
  }
78
93
  function getPropValue(prop, filter = (a) => true) {
79
- if (prop?.type !== AST_NODE_TYPES.Property) return unit;
94
+ if (prop?.type !== AST_NODE_TYPES$1.Property) return unit;
80
95
  const { value } = prop;
81
96
  let v = value;
82
97
  switch (value.type) {
83
- case AST_NODE_TYPES.Literal: {
98
+ case AST_NODE_TYPES$1.Literal: {
84
99
  v = value.value;
85
100
  break;
86
101
  }
@@ -93,22 +108,22 @@ function getOptions(node, initialScope) {
93
108
  }
94
109
  function getOpts(node2) {
95
110
  switch (node2.type) {
96
- case AST_NODE_TYPES.Identifier: {
111
+ case AST_NODE_TYPES$1.Identifier: {
97
112
  const variable = VAR.findVariable(node2, initialScope);
98
113
  const variableNode = VAR.getVariableInitNode(variable, 0);
99
- if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
114
+ if (variableNode?.type === AST_NODE_TYPES$1.ObjectExpression) {
100
115
  return getOpts(variableNode);
101
116
  }
102
117
  return defaultOptions;
103
118
  }
104
- case AST_NODE_TYPES.Literal: {
119
+ case AST_NODE_TYPES$1.Literal: {
105
120
  return { ...defaultOptions, capture: Boolean(node2.value) };
106
121
  }
107
- case AST_NODE_TYPES.ObjectExpression: {
122
+ case AST_NODE_TYPES$1.ObjectExpression: {
108
123
  const pCapture = findProp(node2.properties, "capture");
109
124
  const vCapture = !!getPropValue(pCapture);
110
125
  const pSignal = findProp(node2.properties, "signal");
111
- const vSignal = pSignal?.type === AST_NODE_TYPES.Property ? getSignalValueExpression(pSignal.value, initialScope) : unit;
126
+ const vSignal = pSignal?.type === AST_NODE_TYPES$1.Property ? getSignalValueExpression(pSignal.value, initialScope) : unit;
112
127
  return { capture: vCapture, signal: vSignal };
113
128
  }
114
129
  default: {
@@ -149,7 +164,7 @@ function create(context) {
149
164
  const abortedSignals = [];
150
165
  function isSameObject(a, b) {
151
166
  switch (true) {
152
- case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
167
+ case (a.type === AST_NODE_TYPES$1.MemberExpression && b.type === AST_NODE_TYPES$1.MemberExpression):
153
168
  return AST.isNodeEqual(a.object, b.object);
154
169
  // TODO: Maybe there other cases to consider here.
155
170
  default:
@@ -271,9 +286,9 @@ var RULE_NAME2 = "no-leaked-interval";
271
286
  var RULE_FEATURES2 = [];
272
287
  function getCallKind2(node) {
273
288
  switch (true) {
274
- case (node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setInterval", "clearInterval"))(node.callee.name)):
289
+ case (node.callee.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("setInterval", "clearInterval"))(node.callee.name)):
275
290
  return node.callee.name;
276
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setInterval", "clearInterval"))(node.callee.property.name)):
291
+ case (node.callee.type === AST_NODE_TYPES$1.MemberExpression && node.callee.property.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("setInterval", "clearInterval"))(node.callee.property.name)):
277
292
  return node.callee.property.name;
278
293
  default:
279
294
  return "other";
@@ -399,16 +414,16 @@ function create2(context) {
399
414
  var RULE_NAME3 = "no-leaked-resize-observer";
400
415
  var RULE_FEATURES3 = [];
401
416
  function isNewResizeObserver(node) {
402
- return node?.type === AST_NODE_TYPES.NewExpression && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "ResizeObserver";
417
+ return node?.type === AST_NODE_TYPES$1.NewExpression && node.callee.type === AST_NODE_TYPES$1.Identifier && node.callee.name === "ResizeObserver";
403
418
  }
404
419
  function isFromObserver(context, node) {
405
420
  switch (true) {
406
- case node.type === AST_NODE_TYPES.Identifier: {
421
+ case node.type === AST_NODE_TYPES$1.Identifier: {
407
422
  const initialScope = context.sourceCode.getScope(node);
408
423
  const object = VAR.getVariableInitNode(VAR.findVariable(node, initialScope), 0);
409
424
  return isNewResizeObserver(object);
410
425
  }
411
- case node.type === AST_NODE_TYPES.MemberExpression:
426
+ case node.type === AST_NODE_TYPES$1.MemberExpression:
412
427
  return isFromObserver(context, node.object);
413
428
  default:
414
429
  return false;
@@ -416,9 +431,9 @@ function isFromObserver(context, node) {
416
431
  }
417
432
  function getCallKind3(context, node) {
418
433
  switch (true) {
419
- case (node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("observe", "unobserve", "disconnect"))(node.callee.name) && isFromObserver(context, node.callee)):
434
+ case (node.callee.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("observe", "unobserve", "disconnect"))(node.callee.name) && isFromObserver(context, node.callee)):
420
435
  return node.callee.name;
421
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && isMatching(P.union("observe", "unobserve", "disconnect"))(node.callee.property.name) && isFromObserver(context, node.callee)):
436
+ case (node.callee.type === AST_NODE_TYPES$1.MemberExpression && node.callee.property.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("observe", "unobserve", "disconnect"))(node.callee.property.name) && isFromObserver(context, node.callee)):
422
437
  return node.callee.property.name;
423
438
  default:
424
439
  return "other";
@@ -463,7 +478,7 @@ function create3(context) {
463
478
  fEntries.pop();
464
479
  },
465
480
  ["CallExpression"](node) {
466
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) {
481
+ if (node.callee.type !== AST_NODE_TYPES$1.MemberExpression) {
467
482
  return;
468
483
  }
469
484
  const fKind = fEntries.findLast((x) => x.kind !== "other")?.kind;
@@ -541,7 +556,7 @@ function create3(context) {
541
556
  }
542
557
  const oentries = oEntries.filter((e) => ER4.isInstanceIdEqual(context, e.observer, id));
543
558
  const uentries = uEntries.filter((e) => ER4.isInstanceIdEqual(context, e.observer, id));
544
- const isDynamic = (node2) => node2?.type === AST_NODE_TYPES.CallExpression || AST.isConditional(node2);
559
+ const isDynamic = (node2) => node2?.type === AST_NODE_TYPES$1.CallExpression || isConditional(node2);
545
560
  const isPhaseNode = (node2) => node2 === phaseNode;
546
561
  const hasDynamicallyAdded = oentries.some((e) => !isPhaseNode(AST.findParentNode(e.node, or(isDynamic, isPhaseNode))));
547
562
  if (hasDynamicallyAdded) {
@@ -562,9 +577,9 @@ var RULE_NAME4 = "no-leaked-timeout";
562
577
  var RULE_FEATURES4 = [];
563
578
  function getCallKind4(node) {
564
579
  switch (true) {
565
- case (node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setTimeout", "clearTimeout"))(node.callee.name)):
580
+ case (node.callee.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("setTimeout", "clearTimeout"))(node.callee.name)):
566
581
  return node.callee.name;
567
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setTimeout", "clearTimeout"))(node.callee.property.name)):
582
+ case (node.callee.type === AST_NODE_TYPES$1.MemberExpression && node.callee.property.type === AST_NODE_TYPES$1.Identifier && isMatching(P.union("setTimeout", "clearTimeout"))(node.callee.property.name)):
568
583
  return node.callee.property.name;
569
584
  default:
570
585
  return "other";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "1.52.3-beta.12",
3
+ "version": "1.52.3-beta.13",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -43,17 +43,17 @@
43
43
  "./package.json"
44
44
  ],
45
45
  "dependencies": {
46
- "@typescript-eslint/scope-manager": "^8.35.1",
47
- "@typescript-eslint/types": "^8.35.1",
48
- "@typescript-eslint/utils": "^8.35.1",
46
+ "@typescript-eslint/scope-manager": "^8.36.0",
47
+ "@typescript-eslint/types": "^8.36.0",
48
+ "@typescript-eslint/utils": "^8.36.0",
49
49
  "string-ts": "^2.2.1",
50
50
  "ts-pattern": "^5.7.1",
51
- "@eslint-react/kit": "1.52.3-beta.12",
52
- "@eslint-react/ast": "1.52.3-beta.12",
53
- "@eslint-react/shared": "1.52.3-beta.12",
54
- "@eslint-react/eff": "1.52.3-beta.12",
55
- "@eslint-react/var": "1.52.3-beta.12",
56
- "@eslint-react/core": "1.52.3-beta.12"
51
+ "@eslint-react/core": "1.52.3-beta.13",
52
+ "@eslint-react/ast": "1.52.3-beta.13",
53
+ "@eslint-react/eff": "1.52.3-beta.13",
54
+ "@eslint-react/kit": "1.52.3-beta.13",
55
+ "@eslint-react/shared": "1.52.3-beta.13",
56
+ "@eslint-react/var": "1.52.3-beta.13"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/react": "^19.1.8",