eslint-plugin-react-web-api 2.0.0-next.146 → 2.0.0-next.147

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