eslint-plugin-react-web-api 1.23.1-beta.2 → 1.23.1-beta.6
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 +51 -54
- package/dist/index.mjs +52 -55
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var VAR2__namespace = /*#__PURE__*/_interopNamespace(VAR2);
|
|
|
34
34
|
|
|
35
35
|
// package.json
|
|
36
36
|
var name = "eslint-plugin-react-web-api";
|
|
37
|
-
var version = "1.23.1-beta.
|
|
37
|
+
var version = "1.23.1-beta.6";
|
|
38
38
|
var createRule = shared.createRuleForPlugin("web-api");
|
|
39
39
|
function getInstanceID(node, prev) {
|
|
40
40
|
switch (true) {
|
|
@@ -59,8 +59,6 @@ function isInstanceIDEqual(a, b, context) {
|
|
|
59
59
|
context.sourceCode.getScope(b)
|
|
60
60
|
]);
|
|
61
61
|
}
|
|
62
|
-
var EventListenerEntry = eff.Data.taggedEnum();
|
|
63
|
-
var ObserverEntry = eff.Data.taggedEnum();
|
|
64
62
|
|
|
65
63
|
// src/rules/no-leaked-event-listener.ts
|
|
66
64
|
var RULE_NAME = "no-leaked-event-listener";
|
|
@@ -85,6 +83,20 @@ function getCallKind(node) {
|
|
|
85
83
|
function getFunctionKind(node) {
|
|
86
84
|
return eff.O.getOrElse(getPhaseKindOfFunction(node), eff.F.constant("other"));
|
|
87
85
|
}
|
|
86
|
+
function getSignalValueExpression(node, initialScope) {
|
|
87
|
+
switch (node.type) {
|
|
88
|
+
case utils.AST_NODE_TYPES.Identifier:
|
|
89
|
+
return eff.F.pipe(
|
|
90
|
+
VAR2__namespace.findVariable(node, initialScope),
|
|
91
|
+
eff.O.flatMap(VAR2__namespace.getVariableNode(0)),
|
|
92
|
+
eff.O.flatMap((n) => getSignalValueExpression(n, initialScope))
|
|
93
|
+
);
|
|
94
|
+
case utils.AST_NODE_TYPES.MemberExpression:
|
|
95
|
+
return eff.O.some(node);
|
|
96
|
+
default:
|
|
97
|
+
return eff.O.none();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
88
100
|
function getOptions(node, initialScope) {
|
|
89
101
|
const findProp = (properties, propName) => {
|
|
90
102
|
return JSX__namespace.findPropInProperties(properties, initialScope)(propName);
|
|
@@ -124,21 +136,7 @@ function getOptions(node, initialScope) {
|
|
|
124
136
|
const vSignal = eff.O.flatMap(pSignal, (prop) => {
|
|
125
137
|
if (prop.type !== utils.AST_NODE_TYPES.Property) return eff.O.none();
|
|
126
138
|
const { value } = prop;
|
|
127
|
-
|
|
128
|
-
switch (node3.type) {
|
|
129
|
-
case utils.AST_NODE_TYPES.Identifier:
|
|
130
|
-
return eff.F.pipe(
|
|
131
|
-
VAR2__namespace.findVariable(node3, initialScope),
|
|
132
|
-
eff.O.flatMap(VAR2__namespace.getVariableNode(0)),
|
|
133
|
-
eff.O.flatMap(getSignalExp)
|
|
134
|
-
);
|
|
135
|
-
case utils.AST_NODE_TYPES.MemberExpression:
|
|
136
|
-
return eff.O.some(node3);
|
|
137
|
-
default:
|
|
138
|
-
return eff.O.none();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
return getSignalExp(value);
|
|
139
|
+
return getSignalValueExpression(value, initialScope);
|
|
142
140
|
});
|
|
143
141
|
return { capture: vCapture, once: vOnce, signal: vSignal };
|
|
144
142
|
}
|
|
@@ -157,9 +155,9 @@ var no_leaked_event_listener_default = createRule({
|
|
|
157
155
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
158
156
|
},
|
|
159
157
|
messages: {
|
|
160
|
-
noLeakedEventListenerInEffect: "
|
|
161
|
-
noLeakedEventListenerInLifecycle: "
|
|
162
|
-
noLeakedEventListenerOfInlineFunction: "A '{{eventMethodKind}}' should not have an inline listener function."
|
|
158
|
+
noLeakedEventListenerInEffect: "An 'addEventListener' in '{{effectMethodKind}}' should have a corresponding 'removeEventListener' in its cleanup function.",
|
|
159
|
+
noLeakedEventListenerInLifecycle: "An 'addEventListener' in 'componentDidMount' should have a corresponding 'removeEventListener' in 'componentWillUnmount' method.",
|
|
160
|
+
noLeakedEventListenerOfInlineFunction: "A/an '{{eventMethodKind}}' should not have an inline listener function."
|
|
163
161
|
},
|
|
164
162
|
schema: []
|
|
165
163
|
},
|
|
@@ -217,28 +215,30 @@ var no_leaked_event_listener_default = createRule({
|
|
|
217
215
|
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
|
|
218
216
|
const { callee } = node;
|
|
219
217
|
eff.O.map(checkInlineFunction(node, callKind, opts), context.report);
|
|
220
|
-
aEntries.push(
|
|
218
|
+
aEntries.push({
|
|
221
219
|
...opts,
|
|
220
|
+
kind: "addEventListener",
|
|
222
221
|
type,
|
|
223
222
|
node,
|
|
224
223
|
callee,
|
|
225
224
|
listener,
|
|
226
225
|
phase: fKind
|
|
227
|
-
})
|
|
226
|
+
});
|
|
228
227
|
}).with("removeEventListener", (callKind) => {
|
|
229
228
|
const [type, listener, options] = node.arguments;
|
|
230
229
|
if (!type || !listener) return;
|
|
231
230
|
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
|
|
232
231
|
const { callee } = node;
|
|
233
232
|
eff.O.map(checkInlineFunction(node, callKind, opts), context.report);
|
|
234
|
-
rEntries.push(
|
|
233
|
+
rEntries.push({
|
|
235
234
|
...opts,
|
|
235
|
+
kind: "removeEventListener",
|
|
236
236
|
type,
|
|
237
237
|
node,
|
|
238
238
|
callee,
|
|
239
239
|
listener,
|
|
240
240
|
phase: fKind
|
|
241
|
-
})
|
|
241
|
+
});
|
|
242
242
|
}).with("abort", () => {
|
|
243
243
|
abortedSignals.push(node.callee);
|
|
244
244
|
}).otherwise(eff.F.constVoid);
|
|
@@ -458,41 +458,38 @@ var no_leaked_resize_observer_default = createRule({
|
|
|
458
458
|
if (!core.ERPhaseRelevance.has(fKind)) return;
|
|
459
459
|
const { object } = node.callee;
|
|
460
460
|
tsPattern.match(getCallKind3(node, context)).with("disconnect", () => {
|
|
461
|
-
dEntries.push(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
);
|
|
461
|
+
dEntries.push({
|
|
462
|
+
kind: "disconnect",
|
|
463
|
+
node,
|
|
464
|
+
callee: node.callee,
|
|
465
|
+
observer: object,
|
|
466
|
+
observerKind: "ResizeObserver",
|
|
467
|
+
phase: fKind
|
|
468
|
+
});
|
|
470
469
|
}).with("observe", () => {
|
|
471
470
|
const [element] = node.arguments;
|
|
472
471
|
if (!element) return;
|
|
473
|
-
oEntries.push(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
);
|
|
472
|
+
oEntries.push({
|
|
473
|
+
kind: "observe",
|
|
474
|
+
node,
|
|
475
|
+
callee: node.callee,
|
|
476
|
+
element,
|
|
477
|
+
observer: object,
|
|
478
|
+
observerKind: "ResizeObserver",
|
|
479
|
+
phase: fKind
|
|
480
|
+
});
|
|
483
481
|
}).with("unobserve", () => {
|
|
484
482
|
const [element] = node.arguments;
|
|
485
483
|
if (!element) return;
|
|
486
|
-
uEntries.push(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
);
|
|
484
|
+
uEntries.push({
|
|
485
|
+
kind: "unobserve",
|
|
486
|
+
node,
|
|
487
|
+
callee: node.callee,
|
|
488
|
+
element,
|
|
489
|
+
observer: object,
|
|
490
|
+
observerKind: "ResizeObserver",
|
|
491
|
+
phase: fKind
|
|
492
|
+
});
|
|
496
493
|
}).otherwise(eff.F.constVoid);
|
|
497
494
|
},
|
|
498
495
|
["NewExpression"](node) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AST2 from '@eslint-react/ast';
|
|
2
2
|
import { ERPhaseRelevance, isSetupFunction, isCleanupFunction, isComponentDidMountFunction, isComponentWillUnmountFunction, isInversePhase } from '@eslint-react/core';
|
|
3
|
-
import {
|
|
3
|
+
import { O, F, or, not, isBoolean } from '@eslint-react/eff';
|
|
4
4
|
import * as JSX from '@eslint-react/jsx';
|
|
5
5
|
import * as VAR2 from '@eslint-react/var';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
@@ -10,7 +10,7 @@ import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
|
|
|
10
10
|
|
|
11
11
|
// package.json
|
|
12
12
|
var name = "eslint-plugin-react-web-api";
|
|
13
|
-
var version = "1.23.1-beta.
|
|
13
|
+
var version = "1.23.1-beta.6";
|
|
14
14
|
var createRule = createRuleForPlugin("web-api");
|
|
15
15
|
function getInstanceID(node, prev) {
|
|
16
16
|
switch (true) {
|
|
@@ -35,8 +35,6 @@ function isInstanceIDEqual(a, b, context) {
|
|
|
35
35
|
context.sourceCode.getScope(b)
|
|
36
36
|
]);
|
|
37
37
|
}
|
|
38
|
-
var EventListenerEntry = Data.taggedEnum();
|
|
39
|
-
var ObserverEntry = Data.taggedEnum();
|
|
40
38
|
|
|
41
39
|
// src/rules/no-leaked-event-listener.ts
|
|
42
40
|
var RULE_NAME = "no-leaked-event-listener";
|
|
@@ -61,6 +59,20 @@ function getCallKind(node) {
|
|
|
61
59
|
function getFunctionKind(node) {
|
|
62
60
|
return O.getOrElse(getPhaseKindOfFunction(node), F.constant("other"));
|
|
63
61
|
}
|
|
62
|
+
function getSignalValueExpression(node, initialScope) {
|
|
63
|
+
switch (node.type) {
|
|
64
|
+
case AST_NODE_TYPES.Identifier:
|
|
65
|
+
return F.pipe(
|
|
66
|
+
VAR2.findVariable(node, initialScope),
|
|
67
|
+
O.flatMap(VAR2.getVariableNode(0)),
|
|
68
|
+
O.flatMap((n) => getSignalValueExpression(n, initialScope))
|
|
69
|
+
);
|
|
70
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
71
|
+
return O.some(node);
|
|
72
|
+
default:
|
|
73
|
+
return O.none();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
64
76
|
function getOptions(node, initialScope) {
|
|
65
77
|
const findProp = (properties, propName) => {
|
|
66
78
|
return JSX.findPropInProperties(properties, initialScope)(propName);
|
|
@@ -100,21 +112,7 @@ function getOptions(node, initialScope) {
|
|
|
100
112
|
const vSignal = O.flatMap(pSignal, (prop) => {
|
|
101
113
|
if (prop.type !== AST_NODE_TYPES.Property) return O.none();
|
|
102
114
|
const { value } = prop;
|
|
103
|
-
|
|
104
|
-
switch (node3.type) {
|
|
105
|
-
case AST_NODE_TYPES.Identifier:
|
|
106
|
-
return F.pipe(
|
|
107
|
-
VAR2.findVariable(node3, initialScope),
|
|
108
|
-
O.flatMap(VAR2.getVariableNode(0)),
|
|
109
|
-
O.flatMap(getSignalExp)
|
|
110
|
-
);
|
|
111
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
112
|
-
return O.some(node3);
|
|
113
|
-
default:
|
|
114
|
-
return O.none();
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return getSignalExp(value);
|
|
115
|
+
return getSignalValueExpression(value, initialScope);
|
|
118
116
|
});
|
|
119
117
|
return { capture: vCapture, once: vOnce, signal: vSignal };
|
|
120
118
|
}
|
|
@@ -133,9 +131,9 @@ var no_leaked_event_listener_default = createRule({
|
|
|
133
131
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
134
132
|
},
|
|
135
133
|
messages: {
|
|
136
|
-
noLeakedEventListenerInEffect: "
|
|
137
|
-
noLeakedEventListenerInLifecycle: "
|
|
138
|
-
noLeakedEventListenerOfInlineFunction: "A '{{eventMethodKind}}' should not have an inline listener function."
|
|
134
|
+
noLeakedEventListenerInEffect: "An 'addEventListener' in '{{effectMethodKind}}' should have a corresponding 'removeEventListener' in its cleanup function.",
|
|
135
|
+
noLeakedEventListenerInLifecycle: "An 'addEventListener' in 'componentDidMount' should have a corresponding 'removeEventListener' in 'componentWillUnmount' method.",
|
|
136
|
+
noLeakedEventListenerOfInlineFunction: "A/an '{{eventMethodKind}}' should not have an inline listener function."
|
|
139
137
|
},
|
|
140
138
|
schema: []
|
|
141
139
|
},
|
|
@@ -193,28 +191,30 @@ var no_leaked_event_listener_default = createRule({
|
|
|
193
191
|
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
|
|
194
192
|
const { callee } = node;
|
|
195
193
|
O.map(checkInlineFunction(node, callKind, opts), context.report);
|
|
196
|
-
aEntries.push(
|
|
194
|
+
aEntries.push({
|
|
197
195
|
...opts,
|
|
196
|
+
kind: "addEventListener",
|
|
198
197
|
type,
|
|
199
198
|
node,
|
|
200
199
|
callee,
|
|
201
200
|
listener,
|
|
202
201
|
phase: fKind
|
|
203
|
-
})
|
|
202
|
+
});
|
|
204
203
|
}).with("removeEventListener", (callKind) => {
|
|
205
204
|
const [type, listener, options] = node.arguments;
|
|
206
205
|
if (!type || !listener) return;
|
|
207
206
|
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
|
|
208
207
|
const { callee } = node;
|
|
209
208
|
O.map(checkInlineFunction(node, callKind, opts), context.report);
|
|
210
|
-
rEntries.push(
|
|
209
|
+
rEntries.push({
|
|
211
210
|
...opts,
|
|
211
|
+
kind: "removeEventListener",
|
|
212
212
|
type,
|
|
213
213
|
node,
|
|
214
214
|
callee,
|
|
215
215
|
listener,
|
|
216
216
|
phase: fKind
|
|
217
|
-
})
|
|
217
|
+
});
|
|
218
218
|
}).with("abort", () => {
|
|
219
219
|
abortedSignals.push(node.callee);
|
|
220
220
|
}).otherwise(F.constVoid);
|
|
@@ -434,41 +434,38 @@ var no_leaked_resize_observer_default = createRule({
|
|
|
434
434
|
if (!ERPhaseRelevance.has(fKind)) return;
|
|
435
435
|
const { object } = node.callee;
|
|
436
436
|
match(getCallKind3(node, context)).with("disconnect", () => {
|
|
437
|
-
dEntries.push(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
);
|
|
437
|
+
dEntries.push({
|
|
438
|
+
kind: "disconnect",
|
|
439
|
+
node,
|
|
440
|
+
callee: node.callee,
|
|
441
|
+
observer: object,
|
|
442
|
+
observerKind: "ResizeObserver",
|
|
443
|
+
phase: fKind
|
|
444
|
+
});
|
|
446
445
|
}).with("observe", () => {
|
|
447
446
|
const [element] = node.arguments;
|
|
448
447
|
if (!element) return;
|
|
449
|
-
oEntries.push(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
);
|
|
448
|
+
oEntries.push({
|
|
449
|
+
kind: "observe",
|
|
450
|
+
node,
|
|
451
|
+
callee: node.callee,
|
|
452
|
+
element,
|
|
453
|
+
observer: object,
|
|
454
|
+
observerKind: "ResizeObserver",
|
|
455
|
+
phase: fKind
|
|
456
|
+
});
|
|
459
457
|
}).with("unobserve", () => {
|
|
460
458
|
const [element] = node.arguments;
|
|
461
459
|
if (!element) return;
|
|
462
|
-
uEntries.push(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
);
|
|
460
|
+
uEntries.push({
|
|
461
|
+
kind: "unobserve",
|
|
462
|
+
node,
|
|
463
|
+
callee: node.callee,
|
|
464
|
+
element,
|
|
465
|
+
observer: object,
|
|
466
|
+
observerKind: "ResizeObserver",
|
|
467
|
+
phase: fKind
|
|
468
|
+
});
|
|
472
469
|
}).otherwise(F.constVoid);
|
|
473
470
|
},
|
|
474
471
|
["NewExpression"](node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-web-api",
|
|
3
|
-
"version": "1.23.1-beta.
|
|
3
|
+
"version": "1.23.1-beta.6",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for interacting with Web APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"@typescript-eslint/utils": "^8.19.0",
|
|
47
47
|
"string-ts": "^2.2.0",
|
|
48
48
|
"ts-pattern": "^5.6.0",
|
|
49
|
-
"@eslint-react/ast": "1.23.1-beta.
|
|
50
|
-
"@eslint-react/core": "1.23.1-beta.
|
|
51
|
-
"@eslint-react/eff": "1.23.1-beta.
|
|
52
|
-
"@eslint-react/jsx": "1.23.1-beta.
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/ast": "1.23.1-beta.6",
|
|
50
|
+
"@eslint-react/core": "1.23.1-beta.6",
|
|
51
|
+
"@eslint-react/eff": "1.23.1-beta.6",
|
|
52
|
+
"@eslint-react/jsx": "1.23.1-beta.6",
|
|
53
|
+
"@eslint-react/shared": "1.23.1-beta.6",
|
|
54
|
+
"@eslint-react/types": "1.23.1-beta.6",
|
|
55
|
+
"@eslint-react/var": "1.23.1-beta.6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/react": "^19.0.2",
|