eslint-plugin-react-web-api 5.24.0-beta.1 → 5.24.0
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 +29 -10
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -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.24.0
|
|
30
|
+
var version = "5.24.0";
|
|
31
31
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/utils/create-rule.ts
|
|
@@ -38,10 +38,23 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region ../../.pkgs/eff/dist/index.js
|
|
41
|
+
function and(a, b) {
|
|
42
|
+
return (data) => a(data) && b(data);
|
|
43
|
+
}
|
|
41
44
|
function or(a, b) {
|
|
42
45
|
return (data) => a(data) || b(data);
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
48
|
+
* A function that checks if the passed parameter is a string and narrows its type accordingly.
|
|
49
|
+
*
|
|
50
|
+
* @param data - The variable to check.
|
|
51
|
+
* @returns True if the passed input is a string, false otherwise.
|
|
52
|
+
* @category guards
|
|
53
|
+
*/
|
|
54
|
+
function isString(data) {
|
|
55
|
+
return typeof data === "string";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
45
58
|
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
46
59
|
* to right.
|
|
47
60
|
*
|
|
@@ -574,6 +587,7 @@ function getOptions(context, node) {
|
|
|
574
587
|
//#endregion
|
|
575
588
|
//#region src/rules/no-leaked-event-listener/no-leaked-event-listener.ts
|
|
576
589
|
const RULE_NAME$5 = "no-leaked-event-listener";
|
|
590
|
+
const isUseEffectCallback$5 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
577
591
|
function getCallKind$5(node) {
|
|
578
592
|
const name = Extract.getCalleeName(node);
|
|
579
593
|
if (name != null && isMatching(P.union("addEventListener", "removeEventListener"))(name)) return name;
|
|
@@ -616,7 +630,7 @@ function resolveCleanupCallee(context, node) {
|
|
|
616
630
|
for (const prop of init.properties) {
|
|
617
631
|
if (prop.type !== AST_NODE_TYPES.Property || prop.computed) continue;
|
|
618
632
|
const key = Extract.unwrap(prop.key);
|
|
619
|
-
if ((key.type === AST_NODE_TYPES.Identifier ? key.name : key.type === AST_NODE_TYPES.Literal &&
|
|
633
|
+
if ((key.type === AST_NODE_TYPES.Identifier ? key.name : key.type === AST_NODE_TYPES.Literal && isString(key.value) ? key.value : null) !== property.name) continue;
|
|
620
634
|
const value = Extract.unwrap(prop.value);
|
|
621
635
|
if (Check.isFunction(value)) return {
|
|
622
636
|
kind: "function",
|
|
@@ -681,7 +695,7 @@ function create$5(context) {
|
|
|
681
695
|
}
|
|
682
696
|
return {
|
|
683
697
|
["CallExpression"](node) {
|
|
684
|
-
const fn = Traverse.findParent(node,
|
|
698
|
+
const fn = Traverse.findParent(node, isUseEffectCallback$5);
|
|
685
699
|
if (fn == null) return;
|
|
686
700
|
const fKind = isUseEffectSetupCallback(fn) ? "setup" : "cleanup";
|
|
687
701
|
const setupFn = fKind === "setup" ? fn : Traverse.findParent(fn, Check.isFunction);
|
|
@@ -763,6 +777,7 @@ function resolveToObjectExpression(context, node) {
|
|
|
763
777
|
//#endregion
|
|
764
778
|
//#region src/rules/no-leaked-fetch/no-leaked-fetch.ts
|
|
765
779
|
const RULE_NAME$4 = "no-leaked-fetch";
|
|
780
|
+
const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
766
781
|
function getCallKind$4(node) {
|
|
767
782
|
const name = Extract.getCalleeName(node);
|
|
768
783
|
if (name != null && isMatching(P.union("fetch", "abort"))(name)) return name;
|
|
@@ -851,7 +866,7 @@ function create$4(context) {
|
|
|
851
866
|
node
|
|
852
867
|
});
|
|
853
868
|
}).with("abort", () => {
|
|
854
|
-
const fn = Traverse.findParent(node,
|
|
869
|
+
const fn = Traverse.findParent(node, isUseEffectCallback$4);
|
|
855
870
|
if (fn == null || !isUseEffectCleanupCallback(fn)) return;
|
|
856
871
|
const controller = getAbortController(node);
|
|
857
872
|
if (controller == null) return;
|
|
@@ -902,6 +917,7 @@ function isFromObserver$1(context, node, name) {
|
|
|
902
917
|
//#endregion
|
|
903
918
|
//#region src/rules/no-leaked-intersection-observer/no-leaked-intersection-observer.ts
|
|
904
919
|
const RULE_NAME$3 = "no-leaked-intersection-observer";
|
|
920
|
+
const isUseEffectCallback$3 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
905
921
|
function getCallKind$3(context, node) {
|
|
906
922
|
const callee = Extract.unwrap(node.callee);
|
|
907
923
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return "other";
|
|
@@ -932,7 +948,7 @@ function create$3(context) {
|
|
|
932
948
|
const dEntries = [];
|
|
933
949
|
return {
|
|
934
950
|
["CallExpression"](node) {
|
|
935
|
-
if (Traverse.findParent(node,
|
|
951
|
+
if (Traverse.findParent(node, isUseEffectCallback$3) == null) return;
|
|
936
952
|
const callee = Extract.unwrap(node.callee);
|
|
937
953
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
938
954
|
const { object } = callee;
|
|
@@ -963,7 +979,7 @@ function create$3(context) {
|
|
|
963
979
|
}).otherwise(() => null);
|
|
964
980
|
},
|
|
965
981
|
["NewExpression"](node) {
|
|
966
|
-
const fn = Traverse.findParent(node, (
|
|
982
|
+
const fn = Traverse.findParent(node, and(Check.isFunction, isUseEffectCallback$3));
|
|
967
983
|
if (fn == null) return;
|
|
968
984
|
if (!isNewObserver$1(node, "IntersectionObserver")) return;
|
|
969
985
|
const id = resolveEnclosingAssignmentTarget(node);
|
|
@@ -1010,6 +1026,7 @@ function create$3(context) {
|
|
|
1010
1026
|
//#endregion
|
|
1011
1027
|
//#region src/rules/no-leaked-interval/no-leaked-interval.ts
|
|
1012
1028
|
const RULE_NAME$2 = "no-leaked-interval";
|
|
1029
|
+
const isUseEffectCallback$2 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
1013
1030
|
function getCallKind$2(node) {
|
|
1014
1031
|
const name = Extract.getCalleeName(node);
|
|
1015
1032
|
if (name != null && isMatching(P.union("setInterval", "clearInterval"))(name)) return name;
|
|
@@ -1038,7 +1055,7 @@ function create$2(context) {
|
|
|
1038
1055
|
}
|
|
1039
1056
|
return {
|
|
1040
1057
|
["CallExpression"](node) {
|
|
1041
|
-
if (Traverse.findParent(node,
|
|
1058
|
+
if (Traverse.findParent(node, isUseEffectCallback$2) == null) return;
|
|
1042
1059
|
match(getCallKind$2(node)).with("setInterval", () => {
|
|
1043
1060
|
const intervalIdNode = resolveEnclosingAssignmentTarget(node);
|
|
1044
1061
|
if (intervalIdNode == null) {
|
|
@@ -1095,6 +1112,7 @@ function isFromObserver(context, node, name) {
|
|
|
1095
1112
|
//#endregion
|
|
1096
1113
|
//#region src/rules/no-leaked-resize-observer/no-leaked-resize-observer.ts
|
|
1097
1114
|
const RULE_NAME$1 = "no-leaked-resize-observer";
|
|
1115
|
+
const isUseEffectCallback$1 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
1098
1116
|
function getCallKind$1(context, node) {
|
|
1099
1117
|
const callee = Extract.unwrap(node.callee);
|
|
1100
1118
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return "other";
|
|
@@ -1125,7 +1143,7 @@ function create$1(context) {
|
|
|
1125
1143
|
const dEntries = [];
|
|
1126
1144
|
return {
|
|
1127
1145
|
["CallExpression"](node) {
|
|
1128
|
-
if (Traverse.findParent(node,
|
|
1146
|
+
if (Traverse.findParent(node, isUseEffectCallback$1) == null) return;
|
|
1129
1147
|
const callee = Extract.unwrap(node.callee);
|
|
1130
1148
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
1131
1149
|
const { object } = callee;
|
|
@@ -1156,7 +1174,7 @@ function create$1(context) {
|
|
|
1156
1174
|
}).otherwise(() => null);
|
|
1157
1175
|
},
|
|
1158
1176
|
["NewExpression"](node) {
|
|
1159
|
-
const fn = Traverse.findParent(node, (
|
|
1177
|
+
const fn = Traverse.findParent(node, and(Check.isFunction, isUseEffectCallback$1));
|
|
1160
1178
|
if (fn == null) return;
|
|
1161
1179
|
if (!isNewObserver(node, "ResizeObserver")) return;
|
|
1162
1180
|
const id = resolveEnclosingAssignmentTarget(node);
|
|
@@ -1203,6 +1221,7 @@ function create$1(context) {
|
|
|
1203
1221
|
//#endregion
|
|
1204
1222
|
//#region src/rules/no-leaked-timeout/no-leaked-timeout.ts
|
|
1205
1223
|
const RULE_NAME = "no-leaked-timeout";
|
|
1224
|
+
const isUseEffectCallback = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
1206
1225
|
function getCallKind(node) {
|
|
1207
1226
|
const name = Extract.getCalleeName(node);
|
|
1208
1227
|
if (name != null && isMatching(P.union("setTimeout", "clearTimeout"))(name)) return name;
|
|
@@ -1231,7 +1250,7 @@ function create(context) {
|
|
|
1231
1250
|
}
|
|
1232
1251
|
return {
|
|
1233
1252
|
["CallExpression"](node) {
|
|
1234
|
-
if (Traverse.findParent(node,
|
|
1253
|
+
if (Traverse.findParent(node, isUseEffectCallback) == null) return;
|
|
1235
1254
|
match(getCallKind(node)).with("setTimeout", () => {
|
|
1236
1255
|
const timeoutIdNode = resolveEnclosingAssignmentTarget(node);
|
|
1237
1256
|
if (timeoutIdNode == null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-web-api",
|
|
3
|
-
"version": "5.24.0
|
|
3
|
+
"version": "5.24.0",
|
|
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.24.0
|
|
41
|
-
"@eslint-react/core": "5.24.0
|
|
42
|
-
"@eslint-react/eslint": "5.24.0
|
|
43
|
-
"@eslint-react/shared": "5.24.0
|
|
44
|
-
"@eslint-react/var": "5.24.0
|
|
40
|
+
"@eslint-react/ast": "5.24.0",
|
|
41
|
+
"@eslint-react/core": "5.24.0",
|
|
42
|
+
"@eslint-react/eslint": "5.24.0",
|
|
43
|
+
"@eslint-react/shared": "5.24.0",
|
|
44
|
+
"@eslint-react/var": "5.24.0",
|
|
45
45
|
"@typescript-eslint/types": "^8.71.0",
|
|
46
46
|
"@typescript-eslint/utils": "^8.71.0",
|
|
47
47
|
"ts-pattern": "^5.9.0"
|