eslint-plugin-react-web-api 5.30.0-beta.16 → 5.30.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +70 -13
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __exportAll = (all, no_symbols) => {
20
20
  };
21
21
  // package.json
22
22
  var name$1 = "eslint-plugin-react-web-api";
23
- var version = "5.30.0-beta.16";
23
+ var version = "5.30.0-beta.17";
24
24
  // src/utils/create-rule.ts
25
25
  function getDocsUrl(ruleName) {
26
26
  return `https://eslint-react.xyz/docs/rules/web-api-${ruleName}`;
@@ -143,9 +143,9 @@ function getCallKind$5(node) {
143
143
  function isGlobalObject(node) {
144
144
  return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
145
145
  }
146
- function isSameObject(a, b) {
146
+ function isSameObject(a, b, isEqual = Compare.isEqual) {
147
147
  switch (true) {
148
- case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return Compare.isEqual(a.object, b.object);
148
+ case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isEqual(a.object, b.object);
149
149
  case a.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(a.object);
150
150
  case b.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(b.object);
151
151
  default: return true;
@@ -171,11 +171,34 @@ function createFactCollector() {
171
171
  };
172
172
  }
173
173
  // src/rules/no-leaked-event-listener/effect.ts
174
+ function getStaticMemberPropertyName(node) {
175
+ const property = Extract.unwrap(node.property);
176
+ if (!node.computed) return Check.isIdentifier(property) ? property.name : null;
177
+ if (property.type === AST_NODE_TYPES.Literal && typeof property.value === "string") return property.value;
178
+ if (property.type === AST_NODE_TYPES.TemplateLiteral && property.expressions.length === 0) return property.quasis[0]?.value.cooked ?? property.quasis[0]?.value.raw ?? null;
179
+ return null;
180
+ }
181
+ function isSameEventExpression(a, b, isEqual = Compare.isEqual) {
182
+ const exprA = Extract.unwrap(a);
183
+ const exprB = Extract.unwrap(b);
184
+ if (exprA.type !== AST_NODE_TYPES.MemberExpression) return isEqual(exprA, exprB);
185
+ if (exprB.type !== AST_NODE_TYPES.MemberExpression) return isEqual(exprA, exprB);
186
+ if (exprA.optional !== exprB.optional) return isEqual(exprA, exprB);
187
+ const propertyA = getStaticMemberPropertyName(exprA);
188
+ const propertyB = getStaticMemberPropertyName(exprB);
189
+ if (propertyA == null) return isEqual(exprA, exprB);
190
+ if (propertyB == null) return isEqual(exprA, exprB);
191
+ if (propertyA !== propertyB) return isEqual(exprA, exprB);
192
+ return isSameEventExpression(exprA.object, exprB.object, isEqual);
193
+ }
174
194
  function isInverseEntry({ context, addEntry, remEntry, cleanupCalleeEntries }) {
175
195
  const { type: aType, callee: aCallee, capture: aCapture, effect: aEffect, listener: aListener, phase: aPhase } = addEntry;
176
196
  const { type: rType, callee: rCallee, capture: rCapture, effect: rEffect, listener: rListener, phase: rPhase } = remEntry;
177
197
  if (aPhase !== "setup") return false;
178
- if (!isSameObject(aCallee, rCallee) || !Compare.isEqual(aListener, rListener) || !isProvenanceEqual(context, aType, rType) || aCapture !== rCapture) return false;
198
+ if (!isSameObject(aCallee, rCallee, isSameEventExpression)) return false;
199
+ if (!isSameEventExpression(aListener, rListener)) return false;
200
+ if (!isSameEventExpression(aType, rType, (a, b) => isProvenanceEqual(context, a, b))) return false;
201
+ if (aCapture !== rCapture) return false;
179
202
  if (rPhase === "cleanup") return true;
180
203
  if (aEffect == null || aEffect !== rEffect) return false;
181
204
  const enclosingFunction = remEntry.enclosingFunction;
@@ -185,7 +208,9 @@ function isInverseEntry({ context, addEntry, remEntry, cleanupCalleeEntries }) {
185
208
  const { functions, names } = callees;
186
209
  if (functions.has(enclosingFunction)) return true;
187
210
  const id = getFunctionId(enclosingFunction);
188
- return id != null && id.type === AST_NODE_TYPES.Identifier && names.has(id.name);
211
+ if (id == null) return false;
212
+ if (id.type !== AST_NODE_TYPES.Identifier) return false;
213
+ return names.has(id.name);
189
214
  }
190
215
  function inferEventListenerViolations(context, facts) {
191
216
  const violations = [];
@@ -240,7 +265,9 @@ function resolveCleanupCallee({ context, node }) {
240
265
  const objectExpression = init == null ? null : Extract.unwrap(init);
241
266
  if (objectExpression?.type !== AST_NODE_TYPES.ObjectExpression) return null;
242
267
  for (const prop of objectExpression.properties) {
243
- if (prop.type !== AST_NODE_TYPES.Property || prop.computed || Extract.getPropertyName(prop, "max") !== property.name) continue;
268
+ if (prop.type !== AST_NODE_TYPES.Property || prop.computed) continue;
269
+ const key = Extract.unwrap(prop.key);
270
+ if (Check.isIdentifier(key) ? key.name !== property.name : key.value !== property.name) continue;
244
271
  const value = Extract.unwrap(prop.value);
245
272
  if (Check.isFunction(value)) return {
246
273
  kind: "function",
@@ -301,7 +328,20 @@ function getListenerOptions({ context, node }) {
301
328
  capture: Boolean(node.value)
302
329
  };
303
330
  case AST_NODE_TYPES.ObjectExpression: {
304
- const pCapture = Extract.findProperty(node.properties, "capture");
331
+ const findOption = (properties, name) => {
332
+ for (const property of properties) {
333
+ if (property.type === AST_NODE_TYPES.Property) {
334
+ const key = Extract.unwrap(property.key);
335
+ if ((!property.computed && Check.isIdentifier(key) ? key.name : key.type === AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0 ? key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null : null) === name) return property;
336
+ }
337
+ if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
338
+ const found = findOption(property.argument.properties, name);
339
+ if (found != null) return found;
340
+ }
341
+ }
342
+ return null;
343
+ };
344
+ const pCapture = findOption(node.properties, "capture");
305
345
  const vCapture = match(pCapture).with(P.nullish, () => false).with({ type: AST_NODE_TYPES.Property }, (prop) => {
306
346
  const value = prop.value;
307
347
  switch (value.type) {
@@ -309,7 +349,7 @@ function getListenerOptions({ context, node }) {
309
349
  default: return Boolean(getStaticValue(value, context.sourceCode.getScope(node))?.value);
310
350
  }
311
351
  }).otherwise(() => false);
312
- const pSignal = Extract.findProperty(node.properties, "signal");
352
+ const pSignal = findOption(node.properties, "signal");
313
353
  return {
314
354
  capture: vCapture,
315
355
  signal: pSignal?.type === AST_NODE_TYPES.Property ? getSignalValueExpression({
@@ -476,7 +516,20 @@ function getFetchController(context, node) {
476
516
  controller: null,
477
517
  isParamSignal: false
478
518
  };
479
- const signalProp = Extract.findProperty(options.properties, "signal");
519
+ const findSignal = (properties) => {
520
+ for (const property of properties) {
521
+ if (property.type === AST_NODE_TYPES.Property) {
522
+ const key = Extract.unwrap(property.key);
523
+ if ((!property.computed && Check.isIdentifier(key) ? key.name : key.type === AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0 ? key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null : null) === "signal") return property;
524
+ }
525
+ if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
526
+ const found = findSignal(property.argument.properties);
527
+ if (found != null) return found;
528
+ }
529
+ }
530
+ return null;
531
+ };
532
+ const signalProp = findSignal(options.properties);
480
533
  if (signalProp?.type !== AST_NODE_TYPES.Property) return {
481
534
  controller: null,
482
535
  isParamSignal: false
@@ -586,8 +639,10 @@ function getCallKind$3(context, node) {
586
639
  const callee = Extract.unwrap(node.callee);
587
640
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return "other";
588
641
  const name = Extract.getCalleeName(node);
589
- if (name != null && isMatching(P.union("observe", "unobserve", "disconnect"))(name) && isFromObserver$1(context, callee, "IntersectionObserver")) return name;
590
- return "other";
642
+ if (name == null) return "other";
643
+ if (!isMatching(P.union("observe", "unobserve", "disconnect"))(name)) return "other";
644
+ if (!isFromObserver$1(context, callee, "IntersectionObserver")) return "other";
645
+ return name;
591
646
  }
592
647
  function isUseRefInitialValue$1(node) {
593
648
  let child = node;
@@ -838,8 +893,10 @@ function getCallKind$1(context, node) {
838
893
  const callee = Extract.unwrap(node.callee);
839
894
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return "other";
840
895
  const name = Extract.getCalleeName(node);
841
- if (name != null && isMatching(P.union("observe", "unobserve", "disconnect"))(name) && isFromObserver(context, callee, "ResizeObserver")) return name;
842
- return "other";
896
+ if (name == null) return "other";
897
+ if (!isMatching(P.union("observe", "unobserve", "disconnect"))(name)) return "other";
898
+ if (!isFromObserver(context, callee, "ResizeObserver")) return "other";
899
+ return name;
843
900
  }
844
901
  function isUseRefInitialValue(node) {
845
902
  let child = node;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "5.30.0-beta.16",
3
+ "version": "5.30.0-beta.17",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -37,11 +37,11 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint-react/ast": "5.30.0-beta.16",
41
- "@eslint-react/core": "5.30.0-beta.16",
42
- "@eslint-react/eslint": "5.30.0-beta.16",
43
- "@eslint-react/shared": "5.30.0-beta.16",
44
- "@eslint-react/var": "5.30.0-beta.16",
40
+ "@eslint-react/ast": "5.30.0-beta.17",
41
+ "@eslint-react/core": "5.30.0-beta.17",
42
+ "@eslint-react/eslint": "5.30.0-beta.17",
43
+ "@eslint-react/shared": "5.30.0-beta.17",
44
+ "@eslint-react/var": "5.30.0-beta.17",
45
45
  "@typescript-eslint/types": "^8.72.1",
46
46
  "@typescript-eslint/utils": "^8.72.1",
47
47
  "ts-pattern": "^5.9.2"