eslint-plugin-react-web-api 5.20.8 → 5.21.1

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 +19 -96
  2. package/package.json +13 -8
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
2
- import { ESLintUtils } from "@typescript-eslint/utils";
2
+ import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
3
3
  import { Check, Compare, Extract, Traverse } from "@eslint-react/ast";
4
4
  import { isUseEffectCleanupCallback, isUseEffectSetupCallback } from "@eslint-react/core";
5
5
  import "@eslint-react/eslint";
@@ -27,7 +27,7 @@ var __exportAll = (all, no_symbols) => {
27
27
  //#endregion
28
28
  //#region package.json
29
29
  var name$1 = "eslint-plugin-react-web-api";
30
- var version = "5.20.8";
30
+ var version = "5.21.1";
31
31
 
32
32
  //#endregion
33
33
  //#region src/utils/create-rule.ts
@@ -96,11 +96,6 @@ function getCallKind$5(node) {
96
96
  if (name != null && isMatching(P.union("addEventListener", "removeEventListener"))(name)) return name;
97
97
  return "other";
98
98
  }
99
- function getFunctionKind$5(node) {
100
- if (isUseEffectSetupCallback(node)) return "setup";
101
- if (isUseEffectCleanupCallback(node)) return "cleanup";
102
- return "other";
103
- }
104
99
  var no_leaked_event_listener_default = createRule({
105
100
  meta: {
106
101
  type: "problem",
@@ -118,7 +113,6 @@ var no_leaked_event_listener_default = createRule({
118
113
  function create$5(context) {
119
114
  if (!context.sourceCode.text.includes("addEventListener")) return {};
120
115
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
121
- const fEntries = [];
122
116
  const aEntries = [];
123
117
  const rEntries = [];
124
118
  function isSameObject(a, b) {
@@ -144,15 +138,10 @@ function create$5(context) {
144
138
  });
145
139
  }
146
140
  return {
147
- [":function"](node) {
148
- fEntries.push(getFunctionKind$5(node));
149
- },
150
- [":function:exit"]() {
151
- fEntries.pop();
152
- },
153
141
  ["CallExpression"](node) {
154
- const fKind = fEntries.findLast((kind) => kind !== "other");
155
- if (fKind == null) return;
142
+ const fn = Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n));
143
+ if (fn == null) return;
144
+ const fKind = isUseEffectSetupCallback(fn) ? "setup" : "cleanup";
156
145
  const callee = Extract.unwrap(node.callee);
157
146
  match(getCallKind$5(node)).with("addEventListener", (callKind) => {
158
147
  if (callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && isInitializedFromReactNative(callee.object.name, context.sourceCode.getScope(node))) return;
@@ -223,11 +212,6 @@ function getCallKind$4(node) {
223
212
  if (name != null && isMatching(P.union("fetch", "abort"))(name)) return name;
224
213
  return "other";
225
214
  }
226
- function getFunctionKind$4(node) {
227
- if (isUseEffectSetupCallback(node)) return "setup";
228
- if (isUseEffectCleanupCallback(node)) return "cleanup";
229
- return "other";
230
- }
231
215
  function getControllerFromSignal(context, node) {
232
216
  node = Extract.unwrap(node);
233
217
  switch (node.type) {
@@ -297,19 +281,13 @@ var no_leaked_fetch_default = createRule({
297
281
  function create$4(context) {
298
282
  if (!context.sourceCode.text.includes("fetch")) return {};
299
283
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
300
- const fEntries = [];
301
284
  const fetchEntries = [];
302
285
  const abortEntries = [];
303
286
  return {
304
- [":function"](node) {
305
- fEntries.push(getFunctionKind$4(node));
306
- },
307
- [":function:exit"]() {
308
- fEntries.pop();
309
- },
310
287
  ["CallExpression"](node) {
311
288
  match(getCallKind$4(node)).with("fetch", () => {
312
- if (fEntries.at(-1) !== "setup") return;
289
+ const fn = Traverse.findParent(node, Check.isFunction);
290
+ if (fn == null || !isUseEffectSetupCallback(fn)) return;
313
291
  const { controller, isParamSignal } = getFetchController(context, node);
314
292
  fetchEntries.push({
315
293
  controller,
@@ -317,7 +295,8 @@ function create$4(context) {
317
295
  node
318
296
  });
319
297
  }).with("abort", () => {
320
- if (fEntries.findLast((kind) => kind !== "other") !== "cleanup") return;
298
+ const fn = Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n));
299
+ if (fn == null || !isUseEffectCleanupCallback(fn)) return;
321
300
  const controller = getAbortController(node);
322
301
  if (controller == null) return;
323
302
  abortEntries.push({
@@ -851,11 +830,6 @@ function getCallKind$3(context, node) {
851
830
  if (name != null && isMatching(P.union("observe", "unobserve", "disconnect"))(name) && isFromObserver$1(context, callee, "IntersectionObserver")) return name;
852
831
  return "other";
853
832
  }
854
- function getFunctionKind$3(node) {
855
- if (isUseEffectSetupCallback(node)) return "setup";
856
- if (isUseEffectCleanupCallback(node)) return "cleanup";
857
- return "other";
858
- }
859
833
  var no_leaked_intersection_observer_default = createRule({
860
834
  meta: {
861
835
  type: "problem",
@@ -873,24 +847,13 @@ var no_leaked_intersection_observer_default = createRule({
873
847
  });
874
848
  function create$3(context) {
875
849
  if (!context.sourceCode.text.includes("IntersectionObserver")) return {};
876
- const fEntries = [];
877
850
  const observers = [];
878
851
  const oEntries = [];
879
852
  const uEntries = [];
880
853
  const dEntries = [];
881
854
  return {
882
- [":function"](node) {
883
- const kind = getFunctionKind$3(node);
884
- fEntries.push({
885
- kind,
886
- node
887
- });
888
- },
889
- [":function:exit"]() {
890
- fEntries.pop();
891
- },
892
855
  ["CallExpression"](node) {
893
- if (fEntries.findLast((x) => x.kind !== "other")?.kind == null) return;
856
+ if (!(Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)) != null)) return;
894
857
  const callee = Extract.unwrap(node.callee);
895
858
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
896
859
  const { object } = callee;
@@ -921,8 +884,8 @@ function create$3(context) {
921
884
  }).otherwise(() => null);
922
885
  },
923
886
  ["NewExpression"](node) {
924
- const fEntry = fEntries.findLast((x) => x.kind !== "other");
925
- if (fEntry == null) return;
887
+ const fn = Traverse.findParent(node, (n) => Check.isFunction(n) && (isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)));
888
+ if (fn == null) return;
926
889
  if (!isNewObserver$1(node, "IntersectionObserver")) return;
927
890
  const id = resolveEnclosingAssignmentTarget(node);
928
891
  if (id == null) {
@@ -935,7 +898,7 @@ function create$3(context) {
935
898
  observers.push({
936
899
  id,
937
900
  node,
938
- phaseNode: fEntry.node
901
+ phaseNode: fn
939
902
  });
940
903
  },
941
904
  ["Program:exit"]() {
@@ -973,11 +936,6 @@ function getCallKind$2(node) {
973
936
  if (name != null && isMatching(P.union("setInterval", "clearInterval"))(name)) return name;
974
937
  return "other";
975
938
  }
976
- function getFunctionKind$2(node) {
977
- if (isUseEffectSetupCallback(node)) return "setup";
978
- if (isUseEffectCleanupCallback(node)) return "cleanup";
979
- return "other";
980
- }
981
939
  var no_leaked_interval_default = createRule({
982
940
  meta: {
983
941
  type: "problem",
@@ -994,21 +952,14 @@ var no_leaked_interval_default = createRule({
994
952
  });
995
953
  function create$2(context) {
996
954
  if (!context.sourceCode.text.includes("setInterval")) return {};
997
- const fEntries = [];
998
955
  const sEntries = [];
999
956
  const cEntries = [];
1000
957
  function isInverseEntry(a, b) {
1001
958
  return isAssignmentTargetEqual(context, a.timerId, b.timerId);
1002
959
  }
1003
960
  return {
1004
- [":function"](node) {
1005
- fEntries.push(getFunctionKind$2(node));
1006
- },
1007
- [":function:exit"]() {
1008
- fEntries.pop();
1009
- },
1010
961
  ["CallExpression"](node) {
1011
- if (fEntries.findLast((kind) => kind !== "other") == null) return;
962
+ if (Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)) == null) return;
1012
963
  match(getCallKind$2(node)).with("setInterval", () => {
1013
964
  const intervalIdNode = resolveEnclosingAssignmentTarget(node);
1014
965
  if (intervalIdNode == null) {
@@ -1072,11 +1023,6 @@ function getCallKind$1(context, node) {
1072
1023
  if (name != null && isMatching(P.union("observe", "unobserve", "disconnect"))(name) && isFromObserver(context, callee, "ResizeObserver")) return name;
1073
1024
  return "other";
1074
1025
  }
1075
- function getFunctionKind$1(node) {
1076
- if (isUseEffectSetupCallback(node)) return "setup";
1077
- if (isUseEffectCleanupCallback(node)) return "cleanup";
1078
- return "other";
1079
- }
1080
1026
  var no_leaked_resize_observer_default = createRule({
1081
1027
  meta: {
1082
1028
  type: "problem",
@@ -1094,24 +1040,13 @@ var no_leaked_resize_observer_default = createRule({
1094
1040
  });
1095
1041
  function create$1(context) {
1096
1042
  if (!context.sourceCode.text.includes("ResizeObserver")) return {};
1097
- const fEntries = [];
1098
1043
  const observers = [];
1099
1044
  const oEntries = [];
1100
1045
  const uEntries = [];
1101
1046
  const dEntries = [];
1102
1047
  return {
1103
- [":function"](node) {
1104
- const kind = getFunctionKind$1(node);
1105
- fEntries.push({
1106
- kind,
1107
- node
1108
- });
1109
- },
1110
- [":function:exit"]() {
1111
- fEntries.pop();
1112
- },
1113
1048
  ["CallExpression"](node) {
1114
- if (fEntries.findLast((x) => x.kind !== "other")?.kind == null) return;
1049
+ if (!(Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)) != null)) return;
1115
1050
  const callee = Extract.unwrap(node.callee);
1116
1051
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
1117
1052
  const { object } = callee;
@@ -1142,8 +1077,8 @@ function create$1(context) {
1142
1077
  }).otherwise(() => null);
1143
1078
  },
1144
1079
  ["NewExpression"](node) {
1145
- const fEntry = fEntries.findLast((x) => x.kind !== "other");
1146
- if (fEntry == null) return;
1080
+ const fn = Traverse.findParent(node, (n) => Check.isFunction(n) && (isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)));
1081
+ if (fn == null) return;
1147
1082
  if (!isNewObserver(node, "ResizeObserver")) return;
1148
1083
  const id = resolveEnclosingAssignmentTarget(node);
1149
1084
  if (id == null) {
@@ -1156,7 +1091,7 @@ function create$1(context) {
1156
1091
  observers.push({
1157
1092
  id,
1158
1093
  node,
1159
- phaseNode: fEntry.node
1094
+ phaseNode: fn
1160
1095
  });
1161
1096
  },
1162
1097
  ["Program:exit"]() {
@@ -1194,11 +1129,6 @@ function getCallKind(node) {
1194
1129
  if (name != null && isMatching(P.union("setTimeout", "clearTimeout"))(name)) return name;
1195
1130
  return "other";
1196
1131
  }
1197
- function getFunctionKind(node) {
1198
- if (isUseEffectSetupCallback(node)) return "setup";
1199
- if (isUseEffectCleanupCallback(node)) return "cleanup";
1200
- return "other";
1201
- }
1202
1132
  var no_leaked_timeout_default = createRule({
1203
1133
  meta: {
1204
1134
  type: "problem",
@@ -1215,21 +1145,14 @@ var no_leaked_timeout_default = createRule({
1215
1145
  });
1216
1146
  function create(context) {
1217
1147
  if (!context.sourceCode.text.includes("setTimeout")) return {};
1218
- const fEntries = [];
1219
1148
  const sEntries = [];
1220
1149
  const cEntries = [];
1221
1150
  function isInverseEntry(a, b) {
1222
1151
  return isAssignmentTargetEqual(context, a.timerId, b.timerId);
1223
1152
  }
1224
1153
  return {
1225
- [":function"](node) {
1226
- fEntries.push(getFunctionKind(node));
1227
- },
1228
- [":function:exit"]() {
1229
- fEntries.pop();
1230
- },
1231
1154
  ["CallExpression"](node) {
1232
- if (fEntries.findLast((kind) => kind !== "other") == null) return;
1155
+ if (Traverse.findParent(node, (n) => isUseEffectSetupCallback(n) || isUseEffectCleanupCallback(n)) == null) return;
1233
1156
  match(getCallKind(node)).with("setTimeout", () => {
1234
1157
  const timeoutIdNode = resolveEnclosingAssignmentTarget(node);
1235
1158
  if (timeoutIdNode == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "5.20.8",
3
+ "version": "5.21.1",
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.20.8",
41
- "@eslint-react/core": "5.20.8",
42
- "@eslint-react/eslint": "5.20.8",
43
- "@eslint-react/shared": "5.20.8",
44
- "@eslint-react/var": "5.20.8",
45
- "@typescript-eslint/types": "^8.70.0",
46
- "@typescript-eslint/utils": "^8.70.0",
40
+ "@eslint-react/ast": "5.21.1",
41
+ "@eslint-react/core": "5.21.1",
42
+ "@eslint-react/eslint": "5.21.1",
43
+ "@eslint-react/shared": "5.21.1",
44
+ "@eslint-react/var": "5.21.1",
45
+ "@typescript-eslint/types": "^8.70.1",
46
+ "@typescript-eslint/utils": "^8.70.1",
47
47
  "ts-pattern": "^5.9.0"
48
48
  },
49
49
  "devDependencies": {
@@ -60,6 +60,11 @@
60
60
  "eslint": "*",
61
61
  "typescript": "*"
62
62
  },
63
+ "peerDependenciesMeta": {
64
+ "eslint": {
65
+ "optional": true
66
+ }
67
+ },
63
68
  "engines": {
64
69
  "node": ">=22.0.0"
65
70
  },