eslint-plugin-react-web-api 2.0.0-next.18 → 2.0.0-next.180
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/README.md +20 -17
- package/dist/index.d.ts +19 -44
- package/dist/index.js +621 -687
- package/package.json +16 -17
package/dist/index.js
CHANGED
|
@@ -1,737 +1,671 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as AST from
|
|
3
|
-
import * as
|
|
4
|
-
import {
|
|
5
|
-
import * as VAR from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { DEFAULT_ESLINT_REACT_SETTINGS, getConfigAdapters, getDocsUrl } from "@eslint-react/shared";
|
|
2
|
+
import * as AST from "@eslint-react/ast";
|
|
3
|
+
import * as ER from "@eslint-react/core";
|
|
4
|
+
import { or, unit } from "@eslint-react/eff";
|
|
5
|
+
import * as VAR from "@eslint-react/var";
|
|
6
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
7
|
+
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
8
|
+
import { P, isMatching, match } from "ts-pattern";
|
|
9
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/types";
|
|
9
10
|
|
|
11
|
+
//#region rolldown:runtime
|
|
10
12
|
var __defProp = Object.defineProperty;
|
|
11
|
-
var __export = (
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var __export = (all) => {
|
|
14
|
+
let target = {};
|
|
15
|
+
for (var name$2 in all) __defProp(target, name$2, {
|
|
16
|
+
get: all[name$2],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
return target;
|
|
14
20
|
};
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__export(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/configs/recommended.ts
|
|
24
|
+
var recommended_exports = __export({
|
|
25
|
+
name: () => name$1,
|
|
26
|
+
rules: () => rules,
|
|
27
|
+
settings: () => settings
|
|
22
28
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
var settings = {
|
|
31
|
-
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
29
|
+
const name$1 = "react-web-api/recommended";
|
|
30
|
+
const rules = {
|
|
31
|
+
"react-web-api/no-leaked-event-listener": "warn",
|
|
32
|
+
"react-web-api/no-leaked-interval": "warn",
|
|
33
|
+
"react-web-api/no-leaked-resize-observer": "warn",
|
|
34
|
+
"react-web-api/no-leaked-timeout": "warn"
|
|
32
35
|
};
|
|
36
|
+
const settings = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region package.json
|
|
40
|
+
var name = "eslint-plugin-react-web-api";
|
|
41
|
+
var version = "2.0.0-next.180";
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/utils/create-rule.ts
|
|
45
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl("web-api"));
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/utils/get-phase-kind-of-function.ts
|
|
38
49
|
function getPhaseKindOfFunction(node) {
|
|
39
|
-
|
|
50
|
+
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfUseEffectCleanup, () => "cleanup").when(isFunctionOfComponentDidMount, () => "mount").when(isFunctionOfComponentWillUnmount, () => "unmount").otherwise(() => null);
|
|
40
51
|
}
|
|
41
52
|
function isFunctionOfUseEffectSetup(node) {
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
if (node == null) return false;
|
|
54
|
+
return node.parent?.type === AST_NODE_TYPES$1.CallExpression && node.parent.arguments.at(0) === node && ER.isUseEffectLikeCall(node.parent);
|
|
44
55
|
}
|
|
45
56
|
function isFunctionOfUseEffectCleanup(node) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
if (node == null) return false;
|
|
58
|
+
const pReturn = AST.findParentNode(node, AST.is(AST_NODE_TYPES$1.ReturnStatement));
|
|
59
|
+
const pFunction = AST.findParentNode(node, AST.isFunction);
|
|
60
|
+
const pFunctionOfReturn = AST.findParentNode(pReturn, AST.isFunction);
|
|
61
|
+
if (pFunction !== pFunctionOfReturn) return false;
|
|
62
|
+
return isFunctionOfUseEffectSetup(pFunction);
|
|
52
63
|
}
|
|
53
64
|
function isFunctionOfComponentDidMount(node) {
|
|
54
|
-
|
|
65
|
+
return AST.isFunction(node) && ER.isComponentDidMount(node.parent) && node.parent.value === node;
|
|
55
66
|
}
|
|
56
67
|
function isFunctionOfComponentWillUnmount(node) {
|
|
57
|
-
|
|
68
|
+
return AST.isFunction(node) && ER.isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/utils/is-conditional.ts
|
|
73
|
+
const isControlFlow = or(AST.isLoop, AST.isOneOf([AST_NODE_TYPES$1.IfStatement, AST_NODE_TYPES$1.SwitchStatement]));
|
|
74
|
+
const isConditional = or(isControlFlow, AST.isOneOf([AST_NODE_TYPES$1.LogicalExpression, AST_NODE_TYPES$1.ConditionalExpression]));
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/rules/no-leaked-event-listener.ts
|
|
78
|
+
const RULE_NAME$3 = "no-leaked-event-listener";
|
|
79
|
+
const RULE_FEATURES$3 = [];
|
|
80
|
+
const defaultOptions = {
|
|
81
|
+
capture: false,
|
|
82
|
+
signal: unit
|
|
67
83
|
};
|
|
68
|
-
function getCallKind(node) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
default:
|
|
75
|
-
return "other";
|
|
76
|
-
}
|
|
84
|
+
function getCallKind$3(node) {
|
|
85
|
+
switch (true) {
|
|
86
|
+
case node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("addEventListener", "removeEventListener", "abort"))(node.callee.name): return node.callee.name;
|
|
87
|
+
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): return node.callee.property.name;
|
|
88
|
+
default: return "other";
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
|
-
function getFunctionKind(node) {
|
|
79
|
-
|
|
91
|
+
function getFunctionKind$1(node) {
|
|
92
|
+
return getPhaseKindOfFunction(node) ?? "other";
|
|
80
93
|
}
|
|
81
94
|
function getSignalValueExpression(node, initialScope) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return node;
|
|
89
|
-
default:
|
|
90
|
-
return _;
|
|
91
|
-
}
|
|
95
|
+
if (node == null) return unit;
|
|
96
|
+
switch (node.type) {
|
|
97
|
+
case AST_NODE_TYPES.Identifier: return getSignalValueExpression(VAR.getVariableDefinitionNode(VAR.findVariable(node, initialScope), 0), initialScope);
|
|
98
|
+
case AST_NODE_TYPES.MemberExpression: return node;
|
|
99
|
+
default: return unit;
|
|
100
|
+
}
|
|
92
101
|
}
|
|
93
102
|
function getOptions(node, initialScope) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return getOpts(node);
|
|
103
|
+
function findProp(properties, propName) {
|
|
104
|
+
return VAR.findProperty(propName, properties, initialScope);
|
|
105
|
+
}
|
|
106
|
+
function getPropValue(prop, filter = (a) => true) {
|
|
107
|
+
if (prop?.type !== AST_NODE_TYPES.Property) return unit;
|
|
108
|
+
const { value } = prop;
|
|
109
|
+
let v = value;
|
|
110
|
+
switch (value.type) {
|
|
111
|
+
case AST_NODE_TYPES.Literal:
|
|
112
|
+
v = value.value;
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
v = getStaticValue(value, initialScope)?.value;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return filter(v) ? v : unit;
|
|
119
|
+
}
|
|
120
|
+
function getOpts(node$1) {
|
|
121
|
+
switch (node$1.type) {
|
|
122
|
+
case AST_NODE_TYPES.Identifier: {
|
|
123
|
+
const variable = VAR.findVariable(node$1, initialScope);
|
|
124
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
125
|
+
if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) return getOpts(variableNode);
|
|
126
|
+
return defaultOptions;
|
|
127
|
+
}
|
|
128
|
+
case AST_NODE_TYPES.Literal: return {
|
|
129
|
+
...defaultOptions,
|
|
130
|
+
capture: Boolean(node$1.value)
|
|
131
|
+
};
|
|
132
|
+
case AST_NODE_TYPES.ObjectExpression: {
|
|
133
|
+
const pCapture = findProp(node$1.properties, "capture");
|
|
134
|
+
const vCapture = !!getPropValue(pCapture);
|
|
135
|
+
const pSignal = findProp(node$1.properties, "signal");
|
|
136
|
+
const vSignal = pSignal?.type === AST_NODE_TYPES.Property ? getSignalValueExpression(pSignal.value, initialScope) : unit;
|
|
137
|
+
return {
|
|
138
|
+
capture: vCapture,
|
|
139
|
+
signal: vSignal
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
default: return defaultOptions;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return getOpts(node);
|
|
139
146
|
}
|
|
140
147
|
var no_leaked_event_listener_default = createRule({
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
meta: {
|
|
149
|
+
type: "problem",
|
|
150
|
+
docs: {
|
|
151
|
+
description: "Prevents leaked `addEventListener` in a component or custom Hook.",
|
|
152
|
+
[Symbol.for("rule_features")]: RULE_FEATURES$3
|
|
153
|
+
},
|
|
154
|
+
messages: {
|
|
155
|
+
expectedRemoveEventListenerInCleanup: "An 'addEventListener' in '{{effectMethodKind}}' should have a corresponding 'removeEventListener' in its cleanup function.",
|
|
156
|
+
expectedRemoveEventListenerInUnmount: "An 'addEventListener' in 'componentDidMount' should have a corresponding 'removeEventListener' in 'componentWillUnmount' method.",
|
|
157
|
+
unexpectedInlineFunction: "A/an '{{eventMethodKind}}' should not have an inline listener function."
|
|
158
|
+
},
|
|
159
|
+
schema: []
|
|
160
|
+
},
|
|
161
|
+
name: RULE_NAME$3,
|
|
162
|
+
create: create$3,
|
|
163
|
+
defaultOptions: []
|
|
157
164
|
});
|
|
158
|
-
function create(context) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
if (rEntries.some((rEntry) => isInverseEntry(aEntry, rEntry))) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
switch (aEntry.phase) {
|
|
267
|
-
case "setup":
|
|
268
|
-
case "cleanup":
|
|
269
|
-
context.report({
|
|
270
|
-
messageId: "expectedRemoveEventListenerInCleanup",
|
|
271
|
-
node: aEntry.node,
|
|
272
|
-
data: {
|
|
273
|
-
effectMethodKind: "useEffect"
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
continue;
|
|
277
|
-
case "mount":
|
|
278
|
-
case "unmount":
|
|
279
|
-
context.report({
|
|
280
|
-
messageId: "expectedRemoveEventListenerInUnmount",
|
|
281
|
-
node: aEntry.node
|
|
282
|
-
});
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
};
|
|
165
|
+
function create$3(context) {
|
|
166
|
+
if (!context.sourceCode.text.includes("addEventListener")) return {};
|
|
167
|
+
if (!/use\w*Effect|componentDidMount|componentWillUnmount/u.test(context.sourceCode.text)) return {};
|
|
168
|
+
const fEntries = [];
|
|
169
|
+
const aEntries = [];
|
|
170
|
+
const rEntries = [];
|
|
171
|
+
const abortedSignals = [];
|
|
172
|
+
function isSameObject(a, b) {
|
|
173
|
+
switch (true) {
|
|
174
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return AST.isNodeEqual(a.object, b.object);
|
|
175
|
+
default: return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function isInverseEntry(aEntry, rEntry) {
|
|
179
|
+
const { type: aType, callee: aCallee, capture: aCapture, listener: aListener, phase: aPhase } = aEntry;
|
|
180
|
+
const { type: rType, callee: rCallee, capture: rCapture, listener: rListener, phase: rPhase } = rEntry;
|
|
181
|
+
if (!ER.isInversePhase(aPhase, rPhase)) return false;
|
|
182
|
+
return isSameObject(aCallee, rCallee) && AST.isNodeEqual(aListener, rListener) && VAR.isNodeValueEqual(aType, rType, [context.sourceCode.getScope(aType), context.sourceCode.getScope(rType)]) && aCapture === rCapture;
|
|
183
|
+
}
|
|
184
|
+
function checkInlineFunction(node, callKind, options) {
|
|
185
|
+
const listener = node.arguments.at(1);
|
|
186
|
+
if (!AST.isFunction(listener)) return;
|
|
187
|
+
if (options.signal != null) return;
|
|
188
|
+
context.report({
|
|
189
|
+
messageId: "unexpectedInlineFunction",
|
|
190
|
+
node: listener,
|
|
191
|
+
data: { eventMethodKind: callKind }
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
[":function"](node) {
|
|
196
|
+
const kind = getFunctionKind$1(node);
|
|
197
|
+
fEntries.push({
|
|
198
|
+
kind,
|
|
199
|
+
node
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
[":function:exit"]() {
|
|
203
|
+
fEntries.pop();
|
|
204
|
+
},
|
|
205
|
+
["CallExpression"](node) {
|
|
206
|
+
const fKind = fEntries.findLast((x) => x.kind !== "other")?.kind;
|
|
207
|
+
if (fKind == null) return;
|
|
208
|
+
if (!ER.ComponentPhaseRelevance.has(fKind)) return;
|
|
209
|
+
match(getCallKind$3(node)).with("addEventListener", (callKind) => {
|
|
210
|
+
const [type, listener, options] = node.arguments;
|
|
211
|
+
if (type == null || listener == null) return;
|
|
212
|
+
const opts = options == null ? defaultOptions : getOptions(options, context.sourceCode.getScope(options));
|
|
213
|
+
const { callee } = node;
|
|
214
|
+
checkInlineFunction(node, callKind, opts);
|
|
215
|
+
aEntries.push({
|
|
216
|
+
...opts,
|
|
217
|
+
kind: "addEventListener",
|
|
218
|
+
type,
|
|
219
|
+
node,
|
|
220
|
+
callee,
|
|
221
|
+
listener,
|
|
222
|
+
phase: fKind
|
|
223
|
+
});
|
|
224
|
+
}).with("removeEventListener", (callKind) => {
|
|
225
|
+
const [type, listener, options] = node.arguments;
|
|
226
|
+
if (type == null || listener == null) return;
|
|
227
|
+
const opts = options == null ? defaultOptions : getOptions(options, context.sourceCode.getScope(options));
|
|
228
|
+
const { callee } = node;
|
|
229
|
+
checkInlineFunction(node, callKind, opts);
|
|
230
|
+
rEntries.push({
|
|
231
|
+
...opts,
|
|
232
|
+
kind: "removeEventListener",
|
|
233
|
+
type,
|
|
234
|
+
node,
|
|
235
|
+
callee,
|
|
236
|
+
listener,
|
|
237
|
+
phase: fKind
|
|
238
|
+
});
|
|
239
|
+
}).with("abort", () => {
|
|
240
|
+
abortedSignals.push(node.callee);
|
|
241
|
+
}).otherwise(() => null);
|
|
242
|
+
},
|
|
243
|
+
["Program:exit"]() {
|
|
244
|
+
for (const aEntry of aEntries) {
|
|
245
|
+
const signal = aEntry.signal;
|
|
246
|
+
if (signal != null && abortedSignals.some((a) => isSameObject(a, signal))) continue;
|
|
247
|
+
if (rEntries.some((rEntry) => isInverseEntry(aEntry, rEntry))) continue;
|
|
248
|
+
switch (aEntry.phase) {
|
|
249
|
+
case "setup":
|
|
250
|
+
case "cleanup":
|
|
251
|
+
context.report({
|
|
252
|
+
messageId: "expectedRemoveEventListenerInCleanup",
|
|
253
|
+
node: aEntry.node,
|
|
254
|
+
data: { effectMethodKind: "useEffect" }
|
|
255
|
+
});
|
|
256
|
+
continue;
|
|
257
|
+
case "mount":
|
|
258
|
+
case "unmount":
|
|
259
|
+
context.report({
|
|
260
|
+
messageId: "expectedRemoveEventListenerInUnmount",
|
|
261
|
+
node: aEntry.node
|
|
262
|
+
});
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
288
268
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/rules/no-leaked-interval.ts
|
|
272
|
+
const RULE_NAME$2 = "no-leaked-interval";
|
|
273
|
+
const RULE_FEATURES$2 = [];
|
|
274
|
+
function getCallKind$2(node) {
|
|
275
|
+
switch (true) {
|
|
276
|
+
case node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setInterval", "clearInterval"))(node.callee.name): return node.callee.name;
|
|
277
|
+
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): return node.callee.property.name;
|
|
278
|
+
default: return "other";
|
|
279
|
+
}
|
|
300
280
|
}
|
|
301
281
|
var no_leaked_interval_default = createRule({
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
282
|
+
meta: {
|
|
283
|
+
type: "problem",
|
|
284
|
+
docs: {
|
|
285
|
+
description: "Prevents leaked `setInterval` in a component or custom Hook.",
|
|
286
|
+
[Symbol.for("rule_features")]: RULE_FEATURES$2
|
|
287
|
+
},
|
|
288
|
+
messages: {
|
|
289
|
+
expectedClearIntervalInCleanup: "A 'setInterval' created in '{{ kind }}' must be cleared with 'clearInterval' in the cleanup function.",
|
|
290
|
+
expectedClearIntervalInUnmount: "A 'setInterval' created in '{{ kind }}' must be cleared with 'clearInterval' in the 'componentWillUnmount' method.",
|
|
291
|
+
expectedIntervalId: "A 'setInterval' must be assigned to a variable for proper cleanup."
|
|
292
|
+
},
|
|
293
|
+
schema: []
|
|
294
|
+
},
|
|
295
|
+
name: RULE_NAME$2,
|
|
296
|
+
create: create$2,
|
|
297
|
+
defaultOptions: []
|
|
318
298
|
});
|
|
319
|
-
function
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
continue;
|
|
403
|
-
case "mount":
|
|
404
|
-
case "unmount":
|
|
405
|
-
context.report({
|
|
406
|
-
messageId: "expectedClearIntervalInUnmount",
|
|
407
|
-
node: sEntry.node,
|
|
408
|
-
data: {
|
|
409
|
-
kind: "componentDidMount"
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
};
|
|
299
|
+
function create$2(context) {
|
|
300
|
+
if (!context.sourceCode.text.includes("setInterval")) return {};
|
|
301
|
+
const fEntries = [];
|
|
302
|
+
const sEntries = [];
|
|
303
|
+
const cEntries = [];
|
|
304
|
+
function isInverseEntry(a, b) {
|
|
305
|
+
return ER.isInstanceIdEqual(context, a.timerId, b.timerId);
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
[":function"](node) {
|
|
309
|
+
const kind = getPhaseKindOfFunction(node) ?? "other";
|
|
310
|
+
fEntries.push({
|
|
311
|
+
kind,
|
|
312
|
+
node
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
[":function:exit"]() {
|
|
316
|
+
fEntries.pop();
|
|
317
|
+
},
|
|
318
|
+
["CallExpression"](node) {
|
|
319
|
+
switch (getCallKind$2(node)) {
|
|
320
|
+
case "setInterval": {
|
|
321
|
+
const fEntry = fEntries.findLast((x) => x.kind !== "other");
|
|
322
|
+
if (fEntry == null) break;
|
|
323
|
+
if (!ER.ComponentPhaseRelevance.has(fEntry.kind)) break;
|
|
324
|
+
const intervalIdNode = VAR.findAssignmentTarget(node);
|
|
325
|
+
if (intervalIdNode == null) {
|
|
326
|
+
context.report({
|
|
327
|
+
messageId: "expectedIntervalId",
|
|
328
|
+
node
|
|
329
|
+
});
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
sEntries.push({
|
|
333
|
+
kind: "interval",
|
|
334
|
+
node,
|
|
335
|
+
callee: node.callee,
|
|
336
|
+
phase: fEntry.kind,
|
|
337
|
+
timerId: intervalIdNode
|
|
338
|
+
});
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "clearInterval": {
|
|
342
|
+
const fEntry = fEntries.findLast((x) => x.kind !== "other");
|
|
343
|
+
if (fEntry == null) break;
|
|
344
|
+
if (!ER.ComponentPhaseRelevance.has(fEntry.kind)) break;
|
|
345
|
+
const [intervalIdNode] = node.arguments;
|
|
346
|
+
if (intervalIdNode == null) break;
|
|
347
|
+
cEntries.push({
|
|
348
|
+
kind: "interval",
|
|
349
|
+
node,
|
|
350
|
+
callee: node.callee,
|
|
351
|
+
phase: fEntry.kind,
|
|
352
|
+
timerId: intervalIdNode
|
|
353
|
+
});
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
["Program:exit"]() {
|
|
359
|
+
for (const sEntry of sEntries) {
|
|
360
|
+
if (cEntries.some((cEntry) => isInverseEntry(sEntry, cEntry))) continue;
|
|
361
|
+
switch (sEntry.phase) {
|
|
362
|
+
case "setup":
|
|
363
|
+
case "cleanup":
|
|
364
|
+
context.report({
|
|
365
|
+
messageId: "expectedClearIntervalInCleanup",
|
|
366
|
+
node: sEntry.node,
|
|
367
|
+
data: { kind: "useEffect" }
|
|
368
|
+
});
|
|
369
|
+
continue;
|
|
370
|
+
case "mount":
|
|
371
|
+
case "unmount":
|
|
372
|
+
context.report({
|
|
373
|
+
messageId: "expectedClearIntervalInUnmount",
|
|
374
|
+
node: sEntry.node,
|
|
375
|
+
data: { kind: "componentDidMount" }
|
|
376
|
+
});
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
417
382
|
}
|
|
418
|
-
|
|
419
|
-
|
|
383
|
+
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/rules/no-leaked-resize-observer.ts
|
|
386
|
+
const RULE_NAME$1 = "no-leaked-resize-observer";
|
|
387
|
+
const RULE_FEATURES$1 = [];
|
|
420
388
|
function isNewResizeObserver(node) {
|
|
421
|
-
|
|
389
|
+
return node?.type === AST_NODE_TYPES.NewExpression && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "ResizeObserver";
|
|
422
390
|
}
|
|
423
391
|
function isFromObserver(context, node) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
392
|
+
switch (true) {
|
|
393
|
+
case node.type === AST_NODE_TYPES.Identifier: {
|
|
394
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
395
|
+
const object = VAR.getVariableDefinitionNode(VAR.findVariable(node, initialScope), 0);
|
|
396
|
+
return isNewResizeObserver(object);
|
|
397
|
+
}
|
|
398
|
+
case node.type === AST_NODE_TYPES.MemberExpression: return isFromObserver(context, node.object);
|
|
399
|
+
default: return false;
|
|
400
|
+
}
|
|
435
401
|
}
|
|
436
|
-
function
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
default:
|
|
443
|
-
return "other";
|
|
444
|
-
}
|
|
402
|
+
function getCallKind$1(context, node) {
|
|
403
|
+
switch (true) {
|
|
404
|
+
case node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("observe", "unobserve", "disconnect"))(node.callee.name) && isFromObserver(context, node.callee): return node.callee.name;
|
|
405
|
+
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): return node.callee.property.name;
|
|
406
|
+
default: return "other";
|
|
407
|
+
}
|
|
445
408
|
}
|
|
446
|
-
function
|
|
447
|
-
|
|
409
|
+
function getFunctionKind(node) {
|
|
410
|
+
return getPhaseKindOfFunction(node) ?? "other";
|
|
448
411
|
}
|
|
449
412
|
var no_leaked_resize_observer_default = createRule({
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
413
|
+
meta: {
|
|
414
|
+
type: "problem",
|
|
415
|
+
docs: {
|
|
416
|
+
description: "Prevents leaked `ResizeObserver` in a component or custom Hook.",
|
|
417
|
+
[Symbol.for("rule_features")]: RULE_FEATURES$1
|
|
418
|
+
},
|
|
419
|
+
messages: {
|
|
420
|
+
expectedDisconnectInControlFlow: "Dynamically added 'ResizeObserver.observe' should be cleared all at once using 'ResizeObserver.disconnect' in the cleanup function.",
|
|
421
|
+
expectedDisconnectOrUnobserveInCleanup: "A 'ResizeObserver' instance created in 'useEffect' must be disconnected in the cleanup function.",
|
|
422
|
+
unexpectedFloatingInstance: "A 'ResizeObserver' instance created in component or custom Hook must be assigned to a variable for proper cleanup."
|
|
423
|
+
},
|
|
424
|
+
schema: []
|
|
425
|
+
},
|
|
426
|
+
name: RULE_NAME$1,
|
|
427
|
+
create: create$1,
|
|
428
|
+
defaultOptions: []
|
|
466
429
|
});
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
for (const oEntry of oentries) {
|
|
571
|
-
if (uentries.some((uEntry) => ER4.isInstanceIdEqual(context, uEntry.element, oEntry.element))) {
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
context.report({ messageId: "expectedDisconnectOrUnobserveInCleanup", node: oEntry.node });
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
};
|
|
430
|
+
function create$1(context) {
|
|
431
|
+
if (!context.sourceCode.text.includes("ResizeObserver")) return {};
|
|
432
|
+
const fEntries = [];
|
|
433
|
+
const observers = [];
|
|
434
|
+
const oEntries = [];
|
|
435
|
+
const uEntries = [];
|
|
436
|
+
const dEntries = [];
|
|
437
|
+
return {
|
|
438
|
+
[":function"](node) {
|
|
439
|
+
const kind = getFunctionKind(node);
|
|
440
|
+
fEntries.push({
|
|
441
|
+
kind,
|
|
442
|
+
node
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
[":function:exit"]() {
|
|
446
|
+
fEntries.pop();
|
|
447
|
+
},
|
|
448
|
+
["CallExpression"](node) {
|
|
449
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
450
|
+
const fKind = fEntries.findLast((x) => x.kind !== "other")?.kind;
|
|
451
|
+
if (fKind == null || !ER.ComponentPhaseRelevance.has(fKind)) return;
|
|
452
|
+
const { object } = node.callee;
|
|
453
|
+
match(getCallKind$1(context, node)).with("disconnect", () => {
|
|
454
|
+
dEntries.push({
|
|
455
|
+
kind: "disconnect",
|
|
456
|
+
node,
|
|
457
|
+
callee: node.callee,
|
|
458
|
+
observer: object,
|
|
459
|
+
observerKind: "ResizeObserver",
|
|
460
|
+
phase: fKind
|
|
461
|
+
});
|
|
462
|
+
}).with("observe", () => {
|
|
463
|
+
const [element] = node.arguments;
|
|
464
|
+
if (element == null) return;
|
|
465
|
+
oEntries.push({
|
|
466
|
+
kind: "observe",
|
|
467
|
+
node,
|
|
468
|
+
callee: node.callee,
|
|
469
|
+
element,
|
|
470
|
+
observer: object,
|
|
471
|
+
observerKind: "ResizeObserver",
|
|
472
|
+
phase: fKind
|
|
473
|
+
});
|
|
474
|
+
}).with("unobserve", () => {
|
|
475
|
+
const [element] = node.arguments;
|
|
476
|
+
if (element == null) return;
|
|
477
|
+
uEntries.push({
|
|
478
|
+
kind: "unobserve",
|
|
479
|
+
node,
|
|
480
|
+
callee: node.callee,
|
|
481
|
+
element,
|
|
482
|
+
observer: object,
|
|
483
|
+
observerKind: "ResizeObserver",
|
|
484
|
+
phase: fKind
|
|
485
|
+
});
|
|
486
|
+
}).otherwise(() => null);
|
|
487
|
+
},
|
|
488
|
+
["NewExpression"](node) {
|
|
489
|
+
const fEntry = fEntries.findLast((x) => x.kind !== "other");
|
|
490
|
+
if (fEntry == null) return;
|
|
491
|
+
if (!ER.ComponentPhaseRelevance.has(fEntry.kind)) return;
|
|
492
|
+
if (!isNewResizeObserver(node)) return;
|
|
493
|
+
const id = ER.getInstanceId(node);
|
|
494
|
+
if (id == null) {
|
|
495
|
+
context.report({
|
|
496
|
+
messageId: "unexpectedFloatingInstance",
|
|
497
|
+
node
|
|
498
|
+
});
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
observers.push({
|
|
502
|
+
id,
|
|
503
|
+
node,
|
|
504
|
+
phase: fEntry.kind,
|
|
505
|
+
phaseNode: fEntry.node
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
["Program:exit"]() {
|
|
509
|
+
for (const { id, node, phaseNode } of observers) {
|
|
510
|
+
if (dEntries.some((e) => ER.isInstanceIdEqual(context, e.observer, id))) continue;
|
|
511
|
+
const oentries = oEntries.filter((e) => ER.isInstanceIdEqual(context, e.observer, id));
|
|
512
|
+
const uentries = uEntries.filter((e) => ER.isInstanceIdEqual(context, e.observer, id));
|
|
513
|
+
const isDynamic = (node$1) => node$1?.type === AST_NODE_TYPES.CallExpression || isConditional(node$1);
|
|
514
|
+
const isPhaseNode = (node$1) => node$1 === phaseNode;
|
|
515
|
+
if (oentries.some((e) => !isPhaseNode(AST.findParentNode(e.node, or(isDynamic, isPhaseNode))))) {
|
|
516
|
+
context.report({
|
|
517
|
+
messageId: "expectedDisconnectInControlFlow",
|
|
518
|
+
node
|
|
519
|
+
});
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
for (const oEntry of oentries) {
|
|
523
|
+
if (uentries.some((uEntry) => ER.isInstanceIdEqual(context, uEntry.element, oEntry.element))) continue;
|
|
524
|
+
context.report({
|
|
525
|
+
messageId: "expectedDisconnectOrUnobserveInCleanup",
|
|
526
|
+
node: oEntry.node
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
};
|
|
579
532
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
533
|
+
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region src/rules/no-leaked-timeout.ts
|
|
536
|
+
const RULE_NAME = "no-leaked-timeout";
|
|
537
|
+
const RULE_FEATURES = [];
|
|
538
|
+
function getCallKind(node) {
|
|
539
|
+
switch (true) {
|
|
540
|
+
case node.callee.type === AST_NODE_TYPES.Identifier && isMatching(P.union("setTimeout", "clearTimeout"))(node.callee.name): return node.callee.name;
|
|
541
|
+
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): return node.callee.property.name;
|
|
542
|
+
default: return "other";
|
|
543
|
+
}
|
|
591
544
|
}
|
|
592
545
|
var no_leaked_timeout_default = createRule({
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
546
|
+
meta: {
|
|
547
|
+
type: "problem",
|
|
548
|
+
docs: {
|
|
549
|
+
description: "Prevents leaked `setTimeout` in a component or custom Hook.",
|
|
550
|
+
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
551
|
+
},
|
|
552
|
+
messages: {
|
|
553
|
+
expectedClearTimeoutInCleanup: "A 'setTimeout' created in '{{ kind }}' must be cleared with 'clearTimeout' in the cleanup function.",
|
|
554
|
+
expectedClearTimeoutInUnmount: "A 'setTimeout' created in '{{ kind }}' must be cleared with 'clearTimeout' in the 'componentWillUnmount' method.",
|
|
555
|
+
expectedTimeoutId: "A 'setTimeout' must be assigned to a variable for proper cleanup."
|
|
556
|
+
},
|
|
557
|
+
schema: []
|
|
558
|
+
},
|
|
559
|
+
name: RULE_NAME,
|
|
560
|
+
create,
|
|
561
|
+
defaultOptions: []
|
|
609
562
|
});
|
|
610
|
-
function
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
data: {
|
|
690
|
-
kind: "componentDidMount"
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
};
|
|
563
|
+
function create(context) {
|
|
564
|
+
if (!context.sourceCode.text.includes("setTimeout")) return {};
|
|
565
|
+
const fEntries = [];
|
|
566
|
+
const sEntries = [];
|
|
567
|
+
const rEntries = [];
|
|
568
|
+
function isInverseEntry(a, b) {
|
|
569
|
+
return ER.isInstanceIdEqual(context, a.timerId, b.timerId);
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
[":function"](node) {
|
|
573
|
+
const kind = getPhaseKindOfFunction(node) ?? "other";
|
|
574
|
+
fEntries.push({
|
|
575
|
+
kind,
|
|
576
|
+
node
|
|
577
|
+
});
|
|
578
|
+
},
|
|
579
|
+
[":function:exit"]() {
|
|
580
|
+
fEntries.pop();
|
|
581
|
+
},
|
|
582
|
+
["CallExpression"](node) {
|
|
583
|
+
const fEntry = fEntries.findLast((f) => f.kind !== "other");
|
|
584
|
+
if (!ER.ComponentPhaseRelevance.has(fEntry?.kind)) return;
|
|
585
|
+
switch (getCallKind(node)) {
|
|
586
|
+
case "setTimeout": {
|
|
587
|
+
const timeoutIdNode = VAR.findAssignmentTarget(node);
|
|
588
|
+
if (timeoutIdNode == null) {
|
|
589
|
+
context.report({
|
|
590
|
+
messageId: "expectedTimeoutId",
|
|
591
|
+
node
|
|
592
|
+
});
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
sEntries.push({
|
|
596
|
+
kind: "timeout",
|
|
597
|
+
node,
|
|
598
|
+
callee: node.callee,
|
|
599
|
+
phase: fEntry.kind,
|
|
600
|
+
timerId: timeoutIdNode
|
|
601
|
+
});
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
case "clearTimeout": {
|
|
605
|
+
const [timeoutIdNode] = node.arguments;
|
|
606
|
+
if (timeoutIdNode == null) break;
|
|
607
|
+
rEntries.push({
|
|
608
|
+
kind: "timeout",
|
|
609
|
+
node,
|
|
610
|
+
callee: node.callee,
|
|
611
|
+
phase: fEntry.kind,
|
|
612
|
+
timerId: timeoutIdNode
|
|
613
|
+
});
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
["Program:exit"]() {
|
|
619
|
+
for (const sEntry of sEntries) {
|
|
620
|
+
if (rEntries.some((rEntry) => isInverseEntry(sEntry, rEntry))) continue;
|
|
621
|
+
switch (sEntry.phase) {
|
|
622
|
+
case "setup":
|
|
623
|
+
case "cleanup":
|
|
624
|
+
context.report({
|
|
625
|
+
messageId: "expectedClearTimeoutInCleanup",
|
|
626
|
+
node: sEntry.node,
|
|
627
|
+
data: { kind: "useEffect" }
|
|
628
|
+
});
|
|
629
|
+
continue;
|
|
630
|
+
case "mount":
|
|
631
|
+
case "unmount":
|
|
632
|
+
context.report({
|
|
633
|
+
messageId: "expectedClearTimeoutInUnmount",
|
|
634
|
+
node: sEntry.node,
|
|
635
|
+
data: { kind: "componentDidMount" }
|
|
636
|
+
});
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
698
642
|
}
|
|
699
643
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/plugin.ts
|
|
646
|
+
const plugin = {
|
|
647
|
+
meta: {
|
|
648
|
+
name,
|
|
649
|
+
version
|
|
650
|
+
},
|
|
651
|
+
rules: {
|
|
652
|
+
"no-leaked-event-listener": no_leaked_event_listener_default,
|
|
653
|
+
"no-leaked-interval": no_leaked_interval_default,
|
|
654
|
+
"no-leaked-resize-observer": no_leaked_resize_observer_default,
|
|
655
|
+
"no-leaked-timeout": no_leaked_timeout_default
|
|
656
|
+
}
|
|
712
657
|
};
|
|
713
658
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
function makeLegacyConfig({ rules: rules2 }) {
|
|
724
|
-
return {
|
|
725
|
-
plugins: ["react-web-api"],
|
|
726
|
-
rules: rules2
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
var index_default = {
|
|
730
|
-
...plugin,
|
|
731
|
-
configs: {
|
|
732
|
-
["recommended"]: makeConfig(recommended_exports),
|
|
733
|
-
["recommended-legacy"]: makeLegacyConfig(recommended_exports)
|
|
734
|
-
}
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/index.ts
|
|
661
|
+
const { toFlatConfig, toLegacyConfig } = getConfigAdapters("react-web-api", plugin);
|
|
662
|
+
var src_default = {
|
|
663
|
+
...plugin,
|
|
664
|
+
configs: {
|
|
665
|
+
["recommended"]: toFlatConfig(recommended_exports),
|
|
666
|
+
["recommended-legacy"]: toLegacyConfig(recommended_exports)
|
|
667
|
+
}
|
|
735
668
|
};
|
|
736
669
|
|
|
737
|
-
|
|
670
|
+
//#endregion
|
|
671
|
+
export { src_default as default };
|