eslint-plugin-react-web-api 5.30.1 → 5.30.3
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 +125 -80
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var __exportAll = (all, flags) => {
|
|
|
20
20
|
};
|
|
21
21
|
// package.json
|
|
22
22
|
var name$1 = "eslint-plugin-react-web-api";
|
|
23
|
-
var version = "5.30.
|
|
23
|
+
var version = "5.30.3";
|
|
24
24
|
// src/utils/create-rule.ts
|
|
25
25
|
function getDocsUrl(ruleName) {
|
|
26
26
|
return `https://eslint-react.xyz/docs/rules/web-api-${ruleName}`;
|
|
@@ -140,14 +140,14 @@ function getCallKind$5(node) {
|
|
|
140
140
|
if (name != null && isMatching(P.union("addEventListener", "removeEventListener"))(name)) return name;
|
|
141
141
|
return "other";
|
|
142
142
|
}
|
|
143
|
-
function isGlobalObject(node) {
|
|
143
|
+
function isGlobalObject$1(node) {
|
|
144
144
|
return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
|
|
145
145
|
}
|
|
146
146
|
function isSameObject(a, b, isEqual = Compare.isEqual) {
|
|
147
147
|
switch (true) {
|
|
148
148
|
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isEqual(a.object, b.object);
|
|
149
|
-
case a.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(a.object);
|
|
150
|
-
case b.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject(b.object);
|
|
149
|
+
case a.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject$1(a.object);
|
|
150
|
+
case b.type === AST_NODE_TYPES.MemberExpression: return isGlobalObject$1(b.object);
|
|
151
151
|
default: return true;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -462,84 +462,48 @@ function resolveToObjectExpression(context, node) {
|
|
|
462
462
|
default: return null;
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
468
|
-
function getCallKind$4(node) {
|
|
469
|
-
const name = Extract.getCalleeName(node);
|
|
470
|
-
if (name != null && isMatching(P.union("fetch", "abort"))(name)) return name;
|
|
471
|
-
return "other";
|
|
465
|
+
function isGlobalObject(node) {
|
|
466
|
+
return Check.isIdentifier(node) && (node.name === "window" || node.name === "globalThis" || node.name === "self");
|
|
472
467
|
}
|
|
473
|
-
function
|
|
474
|
-
node = Extract.unwrap(node);
|
|
468
|
+
function isNameBoundInScope(name, node) {
|
|
475
469
|
switch (node.type) {
|
|
476
|
-
case AST_NODE_TYPES.
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
case AST_NODE_TYPES.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
const resolvedUnwrapped = resolved == null ? null : Extract.unwrap(resolved);
|
|
488
|
-
if (resolvedUnwrapped?.type === AST_NODE_TYPES.MemberExpression) return {
|
|
489
|
-
controller: resolvedUnwrapped.object,
|
|
490
|
-
isParamSignal: false
|
|
491
|
-
};
|
|
492
|
-
if (resolved != null && Check.isFunction(resolved)) return {
|
|
493
|
-
controller: node,
|
|
494
|
-
isParamSignal: true
|
|
495
|
-
};
|
|
496
|
-
if (resolvedUnwrapped != null) return getControllerFromSignal(context, resolvedUnwrapped, seen);
|
|
497
|
-
return {
|
|
498
|
-
controller: null,
|
|
499
|
-
isParamSignal: false
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
default: return {
|
|
503
|
-
controller: null,
|
|
504
|
-
isParamSignal: false
|
|
505
|
-
};
|
|
470
|
+
case AST_NODE_TYPES.FunctionDeclaration:
|
|
471
|
+
case AST_NODE_TYPES.ArrowFunctionExpression: return node.params.some((param) => isNameBoundInPattern(name, param));
|
|
472
|
+
case AST_NODE_TYPES.FunctionExpression: return node.id?.name === name || node.params.some((param) => isNameBoundInPattern(name, param));
|
|
473
|
+
case AST_NODE_TYPES.CatchClause: return node.param != null && isNameBoundInPattern(name, node.param);
|
|
474
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
475
|
+
case AST_NODE_TYPES.Program:
|
|
476
|
+
case AST_NODE_TYPES.StaticBlock: return node.body.some((statement) => isNameBoundInStatement(name, statement));
|
|
477
|
+
case AST_NODE_TYPES.ForStatement: return node.init?.type === AST_NODE_TYPES.VariableDeclaration && isNameBoundInStatement(name, node.init);
|
|
478
|
+
case AST_NODE_TYPES.ForInStatement:
|
|
479
|
+
case AST_NODE_TYPES.ForOfStatement: return node.left.type === AST_NODE_TYPES.VariableDeclaration && isNameBoundInStatement(name, node.left);
|
|
480
|
+
default: return false;
|
|
506
481
|
}
|
|
507
482
|
}
|
|
508
|
-
function
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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);
|
|
533
|
-
if (signalProp?.type !== AST_NODE_TYPES.Property) return {
|
|
534
|
-
controller: null,
|
|
535
|
-
isParamSignal: false
|
|
536
|
-
};
|
|
537
|
-
return getControllerFromSignal(context, signalProp.value);
|
|
483
|
+
function isNameBoundInStatement(name, statement) {
|
|
484
|
+
switch (statement.type) {
|
|
485
|
+
case AST_NODE_TYPES.FunctionDeclaration:
|
|
486
|
+
case AST_NODE_TYPES.ClassDeclaration: return statement.id?.name === name;
|
|
487
|
+
case AST_NODE_TYPES.VariableDeclaration: return statement.declarations.some((declarator) => isNameBoundInPattern(name, declarator.id));
|
|
488
|
+
case AST_NODE_TYPES.ImportDeclaration: return statement.specifiers.some((specifier) => specifier.local.name === name);
|
|
489
|
+
case AST_NODE_TYPES.ExportNamedDeclaration: return statement.declaration != null && isNameBoundInStatement(name, statement.declaration);
|
|
490
|
+
case AST_NODE_TYPES.ExportDefaultDeclaration: return (statement.declaration.type === AST_NODE_TYPES.FunctionDeclaration || statement.declaration.type === AST_NODE_TYPES.ClassDeclaration) && statement.declaration.id?.name === name;
|
|
491
|
+
case AST_NODE_TYPES.TSImportEqualsDeclaration:
|
|
492
|
+
case AST_NODE_TYPES.TSEnumDeclaration: return statement.id.name === name;
|
|
493
|
+
case AST_NODE_TYPES.TSModuleDeclaration: return statement.id.type === AST_NODE_TYPES.Identifier && statement.id.name === name;
|
|
494
|
+
default: return false;
|
|
495
|
+
}
|
|
538
496
|
}
|
|
539
|
-
function
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
497
|
+
function isNameBoundInPattern(name, pattern) {
|
|
498
|
+
switch (pattern.type) {
|
|
499
|
+
case AST_NODE_TYPES.Identifier: return pattern.name === name;
|
|
500
|
+
case AST_NODE_TYPES.ArrayPattern: return pattern.elements.some((element) => element != null && isNameBoundInPattern(name, element));
|
|
501
|
+
case AST_NODE_TYPES.ObjectPattern: return pattern.properties.some((property) => property.type === AST_NODE_TYPES.RestElement ? isNameBoundInPattern(name, property.argument) : isNameBoundInPattern(name, property.value));
|
|
502
|
+
case AST_NODE_TYPES.AssignmentPattern: return isNameBoundInPattern(name, pattern.left);
|
|
503
|
+
case AST_NODE_TYPES.RestElement: return isNameBoundInPattern(name, pattern.argument);
|
|
504
|
+
case AST_NODE_TYPES.TSParameterProperty: return isNameBoundInPattern(name, pattern.parameter);
|
|
505
|
+
default: return false;
|
|
506
|
+
}
|
|
543
507
|
}
|
|
544
508
|
var no_leaked_fetch_default = createRule({
|
|
545
509
|
meta: {
|
|
@@ -551,7 +515,7 @@ var no_leaked_fetch_default = createRule({
|
|
|
551
515
|
},
|
|
552
516
|
schema: []
|
|
553
517
|
},
|
|
554
|
-
name:
|
|
518
|
+
name: "no-leaked-fetch",
|
|
555
519
|
create: create$4
|
|
556
520
|
});
|
|
557
521
|
function create$4(context) {
|
|
@@ -560,7 +524,7 @@ function create$4(context) {
|
|
|
560
524
|
const fetchEntries = [];
|
|
561
525
|
const abortEntries = [];
|
|
562
526
|
return {
|
|
563
|
-
|
|
527
|
+
CallExpression(node) {
|
|
564
528
|
match(getCallKind$4(node)).with("fetch", () => {
|
|
565
529
|
const fn = Traverse.findParent(node, Check.isFunction);
|
|
566
530
|
if (fn == null || !isUseEffectSetupCallback(fn)) return;
|
|
@@ -581,7 +545,7 @@ function create$4(context) {
|
|
|
581
545
|
});
|
|
582
546
|
}).otherwise(() => null);
|
|
583
547
|
},
|
|
584
|
-
|
|
548
|
+
"Program:exit"() {
|
|
585
549
|
for (const fEntry of fetchEntries) {
|
|
586
550
|
const controller = fEntry.controller;
|
|
587
551
|
if (controller == null) {
|
|
@@ -600,6 +564,87 @@ function create$4(context) {
|
|
|
600
564
|
}
|
|
601
565
|
};
|
|
602
566
|
}
|
|
567
|
+
const isUseEffectCallback$4 = or(isUseEffectSetupCallback, isUseEffectCleanupCallback);
|
|
568
|
+
function getCallKind$4(node) {
|
|
569
|
+
const callee = Extract.unwrap(node.callee);
|
|
570
|
+
switch (true) {
|
|
571
|
+
case Check.isIdentifier(callee, "fetch") && !Traverse.hasParent(node, (n) => isNameBoundInScope("fetch", n)): return "fetch";
|
|
572
|
+
case callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && Check.isIdentifier(callee.property, "fetch") && isGlobalObject(Extract.unwrap(callee.object)): return "fetch";
|
|
573
|
+
case Extract.getCalleeName(node) === "abort": return "abort";
|
|
574
|
+
default: return "other";
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function getFetchController(context, node) {
|
|
578
|
+
const [, optionsArg] = node.arguments;
|
|
579
|
+
if (optionsArg == null) return {
|
|
580
|
+
controller: null,
|
|
581
|
+
isParamSignal: false
|
|
582
|
+
};
|
|
583
|
+
const options = resolveToObjectExpression(context, optionsArg);
|
|
584
|
+
if (options == null) return {
|
|
585
|
+
controller: null,
|
|
586
|
+
isParamSignal: false
|
|
587
|
+
};
|
|
588
|
+
const signalProp = findSignalProperty(options.properties);
|
|
589
|
+
if (signalProp?.type !== AST_NODE_TYPES.Property) return {
|
|
590
|
+
controller: null,
|
|
591
|
+
isParamSignal: false
|
|
592
|
+
};
|
|
593
|
+
return getControllerFromSignal(context, signalProp.value);
|
|
594
|
+
}
|
|
595
|
+
function getControllerFromSignal(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
596
|
+
node = Extract.unwrap(node);
|
|
597
|
+
switch (node.type) {
|
|
598
|
+
case AST_NODE_TYPES.MemberExpression: return {
|
|
599
|
+
controller: node.object,
|
|
600
|
+
isParamSignal: false
|
|
601
|
+
};
|
|
602
|
+
case AST_NODE_TYPES.Identifier: {
|
|
603
|
+
if (seen.has(node)) return {
|
|
604
|
+
controller: null,
|
|
605
|
+
isParamSignal: false
|
|
606
|
+
};
|
|
607
|
+
seen.add(node);
|
|
608
|
+
const resolved = resolveOrigin(context, node);
|
|
609
|
+
const resolvedUnwrapped = resolved == null ? null : Extract.unwrap(resolved);
|
|
610
|
+
if (resolvedUnwrapped?.type === AST_NODE_TYPES.MemberExpression) return {
|
|
611
|
+
controller: resolvedUnwrapped.object,
|
|
612
|
+
isParamSignal: false
|
|
613
|
+
};
|
|
614
|
+
if (resolved != null && Check.isFunction(resolved)) return {
|
|
615
|
+
controller: node,
|
|
616
|
+
isParamSignal: true
|
|
617
|
+
};
|
|
618
|
+
if (resolvedUnwrapped != null) return getControllerFromSignal(context, resolvedUnwrapped, seen);
|
|
619
|
+
return {
|
|
620
|
+
controller: null,
|
|
621
|
+
isParamSignal: false
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
default: return {
|
|
625
|
+
controller: null,
|
|
626
|
+
isParamSignal: false
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function findSignalProperty(properties) {
|
|
631
|
+
for (const property of properties) {
|
|
632
|
+
if (property.type === AST_NODE_TYPES.Property) {
|
|
633
|
+
const key = Extract.unwrap(property.key);
|
|
634
|
+
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;
|
|
635
|
+
}
|
|
636
|
+
if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
|
|
637
|
+
const found = findSignalProperty(property.argument.properties);
|
|
638
|
+
if (found != null) return found;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
function getAbortController(node) {
|
|
644
|
+
const callee = Extract.unwrap(node.callee);
|
|
645
|
+
if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.object;
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
603
648
|
// src/rules/no-leaked-intersection-observer/lib.ts
|
|
604
649
|
function isNewObserver$1(node, name) {
|
|
605
650
|
if (node?.type !== AST_NODE_TYPES.NewExpression) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-web-api",
|
|
3
|
-
"version": "5.30.
|
|
3
|
+
"version": "5.30.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for interacting with Web APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,25 +37,25 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@eslint-react/ast": "5.30.
|
|
41
|
-
"@eslint-react/core": "5.30.
|
|
42
|
-
"@eslint-react/eslint": "5.30.
|
|
43
|
-
"@eslint-react/shared": "5.30.
|
|
44
|
-
"@eslint-react/var": "5.30.
|
|
45
|
-
"@typescript-eslint/types": "^8.72.
|
|
46
|
-
"@typescript-eslint/utils": "^8.72.
|
|
40
|
+
"@eslint-react/ast": "5.30.3",
|
|
41
|
+
"@eslint-react/core": "5.30.3",
|
|
42
|
+
"@eslint-react/eslint": "5.30.3",
|
|
43
|
+
"@eslint-react/shared": "5.30.3",
|
|
44
|
+
"@eslint-react/var": "5.30.3",
|
|
45
|
+
"@typescript-eslint/types": "^8.72.2",
|
|
46
|
+
"@typescript-eslint/utils": "^8.72.2",
|
|
47
47
|
"ts-pattern": "^5.9.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@local/configs": "0.0.0",
|
|
51
51
|
"@local/eff": "0.0.0",
|
|
52
52
|
"@local/testkit": "0.0.0",
|
|
53
|
-
"@tsconfig/node20": "^20.1.
|
|
53
|
+
"@tsconfig/node20": "^20.1.11",
|
|
54
54
|
"@types/node": "^20.19.43",
|
|
55
55
|
"@types/react": "^19.3.0",
|
|
56
56
|
"@types/react-dom": "^19.3.0",
|
|
57
57
|
"dedent": "^1.7.2",
|
|
58
|
-
"eslint": "^10.
|
|
58
|
+
"eslint": "^10.15.0",
|
|
59
59
|
"tsdown": "^0.23.7",
|
|
60
60
|
"typescript": "6.0.3"
|
|
61
61
|
},
|