@sarj/eslint-plugin 16.36.7 → 16.38.52
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.cjs +907 -767
- package/dist/index.js +901 -761
- package/dist/rule-examples.cjs +168 -44
- package/dist/rule-examples.js +168 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -627,41 +627,230 @@ var no_mutating_input_with_result_default = createRule({
|
|
|
627
627
|
});
|
|
628
628
|
|
|
629
629
|
// src/rules/no-negative-only-http-status-assertion.ts
|
|
630
|
-
import { AST_NODE_TYPES as
|
|
630
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ASTUtils as ASTUtils7 } from "@typescript-eslint/utils";
|
|
631
|
+
|
|
632
|
+
// src/rules/_native-fetch-reference.ts
|
|
633
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ASTUtils as ASTUtils5 } from "@typescript-eslint/utils";
|
|
634
|
+
|
|
635
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
636
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6, ASTUtils as ASTUtils4 } from "@typescript-eslint/utils";
|
|
637
|
+
|
|
638
|
+
// src/rules/_stable-value-binding.ts
|
|
639
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
640
|
+
function typeOnlyReference(reference) {
|
|
641
|
+
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
642
|
+
let current = outerExpression(reference.identifier);
|
|
643
|
+
while (current.parent?.type === AST_NODE_TYPES4.TSQualifiedName && current.parent.left === current) {
|
|
644
|
+
current = current.parent;
|
|
645
|
+
}
|
|
646
|
+
return current.parent?.type === AST_NODE_TYPES4.TSTypeQuery && current.parent.exprName === current;
|
|
647
|
+
}
|
|
648
|
+
function stableValueBinding(variable, acceptRead) {
|
|
649
|
+
let initializer;
|
|
650
|
+
return variable.references.every((reference) => {
|
|
651
|
+
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
652
|
+
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
653
|
+
initializer = reference.identifier;
|
|
654
|
+
return true;
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/rules/_static-string.ts
|
|
659
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
660
|
+
function staticString(node) {
|
|
661
|
+
if (node === void 0) return null;
|
|
662
|
+
const value = unwrapExpression(node);
|
|
663
|
+
if (value.type === AST_NODE_TYPES5.Literal && typeof value.value === "string") return value.value;
|
|
664
|
+
return value.type === AST_NODE_TYPES5.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
665
|
+
}
|
|
666
|
+
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
667
|
+
function scopedStaticString(node, sourceCode) {
|
|
668
|
+
let value = unwrapExpression(node);
|
|
669
|
+
if (value.type !== AST_NODE_TYPES5.Identifier) return staticString(value);
|
|
670
|
+
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
671
|
+
if (values === void 0) {
|
|
672
|
+
values = /* @__PURE__ */ new WeakMap();
|
|
673
|
+
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
674
|
+
}
|
|
675
|
+
const seen = /* @__PURE__ */ new Set();
|
|
676
|
+
const pending = [];
|
|
677
|
+
let result = null;
|
|
678
|
+
while (value.type === AST_NODE_TYPES5.Identifier) {
|
|
679
|
+
const binding3 = ASTUtils3.findVariable(sourceCode.getScope(value), value.name);
|
|
680
|
+
if (binding3 === null || seen.has(binding3)) break;
|
|
681
|
+
if (values.has(binding3)) {
|
|
682
|
+
result = values.get(binding3) ?? null;
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
seen.add(binding3);
|
|
686
|
+
pending.push(binding3);
|
|
687
|
+
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
688
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== AST_NODE_TYPES5.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
689
|
+
value = unwrapExpression(definition.node.init);
|
|
690
|
+
if (value.type !== AST_NODE_TYPES5.Identifier) result = staticString(value);
|
|
691
|
+
}
|
|
692
|
+
for (const binding3 of pending) values.set(binding3, result);
|
|
693
|
+
return result;
|
|
694
|
+
}
|
|
695
|
+
function staticPropertyName(node, sourceCode) {
|
|
696
|
+
const direct = ASTUtils3.getPropertyName(node);
|
|
697
|
+
if (direct !== null || !node.computed) return direct;
|
|
698
|
+
const key = node.type === AST_NODE_TYPES5.MemberExpression ? node.property : node.key;
|
|
699
|
+
return scopedStaticString(key, sourceCode);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
703
|
+
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
704
|
+
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
705
|
+
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
706
|
+
const index = runtimeIndex(sourceCode);
|
|
707
|
+
const cached = index.results.get(name);
|
|
708
|
+
if (cached !== void 0) return cached;
|
|
709
|
+
const changed = index.nodes.some((node) => node.type === AST_NODE_TYPES6.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "fetch" && node.type === AST_NODE_TYPES6.Property && node.parent.type === AST_NODE_TYPES6.ObjectPattern && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === AST_NODE_TYPES6.Literal && "regex" in node) || index.references.some((reference) => (name !== "fetch" || !typeOnlyReference(reference)) && unsafeReference(reference.identifier, sourceCode, name, index));
|
|
710
|
+
index.results.set(name, !changed);
|
|
711
|
+
return !changed;
|
|
712
|
+
}
|
|
713
|
+
function runtimeIndex(sourceCode) {
|
|
714
|
+
const cached = INDEXES.get(sourceCode);
|
|
715
|
+
if (cached !== void 0) return cached;
|
|
716
|
+
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false)) ?? [];
|
|
717
|
+
const nodes = [];
|
|
718
|
+
const pending = [sourceCode.ast];
|
|
719
|
+
while (pending.length > 0) {
|
|
720
|
+
const node = pending.pop();
|
|
721
|
+
if (node === void 0) continue;
|
|
722
|
+
nodes.push(node);
|
|
723
|
+
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
724
|
+
pending.push(child);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
const index = { references, nodes, results: /* @__PURE__ */ new Map(), fetchAliases: /* @__PURE__ */ new Map() };
|
|
728
|
+
INDEXES.set(sourceCode, index);
|
|
729
|
+
return index;
|
|
730
|
+
}
|
|
731
|
+
function unsafeReference(node, sourceCode, name, index) {
|
|
732
|
+
if (!ambient(node, sourceCode)) return false;
|
|
733
|
+
if (node.name === "eval" || node.name === "Function") return true;
|
|
734
|
+
if (node.name === name) return name === "fetch" ? !fetchRead(node, sourceCode, index) : !nativeRead(node, name);
|
|
735
|
+
if (!GLOBAL_OBJECTS.has(node.name)) return false;
|
|
736
|
+
const value = outerExpression(node);
|
|
737
|
+
const property = value.parent;
|
|
738
|
+
if (name === "fetch" && property?.type === AST_NODE_TYPES6.UnaryExpression && property.operator === "typeof") return false;
|
|
739
|
+
if (property?.type !== AST_NODE_TYPES6.MemberExpression || property.object !== value) {
|
|
740
|
+
return name !== "fetch" || !fetchProjection(value, sourceCode, index);
|
|
741
|
+
}
|
|
742
|
+
const key = staticPropertyName(property, sourceCode);
|
|
743
|
+
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
744
|
+
if (name === "fetch" && GLOBAL_OBJECTS.has(key)) return true;
|
|
745
|
+
return key === name && !(name === "fetch" ? fetchRead(property, sourceCode, index) : nativeRead(property, name));
|
|
746
|
+
}
|
|
747
|
+
function ambient(node, sourceCode) {
|
|
748
|
+
const variable = ASTUtils4.findVariable(sourceCode.getScope(node), node.name);
|
|
749
|
+
return variable === null || variable.defs.length === 0;
|
|
750
|
+
}
|
|
751
|
+
function fetchUse(node, sourceCode) {
|
|
752
|
+
const value = outerExpression(node);
|
|
753
|
+
const parent = value.parent;
|
|
754
|
+
if (parent?.type === AST_NODE_TYPES6.CallExpression && parent.callee === value || parent?.type === AST_NODE_TYPES6.UnaryExpression && parent.operator === "typeof") return true;
|
|
755
|
+
if (parent?.type !== AST_NODE_TYPES6.VariableDeclarator || parent.init !== value || parent.id.type !== AST_NODE_TYPES6.Identifier) return false;
|
|
756
|
+
return stableConstBinding(parent.id, sourceCode) ?? false;
|
|
757
|
+
}
|
|
758
|
+
function stableConstBinding(node, sourceCode) {
|
|
759
|
+
const binding3 = ASTUtils4.findVariable(sourceCode.getScope(node), node.name);
|
|
760
|
+
if (binding3 === null || binding3.defs.length !== 1) return null;
|
|
761
|
+
const [definition] = binding3.defs;
|
|
762
|
+
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && definition.parent.parent.type !== AST_NODE_TYPES6.ExportNamedDeclaration && !binding3.references.some((reference) => reference.isWrite() && reference.init !== true) ? binding3 : null;
|
|
763
|
+
}
|
|
764
|
+
function fetchRead(node, sourceCode, index) {
|
|
765
|
+
const use = fetchUse(node, sourceCode);
|
|
766
|
+
return use === true || use !== false && fetchAliasRead(use, sourceCode, index);
|
|
767
|
+
}
|
|
768
|
+
function fetchAliasRead(binding3, sourceCode, index) {
|
|
769
|
+
const pending = [binding3];
|
|
770
|
+
const visited = [];
|
|
771
|
+
let safe = true;
|
|
772
|
+
while (pending.length > 0 && safe) {
|
|
773
|
+
const current = pending.pop();
|
|
774
|
+
if (current === void 0) continue;
|
|
775
|
+
const cached = index.fetchAliases.get(current);
|
|
776
|
+
if (cached === "safe") continue;
|
|
777
|
+
if (cached !== void 0) {
|
|
778
|
+
safe = false;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
index.fetchAliases.set(current, "visiting");
|
|
782
|
+
visited.push(current);
|
|
783
|
+
const captures = fetchAliasCaptures(current, sourceCode);
|
|
784
|
+
if (captures === false) {
|
|
785
|
+
safe = false;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
for (const captured of captures) pending.push(captured);
|
|
789
|
+
}
|
|
790
|
+
for (const current of visited) index.fetchAliases.set(current, safe ? "safe" : "unsafe");
|
|
791
|
+
return safe;
|
|
792
|
+
}
|
|
793
|
+
function fetchAliasCaptures(binding3, sourceCode) {
|
|
794
|
+
const captures = [];
|
|
795
|
+
for (const reference of binding3.references) {
|
|
796
|
+
if (reference.isValueReference === false || reference.init === true || typeOnlyReference(reference)) continue;
|
|
797
|
+
const use = fetchUse(reference.identifier, sourceCode);
|
|
798
|
+
if (use === false) return false;
|
|
799
|
+
if (use !== true) captures.push(use);
|
|
800
|
+
}
|
|
801
|
+
return captures;
|
|
802
|
+
}
|
|
803
|
+
function fetchProjection(node, sourceCode, index) {
|
|
804
|
+
const declaration = node.parent;
|
|
805
|
+
if (declaration?.type !== AST_NODE_TYPES6.VariableDeclarator || declaration.init !== node || declaration.id.type !== AST_NODE_TYPES6.ObjectPattern || declaration.id.properties.length !== 1) return false;
|
|
806
|
+
const [property] = declaration.id.properties;
|
|
807
|
+
if (property?.type !== AST_NODE_TYPES6.Property || staticPropertyName(property, sourceCode) !== "fetch" || property.value.type !== AST_NODE_TYPES6.Identifier) return false;
|
|
808
|
+
const binding3 = stableConstBinding(property.value, sourceCode);
|
|
809
|
+
return binding3 !== null && fetchAliasRead(binding3, sourceCode, index);
|
|
810
|
+
}
|
|
811
|
+
function nativeRead(node, name) {
|
|
812
|
+
const value = outerExpression(node);
|
|
813
|
+
const parent = value.parent;
|
|
814
|
+
if (parent?.type === AST_NODE_TYPES6.UnaryExpression && parent.operator === "typeof") return true;
|
|
815
|
+
if (name !== "Error") return false;
|
|
816
|
+
return parent?.type === AST_NODE_TYPES6.NewExpression && parent.callee === value || parent?.type === AST_NODE_TYPES6.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
817
|
+
}
|
|
631
818
|
|
|
632
819
|
// src/rules/_native-fetch-reference.ts
|
|
633
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES4, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
634
820
|
var GLOBAL_RECEIVERS = /* @__PURE__ */ new Set(["globalThis", "self", "window"]);
|
|
635
|
-
function nativeFetchReference(node, sourceCode
|
|
821
|
+
function nativeFetchReference(node, sourceCode) {
|
|
822
|
+
return lexicalFetchReference(node, sourceCode) && nativeRuntimeUnchanged(sourceCode, "fetch");
|
|
823
|
+
}
|
|
824
|
+
function lexicalFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
636
825
|
const expression = unwrapExpression(node);
|
|
637
|
-
if (expression.type ===
|
|
638
|
-
return
|
|
826
|
+
if (expression.type === AST_NODE_TYPES7.MemberExpression) {
|
|
827
|
+
return staticPropertyName(expression, sourceCode) === "fetch" && globalReceiver(expression.object, sourceCode);
|
|
639
828
|
}
|
|
640
|
-
if (expression.type !==
|
|
641
|
-
const binding3 =
|
|
829
|
+
if (expression.type !== AST_NODE_TYPES7.Identifier) return false;
|
|
830
|
+
const binding3 = ASTUtils5.findVariable(sourceCode.getScope(expression), expression.name);
|
|
642
831
|
if (binding3 === null || binding3.defs.length === 0) return expression.name === "fetch";
|
|
643
832
|
if (seen.has(binding3) || seen.size >= 8 || binding3.defs.length !== 1 || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
644
833
|
seen.add(binding3);
|
|
645
834
|
const [definition] = binding3.defs;
|
|
646
835
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null) return false;
|
|
647
|
-
if (definition.node.id.type ===
|
|
648
|
-
return
|
|
836
|
+
if (definition.node.id.type === AST_NODE_TYPES7.Identifier) {
|
|
837
|
+
return lexicalFetchReference(definition.node.init, sourceCode, seen);
|
|
649
838
|
}
|
|
650
|
-
return definition.node.id.type ===
|
|
839
|
+
return definition.node.id.type === AST_NODE_TYPES7.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === AST_NODE_TYPES7.Property && staticPropertyName(property, sourceCode) === "fetch" && property.value.type === AST_NODE_TYPES7.Identifier && ASTUtils5.findVariable(sourceCode.getScope(property.value), property.value.name) === binding3);
|
|
651
840
|
}
|
|
652
841
|
function globalReceiver(node, sourceCode) {
|
|
653
842
|
const receiver = unwrapExpression(node);
|
|
654
|
-
return receiver.type ===
|
|
843
|
+
return receiver.type === AST_NODE_TYPES7.Identifier && GLOBAL_RECEIVERS.has(receiver.name) && !ASTUtils5.findVariable(sourceCode.getScope(receiver), receiver.name)?.defs.length;
|
|
655
844
|
}
|
|
656
845
|
|
|
657
846
|
// src/rules/_test-mock-provenance.ts
|
|
658
|
-
import { AST_NODE_TYPES as
|
|
847
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ASTUtils as ASTUtils6 } from "@typescript-eslint/utils";
|
|
659
848
|
function importedTestMockNamespace(source, identifier) {
|
|
660
|
-
const binding3 =
|
|
849
|
+
const binding3 = ASTUtils6.findVariable(source.getScope(identifier), identifier.name);
|
|
661
850
|
const importedBinding = runtimeImportBinding(binding3);
|
|
662
|
-
if (importedBinding === null || importedBinding.specifier.type !==
|
|
851
|
+
if (importedBinding === null || importedBinding.specifier.type !== AST_NODE_TYPES8.ImportSpecifier) return null;
|
|
663
852
|
const specifier = importedBinding.specifier;
|
|
664
|
-
const imported = specifier.imported.type ===
|
|
853
|
+
const imported = specifier.imported.type === AST_NODE_TYPES8.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
665
854
|
const module = importedBinding.module;
|
|
666
855
|
if (module === "vitest" && (imported === "vi" || imported === "vitest")) return "vitest";
|
|
667
856
|
if (module === "@jest/globals" && imported === "jest") return "jest";
|
|
@@ -669,12 +858,12 @@ function importedTestMockNamespace(source, identifier) {
|
|
|
669
858
|
}
|
|
670
859
|
function isUnshadowedTestMockGlobal(source, identifier) {
|
|
671
860
|
if (identifier.name !== "vi" && identifier.name !== "jest") return false;
|
|
672
|
-
const binding3 =
|
|
861
|
+
const binding3 = ASTUtils6.findVariable(source.getScope(identifier), identifier.name);
|
|
673
862
|
return binding3 === null || binding3.defs.length === 0 && !binding3.references.some((reference) => reference.isWrite());
|
|
674
863
|
}
|
|
675
864
|
var TEST_FRAMEWORK_MODULES = /* @__PURE__ */ new Set(["@jest/globals", "@playwright/test", "bun:test", "node:test", "vitest"]);
|
|
676
865
|
function runtimeTestFrameworkName(source, identifier, kind) {
|
|
677
|
-
const binding3 =
|
|
866
|
+
const binding3 = ASTUtils6.findVariable(source.getScope(identifier), identifier.name);
|
|
678
867
|
if (binding3 === null || binding3.defs.length === 0) {
|
|
679
868
|
return binding3?.references.some((reference) => reference.isWrite()) ? null : identifier.name;
|
|
680
869
|
}
|
|
@@ -682,22 +871,22 @@ function runtimeTestFrameworkName(source, identifier, kind) {
|
|
|
682
871
|
if (importedBinding === null) return null;
|
|
683
872
|
const { specifier, module } = importedBinding;
|
|
684
873
|
const isNodeAssertion = kind === "assertion" && (module === "node:assert" || module === "node:assert/strict");
|
|
685
|
-
if (specifier.type ===
|
|
874
|
+
if (specifier.type === AST_NODE_TYPES8.ImportSpecifier) {
|
|
686
875
|
if (isNodeAssertion) return "assert";
|
|
687
876
|
if (!TEST_FRAMEWORK_MODULES.has(module)) return null;
|
|
688
|
-
const imported = specifier.imported.type ===
|
|
877
|
+
const imported = specifier.imported.type === AST_NODE_TYPES8.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
689
878
|
return imported;
|
|
690
879
|
}
|
|
691
880
|
if (isNodeAssertion) return "assert";
|
|
692
|
-
return kind === "test" && module === "node:test" && specifier.type ===
|
|
881
|
+
return kind === "test" && module === "node:test" && specifier.type === AST_NODE_TYPES8.ImportDefaultSpecifier ? "test" : null;
|
|
693
882
|
}
|
|
694
883
|
function runtimeImportBinding(binding3) {
|
|
695
884
|
if (binding3?.defs.length !== 1) return null;
|
|
696
885
|
const definition = binding3.defs[0];
|
|
697
|
-
if (definition?.type !== "ImportBinding" || definition.parent.type !==
|
|
886
|
+
if (definition?.type !== "ImportBinding" || definition.parent.type !== AST_NODE_TYPES8.ImportDeclaration || definition.parent.importKind === "type") return null;
|
|
698
887
|
const specifier = definition.node;
|
|
699
|
-
if (specifier.type !==
|
|
700
|
-
if (specifier.type ===
|
|
888
|
+
if (specifier.type !== AST_NODE_TYPES8.ImportSpecifier && specifier.type !== AST_NODE_TYPES8.ImportDefaultSpecifier && specifier.type !== AST_NODE_TYPES8.ImportNamespaceSpecifier) return null;
|
|
889
|
+
if (specifier.type === AST_NODE_TYPES8.ImportSpecifier && specifier.importKind === "type") return null;
|
|
701
890
|
return { module: definition.parent.source.value, specifier };
|
|
702
891
|
}
|
|
703
892
|
function vitestFixtureTestName(source, identifier) {
|
|
@@ -705,24 +894,24 @@ function vitestFixtureTestName(source, identifier) {
|
|
|
705
894
|
}
|
|
706
895
|
function fixtureTestName(node, source, seen) {
|
|
707
896
|
node = unwrapExpression(node);
|
|
708
|
-
if (node.type ===
|
|
897
|
+
if (node.type === AST_NODE_TYPES8.CallExpression) {
|
|
709
898
|
const callee = unwrapExpression(node.callee);
|
|
710
|
-
return !node.optional && callee.type ===
|
|
899
|
+
return !node.optional && callee.type === AST_NODE_TYPES8.MemberExpression && !callee.optional && ASTUtils6.getPropertyName(callee) === "extend" && node.arguments.length > 0 && !node.arguments.some((argument) => argument.type === AST_NODE_TYPES8.SpreadElement) ? fixtureTestName(callee.object, source, seen) : null;
|
|
711
900
|
}
|
|
712
|
-
if (node.type !==
|
|
713
|
-
const binding3 =
|
|
901
|
+
if (node.type !== AST_NODE_TYPES8.Identifier) return null;
|
|
902
|
+
const binding3 = ASTUtils6.findVariable(source.getScope(node), node.name);
|
|
714
903
|
if (binding3 === null || seen.has(binding3) || !unchangedFixtureApi(binding3)) return null;
|
|
715
904
|
seen.add(binding3);
|
|
716
905
|
const imported = runtimeImportBinding(binding3);
|
|
717
|
-
if (imported?.module === "vitest" && imported.specifier.type ===
|
|
906
|
+
if (imported?.module === "vitest" && imported.specifier.type === AST_NODE_TYPES8.ImportSpecifier) {
|
|
718
907
|
const name = imported.specifier.imported;
|
|
719
|
-
const value = name.type ===
|
|
908
|
+
const value = name.type === AST_NODE_TYPES8.Identifier ? name.name : name.value;
|
|
720
909
|
return value === "test" || value === "it" ? value : null;
|
|
721
910
|
}
|
|
722
911
|
const definition = binding3.defs[0];
|
|
723
|
-
if (binding3.defs.length !== 1 || definition?.node.type !==
|
|
912
|
+
if (binding3.defs.length !== 1 || definition?.node.type !== AST_NODE_TYPES8.VariableDeclarator || definition.node.id.type !== AST_NODE_TYPES8.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0]) return null;
|
|
724
913
|
const initializer = unwrapExpression(definition.node.init);
|
|
725
|
-
return initializer.type ===
|
|
914
|
+
return initializer.type === AST_NODE_TYPES8.CallExpression ? fixtureTestName(initializer, source, seen) : null;
|
|
726
915
|
}
|
|
727
916
|
var FIXTURE_API_STABILITY = /* @__PURE__ */ new WeakMap();
|
|
728
917
|
function unchangedFixtureApi(binding3) {
|
|
@@ -732,9 +921,9 @@ function unchangedFixtureApi(binding3) {
|
|
|
732
921
|
if (reference.isWrite()) return reference.init === true;
|
|
733
922
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
734
923
|
let use = outerExpression(reference.identifier);
|
|
735
|
-
while (use.parent?.type ===
|
|
924
|
+
while (use.parent?.type === AST_NODE_TYPES8.MemberExpression && use.parent.object === use) use = outerExpression(use.parent);
|
|
736
925
|
const parent = use.parent;
|
|
737
|
-
return parent?.type ===
|
|
926
|
+
return parent?.type === AST_NODE_TYPES8.CallExpression && parent.callee === use || parent?.type === AST_NODE_TYPES8.ExportSpecifier || parent?.type === AST_NODE_TYPES8.ExportDefaultDeclaration || parent?.type === AST_NODE_TYPES8.TSTypeQuery || parent?.type === AST_NODE_TYPES8.UnaryExpression && parent.operator === "typeof";
|
|
738
927
|
});
|
|
739
928
|
FIXTURE_API_STABILITY.set(binding3, unchanged);
|
|
740
929
|
return unchanged;
|
|
@@ -764,72 +953,72 @@ var NO_NEGATIVE_ONLY_HTTP_STATUS_ASSERTION_DOCUMENTATION = {
|
|
|
764
953
|
]
|
|
765
954
|
};
|
|
766
955
|
function statusAssertion(source, call) {
|
|
767
|
-
if (call.arguments.length !== 1 || call.arguments[0]?.type !==
|
|
768
|
-
const matcher =
|
|
956
|
+
if (call.arguments.length !== 1 || call.arguments[0]?.type !== AST_NODE_TYPES9.Literal || typeof call.arguments[0].value !== "number" || call.callee.type !== AST_NODE_TYPES9.MemberExpression) return null;
|
|
957
|
+
const matcher = ASTUtils7.getPropertyName(call.callee);
|
|
769
958
|
if (matcher === null) return null;
|
|
770
959
|
let object = unwrapExpression(call.callee.object);
|
|
771
|
-
const negative = object.type ===
|
|
772
|
-
if (negative && object.type ===
|
|
773
|
-
if (object.type !==
|
|
960
|
+
const negative = object.type === AST_NODE_TYPES9.MemberExpression && ASTUtils7.getPropertyName(object) === "not";
|
|
961
|
+
if (negative && object.type === AST_NODE_TYPES9.MemberExpression) object = unwrapExpression(object.object);
|
|
962
|
+
if (object.type !== AST_NODE_TYPES9.CallExpression || object.arguments.length !== 1 || object.callee.type !== AST_NODE_TYPES9.Identifier || runtimeTestFrameworkName(source, object.callee, "assertion") !== "expect") return null;
|
|
774
963
|
const argument = object.arguments[0];
|
|
775
|
-
const response = argument === void 0 || argument.type ===
|
|
964
|
+
const response = argument === void 0 || argument.type === AST_NODE_TYPES9.SpreadElement ? null : fetchResponse(source, argument);
|
|
776
965
|
return response === null ? null : { response, expected: call.arguments[0].value, matcher, negative };
|
|
777
966
|
}
|
|
778
967
|
function fetchResponse(source, value) {
|
|
779
968
|
const node = unwrapExpression(value);
|
|
780
|
-
if (node.type !==
|
|
969
|
+
if (node.type !== AST_NODE_TYPES9.MemberExpression || ASTUtils7.getPropertyName(node) !== "status" || node.object.type !== AST_NODE_TYPES9.Identifier) return null;
|
|
781
970
|
return responseBinding(source, node.object);
|
|
782
971
|
}
|
|
783
972
|
function responseBinding(source, node, seen = /* @__PURE__ */ new Set()) {
|
|
784
|
-
const variable =
|
|
973
|
+
const variable = ASTUtils7.findVariable(source.getScope(node), node.name);
|
|
785
974
|
const definition = variable?.defs[0]?.node;
|
|
786
975
|
if (variable?.defs.length !== 1 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
787
976
|
seen.add(variable);
|
|
788
977
|
const parameter = variable.defs[0];
|
|
789
|
-
if (parameter?.type === "Parameter" && parameter.name.type ===
|
|
978
|
+
if (parameter?.type === "Parameter" && parameter.name.type === AST_NODE_TYPES9.Identifier) {
|
|
790
979
|
const annotation = parameter.name.typeAnnotation?.typeAnnotation;
|
|
791
|
-
return annotation?.type ===
|
|
980
|
+
return annotation?.type === AST_NODE_TYPES9.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES9.Identifier && annotation.typeName.name === "Response" && (ASTUtils7.findVariable(source.getScope(annotation.typeName), "Response")?.defs.length ?? 0) === 0 ? variable : null;
|
|
792
981
|
}
|
|
793
|
-
if (definition?.type !==
|
|
982
|
+
if (definition?.type !== AST_NODE_TYPES9.VariableDeclarator || definition.parent.kind !== "const" || definition.init === null) return null;
|
|
794
983
|
let initial = unwrapExpression(definition.init);
|
|
795
|
-
if (initial.type ===
|
|
796
|
-
if (initial.type ===
|
|
984
|
+
if (initial.type === AST_NODE_TYPES9.AwaitExpression) initial = unwrapExpression(initial.argument);
|
|
985
|
+
if (initial.type === AST_NODE_TYPES9.Identifier) return responseBinding(source, initial, seen);
|
|
797
986
|
return nativeResponse(initial, source) ? variable : null;
|
|
798
987
|
}
|
|
799
988
|
function nativeResponse(initial, source) {
|
|
800
|
-
if (initial.type ===
|
|
801
|
-
if (initial.type ===
|
|
802
|
-
if (initial.type !==
|
|
989
|
+
if (initial.type === AST_NODE_TYPES9.NewExpression && initial.callee.type === AST_NODE_TYPES9.Identifier && initial.callee.name === "Response" && (ASTUtils7.findVariable(source.getScope(initial.callee), "Response")?.defs.length ?? 0) === 0) return true;
|
|
990
|
+
if (initial.type === AST_NODE_TYPES9.CallExpression && nativeFetchReference(initial.callee, source)) return true;
|
|
991
|
+
if (initial.type !== AST_NODE_TYPES9.CallExpression || initial.callee.type !== AST_NODE_TYPES9.Identifier) return false;
|
|
803
992
|
const callee = initial.callee;
|
|
804
|
-
const binding3 =
|
|
993
|
+
const binding3 = ASTUtils7.findVariable(source.getScope(callee), callee.name);
|
|
805
994
|
if ((binding3?.defs.length ?? 0) === 0) return callee.name === "fetch";
|
|
806
995
|
const imported = binding3?.defs[0];
|
|
807
|
-
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !==
|
|
996
|
+
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !== AST_NODE_TYPES9.ImportDeclaration || imported.parent.importKind === "type" || !FETCH_MODULES.has(imported.parent.source.value)) return false;
|
|
808
997
|
const specifier = imported.node;
|
|
809
|
-
if (specifier.type ===
|
|
810
|
-
if (specifier.type !==
|
|
811
|
-
const importedName7 = specifier.imported.type ===
|
|
998
|
+
if (specifier.type === AST_NODE_TYPES9.ImportDefaultSpecifier) return imported.parent.source.value === "node-fetch";
|
|
999
|
+
if (specifier.type !== AST_NODE_TYPES9.ImportSpecifier || specifier.importKind === "type") return false;
|
|
1000
|
+
const importedName7 = specifier.imported.type === AST_NODE_TYPES9.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
812
1001
|
return importedName7 === "fetch";
|
|
813
1002
|
}
|
|
814
1003
|
function enclosingTest(source, node) {
|
|
815
1004
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
816
|
-
if (current.type ===
|
|
817
|
-
if (current.type !==
|
|
1005
|
+
if (current.type === AST_NODE_TYPES9.FunctionDeclaration) return null;
|
|
1006
|
+
if (current.type !== AST_NODE_TYPES9.ArrowFunctionExpression && current.type !== AST_NODE_TYPES9.FunctionExpression) continue;
|
|
818
1007
|
const registration2 = directArgumentCall(current);
|
|
819
1008
|
const callee = registration2?.callee;
|
|
820
|
-
if (callee?.type !==
|
|
1009
|
+
if (callee?.type !== AST_NODE_TYPES9.Identifier) return null;
|
|
821
1010
|
const name = runtimeTestFrameworkName(source, callee, "test") ?? vitestFixtureTestName(source, callee);
|
|
822
1011
|
return name === "test" || name === "it" ? current : null;
|
|
823
1012
|
}
|
|
824
1013
|
return null;
|
|
825
1014
|
}
|
|
826
1015
|
function hasExactStatus(source, test, response) {
|
|
827
|
-
if (test.body.type !==
|
|
1016
|
+
if (test.body.type !== AST_NODE_TYPES9.BlockStatement) return false;
|
|
828
1017
|
return test.body.body.some((statement) => {
|
|
829
|
-
if (statement.type !==
|
|
1018
|
+
if (statement.type !== AST_NODE_TYPES9.ExpressionStatement) return false;
|
|
830
1019
|
let expression = unwrapExpression(statement.expression);
|
|
831
|
-
if (expression.type ===
|
|
832
|
-
if (expression.type !==
|
|
1020
|
+
if (expression.type === AST_NODE_TYPES9.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1021
|
+
if (expression.type !== AST_NODE_TYPES9.CallExpression) return false;
|
|
833
1022
|
const assertion = statusAssertion(source, expression);
|
|
834
1023
|
return assertion !== null && assertion.response === response && !assertion.negative && EXACT_MATCHERS.has(assertion.matcher) && Number.isInteger(assertion.expected) && assertion.expected >= HTTP_STATUS_MIN && assertion.expected <= SERVER_ERROR_MAX;
|
|
835
1024
|
});
|
|
@@ -860,7 +1049,7 @@ var no_negative_only_http_status_assertion_default = createRule({
|
|
|
860
1049
|
});
|
|
861
1050
|
|
|
862
1051
|
// src/rules/prefer-test-fixture-reuse.ts
|
|
863
|
-
import { AST_NODE_TYPES as
|
|
1052
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10, ASTUtils as ASTUtils8 } from "@typescript-eslint/utils";
|
|
864
1053
|
var MAX_DEPTH = 8;
|
|
865
1054
|
var FRAMEWORKS = /* @__PURE__ */ new Set(["vitest", "@playwright/test"]);
|
|
866
1055
|
var TEST_MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "sequential"]);
|
|
@@ -882,24 +1071,24 @@ var PREFER_TEST_FIXTURE_REUSE_DOCUMENTATION = {
|
|
|
882
1071
|
]
|
|
883
1072
|
};
|
|
884
1073
|
function stableBinding(source, identifier) {
|
|
885
|
-
const variable =
|
|
1074
|
+
const variable = ASTUtils8.findVariable(source.getScope(identifier), identifier.name);
|
|
886
1075
|
if (variable?.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
887
1076
|
return variable;
|
|
888
1077
|
}
|
|
889
1078
|
function constructorBinding(source, node, depth = 0) {
|
|
890
1079
|
node = unwrapExpression(node);
|
|
891
|
-
if (node.type !==
|
|
1080
|
+
if (node.type !== AST_NODE_TYPES10.Identifier || depth >= MAX_DEPTH) return null;
|
|
892
1081
|
const variable = stableBinding(source, node);
|
|
893
1082
|
const definition = variable?.defs[0];
|
|
894
1083
|
if (variable === null || definition === void 0) return null;
|
|
895
1084
|
if (definition.type === "ClassName") return variable;
|
|
896
|
-
if (definition.type === "ImportBinding" && definition.parent.type ===
|
|
897
|
-
if (definition.node.type ===
|
|
1085
|
+
if (definition.type === "ImportBinding" && definition.parent.type === AST_NODE_TYPES10.ImportDeclaration && definition.parent.importKind !== "type" && (definition.node.type !== AST_NODE_TYPES10.ImportSpecifier || definition.node.importKind !== "type")) return variable;
|
|
1086
|
+
if (definition.node.type === AST_NODE_TYPES10.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < node.range[0]) return constructorBinding(source, definition.node.init, depth + 1);
|
|
898
1087
|
return null;
|
|
899
1088
|
}
|
|
900
1089
|
function fixtureApi(source, expression, depth = 0) {
|
|
901
1090
|
const node = unwrapExpression(expression);
|
|
902
|
-
if (node.type !==
|
|
1091
|
+
if (node.type !== AST_NODE_TYPES10.Identifier || depth >= MAX_DEPTH) return null;
|
|
903
1092
|
const variable = stableBinding(source, node);
|
|
904
1093
|
const definition = variable?.defs[0];
|
|
905
1094
|
if (variable === null || definition === void 0) return null;
|
|
@@ -911,35 +1100,35 @@ function fixtureApi(source, expression, depth = 0) {
|
|
|
911
1100
|
}
|
|
912
1101
|
function importedFixtureApi(variable) {
|
|
913
1102
|
const definition = variable.defs[0];
|
|
914
|
-
if (definition?.type === "ImportBinding" && definition.parent.type ===
|
|
1103
|
+
if (definition?.type === "ImportBinding" && definition.parent.type === AST_NODE_TYPES10.ImportDeclaration && FRAMEWORKS.has(definition.parent.source.value) && definition.parent.importKind !== "type" && definition.node.type === AST_NODE_TYPES10.ImportSpecifier && definition.node.importKind !== "type") {
|
|
915
1104
|
const imported = definition.node.imported;
|
|
916
|
-
const name = imported.type ===
|
|
1105
|
+
const name = imported.type === AST_NODE_TYPES10.Identifier ? imported.name : imported.value;
|
|
917
1106
|
return name === "test" || name === "it";
|
|
918
1107
|
}
|
|
919
1108
|
return false;
|
|
920
1109
|
}
|
|
921
1110
|
function fixtureExtension(declaration, before) {
|
|
922
|
-
if (declaration.type !==
|
|
1111
|
+
if (declaration.type !== AST_NODE_TYPES10.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= before) return null;
|
|
923
1112
|
const initial = unwrapExpression(declaration.init);
|
|
924
|
-
if (initial.type !==
|
|
1113
|
+
if (initial.type !== AST_NODE_TYPES10.CallExpression || initial.optional || initial.arguments.length !== 1 || initial.callee.type !== AST_NODE_TYPES10.MemberExpression || initial.callee.optional || ASTUtils8.getPropertyName(initial.callee) !== "extend") return null;
|
|
925
1114
|
const declarations = initial.arguments[0];
|
|
926
|
-
if (declarations?.type !==
|
|
1115
|
+
if (declarations?.type !== AST_NODE_TYPES10.ObjectExpression || declarations.properties.some((property) => property.type !== AST_NODE_TYPES10.Property || property.computed || property.kind !== "init")) return null;
|
|
927
1116
|
return { receiver: initial.callee.object, declarations };
|
|
928
1117
|
}
|
|
929
1118
|
function fixtureApiStable(variable) {
|
|
930
1119
|
return !variable.references.some((reference) => {
|
|
931
1120
|
if (reference.isWrite() || reference.isTypeReference && !reference.isValueReference) return false;
|
|
932
1121
|
let use = reference.identifier;
|
|
933
|
-
while (use.parent?.type ===
|
|
934
|
-
return use.parent?.type !==
|
|
1122
|
+
while (use.parent?.type === AST_NODE_TYPES10.MemberExpression && use.parent.object === use) use = use.parent;
|
|
1123
|
+
return use.parent?.type !== AST_NODE_TYPES10.CallExpression || use.parent.callee !== use;
|
|
935
1124
|
});
|
|
936
1125
|
}
|
|
937
1126
|
function fixtureConstructors(source, declarations, inherited) {
|
|
938
1127
|
const result = new Map(inherited);
|
|
939
1128
|
for (const property of declarations.properties) {
|
|
940
|
-
if (property.type !==
|
|
941
|
-
const name =
|
|
942
|
-
if (name === null || property.value.type ===
|
|
1129
|
+
if (property.type !== AST_NODE_TYPES10.Property || property.computed || property.value.type === AST_NODE_TYPES10.AssignmentPattern) continue;
|
|
1130
|
+
const name = ASTUtils8.getPropertyName(property);
|
|
1131
|
+
if (name === null || property.value.type === AST_NODE_TYPES10.TSEmptyBodyFunctionExpression) continue;
|
|
943
1132
|
const constructor = fixtureConstructor(source, property.value);
|
|
944
1133
|
if (constructor === null) result.delete(name);
|
|
945
1134
|
else result.set(name, constructor);
|
|
@@ -948,24 +1137,24 @@ function fixtureConstructors(source, declarations, inherited) {
|
|
|
948
1137
|
}
|
|
949
1138
|
function fixtureConstructor(source, value) {
|
|
950
1139
|
value = unwrapExpression(value);
|
|
951
|
-
if (value.type !==
|
|
1140
|
+
if (value.type !== AST_NODE_TYPES10.ArrowFunctionExpression && value.type !== AST_NODE_TYPES10.FunctionExpression) return newConstructor(source, value);
|
|
952
1141
|
const use = value.params[1];
|
|
953
|
-
if (use?.type !==
|
|
1142
|
+
if (use?.type !== AST_NODE_TYPES10.Identifier) return null;
|
|
954
1143
|
const binding3 = stableBinding(source, use);
|
|
955
|
-
const calls = scopeNodes(value.body, source).filter((node) => node.type ===
|
|
1144
|
+
const calls = scopeNodes(value.body, source).filter((node) => node.type === AST_NODE_TYPES10.CallExpression && !node.optional && node.arguments.length === 1 && node.callee.type === AST_NODE_TYPES10.Identifier && stableBinding(source, node.callee) === binding3);
|
|
956
1145
|
if (calls.length !== 1 || binding3 === null) return null;
|
|
957
1146
|
const argument = calls[0]?.arguments[0];
|
|
958
|
-
return argument === void 0 || argument.type ===
|
|
1147
|
+
return argument === void 0 || argument.type === AST_NODE_TYPES10.SpreadElement ? null : newConstructor(source, argument);
|
|
959
1148
|
}
|
|
960
1149
|
function newConstructor(source, expression) {
|
|
961
1150
|
const value = unwrapExpression(expression);
|
|
962
|
-
if (value.type ===
|
|
963
|
-
if (value.type !==
|
|
1151
|
+
if (value.type === AST_NODE_TYPES10.NewExpression) return constructorBinding(source, value.callee);
|
|
1152
|
+
if (value.type !== AST_NODE_TYPES10.Identifier) return null;
|
|
964
1153
|
const variable = stableBinding(source, value);
|
|
965
1154
|
const declaration = variable?.defs[0]?.node;
|
|
966
|
-
if (declaration?.type !==
|
|
1155
|
+
if (declaration?.type !== AST_NODE_TYPES10.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= value.range[0]) return null;
|
|
967
1156
|
const initial = unwrapExpression(declaration.init);
|
|
968
|
-
return initial.type ===
|
|
1157
|
+
return initial.type === AST_NODE_TYPES10.NewExpression ? constructorBinding(source, initial.callee) : null;
|
|
969
1158
|
}
|
|
970
1159
|
function scopeNodes(root, source) {
|
|
971
1160
|
const result = [];
|
|
@@ -974,7 +1163,7 @@ function scopeNodes(root, source) {
|
|
|
974
1163
|
const node = pending.pop();
|
|
975
1164
|
if (node === void 0) continue;
|
|
976
1165
|
result.push(node);
|
|
977
|
-
if (node !== root && (node.type ===
|
|
1166
|
+
if (node !== root && (node.type === AST_NODE_TYPES10.ArrowFunctionExpression || node.type === AST_NODE_TYPES10.FunctionExpression || node.type === AST_NODE_TYPES10.FunctionDeclaration || node.type === AST_NODE_TYPES10.ClassDeclaration || node.type === AST_NODE_TYPES10.ClassExpression)) continue;
|
|
978
1167
|
for (const key of source.visitorKeys[node.type] ?? []) {
|
|
979
1168
|
const value = Reflect.get(node, key);
|
|
980
1169
|
if (Array.isArray(value)) pending.push(...value.filter(isNode2));
|
|
@@ -988,13 +1177,13 @@ function isNode2(value) {
|
|
|
988
1177
|
}
|
|
989
1178
|
function testApiCallee(expression) {
|
|
990
1179
|
let node = unwrapExpression(expression);
|
|
991
|
-
while (node.type ===
|
|
1180
|
+
while (node.type === AST_NODE_TYPES10.MemberExpression && !node.optional && TEST_MODIFIERS.has(ASTUtils8.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
992
1181
|
return node;
|
|
993
1182
|
}
|
|
994
1183
|
function requestingFunction(node) {
|
|
995
1184
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
996
|
-
if (current.type ===
|
|
997
|
-
if (current.type ===
|
|
1185
|
+
if (current.type === AST_NODE_TYPES10.ArrowFunctionExpression || current.type === AST_NODE_TYPES10.FunctionExpression) return current;
|
|
1186
|
+
if (current.type === AST_NODE_TYPES10.FunctionDeclaration) return null;
|
|
998
1187
|
}
|
|
999
1188
|
return null;
|
|
1000
1189
|
}
|
|
@@ -1016,13 +1205,13 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1016
1205
|
const call = functionNode === null ? null : directArgumentCall(functionNode);
|
|
1017
1206
|
if (functionNode === null || call === null) return;
|
|
1018
1207
|
const parameter = functionNode.params[0];
|
|
1019
|
-
if (parameter?.type !==
|
|
1208
|
+
if (parameter?.type !== AST_NODE_TYPES10.ObjectPattern) return;
|
|
1020
1209
|
const entries = fixtureApi(context.sourceCode, testApiCallee(call.callee));
|
|
1021
1210
|
const constructor = constructorBinding(context.sourceCode, node.callee);
|
|
1022
1211
|
if (entries === null || constructor === null) return;
|
|
1023
1212
|
for (const property of parameter.properties) {
|
|
1024
|
-
if (property.type !==
|
|
1025
|
-
const name =
|
|
1213
|
+
if (property.type !== AST_NODE_TYPES10.Property || property.computed) continue;
|
|
1214
|
+
const name = ASTUtils8.getPropertyName(property);
|
|
1026
1215
|
if (name !== null && entries.get(name) === constructor) {
|
|
1027
1216
|
context.report({ node, messageId: "reuseFixture", data: { fixture: name } });
|
|
1028
1217
|
return;
|
|
@@ -1034,7 +1223,7 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1034
1223
|
});
|
|
1035
1224
|
|
|
1036
1225
|
// src/rules/no-return-disposed-resource.ts
|
|
1037
|
-
import { AST_NODE_TYPES as
|
|
1226
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11, ASTUtils as ASTUtils9 } from "@typescript-eslint/utils";
|
|
1038
1227
|
var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
1039
1228
|
defaultLevel: "warning",
|
|
1040
1229
|
summary: "Do not return a resource whose using declaration disposes it before the caller receives it.",
|
|
@@ -1054,16 +1243,16 @@ var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
|
1054
1243
|
};
|
|
1055
1244
|
function owningFunction(node) {
|
|
1056
1245
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
1057
|
-
if (current.type ===
|
|
1246
|
+
if (current.type === AST_NODE_TYPES11.FunctionDeclaration || current.type === AST_NODE_TYPES11.FunctionExpression || current.type === AST_NODE_TYPES11.ArrowFunctionExpression) return current;
|
|
1058
1247
|
}
|
|
1059
1248
|
return null;
|
|
1060
1249
|
}
|
|
1061
1250
|
function resourceOwner(source, value, seen = /* @__PURE__ */ new Set()) {
|
|
1062
1251
|
const node = unwrapExpression(value);
|
|
1063
|
-
if (node.type !==
|
|
1064
|
-
const variable =
|
|
1252
|
+
if (node.type !== AST_NODE_TYPES11.Identifier) return null;
|
|
1253
|
+
const variable = ASTUtils9.findVariable(source.getScope(node), node.name);
|
|
1065
1254
|
const definition = variable?.defs[0];
|
|
1066
|
-
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !==
|
|
1255
|
+
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !== AST_NODE_TYPES11.VariableDeclarator) return null;
|
|
1067
1256
|
const declaration = definition.node;
|
|
1068
1257
|
if (declaration.parent.kind === "using" || declaration.parent.kind === "await using") return declaration;
|
|
1069
1258
|
if (declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= node.range[0]) return null;
|
|
@@ -1092,7 +1281,7 @@ var no_return_disposed_resource_default = createRule({
|
|
|
1092
1281
|
});
|
|
1093
1282
|
|
|
1094
1283
|
// src/rules/require-jwt-lifetime.ts
|
|
1095
|
-
import { AST_NODE_TYPES as
|
|
1284
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12, ASTUtils as ASTUtils10 } from "@typescript-eslint/utils";
|
|
1096
1285
|
var REQUIRE_JWT_LIFETIME_DOCUMENTATION = {
|
|
1097
1286
|
defaultLevel: "warning",
|
|
1098
1287
|
summary: "Require an expiration claim or a maximum token age when returning a verified JWT.",
|
|
@@ -1120,36 +1309,36 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1120
1309
|
function inspect(input) {
|
|
1121
1310
|
if (input === null) return;
|
|
1122
1311
|
let node = unwrapExpression(input);
|
|
1123
|
-
if (node.type ===
|
|
1124
|
-
if (node.type !==
|
|
1312
|
+
if (node.type === AST_NODE_TYPES12.AwaitExpression) node = unwrapExpression(node.argument);
|
|
1313
|
+
if (node.type !== AST_NODE_TYPES12.CallExpression || !isVerifier(node.callee)) return;
|
|
1125
1314
|
if (!missingLifetime(node.arguments[2])) return;
|
|
1126
1315
|
context.report({ node, messageId: "lifetime" });
|
|
1127
1316
|
}
|
|
1128
1317
|
function isVerifier(node) {
|
|
1129
1318
|
node = unwrapExpression(node);
|
|
1130
|
-
if (node.type ===
|
|
1131
|
-
const variable =
|
|
1319
|
+
if (node.type === AST_NODE_TYPES12.Identifier) {
|
|
1320
|
+
const variable = ASTUtils10.findVariable(sourceCode.getScope(node), node.name);
|
|
1132
1321
|
const declaration = variable?.defs[0]?.node;
|
|
1133
|
-
return variable?.defs.length === 1 && declaration?.type ===
|
|
1322
|
+
return variable?.defs.length === 1 && declaration?.type === AST_NODE_TYPES12.ImportSpecifier && declaration.parent.type === AST_NODE_TYPES12.ImportDeclaration && declaration.importKind !== "type" && declaration.parent.importKind !== "type" && declaration.parent.source.value === "jose" && declaration.imported.type === AST_NODE_TYPES12.Identifier && declaration.imported.name === "jwtVerify";
|
|
1134
1323
|
}
|
|
1135
|
-
if (node.type !==
|
|
1136
|
-
const definition =
|
|
1137
|
-
return definition?.type ===
|
|
1324
|
+
if (node.type !== AST_NODE_TYPES12.MemberExpression || ASTUtils10.getPropertyName(node) !== "jwtVerify" || node.object.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
1325
|
+
const definition = ASTUtils10.findVariable(sourceCode.getScope(node.object), node.object.name)?.defs[0]?.node;
|
|
1326
|
+
return definition?.type === AST_NODE_TYPES12.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && definition.parent.source.value === "jose";
|
|
1138
1327
|
}
|
|
1139
1328
|
function missingLifetime(options) {
|
|
1140
1329
|
if (options === void 0) return true;
|
|
1141
|
-
if (options.type !==
|
|
1142
|
-
return !options.properties.some((property) => property.type ===
|
|
1330
|
+
if (options.type !== AST_NODE_TYPES12.ObjectExpression || options.properties.some((property) => property.type !== AST_NODE_TYPES12.Property || property.computed)) return false;
|
|
1331
|
+
return !options.properties.some((property) => property.type === AST_NODE_TYPES12.Property && lifetimeProperty(property));
|
|
1143
1332
|
}
|
|
1144
1333
|
function lifetimeProperty(property) {
|
|
1145
|
-
const name = property.key.type ===
|
|
1334
|
+
const name = property.key.type === AST_NODE_TYPES12.Identifier ? property.key.name : property.key.type === AST_NODE_TYPES12.Literal ? property.key.value : null;
|
|
1146
1335
|
if (name === "maxTokenAge") {
|
|
1147
|
-
if (property.value.type !==
|
|
1336
|
+
if (property.value.type !== AST_NODE_TYPES12.Literal) return true;
|
|
1148
1337
|
return typeof property.value.value === "number" && Number.isFinite(property.value.value) || typeof property.value.value === "string" && property.value.value.trim() !== "";
|
|
1149
1338
|
}
|
|
1150
1339
|
if (name !== "requiredClaims") return false;
|
|
1151
|
-
if (property.value.type !==
|
|
1152
|
-
return property.value.elements.some((element) => element?.type ===
|
|
1340
|
+
if (property.value.type !== AST_NODE_TYPES12.ArrayExpression || property.value.elements.some((element) => element?.type !== AST_NODE_TYPES12.Literal)) return true;
|
|
1341
|
+
return property.value.elements.some((element) => element?.type === AST_NODE_TYPES12.Literal && element.value === "exp");
|
|
1153
1342
|
}
|
|
1154
1343
|
return {
|
|
1155
1344
|
ReturnStatement(node) {
|
|
@@ -1163,7 +1352,7 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1163
1352
|
});
|
|
1164
1353
|
|
|
1165
1354
|
// src/rules/no-discarded-validation-result.ts
|
|
1166
|
-
import { AST_NODE_TYPES as
|
|
1355
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13, ASTUtils as ASTUtils11 } from "@typescript-eslint/utils";
|
|
1167
1356
|
|
|
1168
1357
|
// src/rules/_zod.ts
|
|
1169
1358
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
@@ -1199,52 +1388,52 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1199
1388
|
function schema(node, depth = 0) {
|
|
1200
1389
|
if (depth > 24) return null;
|
|
1201
1390
|
node = unwrapExpression(node);
|
|
1202
|
-
if (node.type ===
|
|
1203
|
-
const variable =
|
|
1391
|
+
if (node.type === AST_NODE_TYPES13.Identifier) {
|
|
1392
|
+
const variable = ASTUtils11.findVariable(sourceCode.getScope(node), node.name);
|
|
1204
1393
|
const definition = variable?.defs[0]?.node;
|
|
1205
1394
|
if (variable?.defs.length !== 1) return null;
|
|
1206
|
-
if (definition?.type ===
|
|
1207
|
-
if (definition?.type ===
|
|
1208
|
-
if (definition?.type ===
|
|
1395
|
+
if (definition?.type === AST_NODE_TYPES13.ImportSpecifier && definition.parent.type === AST_NODE_TYPES13.ImportDeclaration && definition.importKind !== "type" && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1396
|
+
if (definition?.type === AST_NODE_TYPES13.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1397
|
+
if (definition?.type === AST_NODE_TYPES13.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && !variable.references.some((reference) => reference.isWrite() && !reference.init)) return schema(definition.init, depth + 1);
|
|
1209
1398
|
return null;
|
|
1210
1399
|
}
|
|
1211
|
-
if (node.type ===
|
|
1400
|
+
if (node.type === AST_NODE_TYPES13.MemberExpression) {
|
|
1212
1401
|
const owner2 = schema(node.object, depth + 1);
|
|
1213
1402
|
return owner2;
|
|
1214
1403
|
}
|
|
1215
|
-
if (node.type !==
|
|
1404
|
+
if (node.type !== AST_NODE_TYPES13.CallExpression) return null;
|
|
1216
1405
|
const owner = schema(node.callee, depth + 1);
|
|
1217
1406
|
if (owner === null) return null;
|
|
1218
|
-
const invokedChange = node.callee.type ===
|
|
1219
|
-
const coerced = node.callee.type ===
|
|
1407
|
+
const invokedChange = node.callee.type === AST_NODE_TYPES13.MemberExpression && CHANGING.has(ASTUtils11.getPropertyName(node.callee) ?? "");
|
|
1408
|
+
const coerced = node.callee.type === AST_NODE_TYPES13.MemberExpression && coercionNamespace(node.callee.object);
|
|
1220
1409
|
const changedArgument = node.arguments.some((argument) => {
|
|
1221
|
-
if (argument.type ===
|
|
1222
|
-
if (argument.type ===
|
|
1410
|
+
if (argument.type === AST_NODE_TYPES13.ArrayExpression) return argument.elements.some((element) => element !== null && schema(element, depth + 1)?.changed === true);
|
|
1411
|
+
if (argument.type === AST_NODE_TYPES13.ObjectExpression) return argument.properties.some((property) => property.type === AST_NODE_TYPES13.Property && schema(property.value, depth + 1)?.changed === true);
|
|
1223
1412
|
return schema(argument, depth + 1)?.changed === true;
|
|
1224
1413
|
});
|
|
1225
1414
|
return { changed: owner.changed || invokedChange || coerced || changedArgument };
|
|
1226
1415
|
}
|
|
1227
1416
|
function coercionNamespace(node) {
|
|
1228
1417
|
let namespace = false;
|
|
1229
|
-
if (node.type ===
|
|
1418
|
+
if (node.type === AST_NODE_TYPES13.MemberExpression && ASTUtils11.getPropertyName(node) === "coerce") {
|
|
1230
1419
|
namespace = true;
|
|
1231
1420
|
node = node.object;
|
|
1232
1421
|
}
|
|
1233
|
-
if (node.type !==
|
|
1234
|
-
const variable =
|
|
1422
|
+
if (node.type !== AST_NODE_TYPES13.Identifier) return false;
|
|
1423
|
+
const variable = ASTUtils11.findVariable(sourceCode.getScope(node), node.name);
|
|
1235
1424
|
const definition = variable?.defs[0]?.node;
|
|
1236
|
-
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !==
|
|
1237
|
-
if (definition.type ===
|
|
1238
|
-
if (definition.type !==
|
|
1239
|
-
const name = definition.imported.type ===
|
|
1425
|
+
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !== AST_NODE_TYPES13.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return false;
|
|
1426
|
+
if (definition.type === AST_NODE_TYPES13.ImportNamespaceSpecifier) return namespace;
|
|
1427
|
+
if (definition.type !== AST_NODE_TYPES13.ImportSpecifier || definition.importKind === "type") return false;
|
|
1428
|
+
const name = definition.imported.type === AST_NODE_TYPES13.Identifier ? definition.imported.name : definition.imported.value;
|
|
1240
1429
|
return namespace ? name === "z" : name === "coerce";
|
|
1241
1430
|
}
|
|
1242
1431
|
return {
|
|
1243
1432
|
ExpressionStatement(statement) {
|
|
1244
1433
|
let expression = unwrapExpression(statement.expression);
|
|
1245
|
-
if (expression.type ===
|
|
1246
|
-
if (expression.type !==
|
|
1247
|
-
const method =
|
|
1434
|
+
if (expression.type === AST_NODE_TYPES13.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1435
|
+
if (expression.type !== AST_NODE_TYPES13.CallExpression || expression.callee.type !== AST_NODE_TYPES13.MemberExpression) return;
|
|
1436
|
+
const method = ASTUtils11.getPropertyName(expression.callee);
|
|
1248
1437
|
if (!(/* @__PURE__ */ new Set(["parse", "parseAsync", "safeParse", "safeParseAsync"])).has(method ?? "")) return;
|
|
1249
1438
|
const owner = schema(expression.callee.object);
|
|
1250
1439
|
if (owner !== null && (owner.changed || method?.startsWith("safe") === true)) context.report({ node: expression, messageId: "discarded" });
|
|
@@ -1254,7 +1443,7 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1254
1443
|
});
|
|
1255
1444
|
|
|
1256
1445
|
// src/rules/production-derived-test-cases.ts
|
|
1257
|
-
import { AST_NODE_TYPES as
|
|
1446
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ASTUtils as ASTUtils12 } from "@typescript-eslint/utils";
|
|
1258
1447
|
var MEMBERSHIP = /(?:^|_)(?:ALLOWED|ELIGIBLE|REQUIRED|SUPPORTED)(?:_|$)/u;
|
|
1259
1448
|
var SUPPORT_PATH = /(?:^|[/_.-])(?:tests?|fixtures?|fakes?|mocks?|stubs?|__tests__)(?:[/_.-]|$)/u;
|
|
1260
1449
|
var PRODUCTION_DERIVED_TEST_CASES_DOCUMENTATION = {
|
|
@@ -1289,52 +1478,52 @@ var production_derived_test_cases_default = createRule({
|
|
|
1289
1478
|
const tables = [];
|
|
1290
1479
|
const asserted = /* @__PURE__ */ new Set();
|
|
1291
1480
|
function binding3(node) {
|
|
1292
|
-
return
|
|
1481
|
+
return ASTUtils12.findVariable(sourceCode.getScope(node), node.name);
|
|
1293
1482
|
}
|
|
1294
1483
|
function importedName7(node, module) {
|
|
1295
1484
|
const variable = binding3(node);
|
|
1296
1485
|
const specifier = variable?.defs[0]?.node;
|
|
1297
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1298
|
-
return specifier.imported.type ===
|
|
1486
|
+
if (variable?.defs.length !== 1 || specifier?.type !== AST_NODE_TYPES14.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== AST_NODE_TYPES14.ImportDeclaration || specifier.parent.importKind === "type" || specifier.parent.source.value !== module || variable.references.some((reference) => reference.isWrite())) return null;
|
|
1487
|
+
return specifier.imported.type === AST_NODE_TYPES14.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1299
1488
|
}
|
|
1300
1489
|
function production(node) {
|
|
1301
1490
|
node = unwrapExpression(node);
|
|
1302
|
-
if (node.type !==
|
|
1491
|
+
if (node.type !== AST_NODE_TYPES14.Identifier) return null;
|
|
1303
1492
|
const variable = binding3(node);
|
|
1304
1493
|
const specifier = variable?.defs[0]?.node;
|
|
1305
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1306
|
-
const name = specifier.imported.type ===
|
|
1494
|
+
if (variable?.defs.length !== 1 || specifier?.type !== AST_NODE_TYPES14.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== AST_NODE_TYPES14.ImportDeclaration || specifier.parent.importKind === "type" || !specifier.parent.source.value.startsWith(".") || SUPPORT_PATH.test(specifier.parent.source.value) || variable.references.some((reference) => reference.isWrite())) return null;
|
|
1495
|
+
const name = specifier.imported.type === AST_NODE_TYPES14.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1307
1496
|
return MEMBERSHIP.test(name) && !name.endsWith("REGISTRY") ? variable : null;
|
|
1308
1497
|
}
|
|
1309
1498
|
function runner(node) {
|
|
1310
1499
|
node = unwrapExpression(node);
|
|
1311
|
-
while (node.type ===
|
|
1312
|
-
if (node.type !==
|
|
1500
|
+
while (node.type === AST_NODE_TYPES14.MemberExpression && ["only", "skip", "concurrent", "sequential"].includes(ASTUtils12.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
1501
|
+
if (node.type !== AST_NODE_TYPES14.Identifier) return false;
|
|
1313
1502
|
const name = importedName7(node, "vitest");
|
|
1314
1503
|
return name === "test" || name === "it" || vitestFixtureTestName(sourceCode, node) !== null;
|
|
1315
1504
|
}
|
|
1316
1505
|
function caseTable(node) {
|
|
1317
|
-
return node.type ===
|
|
1506
|
+
return node.type === AST_NODE_TYPES14.CallExpression && node.callee.type === AST_NODE_TYPES14.MemberExpression && ["each", "for"].includes(ASTUtils12.getPropertyName(node.callee) ?? "") && runner(node.callee.object);
|
|
1318
1507
|
}
|
|
1319
1508
|
function literalTable(node, seen = /* @__PURE__ */ new Set()) {
|
|
1320
1509
|
node = unwrapExpression(node);
|
|
1321
1510
|
if (seen.has(node)) return false;
|
|
1322
1511
|
seen.add(node);
|
|
1323
|
-
if (node.type ===
|
|
1512
|
+
if (node.type === AST_NODE_TYPES14.Identifier) {
|
|
1324
1513
|
const variable = binding3(node);
|
|
1325
1514
|
const definition = variable?.defs[0]?.node;
|
|
1326
|
-
return variable?.defs.length === 1 && definition?.type ===
|
|
1515
|
+
return variable?.defs.length === 1 && definition?.type === AST_NODE_TYPES14.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && variable.references.every((reference) => reference.init || !reference.isWrite() && reference.identifier.parent.type === AST_NODE_TYPES14.CallExpression && (caseTable(reference.identifier.parent) || reference.identifier.parent.callee.type === AST_NODE_TYPES14.Identifier && importedName7(reference.identifier.parent.callee, "vitest") === "expect" || reference.identifier.parent.callee.type === AST_NODE_TYPES14.MemberExpression && ["toEqual", "toStrictEqual"].includes(ASTUtils12.getPropertyName(reference.identifier.parent.callee) ?? ""))) && literalTable(definition.init, seen);
|
|
1327
1516
|
}
|
|
1328
|
-
return node.type ===
|
|
1517
|
+
return node.type === AST_NODE_TYPES14.ArrayExpression && node.elements.every((element) => element?.type === AST_NODE_TYPES14.Literal && !("regex" in element));
|
|
1329
1518
|
}
|
|
1330
1519
|
function unconditional(node) {
|
|
1331
1520
|
const statement = node.parent;
|
|
1332
|
-
if (statement.type !==
|
|
1333
|
-
if (statement.parent.type ===
|
|
1521
|
+
if (statement.type !== AST_NODE_TYPES14.ExpressionStatement) return false;
|
|
1522
|
+
if (statement.parent.type === AST_NODE_TYPES14.Program) return true;
|
|
1334
1523
|
const block = statement.parent;
|
|
1335
|
-
if (block.type !==
|
|
1524
|
+
if (block.type !== AST_NODE_TYPES14.BlockStatement || block.parent.type !== AST_NODE_TYPES14.ArrowFunctionExpression && block.parent.type !== AST_NODE_TYPES14.FunctionExpression) return false;
|
|
1336
1525
|
const call = block.parent.parent;
|
|
1337
|
-
return call.type ===
|
|
1526
|
+
return call.type === AST_NODE_TYPES14.CallExpression && runner(call.callee);
|
|
1338
1527
|
}
|
|
1339
1528
|
return {
|
|
1340
1529
|
CallExpression(node) {
|
|
@@ -1342,9 +1531,9 @@ var production_derived_test_cases_default = createRule({
|
|
|
1342
1531
|
const variable2 = production(node.arguments[0]);
|
|
1343
1532
|
if (variable2 !== null) tables.push({ node, variable: variable2 });
|
|
1344
1533
|
}
|
|
1345
|
-
if (node.callee.type !==
|
|
1534
|
+
if (node.callee.type !== AST_NODE_TYPES14.MemberExpression || !["toEqual", "toStrictEqual"].includes(ASTUtils12.getPropertyName(node.callee) ?? "") || node.arguments.length !== 1 || node.arguments[0] === void 0 || !literalTable(node.arguments[0]) || !unconditional(node)) return;
|
|
1346
1535
|
const expect = node.callee.object;
|
|
1347
|
-
if (expect.type !==
|
|
1536
|
+
if (expect.type !== AST_NODE_TYPES14.CallExpression || expect.callee.type !== AST_NODE_TYPES14.Identifier || importedName7(expect.callee, "vitest") !== "expect" || expect.arguments.length !== 1 || expect.arguments[0] === void 0) return;
|
|
1348
1537
|
const variable = production(expect.arguments[0]);
|
|
1349
1538
|
if (variable !== null) asserted.add(variable);
|
|
1350
1539
|
},
|
|
@@ -1356,14 +1545,14 @@ var production_derived_test_cases_default = createRule({
|
|
|
1356
1545
|
});
|
|
1357
1546
|
|
|
1358
1547
|
// src/rules/require-constrained-schema-integer.ts
|
|
1359
|
-
import { AST_NODE_TYPES as
|
|
1548
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ASTUtils as ASTUtils13 } from "@typescript-eslint/utils";
|
|
1360
1549
|
var FIELD_MINIMUMS = /* @__PURE__ */ new Map([["limit", 1], ["version", 0]]);
|
|
1361
1550
|
var NUMBER_FACTORIES = /* @__PURE__ */ new Set(["number", "int", "int32", "uint32"]);
|
|
1362
1551
|
var PRESERVING = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta", "max", "lte", "lt", "finite", "safe", "multipleOf"]);
|
|
1363
1552
|
function numericLiteral(node) {
|
|
1364
1553
|
node = unwrapExpression(node);
|
|
1365
|
-
if (node.type ===
|
|
1366
|
-
if (node.type ===
|
|
1554
|
+
if (node.type === AST_NODE_TYPES15.Literal && typeof node.value === "number") return node.value;
|
|
1555
|
+
if (node.type === AST_NODE_TYPES15.UnaryExpression && (node.operator === "-" || node.operator === "+")) {
|
|
1367
1556
|
const value = numericLiteral(node.argument);
|
|
1368
1557
|
return value === null ? null : node.operator === "-" ? -value : value;
|
|
1369
1558
|
}
|
|
@@ -1400,35 +1589,35 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1400
1589
|
const sourceCode = context.sourceCode;
|
|
1401
1590
|
function factory(node) {
|
|
1402
1591
|
node = unwrapExpression(node);
|
|
1403
|
-
if (node.type ===
|
|
1592
|
+
if (node.type === AST_NODE_TYPES15.Identifier) {
|
|
1404
1593
|
const definition2 = imported(node);
|
|
1405
|
-
return definition2?.type ===
|
|
1594
|
+
return definition2?.type === AST_NODE_TYPES15.ImportSpecifier ? definition2.imported.type === AST_NODE_TYPES15.Identifier ? definition2.imported.name : definition2.imported.value : null;
|
|
1406
1595
|
}
|
|
1407
|
-
if (node.type !==
|
|
1596
|
+
if (node.type !== AST_NODE_TYPES15.MemberExpression) return null;
|
|
1408
1597
|
let receiver = unwrapExpression(node.object);
|
|
1409
|
-
if (receiver.type ===
|
|
1410
|
-
if (receiver.type !==
|
|
1598
|
+
if (receiver.type === AST_NODE_TYPES15.MemberExpression && ASTUtils13.getPropertyName(receiver) === "coerce") receiver = unwrapExpression(receiver.object);
|
|
1599
|
+
if (receiver.type !== AST_NODE_TYPES15.Identifier) return null;
|
|
1411
1600
|
const definition = imported(receiver);
|
|
1412
|
-
if (definition === null || definition.type ===
|
|
1413
|
-
return
|
|
1601
|
+
if (definition === null || definition.type === AST_NODE_TYPES15.ImportSpecifier && (definition.imported.type === AST_NODE_TYPES15.Identifier ? definition.imported.name : definition.imported.value) !== "z") return null;
|
|
1602
|
+
return ASTUtils13.getPropertyName(node);
|
|
1414
1603
|
}
|
|
1415
1604
|
function imported(identifier) {
|
|
1416
|
-
const variable =
|
|
1605
|
+
const variable = ASTUtils13.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
1417
1606
|
const definition = variable?.defs[0]?.node;
|
|
1418
|
-
if (variable?.defs.length !== 1 || definition?.type !==
|
|
1419
|
-
return definition.type ===
|
|
1607
|
+
if (variable?.defs.length !== 1 || definition?.type !== AST_NODE_TYPES15.ImportSpecifier && definition?.type !== AST_NODE_TYPES15.ImportNamespaceSpecifier || definition.parent.type !== AST_NODE_TYPES15.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1608
|
+
return definition.type === AST_NODE_TYPES15.ImportSpecifier && definition.importKind === "type" ? null : definition;
|
|
1420
1609
|
}
|
|
1421
1610
|
function constrained(value, minimum) {
|
|
1422
1611
|
const calls = [];
|
|
1423
1612
|
value = unwrapExpression(value);
|
|
1424
|
-
while (value.type ===
|
|
1613
|
+
while (value.type === AST_NODE_TYPES15.CallExpression) {
|
|
1425
1614
|
const name = factory(value.callee);
|
|
1426
1615
|
if (name !== null) {
|
|
1427
1616
|
return chainContract(name, calls, minimum);
|
|
1428
1617
|
}
|
|
1429
1618
|
const callee = unwrapExpression(value.callee);
|
|
1430
|
-
if (callee.type !==
|
|
1431
|
-
const method =
|
|
1619
|
+
if (callee.type !== AST_NODE_TYPES15.MemberExpression) return null;
|
|
1620
|
+
const method = ASTUtils13.getPropertyName(callee);
|
|
1432
1621
|
if (method === null) return null;
|
|
1433
1622
|
calls.push({ method, call: value });
|
|
1434
1623
|
value = unwrapExpression(callee.object);
|
|
@@ -1453,7 +1642,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1453
1642
|
}
|
|
1454
1643
|
function lowerBound(call, minimum, exclusive) {
|
|
1455
1644
|
const argument = call.arguments[0];
|
|
1456
|
-
if (argument === void 0 || argument.type ===
|
|
1645
|
+
if (argument === void 0 || argument.type === AST_NODE_TYPES15.SpreadElement) return null;
|
|
1457
1646
|
const bound = numericLiteral(argument);
|
|
1458
1647
|
return bound === null || bound >= minimum - (exclusive ? 1 : 0);
|
|
1459
1648
|
}
|
|
@@ -1462,10 +1651,10 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1462
1651
|
const name = factory(node.callee);
|
|
1463
1652
|
if (name === null || !["object", "strictObject", "looseObject"].includes(name) || node.arguments.length !== 1) return;
|
|
1464
1653
|
const shape = node.arguments[0];
|
|
1465
|
-
if (shape?.type !==
|
|
1654
|
+
if (shape?.type !== AST_NODE_TYPES15.ObjectExpression) return;
|
|
1466
1655
|
for (const property of shape.properties) {
|
|
1467
|
-
if (property.type !==
|
|
1468
|
-
const field =
|
|
1656
|
+
if (property.type !== AST_NODE_TYPES15.Property || property.computed || property.kind !== "init" || property.method) continue;
|
|
1657
|
+
const field = ASTUtils13.getPropertyName(property);
|
|
1469
1658
|
const minimum = field === null ? void 0 : FIELD_MINIMUMS.get(field);
|
|
1470
1659
|
if (minimum === void 0 || field === null || constrained(property.value, minimum) !== false) continue;
|
|
1471
1660
|
context.report({ node: property, messageId: "constrainInteger", data: { field, minimum } });
|
|
@@ -1476,7 +1665,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1476
1665
|
});
|
|
1477
1666
|
|
|
1478
1667
|
// src/rules/no-generic-json-parser.ts
|
|
1479
|
-
import { AST_NODE_TYPES as
|
|
1668
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ASTUtils as ASTUtils14 } from "@typescript-eslint/utils";
|
|
1480
1669
|
var OPEN_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "json", "record", "partialRecord"]);
|
|
1481
1670
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta"]);
|
|
1482
1671
|
var NO_GENERIC_JSON_PARSER_DOCUMENTATION = {
|
|
@@ -1509,60 +1698,60 @@ var no_generic_json_parser_default = createRule({
|
|
|
1509
1698
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1510
1699
|
const sourceCode = context.sourceCode;
|
|
1511
1700
|
function binding3(node) {
|
|
1512
|
-
return
|
|
1701
|
+
return ASTUtils14.findVariable(sourceCode.getScope(node), node.name);
|
|
1513
1702
|
}
|
|
1514
1703
|
function initializer(node) {
|
|
1515
1704
|
const variable = binding3(node);
|
|
1516
1705
|
const definition = variable?.defs[0];
|
|
1517
|
-
if (variable?.defs.length !== 1 || definition?.node.type !==
|
|
1706
|
+
if (variable?.defs.length !== 1 || definition?.node.type !== AST_NODE_TYPES16.VariableDeclarator || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.range[1] >= node.range[0] || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
1518
1707
|
return definition.node.init;
|
|
1519
1708
|
}
|
|
1520
1709
|
function parser(node, seen = /* @__PURE__ */ new Set(), awaited = false) {
|
|
1521
1710
|
node = unwrapExpression(node);
|
|
1522
1711
|
if (seen.has(node)) return null;
|
|
1523
1712
|
seen.add(node);
|
|
1524
|
-
if (node.type ===
|
|
1525
|
-
if (node.type ===
|
|
1713
|
+
if (node.type === AST_NODE_TYPES16.AwaitExpression) return parser(node.argument, seen, true);
|
|
1714
|
+
if (node.type === AST_NODE_TYPES16.Identifier) {
|
|
1526
1715
|
const value = initializer(node);
|
|
1527
1716
|
return value === null ? null : parser(value, seen, awaited);
|
|
1528
1717
|
}
|
|
1529
|
-
if (node.type !==
|
|
1530
|
-
if (
|
|
1718
|
+
if (node.type !== AST_NODE_TYPES16.CallExpression || node.callee.type !== AST_NODE_TYPES16.MemberExpression || !["parse", "parseAsync"].includes(ASTUtils14.getPropertyName(node.callee) ?? "")) return null;
|
|
1719
|
+
if (ASTUtils14.getPropertyName(node.callee) === "parseAsync" && !awaited) return null;
|
|
1531
1720
|
return openSchema(node.callee.object) ? node : null;
|
|
1532
1721
|
}
|
|
1533
1722
|
function openSchema(node, seen = /* @__PURE__ */ new Set()) {
|
|
1534
1723
|
node = unwrapExpression(node);
|
|
1535
1724
|
if (seen.has(node)) return false;
|
|
1536
1725
|
seen.add(node);
|
|
1537
|
-
if (node.type ===
|
|
1726
|
+
if (node.type === AST_NODE_TYPES16.Identifier) {
|
|
1538
1727
|
const value = initializer(node);
|
|
1539
1728
|
return value !== null && openSchema(value, seen);
|
|
1540
1729
|
}
|
|
1541
|
-
if (node.type !==
|
|
1730
|
+
if (node.type !== AST_NODE_TYPES16.CallExpression) return false;
|
|
1542
1731
|
const name = factory(node.callee);
|
|
1543
1732
|
if (name !== null) return OPEN_FACTORIES.has(name);
|
|
1544
1733
|
const callee = unwrapExpression(node.callee);
|
|
1545
|
-
return callee.type ===
|
|
1734
|
+
return callee.type === AST_NODE_TYPES16.MemberExpression && WRAPPERS.has(ASTUtils14.getPropertyName(callee) ?? "") && openSchema(callee.object, seen);
|
|
1546
1735
|
}
|
|
1547
1736
|
function factory(node) {
|
|
1548
1737
|
node = unwrapExpression(node);
|
|
1549
|
-
if (node.type ===
|
|
1738
|
+
if (node.type === AST_NODE_TYPES16.Identifier) {
|
|
1550
1739
|
const definition2 = binding3(node)?.defs[0]?.node;
|
|
1551
|
-
if (definition2?.type !==
|
|
1552
|
-
return definition2.imported.type ===
|
|
1740
|
+
if (definition2?.type !== AST_NODE_TYPES16.ImportSpecifier || definition2.parent.type !== AST_NODE_TYPES16.ImportDeclaration || definition2.importKind === "type" || definition2.parent.importKind === "type" || !isZodModule(definition2.parent.source.value)) return null;
|
|
1741
|
+
return definition2.imported.type === AST_NODE_TYPES16.Identifier ? definition2.imported.name : definition2.imported.value;
|
|
1553
1742
|
}
|
|
1554
|
-
if (node.type !==
|
|
1743
|
+
if (node.type !== AST_NODE_TYPES16.MemberExpression) return null;
|
|
1555
1744
|
const receiver = unwrapExpression(node.object);
|
|
1556
|
-
if (receiver.type !==
|
|
1745
|
+
if (receiver.type !== AST_NODE_TYPES16.Identifier) return null;
|
|
1557
1746
|
const definition = binding3(receiver)?.defs[0]?.node;
|
|
1558
|
-
if (definition === void 0 || definition.type !==
|
|
1559
|
-
if (definition.type ===
|
|
1560
|
-
return
|
|
1747
|
+
if (definition === void 0 || definition.type !== AST_NODE_TYPES16.ImportSpecifier && definition.type !== AST_NODE_TYPES16.ImportNamespaceSpecifier || definition.parent.type !== AST_NODE_TYPES16.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1748
|
+
if (definition.type === AST_NODE_TYPES16.ImportSpecifier && (definition.importKind === "type" || (definition.imported.type === AST_NODE_TYPES16.Identifier ? definition.imported.name : definition.imported.value) !== "z")) return null;
|
|
1749
|
+
return ASTUtils14.getPropertyName(node);
|
|
1561
1750
|
}
|
|
1562
1751
|
const reported = /* @__PURE__ */ new Set();
|
|
1563
1752
|
return {
|
|
1564
1753
|
MemberExpression(node) {
|
|
1565
|
-
const field =
|
|
1754
|
+
const field = ASTUtils14.getPropertyName(node);
|
|
1566
1755
|
if (field === null) return;
|
|
1567
1756
|
const call = parser(node.object);
|
|
1568
1757
|
if (call === null || reported.has(call)) return;
|
|
@@ -1574,7 +1763,7 @@ var no_generic_json_parser_default = createRule({
|
|
|
1574
1763
|
});
|
|
1575
1764
|
|
|
1576
1765
|
// src/rules/no-redundant-local-alias.ts
|
|
1577
|
-
import { AST_NODE_TYPES as
|
|
1766
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
1578
1767
|
var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
1579
1768
|
defaultLevel: "warning",
|
|
1580
1769
|
summary: "Pass the original local into an object field instead of creating a single-use rename.",
|
|
@@ -1593,7 +1782,7 @@ var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
|
1593
1782
|
function stableSource(variable, alias) {
|
|
1594
1783
|
const definition = variable.defs[0];
|
|
1595
1784
|
if (variable.defs.length !== 1 || definition === void 0 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
1596
|
-
return definition.type === "Parameter" || definition.node.type ===
|
|
1785
|
+
return definition.type === "Parameter" || definition.node.type === AST_NODE_TYPES17.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < alias.range[0];
|
|
1597
1786
|
}
|
|
1598
1787
|
var no_redundant_local_alias_default = createRule({
|
|
1599
1788
|
name: "no-redundant-local-alias",
|
|
@@ -1609,18 +1798,18 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1609
1798
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1610
1799
|
return {
|
|
1611
1800
|
VariableDeclarator(node) {
|
|
1612
|
-
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !==
|
|
1801
|
+
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !== AST_NODE_TYPES17.Identifier || node.id.typeAnnotation !== void 0 || node.init?.type !== AST_NODE_TYPES17.Identifier) return;
|
|
1613
1802
|
const scope = context.sourceCode.getScope(node);
|
|
1614
1803
|
if (scope.variableScope.type !== "function") return;
|
|
1615
|
-
const target =
|
|
1616
|
-
const source =
|
|
1804
|
+
const target = ASTUtils15.findVariable(scope, node.id.name);
|
|
1805
|
+
const source = ASTUtils15.findVariable(scope, node.init.name);
|
|
1617
1806
|
if (target === null || source === null || !stableSource(source, node)) return;
|
|
1618
1807
|
const reads = target.references.filter((reference) => reference.isRead());
|
|
1619
1808
|
if (reads.length !== 1 || target.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
1620
1809
|
const read = reads[0];
|
|
1621
1810
|
if (read === void 0 || read.from.variableScope !== scope.variableScope) return;
|
|
1622
1811
|
const property = read.identifier.parent;
|
|
1623
|
-
if (property.type !==
|
|
1812
|
+
if (property.type !== AST_NODE_TYPES17.Property || !property.shorthand || property.value !== read.identifier || property.parent.type !== AST_NODE_TYPES17.ObjectExpression || property.computed || property.method || property.kind !== "init") return;
|
|
1624
1813
|
context.report({ node, messageId: "redundantAlias", data: { source: node.init.name, target: node.id.name } });
|
|
1625
1814
|
}
|
|
1626
1815
|
};
|
|
@@ -1628,10 +1817,10 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1628
1817
|
});
|
|
1629
1818
|
|
|
1630
1819
|
// src/rules/no-test-comments.ts
|
|
1631
|
-
import { AST_NODE_TYPES as
|
|
1820
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19 } from "@typescript-eslint/utils";
|
|
1632
1821
|
|
|
1633
1822
|
// src/rules/_comments.ts
|
|
1634
|
-
import { AST_NODE_TYPES as
|
|
1823
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
1635
1824
|
var REF_RE = /https?:\/\/|\bRFC[- ]?\d+|\bPEP[- ]?\d+|\bCVE-\d{4}|\b(?!UTF-|SHA-|ISO-|AES-|CRC-|MD-|PCM-|EOF-|API-|BASE-)[A-Z][A-Z0-9]{1,9}-\d[A-Z0-9]{0,5}\b|(?<![&\w])#\d{2,6}\b|@[a-z][\w.-]*\.(?:us|com|ai|io|net|org|dev)\b/;
|
|
1636
1825
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
1637
1826
|
var UNITS_RE = /[~<>]?\d+(?:\.\d+)?\s?(?:ms|s\b|sec\b|seconds?\b|min\b|minutes?\b|hours?\b|days?\b|KB|MB|MiB|GiB|kHz|Hz|bytes?\b|bit\b|-bit\b|%|px\b|rps\b|qps\b)|\b[1-5]xx\b|\b(?:301|302|304|307|308|400|401|403|404|405|409|410|412|422|425|429|500|501|502|503|504)\b/;
|
|
@@ -1717,10 +1906,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
1717
1906
|
var NARRATION_MIN_CONTENT = 1;
|
|
1718
1907
|
var TOKEN_PLURAL_MIN = 4;
|
|
1719
1908
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1909
|
+
AST_NODE_TYPES18.ExpressionStatement,
|
|
1910
|
+
AST_NODE_TYPES18.ReturnStatement,
|
|
1911
|
+
AST_NODE_TYPES18.ThrowStatement,
|
|
1912
|
+
AST_NODE_TYPES18.VariableDeclaration
|
|
1724
1913
|
]);
|
|
1725
1914
|
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
1726
1915
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -1779,12 +1968,12 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
1779
1968
|
function restatableStatementNodeBelow(comment, sourceCode) {
|
|
1780
1969
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
1781
1970
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
1782
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
1971
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES18.Program; node = node.parent) {
|
|
1783
1972
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
1784
1973
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
1785
1974
|
return null;
|
|
1786
1975
|
}
|
|
1787
|
-
if (node.type ===
|
|
1976
|
+
if (node.type === AST_NODE_TYPES18.VariableDeclaration && isTrivialInitializer(node)) {
|
|
1788
1977
|
return null;
|
|
1789
1978
|
}
|
|
1790
1979
|
return node;
|
|
@@ -1794,8 +1983,8 @@ function restatableStatementNodeBelow(comment, sourceCode) {
|
|
|
1794
1983
|
function isTrivialInitializer(node) {
|
|
1795
1984
|
return node.declarations.every((declarator) => {
|
|
1796
1985
|
const init = declarator.init;
|
|
1797
|
-
if (init == null || init.type ===
|
|
1798
|
-
return init.type ===
|
|
1986
|
+
if (init == null || init.type === AST_NODE_TYPES18.Literal) return true;
|
|
1987
|
+
return init.type === AST_NODE_TYPES18.ArrayExpression && init.elements.length === 0 || init.type === AST_NODE_TYPES18.ObjectExpression && init.properties.length === 0;
|
|
1799
1988
|
});
|
|
1800
1989
|
}
|
|
1801
1990
|
function restatesStatementHead(body3, statement) {
|
|
@@ -1949,7 +2138,7 @@ var no_test_comments_default = createRule({
|
|
|
1949
2138
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1950
2139
|
const filename = scopedFilename(context);
|
|
1951
2140
|
const unambiguous = /(?:^|\/)(?:tests?|__tests__|fixtures|__fixtures__|__mocks__)\//u.test(filename) || /\.(?:test|spec|e2e|integration)\.[cm]?[jt]sx?$/u.test(filename);
|
|
1952
|
-
const framework = context.sourceCode.ast.body.some((statement) => statement.type ===
|
|
2141
|
+
const framework = context.sourceCode.ast.body.some((statement) => statement.type === AST_NODE_TYPES19.ImportDeclaration && statement.importKind !== "type" && (statement.specifiers.length === 0 || statement.specifiers.some((specifier) => specifier.type !== AST_NODE_TYPES19.ImportSpecifier || specifier.importKind !== "type")) && ["vitest", "@jest/globals", "@playwright/test", "bun:test", "node:test"].includes(statement.source.value));
|
|
1953
2142
|
if (!unambiguous && !framework) return {};
|
|
1954
2143
|
return {
|
|
1955
2144
|
Program() {
|
|
@@ -1999,14 +2188,14 @@ var no_test_comments_default = createRule({
|
|
|
1999
2188
|
});
|
|
2000
2189
|
|
|
2001
2190
|
// src/rules/no-mutating-container-transform.ts
|
|
2002
|
-
import { AST_NODE_TYPES as
|
|
2191
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ASTUtils as ASTUtils16 } from "@typescript-eslint/utils";
|
|
2003
2192
|
var MUTATORS = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
2004
2193
|
var PRIMITIVES = /* @__PURE__ */ new Set([
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2194
|
+
AST_NODE_TYPES20.TSStringKeyword,
|
|
2195
|
+
AST_NODE_TYPES20.TSNumberKeyword,
|
|
2196
|
+
AST_NODE_TYPES20.TSBooleanKeyword,
|
|
2197
|
+
AST_NODE_TYPES20.TSBigIntKeyword,
|
|
2198
|
+
AST_NODE_TYPES20.TSSymbolKeyword
|
|
2010
2199
|
]);
|
|
2011
2200
|
var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
2012
2201
|
defaultLevel: "warning",
|
|
@@ -2025,27 +2214,27 @@ var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
|
2025
2214
|
]
|
|
2026
2215
|
};
|
|
2027
2216
|
function arrayElement(node, sourceCode) {
|
|
2028
|
-
if (node.type ===
|
|
2029
|
-
if (node.type ===
|
|
2217
|
+
if (node.type === AST_NODE_TYPES20.TSArrayType) return node.elementType;
|
|
2218
|
+
if (node.type === AST_NODE_TYPES20.TSTypeReference && node.typeName.type === AST_NODE_TYPES20.Identifier && (node.typeName.name === "Array" || node.typeName.name === "ReadonlyArray") && (ASTUtils16.findVariable(sourceCode.getScope(node.typeName), node.typeName.name)?.defs.length ?? 0) === 0 && node.typeArguments?.params.length === 1) return node.typeArguments.params[0] ?? null;
|
|
2030
2219
|
return null;
|
|
2031
2220
|
}
|
|
2032
2221
|
function returnsArray(node, sourceCode) {
|
|
2033
2222
|
let annotation = node.returnType?.typeAnnotation;
|
|
2034
|
-
if (annotation?.type ===
|
|
2223
|
+
if (annotation?.type === AST_NODE_TYPES20.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES20.Identifier && annotation.typeName.name === "Promise" && (ASTUtils16.findVariable(sourceCode.getScope(annotation.typeName), "Promise")?.defs.length ?? 0) === 0 && annotation.typeArguments?.params.length === 1) annotation = annotation.typeArguments.params[0];
|
|
2035
2224
|
return annotation !== void 0 && arrayElement(annotation, sourceCode) !== null;
|
|
2036
2225
|
}
|
|
2037
2226
|
function supported(statements) {
|
|
2038
2227
|
return statements.every((statement) => {
|
|
2039
2228
|
switch (statement.type) {
|
|
2040
|
-
case
|
|
2041
|
-
case
|
|
2042
|
-
case
|
|
2043
|
-
case
|
|
2044
|
-
case
|
|
2229
|
+
case AST_NODE_TYPES20.ExpressionStatement:
|
|
2230
|
+
case AST_NODE_TYPES20.VariableDeclaration:
|
|
2231
|
+
case AST_NODE_TYPES20.ReturnStatement:
|
|
2232
|
+
case AST_NODE_TYPES20.ThrowStatement:
|
|
2233
|
+
case AST_NODE_TYPES20.EmptyStatement:
|
|
2045
2234
|
return true;
|
|
2046
|
-
case
|
|
2235
|
+
case AST_NODE_TYPES20.BlockStatement:
|
|
2047
2236
|
return supported(statement.body);
|
|
2048
|
-
case
|
|
2237
|
+
case AST_NODE_TYPES20.IfStatement:
|
|
2049
2238
|
return supported([statement.consequent]) && (statement.alternate === null || supported([statement.alternate]));
|
|
2050
2239
|
default:
|
|
2051
2240
|
return false;
|
|
@@ -2066,13 +2255,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2066
2255
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2067
2256
|
const sourceCode = context.sourceCode;
|
|
2068
2257
|
function binding3(node) {
|
|
2069
|
-
return node.type ===
|
|
2258
|
+
return node.type === AST_NODE_TYPES20.Identifier ? ASTUtils16.findVariable(sourceCode.getScope(node), node.name) : null;
|
|
2070
2259
|
}
|
|
2071
2260
|
function inspect(node) {
|
|
2072
|
-
if (node.body?.type !==
|
|
2261
|
+
if (node.body?.type !== AST_NODE_TYPES20.BlockStatement || !returnsArray(node, sourceCode) || !supported(node.body.body)) return;
|
|
2073
2262
|
const initial = /* @__PURE__ */ new Map();
|
|
2074
2263
|
for (const parameter of node.params) {
|
|
2075
|
-
if (parameter.type !==
|
|
2264
|
+
if (parameter.type !== AST_NODE_TYPES20.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
2076
2265
|
const element = arrayElement(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
2077
2266
|
const variable = binding3(parameter);
|
|
2078
2267
|
if (element !== null && PRIMITIVES.has(element.type) && variable !== null) initial.set(variable, parameter.name);
|
|
@@ -2085,26 +2274,26 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2085
2274
|
}
|
|
2086
2275
|
function expression(current, state) {
|
|
2087
2276
|
switch (current.type) {
|
|
2088
|
-
case
|
|
2089
|
-
case
|
|
2090
|
-
case
|
|
2277
|
+
case AST_NODE_TYPES20.FunctionExpression:
|
|
2278
|
+
case AST_NODE_TYPES20.ArrowFunctionExpression:
|
|
2279
|
+
case AST_NODE_TYPES20.ClassExpression:
|
|
2091
2280
|
return;
|
|
2092
|
-
case
|
|
2281
|
+
case AST_NODE_TYPES20.AssignmentExpression:
|
|
2093
2282
|
assignment(current, state);
|
|
2094
2283
|
return;
|
|
2095
|
-
case
|
|
2284
|
+
case AST_NODE_TYPES20.LogicalExpression:
|
|
2096
2285
|
logical(current, state);
|
|
2097
2286
|
return;
|
|
2098
|
-
case
|
|
2287
|
+
case AST_NODE_TYPES20.ConditionalExpression:
|
|
2099
2288
|
conditional(current, state);
|
|
2100
2289
|
return;
|
|
2101
|
-
case
|
|
2290
|
+
case AST_NODE_TYPES20.UpdateExpression:
|
|
2102
2291
|
write(current.argument, state);
|
|
2103
2292
|
break;
|
|
2104
|
-
case
|
|
2293
|
+
case AST_NODE_TYPES20.UnaryExpression:
|
|
2105
2294
|
if (current.operator === "delete") write(current.argument, state);
|
|
2106
2295
|
break;
|
|
2107
|
-
case
|
|
2296
|
+
case AST_NODE_TYPES20.CallExpression:
|
|
2108
2297
|
mutationCall(current, state);
|
|
2109
2298
|
break;
|
|
2110
2299
|
default:
|
|
@@ -2124,13 +2313,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2124
2313
|
function logical(current, state) {
|
|
2125
2314
|
expression(current.left, state);
|
|
2126
2315
|
const left = unwrapExpression(current.left);
|
|
2127
|
-
if (left.type ===
|
|
2316
|
+
if (left.type === AST_NODE_TYPES20.Literal && (current.operator === "&&" && !left.value || current.operator === "||" && !!left.value || current.operator === "??" && left.value !== null)) return;
|
|
2128
2317
|
expression(current.right, state);
|
|
2129
2318
|
}
|
|
2130
2319
|
function conditional(current, state) {
|
|
2131
2320
|
expression(current.test, state);
|
|
2132
2321
|
const test = unwrapExpression(current.test);
|
|
2133
|
-
if (test.type ===
|
|
2322
|
+
if (test.type === AST_NODE_TYPES20.Literal) {
|
|
2134
2323
|
expression(test.value ? current.consequent : current.alternate, state);
|
|
2135
2324
|
return;
|
|
2136
2325
|
}
|
|
@@ -2138,13 +2327,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2138
2327
|
expression(current.alternate, state);
|
|
2139
2328
|
}
|
|
2140
2329
|
function mutationCall(current, state) {
|
|
2141
|
-
if (current.callee.type !==
|
|
2330
|
+
if (current.callee.type !== AST_NODE_TYPES20.MemberExpression || !MUTATORS.has(ASTUtils16.getPropertyName(current.callee) ?? "")) return;
|
|
2142
2331
|
const parameter = origin(current.callee.object, state);
|
|
2143
2332
|
if (parameter !== void 0 && first === null) first = { node: current, parameter };
|
|
2144
2333
|
}
|
|
2145
2334
|
function write(target, state) {
|
|
2146
2335
|
target = unwrapExpression(target);
|
|
2147
|
-
if (target.type !==
|
|
2336
|
+
if (target.type !== AST_NODE_TYPES20.MemberExpression || !target.computed && ASTUtils16.getPropertyName(target) !== "length") return;
|
|
2148
2337
|
const parameter = origin(target.object, state);
|
|
2149
2338
|
if (parameter !== void 0 && first === null) first = { node: target, parameter };
|
|
2150
2339
|
}
|
|
@@ -2154,18 +2343,18 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2154
2343
|
}
|
|
2155
2344
|
function statement(current, state) {
|
|
2156
2345
|
switch (current.type) {
|
|
2157
|
-
case
|
|
2346
|
+
case AST_NODE_TYPES20.BlockStatement:
|
|
2158
2347
|
return statements(current.body, state);
|
|
2159
|
-
case
|
|
2348
|
+
case AST_NODE_TYPES20.IfStatement:
|
|
2160
2349
|
return branch(current, state);
|
|
2161
|
-
case
|
|
2350
|
+
case AST_NODE_TYPES20.VariableDeclaration:
|
|
2162
2351
|
declarations(current, state);
|
|
2163
2352
|
return false;
|
|
2164
|
-
case
|
|
2165
|
-
case
|
|
2353
|
+
case AST_NODE_TYPES20.ReturnStatement:
|
|
2354
|
+
case AST_NODE_TYPES20.ThrowStatement:
|
|
2166
2355
|
if (current.argument !== null) expression(current.argument, state);
|
|
2167
2356
|
return true;
|
|
2168
|
-
case
|
|
2357
|
+
case AST_NODE_TYPES20.ExpressionStatement:
|
|
2169
2358
|
expression(current.expression, state);
|
|
2170
2359
|
return false;
|
|
2171
2360
|
default:
|
|
@@ -2174,7 +2363,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2174
2363
|
}
|
|
2175
2364
|
function branch(current, state) {
|
|
2176
2365
|
expression(current.test, state);
|
|
2177
|
-
if (current.test.type ===
|
|
2366
|
+
if (current.test.type === AST_NODE_TYPES20.Literal) return current.test.value ? statements([current.consequent], state) : current.alternate !== null && statements([current.alternate], state);
|
|
2178
2367
|
const left = new Map(state);
|
|
2179
2368
|
const right = new Map(state);
|
|
2180
2369
|
const leftEnds = statements([current.consequent], left);
|
|
@@ -2206,7 +2395,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2206
2395
|
});
|
|
2207
2396
|
|
|
2208
2397
|
// src/rules/no-redundant-consumer-union.ts
|
|
2209
|
-
import { AST_NODE_TYPES as
|
|
2398
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
2210
2399
|
import ts7 from "typescript";
|
|
2211
2400
|
|
|
2212
2401
|
// src/rules/_checked-native-source.ts
|
|
@@ -2317,11 +2506,11 @@ function finiteMember(member3, checker) {
|
|
|
2317
2506
|
}
|
|
2318
2507
|
|
|
2319
2508
|
// src/rules/_private-consumer-fix.ts
|
|
2320
|
-
import { AST_NODE_TYPES as
|
|
2509
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
2321
2510
|
import ts3 from "typescript";
|
|
2322
2511
|
|
|
2323
2512
|
// src/rules/_type-binding.ts
|
|
2324
|
-
import { AST_NODE_TYPES as
|
|
2513
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
2325
2514
|
function typeBinding(source, identifier) {
|
|
2326
2515
|
let scope = source.getScope(identifier);
|
|
2327
2516
|
while (scope !== null) {
|
|
@@ -2333,26 +2522,78 @@ function typeBinding(source, identifier) {
|
|
|
2333
2522
|
}
|
|
2334
2523
|
return null;
|
|
2335
2524
|
}
|
|
2525
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
2336
2526
|
function retainsNamedTypeUses(source, removed) {
|
|
2337
2527
|
const manager = source.scopeManager;
|
|
2338
2528
|
if (manager === null) return false;
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2529
|
+
const index = referenceIndex(source, manager);
|
|
2530
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
2531
|
+
if (!reference.isRead()) continue;
|
|
2341
2532
|
const binding3 = reference.resolved;
|
|
2342
2533
|
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
2343
|
-
if (binding3.defs.length === 0)
|
|
2344
|
-
|
|
2345
|
-
|
|
2534
|
+
if (binding3.defs.length === 0) continue;
|
|
2535
|
+
const reads = publicReadExtents(index, binding3);
|
|
2536
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
2537
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
2538
|
+
}
|
|
2539
|
+
return true;
|
|
2540
|
+
}
|
|
2541
|
+
function referenceIndex(source, manager) {
|
|
2542
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
2543
|
+
if (cached?.manager === manager) return cached;
|
|
2544
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
2545
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
2546
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
2547
|
+
REFERENCE_INDEXES.set(source, index);
|
|
2548
|
+
return index;
|
|
2549
|
+
}
|
|
2550
|
+
function* referencesWithin(references, removed) {
|
|
2551
|
+
let low = 0;
|
|
2552
|
+
let high = references.length;
|
|
2553
|
+
while (low < high) {
|
|
2554
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
2555
|
+
const reference = references[middle];
|
|
2556
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
2557
|
+
else low = middle + 1;
|
|
2558
|
+
}
|
|
2559
|
+
for (let index = low; index < references.length; index++) {
|
|
2560
|
+
const reference = references[index];
|
|
2561
|
+
if (reference === void 0) continue;
|
|
2562
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
2563
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
function publicReadExtents(index, binding3) {
|
|
2567
|
+
const cached = index.publicReads.get(binding3);
|
|
2568
|
+
if (cached !== void 0) return cached;
|
|
2569
|
+
let type = null;
|
|
2570
|
+
let value = null;
|
|
2571
|
+
let both = null;
|
|
2572
|
+
for (const retained of binding3.references) {
|
|
2573
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
2574
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
2575
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
2576
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
2577
|
+
}
|
|
2578
|
+
const result = { type, value, both };
|
|
2579
|
+
index.publicReads.set(binding3, result);
|
|
2580
|
+
return result;
|
|
2581
|
+
}
|
|
2582
|
+
function extendExtent(extent, identifier) {
|
|
2583
|
+
return {
|
|
2584
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
2585
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
2586
|
+
};
|
|
2346
2587
|
}
|
|
2347
2588
|
function publicTypeUse(identifier) {
|
|
2348
2589
|
let node = identifier;
|
|
2349
2590
|
while (node.parent) {
|
|
2350
|
-
if (node.type ===
|
|
2351
|
-
if (node.type ===
|
|
2352
|
-
return node.parent.type ===
|
|
2591
|
+
if (node.type === AST_NODE_TYPES21.TSTypeAnnotation || node.type === AST_NODE_TYPES21.TSTypePredicate || node.type === AST_NODE_TYPES21.TSAsExpression || node.type === AST_NODE_TYPES21.TSTypeAssertion) return false;
|
|
2592
|
+
if (node.type === AST_NODE_TYPES21.TSTypeAliasDeclaration) {
|
|
2593
|
+
return node.parent.type === AST_NODE_TYPES21.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === AST_NODE_TYPES21.Program;
|
|
2353
2594
|
}
|
|
2354
|
-
if (node.type ===
|
|
2355
|
-
return node.parent.type ===
|
|
2595
|
+
if (node.type === AST_NODE_TYPES21.ExportSpecifier) {
|
|
2596
|
+
return node.parent.type === AST_NODE_TYPES21.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === AST_NODE_TYPES21.Program;
|
|
2356
2597
|
}
|
|
2357
2598
|
node = node.parent;
|
|
2358
2599
|
}
|
|
@@ -2366,8 +2607,8 @@ function insideTypeRange(node, range) {
|
|
|
2366
2607
|
var UNSAFE = ts3.TypeFlags.Any | ts3.TypeFlags.Unknown | ts3.TypeFlags.Never | ts3.TypeFlags.TypeParameter | ts3.TypeFlags.Conditional | ts3.TypeFlags.IndexedAccess | ts3.TypeFlags.Substitution;
|
|
2367
2608
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
2368
2609
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
2369
|
-
const owner = node.type ===
|
|
2370
|
-
if (owner.type !==
|
|
2610
|
+
const owner = node.type === AST_NODE_TYPES22.FunctionDeclaration ? node : node.parent;
|
|
2611
|
+
if (owner.type !== AST_NODE_TYPES22.FunctionDeclaration && owner.type !== AST_NODE_TYPES22.VariableDeclarator) return false;
|
|
2371
2612
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
2372
2613
|
if (!binding3) return false;
|
|
2373
2614
|
const checker = services.program.getTypeChecker();
|
|
@@ -2385,7 +2626,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
2385
2626
|
continue;
|
|
2386
2627
|
}
|
|
2387
2628
|
const call = reference.identifier.parent;
|
|
2388
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2629
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== AST_NODE_TYPES22.CallExpression || call.callee !== reference.identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== AST_NODE_TYPES22.Identifier) return false;
|
|
2389
2630
|
const argument = services.esTreeNodeToTSNodeMap.get(call.arguments[0]);
|
|
2390
2631
|
const type = checker.getTypeAtLocation(argument);
|
|
2391
2632
|
if (!knownArgument(type, argument, fields2, checker) || !checker.isTypeAssignableTo(type, original)) return false;
|
|
@@ -2440,7 +2681,7 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
2440
2681
|
}
|
|
2441
2682
|
|
|
2442
2683
|
// src/rules/_private-scalar-consumer.ts
|
|
2443
|
-
import { AST_NODE_TYPES as
|
|
2684
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
2444
2685
|
import ts6 from "typescript";
|
|
2445
2686
|
|
|
2446
2687
|
// src/rules/_scalar-parameter-view.ts
|
|
@@ -2586,31 +2827,11 @@ function intrinsicAttribute(attribute, view) {
|
|
|
2586
2827
|
return ts5.isJsxAttribute(attribute) && ts5.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
2587
2828
|
}
|
|
2588
2829
|
|
|
2589
|
-
// src/rules/_stable-value-binding.ts
|
|
2590
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
2591
|
-
function typeOnlyReference(reference) {
|
|
2592
|
-
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
2593
|
-
let current = outerExpression(reference.identifier);
|
|
2594
|
-
while (current.parent?.type === AST_NODE_TYPES20.TSQualifiedName && current.parent.left === current) {
|
|
2595
|
-
current = current.parent;
|
|
2596
|
-
}
|
|
2597
|
-
return current.parent?.type === AST_NODE_TYPES20.TSTypeQuery && current.parent.exprName === current;
|
|
2598
|
-
}
|
|
2599
|
-
function stableValueBinding(variable, acceptRead) {
|
|
2600
|
-
let initializer;
|
|
2601
|
-
return variable.references.every((reference) => {
|
|
2602
|
-
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
2603
|
-
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
2604
|
-
initializer = reference.identifier;
|
|
2605
|
-
return true;
|
|
2606
|
-
});
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
2830
|
// src/rules/_private-scalar-consumer.ts
|
|
2610
2831
|
function directEval(node) {
|
|
2611
2832
|
let callee = unwrapExpression(node.callee);
|
|
2612
|
-
while (callee.type ===
|
|
2613
|
-
return callee.type ===
|
|
2833
|
+
while (callee.type === AST_NODE_TYPES23.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
2834
|
+
return callee.type === AST_NODE_TYPES23.Identifier && callee.name === "eval";
|
|
2614
2835
|
}
|
|
2615
2836
|
function primitiveKeyword(node) {
|
|
2616
2837
|
return node !== void 0 && (node.kind === ts6.SyntaxKind.StringKeyword || node.kind === ts6.SyntaxKind.NumberKeyword || node.kind === ts6.SyntaxKind.BooleanKeyword || node.kind === ts6.SyntaxKind.BigIntKeyword);
|
|
@@ -2621,7 +2842,7 @@ function nullishPrimitiveUnion(node) {
|
|
|
2621
2842
|
function consumerAnnotation(node) {
|
|
2622
2843
|
if (node.params.length !== 1) return void 0;
|
|
2623
2844
|
const parameter = node.params[0];
|
|
2624
|
-
return parameter?.type ===
|
|
2845
|
+
return parameter?.type === AST_NODE_TYPES23.Identifier || parameter?.type === AST_NODE_TYPES23.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
2625
2846
|
}
|
|
2626
2847
|
function exportedSymbols(source, checker) {
|
|
2627
2848
|
const symbol = checker.getSymbolAtLocation(source);
|
|
@@ -2652,12 +2873,12 @@ function independentSignature(native) {
|
|
|
2652
2873
|
return parameter !== void 0 && parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!ts6.isIdentifier(parameter.name) || parameter.name.text !== "this");
|
|
2653
2874
|
}
|
|
2654
2875
|
function callableBinding(node, sourceCode) {
|
|
2655
|
-
if (node.type ===
|
|
2656
|
-
if (node.parent.type !==
|
|
2876
|
+
if (node.type === AST_NODE_TYPES23.FunctionDeclaration) {
|
|
2877
|
+
if (node.parent.type !== AST_NODE_TYPES23.Program) return void 0;
|
|
2657
2878
|
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
2658
2879
|
}
|
|
2659
2880
|
const declaration = node.parent;
|
|
2660
|
-
if (declaration.type !==
|
|
2881
|
+
if (declaration.type !== AST_NODE_TYPES23.VariableDeclarator || declaration.init !== node || declaration.id.type !== AST_NODE_TYPES23.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== AST_NODE_TYPES23.Program) return void 0;
|
|
2661
2882
|
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
2662
2883
|
}
|
|
2663
2884
|
function directCalls(binding3) {
|
|
@@ -2665,7 +2886,7 @@ function directCalls(binding3) {
|
|
|
2665
2886
|
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
2666
2887
|
const identifier = reference.identifier;
|
|
2667
2888
|
const call = identifier.parent;
|
|
2668
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2889
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== AST_NODE_TYPES23.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== AST_NODE_TYPES23.Identifier) return false;
|
|
2669
2890
|
calls += 1;
|
|
2670
2891
|
return true;
|
|
2671
2892
|
});
|
|
@@ -2725,13 +2946,13 @@ function localContractBindings(roots, source, services) {
|
|
|
2725
2946
|
}
|
|
2726
2947
|
function localContractReferences(node, source, services) {
|
|
2727
2948
|
switch (node.type) {
|
|
2728
|
-
case
|
|
2949
|
+
case AST_NODE_TYPES24.TSTypeLiteral:
|
|
2729
2950
|
return [];
|
|
2730
|
-
case
|
|
2951
|
+
case AST_NODE_TYPES24.TSIntersectionType:
|
|
2731
2952
|
return node.types;
|
|
2732
|
-
case
|
|
2733
|
-
return !node.typeArguments && node.typeName.type ===
|
|
2734
|
-
case
|
|
2953
|
+
case AST_NODE_TYPES24.TSTypeReference:
|
|
2954
|
+
return !node.typeArguments && node.typeName.type === AST_NODE_TYPES24.Identifier ? [node.typeName] : null;
|
|
2955
|
+
case AST_NODE_TYPES24.Identifier:
|
|
2735
2956
|
return localBindingReferences(node, source, services);
|
|
2736
2957
|
default:
|
|
2737
2958
|
return null;
|
|
@@ -2741,8 +2962,8 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2741
2962
|
const definitions2 = typeBinding(source, identifier)?.defs.filter((definition) => definition.isTypeDefinition).map((definition) => definition.node);
|
|
2742
2963
|
if (!definitions2?.length || !definitions2.every(moduleTypeDeclaration)) return null;
|
|
2743
2964
|
const first = definitions2[0];
|
|
2744
|
-
if (definitions2.length === 1 && first?.type ===
|
|
2745
|
-
const interfaces = definitions2.filter((definition) => definition.type ===
|
|
2965
|
+
if (definitions2.length === 1 && first?.type === AST_NODE_TYPES24.TSTypeAliasDeclaration && !first.typeParameters) return [first.typeAnnotation];
|
|
2966
|
+
const interfaces = definitions2.filter((definition) => definition.type === AST_NODE_TYPES24.TSInterfaceDeclaration);
|
|
2746
2967
|
if (interfaces.length !== definitions2.length || interfaces.some((declaration) => declaration.typeParameters)) return null;
|
|
2747
2968
|
if (interfaces.length > 1) {
|
|
2748
2969
|
const checker = services.program.getTypeChecker();
|
|
@@ -2750,13 +2971,13 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2750
2971
|
if (!symbol || interfaces.some((declaration) => checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(declaration.id)) !== symbol)) return null;
|
|
2751
2972
|
}
|
|
2752
2973
|
const bases = interfaces.flatMap((declaration) => declaration.extends.map((base) => base.expression));
|
|
2753
|
-
return bases.every((base) => base.type ===
|
|
2974
|
+
return bases.every((base) => base.type === AST_NODE_TYPES24.Identifier) ? bases : null;
|
|
2754
2975
|
}
|
|
2755
2976
|
function moduleTypeDeclaration(node) {
|
|
2756
2977
|
const parent = node.parent;
|
|
2757
|
-
if (parent?.type ===
|
|
2758
|
-
if (parent?.type !==
|
|
2759
|
-
return parent.parent.type ===
|
|
2978
|
+
if (parent?.type === AST_NODE_TYPES24.Program) return true;
|
|
2979
|
+
if (parent?.type !== AST_NODE_TYPES24.ExportNamedDeclaration && parent?.type !== AST_NODE_TYPES24.ExportDefaultDeclaration) return false;
|
|
2980
|
+
return parent.parent.type === AST_NODE_TYPES24.Program;
|
|
2760
2981
|
}
|
|
2761
2982
|
function coveringAlternative(leftNode, rightNode, checker, fieldsOf, reads) {
|
|
2762
2983
|
const left = checker.getTypeFromTypeNode(leftNode);
|
|
@@ -2791,7 +3012,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2791
3012
|
let dynamic = false;
|
|
2792
3013
|
const remember = (node) => {
|
|
2793
3014
|
const annotation = consumerAnnotation(node);
|
|
2794
|
-
if (annotation?.type ===
|
|
3015
|
+
if (annotation?.type === AST_NODE_TYPES24.TSUnionType && annotation.types.length === 2) candidates.push(node);
|
|
2795
3016
|
};
|
|
2796
3017
|
return {
|
|
2797
3018
|
FunctionDeclaration: remember,
|
|
@@ -2825,7 +3046,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2825
3046
|
const coverage = coveringAlternative(leftNode, rightNode, checker, fieldsOf, consumer.reads);
|
|
2826
3047
|
if (!coverage) continue;
|
|
2827
3048
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
2828
|
-
if (coverage.mutual && (reportNode.type !==
|
|
3049
|
+
if (coverage.mutual && (reportNode.type !== AST_NODE_TYPES24.TSUnionType || !localContractBindings(reportNode.types, context.sourceCode, services))) continue;
|
|
2829
3050
|
const { covered: coveredNode, covering: coveringNode } = coverage;
|
|
2830
3051
|
const fix = privateUnionFix(context.sourceCode, services, {
|
|
2831
3052
|
candidate: candidate2,
|
|
@@ -2843,7 +3064,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2843
3064
|
});
|
|
2844
3065
|
|
|
2845
3066
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
2846
|
-
import { AST_NODE_TYPES as
|
|
3067
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
2847
3068
|
import ts8 from "typescript";
|
|
2848
3069
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
2849
3070
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
@@ -2894,7 +3115,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2894
3115
|
const candidates = [];
|
|
2895
3116
|
let dynamic = false;
|
|
2896
3117
|
const remember = (node) => {
|
|
2897
|
-
if (consumerAnnotation(node)?.type ===
|
|
3118
|
+
if (consumerAnnotation(node)?.type === AST_NODE_TYPES25.TSTypeLiteral) candidates.push(node);
|
|
2898
3119
|
};
|
|
2899
3120
|
return {
|
|
2900
3121
|
FunctionDeclaration: remember,
|
|
@@ -2928,7 +3149,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2928
3149
|
});
|
|
2929
3150
|
|
|
2930
3151
|
// src/rules/no-excess-jsx-props.ts
|
|
2931
|
-
import { AST_NODE_TYPES as
|
|
3152
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
2932
3153
|
import ts10 from "typescript";
|
|
2933
3154
|
|
|
2934
3155
|
// src/rules/_ordinary-object-effects.ts
|
|
@@ -3270,11 +3491,11 @@ var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3270
3491
|
function plainLiteralFields(node) {
|
|
3271
3492
|
const fields2 = /* @__PURE__ */ new Map();
|
|
3272
3493
|
for (const property of node.properties) {
|
|
3273
|
-
if (property.type !==
|
|
3494
|
+
if (property.type !== AST_NODE_TYPES26.Property || property.kind !== "init") return null;
|
|
3274
3495
|
const key = property.key;
|
|
3275
3496
|
let name;
|
|
3276
|
-
if (!property.computed && key.type ===
|
|
3277
|
-
else if (key.type ===
|
|
3497
|
+
if (!property.computed && key.type === AST_NODE_TYPES26.Identifier) name = key.name;
|
|
3498
|
+
else if (key.type === AST_NODE_TYPES26.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
3278
3499
|
else return null;
|
|
3279
3500
|
if (name === "__proto__") return null;
|
|
3280
3501
|
fields2.set(name, property);
|
|
@@ -3386,35 +3607,35 @@ function localObjectFields(symbol, source, proof) {
|
|
|
3386
3607
|
if (!native || native.getSourceFile() !== source || !initializer || !ts10.isObjectLiteralExpression(initializer)) return null;
|
|
3387
3608
|
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
3388
3609
|
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
3389
|
-
if (declaration.type !==
|
|
3610
|
+
if (declaration.type !== AST_NODE_TYPES26.VariableDeclarator || declaration.parent.kind !== "const" || declaration.id.type !== AST_NODE_TYPES26.Identifier || literal2.type !== AST_NODE_TYPES26.ObjectExpression || declaration.parent.parent.type === AST_NODE_TYPES26.ExportNamedDeclaration) return null;
|
|
3390
3611
|
const fields2 = plainLiteralFields(literal2);
|
|
3391
3612
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3392
3613
|
if (!fields2 || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
3393
3614
|
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
3394
3615
|
const member3 = reference.identifier.parent;
|
|
3395
|
-
return member3.type ===
|
|
3616
|
+
return member3.type === AST_NODE_TYPES26.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields2);
|
|
3396
3617
|
})) return null;
|
|
3397
3618
|
return fields2;
|
|
3398
3619
|
}
|
|
3399
3620
|
function staticMemberKey(member3) {
|
|
3400
3621
|
const property = member3.property;
|
|
3401
|
-
return !member3.computed && property.type ===
|
|
3622
|
+
return !member3.computed && property.type === AST_NODE_TYPES26.Identifier ? property.name : property.type === AST_NODE_TYPES26.Literal && (typeof property.value === "string" || typeof property.value === "number") ? String(property.value) : void 0;
|
|
3402
3623
|
}
|
|
3403
3624
|
function readonlyFieldValue(member3, fields2) {
|
|
3404
3625
|
const key = staticMemberKey(member3);
|
|
3405
3626
|
if (key === void 0 || !fields2.has(key)) return false;
|
|
3406
3627
|
const parent = member3.parent;
|
|
3407
|
-
if (parent.type ===
|
|
3628
|
+
if (parent.type === AST_NODE_TYPES26.Property && parent.value === member3 && parent.parent.type === AST_NODE_TYPES26.ObjectExpression) {
|
|
3408
3629
|
const object = parent.parent;
|
|
3409
3630
|
const owner = object.parent;
|
|
3410
|
-
return owner.type ===
|
|
3631
|
+
return owner.type === AST_NODE_TYPES26.JSXSpreadAttribute && owner.argument === object || owner.type === AST_NODE_TYPES26.VariableDeclarator && owner.init === object;
|
|
3411
3632
|
}
|
|
3412
|
-
return parent.type ===
|
|
3633
|
+
return parent.type === AST_NODE_TYPES26.JSXExpressionContainer && parent.expression === member3 || parent.type === AST_NODE_TYPES26.VariableDeclarator && parent.init === member3;
|
|
3413
3634
|
}
|
|
3414
3635
|
function privateElementDeclaration(opening) {
|
|
3415
3636
|
const value = outerExpression(opening.parent);
|
|
3416
3637
|
const declaration = value.parent;
|
|
3417
|
-
return declaration.type ===
|
|
3638
|
+
return declaration.type === AST_NODE_TYPES26.VariableDeclarator && declaration.init === value && declaration.id.type === AST_NODE_TYPES26.Identifier && declaration.parent.kind === "const" && declaration.parent.parent.type !== AST_NODE_TYPES26.ExportNamedDeclaration ? declaration : null;
|
|
3418
3639
|
}
|
|
3419
3640
|
function closedElementValue(opening, declaration, fields2, reads, proof) {
|
|
3420
3641
|
if (!proof.staticScope || !closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
@@ -3440,10 +3661,10 @@ function closedInvocation(node, proof) {
|
|
|
3440
3661
|
}
|
|
3441
3662
|
function independentInvocation(scope, proof) {
|
|
3442
3663
|
const block = scope.block;
|
|
3443
|
-
if (block.type !==
|
|
3664
|
+
if (block.type !== AST_NODE_TYPES26.ArrowFunctionExpression && block.type !== AST_NODE_TYPES26.FunctionDeclaration && block.type !== AST_NODE_TYPES26.FunctionExpression) return false;
|
|
3444
3665
|
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3445
3666
|
for (const parameter of block.params) {
|
|
3446
|
-
if (parameter.type !==
|
|
3667
|
+
if (parameter.type !== AST_NODE_TYPES26.Identifier || parameter.name === "this") return false;
|
|
3447
3668
|
const binding3 = scope.set.get(parameter.name);
|
|
3448
3669
|
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3449
3670
|
}
|
|
@@ -3451,16 +3672,16 @@ function independentInvocation(scope, proof) {
|
|
|
3451
3672
|
if (typeOnlyReference(reference)) return true;
|
|
3452
3673
|
const value = outerExpression(reference.identifier);
|
|
3453
3674
|
const parent = value.parent;
|
|
3454
|
-
const read = parent?.type ===
|
|
3675
|
+
const read = parent?.type === AST_NODE_TYPES26.MemberExpression && parent.object === value ? parent : value;
|
|
3455
3676
|
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
3456
3677
|
});
|
|
3457
3678
|
}
|
|
3458
3679
|
function consumedElementRead(node, fields2, reads) {
|
|
3459
3680
|
const identifier = outerExpression(node);
|
|
3460
3681
|
const props = identifier.parent;
|
|
3461
|
-
if (!props || props.type !==
|
|
3682
|
+
if (!props || props.type !== AST_NODE_TYPES26.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
3462
3683
|
const member3 = props.parent;
|
|
3463
|
-
if (member3.type !==
|
|
3684
|
+
if (member3.type !== AST_NODE_TYPES26.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
3464
3685
|
const key = staticMemberKey(member3);
|
|
3465
3686
|
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields2);
|
|
3466
3687
|
}
|
|
@@ -3521,9 +3742,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3521
3742
|
};
|
|
3522
3743
|
return {
|
|
3523
3744
|
JSXSpreadAttribute(node) {
|
|
3524
|
-
if (node.argument.type !==
|
|
3745
|
+
if (node.argument.type !== AST_NODE_TYPES26.ObjectExpression) return;
|
|
3525
3746
|
const opening = node.parent;
|
|
3526
|
-
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !==
|
|
3747
|
+
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== AST_NODE_TYPES26.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
3527
3748
|
const declaration = privateElementDeclaration(opening);
|
|
3528
3749
|
if (!declaration) return;
|
|
3529
3750
|
const fields2 = literalFields(node.argument);
|
|
@@ -3544,7 +3765,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3544
3765
|
});
|
|
3545
3766
|
|
|
3546
3767
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3547
|
-
import { AST_NODE_TYPES as
|
|
3768
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27 } from "@typescript-eslint/utils";
|
|
3548
3769
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3549
3770
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3550
3771
|
defaultLevel: "warning",
|
|
@@ -3608,19 +3829,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3608
3829
|
});
|
|
3609
3830
|
function hasUseServerDirective(program) {
|
|
3610
3831
|
for (const statement of program.body) {
|
|
3611
|
-
if (statement.type !==
|
|
3832
|
+
if (statement.type !== AST_NODE_TYPES27.ExpressionStatement || statement.directive === void 0) return false;
|
|
3612
3833
|
if (statement.directive === "use server") return true;
|
|
3613
3834
|
}
|
|
3614
3835
|
return false;
|
|
3615
3836
|
}
|
|
3616
3837
|
function isTypeOnly(node) {
|
|
3617
3838
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3618
|
-
(specifier) => specifier.type ===
|
|
3839
|
+
(specifier) => specifier.type === AST_NODE_TYPES27.ImportSpecifier && specifier.importKind === "type"
|
|
3619
3840
|
);
|
|
3620
3841
|
}
|
|
3621
3842
|
|
|
3622
3843
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3623
|
-
import { AST_NODE_TYPES as
|
|
3844
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ASTUtils as ASTUtils17 } from "@typescript-eslint/utils";
|
|
3624
3845
|
|
|
3625
3846
|
// src/rules/_secret-names.ts
|
|
3626
3847
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -3764,54 +3985,10 @@ function isAuthSecretName(identifier) {
|
|
|
3764
3985
|
return hasApiKey(tokens);
|
|
3765
3986
|
}
|
|
3766
3987
|
|
|
3767
|
-
// src/rules/_static-string.ts
|
|
3768
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES26, ASTUtils as ASTUtils15 } from "@typescript-eslint/utils";
|
|
3769
|
-
function staticString(node) {
|
|
3770
|
-
if (node === void 0) return null;
|
|
3771
|
-
const value = unwrapExpression(node);
|
|
3772
|
-
if (value.type === AST_NODE_TYPES26.Literal && typeof value.value === "string") return value.value;
|
|
3773
|
-
return value.type === AST_NODE_TYPES26.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
3774
|
-
}
|
|
3775
|
-
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
3776
|
-
function scopedStaticString(node, sourceCode) {
|
|
3777
|
-
let value = unwrapExpression(node);
|
|
3778
|
-
if (value.type !== AST_NODE_TYPES26.Identifier) return staticString(value);
|
|
3779
|
-
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
3780
|
-
if (values === void 0) {
|
|
3781
|
-
values = /* @__PURE__ */ new WeakMap();
|
|
3782
|
-
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
3783
|
-
}
|
|
3784
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3785
|
-
const pending = [];
|
|
3786
|
-
let result = null;
|
|
3787
|
-
while (value.type === AST_NODE_TYPES26.Identifier) {
|
|
3788
|
-
const binding3 = ASTUtils15.findVariable(sourceCode.getScope(value), value.name);
|
|
3789
|
-
if (binding3 === null || seen.has(binding3)) break;
|
|
3790
|
-
if (values.has(binding3)) {
|
|
3791
|
-
result = values.get(binding3) ?? null;
|
|
3792
|
-
break;
|
|
3793
|
-
}
|
|
3794
|
-
seen.add(binding3);
|
|
3795
|
-
pending.push(binding3);
|
|
3796
|
-
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
3797
|
-
if (definition?.type !== "Variable" || definition.node.id.type !== AST_NODE_TYPES26.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
3798
|
-
value = unwrapExpression(definition.node.init);
|
|
3799
|
-
if (value.type !== AST_NODE_TYPES26.Identifier) result = staticString(value);
|
|
3800
|
-
}
|
|
3801
|
-
for (const binding3 of pending) values.set(binding3, result);
|
|
3802
|
-
return result;
|
|
3803
|
-
}
|
|
3804
|
-
function staticPropertyName(node, sourceCode) {
|
|
3805
|
-
const direct = ASTUtils15.getPropertyName(node);
|
|
3806
|
-
if (direct !== null || !node.computed) return direct;
|
|
3807
|
-
const key = node.type === AST_NODE_TYPES26.MemberExpression ? node.property : node.key;
|
|
3808
|
-
return scopedStaticString(key, sourceCode);
|
|
3809
|
-
}
|
|
3810
|
-
|
|
3811
3988
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3812
3989
|
var STORAGE_NAMES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
3813
3990
|
var METADATA_WORDS = /* @__PURE__ */ new Set(["page", "cursor", "next", "hint", "expires", "expiry", "expiration"]);
|
|
3814
|
-
var
|
|
3991
|
+
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
3815
3992
|
var NO_CREDENTIAL_IN_BROWSER_STORAGE_DOCUMENTATION = {
|
|
3816
3993
|
defaultLevel: "warning",
|
|
3817
3994
|
summary: "Do not write credential-named values to browser storage or script-readable cookies.",
|
|
@@ -3869,7 +4046,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3869
4046
|
return {
|
|
3870
4047
|
CallExpression(node) {
|
|
3871
4048
|
const callee = unwrapExpression(node.callee);
|
|
3872
|
-
if (callee.type !==
|
|
4049
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES28.Identifier || callee.property.name !== "setItem" || !isStorage(sourceCode, callee.object)) {
|
|
3873
4050
|
return;
|
|
3874
4051
|
}
|
|
3875
4052
|
const [key] = node.arguments;
|
|
@@ -3877,12 +4054,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3877
4054
|
},
|
|
3878
4055
|
AssignmentExpression(node) {
|
|
3879
4056
|
const target = node.left;
|
|
3880
|
-
if (target.type !==
|
|
4057
|
+
if (target.type !== AST_NODE_TYPES28.MemberExpression) return;
|
|
3881
4058
|
if (isStorage(sourceCode, target.object)) {
|
|
3882
4059
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
3883
4060
|
return;
|
|
3884
4061
|
}
|
|
3885
|
-
if (!target.computed && target.property.type ===
|
|
4062
|
+
if (!target.computed && target.property.type === AST_NODE_TYPES28.Identifier && target.property.name === "cookie" && globalMemberName(sourceCode, target.object) === "document") {
|
|
3886
4063
|
report2(node, cookieName(node.right));
|
|
3887
4064
|
}
|
|
3888
4065
|
}
|
|
@@ -3895,36 +4072,36 @@ function isStorage(sourceCode, node) {
|
|
|
3895
4072
|
}
|
|
3896
4073
|
function globalMemberName(sourceCode, node) {
|
|
3897
4074
|
const value = unwrapExpression(node);
|
|
3898
|
-
if (value.type ===
|
|
3899
|
-
if (value.type ===
|
|
4075
|
+
if (value.type === AST_NODE_TYPES28.Identifier) return isUnshadowed(sourceCode, value) ? value.name : null;
|
|
4076
|
+
if (value.type === AST_NODE_TYPES28.MemberExpression && !value.computed && value.object.type === AST_NODE_TYPES28.Identifier && GLOBAL_OBJECTS2.has(value.object.name) && value.property.type === AST_NODE_TYPES28.Identifier && isUnshadowed(sourceCode, value.object)) {
|
|
3900
4077
|
return value.property.name;
|
|
3901
4078
|
}
|
|
3902
4079
|
return null;
|
|
3903
4080
|
}
|
|
3904
4081
|
function isUnshadowed(sourceCode, node) {
|
|
3905
|
-
const variable =
|
|
4082
|
+
const variable = ASTUtils17.findVariable(sourceCode.getScope(node), node.name);
|
|
3906
4083
|
return variable === null || variable.defs.length === 0;
|
|
3907
4084
|
}
|
|
3908
4085
|
function storedPropertyKey(sourceCode, target) {
|
|
3909
|
-
if (!target.computed) return target.property.type ===
|
|
4086
|
+
if (!target.computed) return target.property.type === AST_NODE_TYPES28.Identifier ? target.property.name : null;
|
|
3910
4087
|
return scopedStaticString(target.property, sourceCode);
|
|
3911
4088
|
}
|
|
3912
4089
|
function cookieName(value) {
|
|
3913
4090
|
let expression = unwrapExpression(value);
|
|
3914
|
-
while (expression.type ===
|
|
4091
|
+
while (expression.type === AST_NODE_TYPES28.BinaryExpression && expression.operator === "+") {
|
|
3915
4092
|
expression = unwrapExpression(expression.left);
|
|
3916
4093
|
}
|
|
3917
4094
|
let text = null;
|
|
3918
|
-
if (expression.type ===
|
|
3919
|
-
if (expression.type ===
|
|
4095
|
+
if (expression.type === AST_NODE_TYPES28.Literal && typeof expression.value === "string") text = expression.value;
|
|
4096
|
+
if (expression.type === AST_NODE_TYPES28.TemplateLiteral) text = expression.quasis[0]?.value.cooked ?? null;
|
|
3920
4097
|
if (text === null || !text.includes("=")) return null;
|
|
3921
4098
|
return text.slice(0, text.indexOf("=")).trim();
|
|
3922
4099
|
}
|
|
3923
4100
|
|
|
3924
4101
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
3925
4102
|
import {
|
|
3926
|
-
AST_NODE_TYPES as
|
|
3927
|
-
ASTUtils as
|
|
4103
|
+
AST_NODE_TYPES as AST_NODE_TYPES29,
|
|
4104
|
+
ASTUtils as ASTUtils18,
|
|
3928
4105
|
ESLintUtils as ESLintUtils5
|
|
3929
4106
|
} from "@typescript-eslint/utils";
|
|
3930
4107
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
@@ -4005,27 +4182,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4005
4182
|
}
|
|
4006
4183
|
});
|
|
4007
4184
|
function isNumericParser(sourceCode, callee) {
|
|
4008
|
-
if (callee.type ===
|
|
4185
|
+
if (callee.type === AST_NODE_TYPES29.Identifier) {
|
|
4009
4186
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
4010
4187
|
}
|
|
4011
|
-
return callee.type ===
|
|
4188
|
+
return callee.type === AST_NODE_TYPES29.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES29.Identifier && callee.object.name === "Number" && callee.property.type === AST_NODE_TYPES29.Identifier && NUMBER_PARSERS.has(callee.property.name) && isUnshadowedGlobal(sourceCode, callee.object);
|
|
4012
4189
|
}
|
|
4013
4190
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4014
|
-
const variable =
|
|
4191
|
+
const variable = ASTUtils18.findVariable(sourceCode.getScope(node), node.name);
|
|
4015
4192
|
return variable === null || variable.defs.length === 0;
|
|
4016
4193
|
}
|
|
4017
4194
|
function searchParamGetCall(argument) {
|
|
4018
4195
|
let value = unwrapExpression(argument);
|
|
4019
|
-
if (value.type ===
|
|
4020
|
-
if (value.type ===
|
|
4021
|
-
if (value.type ===
|
|
4022
|
-
if (value.type !==
|
|
4196
|
+
if (value.type === AST_NODE_TYPES29.AwaitExpression) value = unwrapExpression(value.argument);
|
|
4197
|
+
if (value.type === AST_NODE_TYPES29.LogicalExpression && value.operator === "??") value = unwrapExpression(value.left);
|
|
4198
|
+
if (value.type === AST_NODE_TYPES29.ChainExpression) value = value.expression;
|
|
4199
|
+
if (value.type !== AST_NODE_TYPES29.CallExpression || value.callee.type !== AST_NODE_TYPES29.MemberExpression || value.callee.computed || value.callee.property.type !== AST_NODE_TYPES29.Identifier || value.callee.property.name !== "get") {
|
|
4023
4200
|
return null;
|
|
4024
4201
|
}
|
|
4025
4202
|
return value;
|
|
4026
4203
|
}
|
|
4027
4204
|
function isSearchParamReceiver(call, services) {
|
|
4028
|
-
if (call.callee.type !==
|
|
4205
|
+
if (call.callee.type !== AST_NODE_TYPES29.MemberExpression) return false;
|
|
4029
4206
|
const checker = services.program.getTypeChecker();
|
|
4030
4207
|
const type = checker.getNonNullableType(
|
|
4031
4208
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4037,7 +4214,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4037
4214
|
// package.json
|
|
4038
4215
|
var package_default = {
|
|
4039
4216
|
name: "@sarj/eslint-plugin",
|
|
4040
|
-
version: "16.
|
|
4217
|
+
version: "16.38.52",
|
|
4041
4218
|
packageManager: "npm@12.2.1",
|
|
4042
4219
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4043
4220
|
type: "module",
|
|
@@ -4160,15 +4337,15 @@ var package_default = {
|
|
|
4160
4337
|
|
|
4161
4338
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4162
4339
|
import {
|
|
4163
|
-
AST_NODE_TYPES as
|
|
4340
|
+
AST_NODE_TYPES as AST_NODE_TYPES31,
|
|
4164
4341
|
ESLintUtils as ESLintUtils6
|
|
4165
4342
|
} from "@typescript-eslint/utils";
|
|
4166
4343
|
import * as ts12 from "typescript";
|
|
4167
4344
|
|
|
4168
4345
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4169
4346
|
import {
|
|
4170
|
-
AST_NODE_TYPES as
|
|
4171
|
-
ASTUtils as
|
|
4347
|
+
AST_NODE_TYPES as AST_NODE_TYPES30,
|
|
4348
|
+
ASTUtils as ASTUtils19
|
|
4172
4349
|
} from "@typescript-eslint/utils";
|
|
4173
4350
|
import ts11 from "typescript";
|
|
4174
4351
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
@@ -4243,7 +4420,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4243
4420
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4244
4421
|
rejected.expression.expression.getStart()
|
|
4245
4422
|
);
|
|
4246
|
-
return identifier?.type ===
|
|
4423
|
+
return identifier?.type === AST_NODE_TYPES30.Identifier && identifier.name === "TypeError" && (ASTUtils19.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
4247
4424
|
}
|
|
4248
4425
|
function exactConstruction(node, consumer, implementation) {
|
|
4249
4426
|
if (!ts11.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4624,7 +4801,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4624
4801
|
return;
|
|
4625
4802
|
const parameters = signature.getParameters();
|
|
4626
4803
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4627
|
-
if (argument.type !==
|
|
4804
|
+
if (argument.type !== AST_NODE_TYPES31.NewExpression) continue;
|
|
4628
4805
|
const parameter = parameters[index];
|
|
4629
4806
|
if (parameter === void 0) continue;
|
|
4630
4807
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4675,17 +4852,17 @@ import "@typescript-eslint/utils";
|
|
|
4675
4852
|
|
|
4676
4853
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4677
4854
|
import {
|
|
4678
|
-
AST_NODE_TYPES as
|
|
4679
|
-
ASTUtils as
|
|
4855
|
+
AST_NODE_TYPES as AST_NODE_TYPES32,
|
|
4856
|
+
ASTUtils as ASTUtils20
|
|
4680
4857
|
} from "@typescript-eslint/utils";
|
|
4681
4858
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4682
4859
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4683
4860
|
return null;
|
|
4684
4861
|
const [contractStatement, worker, classStatement, factoryStatement] = sourceCode.ast.body;
|
|
4685
|
-
const contract = contractStatement?.type ===
|
|
4686
|
-
const implementation = classStatement?.type ===
|
|
4687
|
-
const factory = factoryStatement?.type ===
|
|
4688
|
-
if (contract?.type !==
|
|
4862
|
+
const contract = contractStatement?.type === AST_NODE_TYPES32.ExportNamedDeclaration ? contractStatement.declaration : null;
|
|
4863
|
+
const implementation = classStatement?.type === AST_NODE_TYPES32.ExportNamedDeclaration ? classStatement.declaration : classStatement;
|
|
4864
|
+
const factory = factoryStatement?.type === AST_NODE_TYPES32.ExportNamedDeclaration ? factoryStatement.declaration : null;
|
|
4865
|
+
if (contract?.type !== AST_NODE_TYPES32.TSTypeAliasDeclaration || worker?.type !== AST_NODE_TYPES32.TSInterfaceDeclaration || implementation?.type !== AST_NODE_TYPES32.ClassDeclaration || implementation !== candidate2 || !ordinaryClass(implementation) || !ordinaryFactory(factory))
|
|
4689
4866
|
return null;
|
|
4690
4867
|
const operation2 = contractOperation(contract);
|
|
4691
4868
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4704,17 +4881,17 @@ function ordinaryClass(node) {
|
|
|
4704
4881
|
return node.id !== null && !node.declare && !node.abstract && node.decorators.length === 0 && node.superClass === null && node.implements.length === 0 && node.typeParameters === void 0 && node.body.body.length === 2;
|
|
4705
4882
|
}
|
|
4706
4883
|
function ordinaryFactory(node) {
|
|
4707
|
-
return node?.type ===
|
|
4884
|
+
return node?.type === AST_NODE_TYPES32.FunctionDeclaration && node.id !== null && !node.declare && !node.async && !node.generator && node.typeParameters === void 0 && node.params.length === 1 && node.body.body.length === 1;
|
|
4708
4885
|
}
|
|
4709
4886
|
function interfaceOperation(node) {
|
|
4710
4887
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4711
4888
|
}
|
|
4712
4889
|
function contractOperation(node) {
|
|
4713
|
-
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type ===
|
|
4890
|
+
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type === AST_NODE_TYPES32.TSTypeLiteral ? singletonOperation(node.typeAnnotation.members) : null;
|
|
4714
4891
|
}
|
|
4715
4892
|
function singletonOperation(members) {
|
|
4716
4893
|
const member3 = members[0];
|
|
4717
|
-
return members.length === 1 && member3?.type ===
|
|
4894
|
+
return members.length === 1 && member3?.type === AST_NODE_TYPES32.TSMethodSignature && member3.kind === "method" && !member3.computed && !member3.optional && member3.key.type === AST_NODE_TYPES32.Identifier && member3.params.length === 0 && member3.typeParameters === void 0 && member3.returnType?.typeAnnotation.type === AST_NODE_TYPES32.TSVoidKeyword ? member3.key.name : null;
|
|
4718
4895
|
}
|
|
4719
4896
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4720
4897
|
const names = declarations.flatMap(
|
|
@@ -4725,7 +4902,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4725
4902
|
);
|
|
4726
4903
|
}
|
|
4727
4904
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4728
|
-
const binding3 =
|
|
4905
|
+
const binding3 = ASTUtils20.findVariable(
|
|
4729
4906
|
sourceCode.getScope(reference),
|
|
4730
4907
|
reference.name
|
|
4731
4908
|
);
|
|
@@ -4733,47 +4910,47 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
4733
4910
|
}
|
|
4734
4911
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
4735
4912
|
const constructor = implementation.body.body[0];
|
|
4736
|
-
if (constructor?.type !==
|
|
4913
|
+
if (constructor?.type !== AST_NODE_TYPES32.MethodDefinition || constructor.value.type !== AST_NODE_TYPES32.FunctionExpression || constructor.kind !== "constructor" || constructor.computed || constructor.static || constructor.decorators.length !== 0 || constructor.optional || constructor.accessibility !== void 0 && constructor.accessibility !== "public" || constructor.value.async || constructor.value.generator || constructor.value.typeParameters !== void 0 || constructor.value.returnType !== void 0 || constructor.value.body.body.length !== 0 || constructor.value.params.length !== 1)
|
|
4737
4914
|
return null;
|
|
4738
4915
|
const property = constructor.value.params[0];
|
|
4739
|
-
if (property?.type !==
|
|
4916
|
+
if (property?.type !== AST_NODE_TYPES32.TSParameterProperty || property.accessibility !== "private" || !property.readonly || property.override || property.decorators.length !== 0 || property.parameter.type !== AST_NODE_TYPES32.Identifier || property.parameter.optional || !typeReference(sourceCode, property.parameter.typeAnnotation, worker))
|
|
4740
4917
|
return null;
|
|
4741
4918
|
return property.parameter.name;
|
|
4742
4919
|
}
|
|
4743
4920
|
function typeReference(sourceCode, annotation, declaration) {
|
|
4744
4921
|
const type = annotation?.typeAnnotation;
|
|
4745
|
-
return type?.type ===
|
|
4922
|
+
return type?.type === AST_NODE_TYPES32.TSTypeReference && type.typeArguments === void 0 && type.typeName.type === AST_NODE_TYPES32.Identifier && sameBinding(sourceCode, type.typeName, declaration);
|
|
4746
4923
|
}
|
|
4747
4924
|
function forwardsOperation(implementation, field, operation2) {
|
|
4748
4925
|
const method = implementation.body.body[1];
|
|
4749
|
-
if (method?.type !==
|
|
4926
|
+
if (method?.type !== AST_NODE_TYPES32.MethodDefinition || method.kind !== "method" || method.value.type !== AST_NODE_TYPES32.FunctionExpression || method.computed || method.static || method.optional || method.override || method.decorators.length !== 0 || method.accessibility !== void 0 && method.accessibility !== "public" || method.key.type !== AST_NODE_TYPES32.Identifier || method.key.name !== operation2 || method.value.async || method.value.generator || method.value.typeParameters !== void 0 || method.value.params.length !== 0 || method.value.body.body.length !== 1 || method.value.returnType?.typeAnnotation.type !== AST_NODE_TYPES32.TSVoidKeyword)
|
|
4750
4927
|
return false;
|
|
4751
4928
|
const statement = method.value.body.body[0];
|
|
4752
|
-
const call = statement?.type ===
|
|
4753
|
-
return call?.type ===
|
|
4929
|
+
const call = statement?.type === AST_NODE_TYPES32.ExpressionStatement ? statement.expression : null;
|
|
4930
|
+
return call?.type === AST_NODE_TYPES32.CallExpression && !call.optional && call.typeArguments === void 0 && call.arguments.length === 0 && forwardedMember(call.callee, field, operation2);
|
|
4754
4931
|
}
|
|
4755
4932
|
function forwardedMember(node, field, operation2) {
|
|
4756
|
-
if (node.type !==
|
|
4933
|
+
if (node.type !== AST_NODE_TYPES32.MemberExpression || node.computed || node.optional || node.property.type !== AST_NODE_TYPES32.Identifier || node.property.name !== operation2)
|
|
4757
4934
|
return false;
|
|
4758
4935
|
const receiver = node.object;
|
|
4759
|
-
return receiver.type ===
|
|
4936
|
+
return receiver.type === AST_NODE_TYPES32.MemberExpression && !receiver.computed && !receiver.optional && receiver.object.type === AST_NODE_TYPES32.ThisExpression && receiver.property.type === AST_NODE_TYPES32.Identifier && receiver.property.name === field;
|
|
4760
4937
|
}
|
|
4761
4938
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
4762
4939
|
const parameter = factory.params[0];
|
|
4763
|
-
if (parameter?.type !==
|
|
4940
|
+
if (parameter?.type !== AST_NODE_TYPES32.Identifier || parameter.optional || !typeReference(sourceCode, parameter.typeAnnotation, worker) || !typeReference(sourceCode, factory.returnType, contract))
|
|
4764
4941
|
return false;
|
|
4765
4942
|
const statement = factory.body.body[0];
|
|
4766
|
-
const constructed = statement?.type ===
|
|
4767
|
-
if (constructed?.type !==
|
|
4943
|
+
const constructed = statement?.type === AST_NODE_TYPES32.ReturnStatement ? statement.argument : null;
|
|
4944
|
+
if (constructed?.type !== AST_NODE_TYPES32.NewExpression || constructed.typeArguments !== void 0 || constructed.callee.type !== AST_NODE_TYPES32.Identifier || !sameBinding(sourceCode, constructed.callee, implementation) || constructed.arguments.length !== 1)
|
|
4768
4945
|
return false;
|
|
4769
4946
|
const argument = constructed.arguments[0];
|
|
4770
|
-
return argument?.type ===
|
|
4947
|
+
return argument?.type === AST_NODE_TYPES32.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
4771
4948
|
}
|
|
4772
4949
|
|
|
4773
4950
|
// src/rules/require-port-for-service.ts
|
|
4774
4951
|
import {
|
|
4775
|
-
ASTUtils as
|
|
4776
|
-
AST_NODE_TYPES as
|
|
4952
|
+
ASTUtils as ASTUtils21,
|
|
4953
|
+
AST_NODE_TYPES as AST_NODE_TYPES33
|
|
4777
4954
|
} from "@typescript-eslint/utils";
|
|
4778
4955
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
4779
4956
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
@@ -4858,50 +5035,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
4858
5035
|
"||="
|
|
4859
5036
|
]);
|
|
4860
5037
|
var staticMemberName = (member3) => {
|
|
4861
|
-
if (member3.property.type ===
|
|
5038
|
+
if (member3.property.type === AST_NODE_TYPES33.PrivateIdentifier)
|
|
4862
5039
|
return `#${member3.property.name}`;
|
|
4863
|
-
return
|
|
5040
|
+
return ASTUtils21.getPropertyName(member3);
|
|
4864
5041
|
};
|
|
4865
5042
|
var detachedValueExports = (program) => {
|
|
4866
5043
|
const names = /* @__PURE__ */ new Set();
|
|
4867
5044
|
for (const statement of program.body) {
|
|
4868
|
-
if (statement.type ===
|
|
5045
|
+
if (statement.type === AST_NODE_TYPES33.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
4869
5046
|
for (const specifier of statement.specifiers) {
|
|
4870
5047
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
4871
5048
|
}
|
|
4872
|
-
} else if (statement.type ===
|
|
5049
|
+
} else if (statement.type === AST_NODE_TYPES33.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES33.Identifier) {
|
|
4873
5050
|
names.add(statement.declaration.name);
|
|
4874
|
-
} else if (statement.type ===
|
|
5051
|
+
} else if (statement.type === AST_NODE_TYPES33.TSExportAssignment && statement.expression.type === AST_NODE_TYPES33.Identifier) {
|
|
4875
5052
|
names.add(statement.expression.name);
|
|
4876
5053
|
}
|
|
4877
5054
|
}
|
|
4878
5055
|
return names;
|
|
4879
5056
|
};
|
|
4880
|
-
var isExportedClass = (node, detached) => node.parent.type ===
|
|
5057
|
+
var isExportedClass = (node, detached) => node.parent.type === AST_NODE_TYPES33.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES33.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
4881
5058
|
var createExportedServiceClassResolver = (program) => {
|
|
4882
5059
|
const detached = detachedValueExports(program);
|
|
4883
5060
|
return (node) => isExportedClass(node, detached);
|
|
4884
5061
|
};
|
|
4885
5062
|
var readTypeReference = (annotation) => {
|
|
4886
|
-
if (annotation?.type ===
|
|
5063
|
+
if (annotation?.type === AST_NODE_TYPES33.TSUnionType) {
|
|
4887
5064
|
const members = annotation.types.filter(
|
|
4888
|
-
(member3) => member3.type !==
|
|
5065
|
+
(member3) => member3.type !== AST_NODE_TYPES33.TSUndefinedKeyword && member3.type !== AST_NODE_TYPES33.TSNullKeyword
|
|
4889
5066
|
);
|
|
4890
5067
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
4891
5068
|
}
|
|
4892
|
-
if (annotation === void 0 || annotation.type !==
|
|
5069
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES33.TSTypeReference)
|
|
4893
5070
|
return null;
|
|
4894
5071
|
const { typeName } = annotation;
|
|
4895
|
-
const rightmost = typeName.type ===
|
|
5072
|
+
const rightmost = typeName.type === AST_NODE_TYPES33.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES33.TSQualifiedName ? typeName.right.name : null;
|
|
4896
5073
|
if (rightmost === null) return null;
|
|
4897
5074
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
4898
5075
|
};
|
|
4899
|
-
var qualifiedName = (name) => name.type ===
|
|
5076
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES33.Identifier ? name.name : name.type === AST_NODE_TYPES33.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
4900
5077
|
var propertySignatureTypes = (members) => {
|
|
4901
5078
|
const types = /* @__PURE__ */ new Map();
|
|
4902
5079
|
for (const member3 of members) {
|
|
4903
|
-
if (member3.type !==
|
|
4904
|
-
if (member3.computed || member3.key.type !==
|
|
5080
|
+
if (member3.type !== AST_NODE_TYPES33.TSPropertySignature) continue;
|
|
5081
|
+
if (member3.computed || member3.key.type !== AST_NODE_TYPES33.Identifier)
|
|
4905
5082
|
continue;
|
|
4906
5083
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
4907
5084
|
if (reference === null) continue;
|
|
@@ -4913,18 +5090,18 @@ var fileTypeIndex = (program) => {
|
|
|
4913
5090
|
const objects = /* @__PURE__ */ new Map();
|
|
4914
5091
|
const functionAliases = localFunctionAliases(program);
|
|
4915
5092
|
function collectDeclaredType(statement) {
|
|
4916
|
-
const declaration = statement.type ===
|
|
4917
|
-
if (declaration?.type ===
|
|
5093
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5094
|
+
if (declaration?.type === AST_NODE_TYPES33.TSInterfaceDeclaration) {
|
|
4918
5095
|
objects.set(
|
|
4919
5096
|
declaration.id.name,
|
|
4920
5097
|
propertySignatureTypes(declaration.body.body)
|
|
4921
5098
|
);
|
|
4922
5099
|
return;
|
|
4923
5100
|
}
|
|
4924
|
-
if (declaration?.type !==
|
|
5101
|
+
if (declaration?.type !== AST_NODE_TYPES33.TSTypeAliasDeclaration) return;
|
|
4925
5102
|
const aliased = declaration.typeAnnotation;
|
|
4926
|
-
const literals = aliased.type ===
|
|
4927
|
-
(part) => part.type ===
|
|
5103
|
+
const literals = aliased.type === AST_NODE_TYPES33.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES33.TSIntersectionType ? aliased.types.filter(
|
|
5104
|
+
(part) => part.type === AST_NODE_TYPES33.TSTypeLiteral
|
|
4928
5105
|
) : [];
|
|
4929
5106
|
if (literals.length === 0) return;
|
|
4930
5107
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -4944,12 +5121,12 @@ function localFunctionAliases(program) {
|
|
|
4944
5121
|
const names = /* @__PURE__ */ new Set();
|
|
4945
5122
|
const parents = /* @__PURE__ */ new Map();
|
|
4946
5123
|
for (const statement of program.body) {
|
|
4947
|
-
const declaration = statement.type ===
|
|
4948
|
-
if (declaration?.type !==
|
|
5124
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5125
|
+
if (declaration?.type !== AST_NODE_TYPES33.TSTypeAliasDeclaration) continue;
|
|
4949
5126
|
const annotation = declaration.typeAnnotation;
|
|
4950
|
-
if (annotation.type ===
|
|
5127
|
+
if (annotation.type === AST_NODE_TYPES33.TSFunctionType || annotation.type === AST_NODE_TYPES33.TSConstructorType)
|
|
4951
5128
|
names.add(declaration.id.name);
|
|
4952
|
-
if (annotation.type ===
|
|
5129
|
+
if (annotation.type === AST_NODE_TYPES33.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES33.Identifier)
|
|
4953
5130
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
4954
5131
|
}
|
|
4955
5132
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -4985,32 +5162,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
4985
5162
|
function scanStoredFields(body4) {
|
|
4986
5163
|
const pending = [...body4.body];
|
|
4987
5164
|
function recordStoredField(current) {
|
|
4988
|
-
if (current.type ===
|
|
5165
|
+
if (current.type === AST_NODE_TYPES33.ArrowFunctionExpression || current.type === AST_NODE_TYPES33.FunctionExpression || current.type === AST_NODE_TYPES33.FunctionDeclaration || current.type === AST_NODE_TYPES33.ClassExpression || current.type === AST_NODE_TYPES33.ClassDeclaration)
|
|
4989
5166
|
return;
|
|
4990
|
-
if (current.type ===
|
|
5167
|
+
if (current.type === AST_NODE_TYPES33.VariableDeclarator && current.id.type === AST_NODE_TYPES33.Identifier)
|
|
4991
5168
|
localBindings2.add(current.id.name);
|
|
4992
|
-
const expression = current.type ===
|
|
5169
|
+
const expression = current.type === AST_NODE_TYPES33.AssignmentExpression ? current : null;
|
|
4993
5170
|
const storedField = writtenInstanceField(current);
|
|
4994
5171
|
if (storedField !== null) {
|
|
4995
5172
|
if (writtenFieldNames.has(storedField))
|
|
4996
5173
|
unstableFieldNames.add(storedField);
|
|
4997
5174
|
writtenFieldNames.add(storedField);
|
|
4998
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5175
|
+
if (expression?.operator !== "=" || expression.parent.type !== AST_NODE_TYPES33.ExpressionStatement || expression.parent.parent !== body4)
|
|
4999
5176
|
unstableFieldNames.add(storedField);
|
|
5000
5177
|
}
|
|
5001
|
-
if (expression?.type !==
|
|
5178
|
+
if (expression?.type !== AST_NODE_TYPES33.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== AST_NODE_TYPES33.MemberExpression || expression.left.object.type !== AST_NODE_TYPES33.ThisExpression || storedField === null) {
|
|
5002
5179
|
enqueueChildren(current);
|
|
5003
5180
|
return;
|
|
5004
5181
|
}
|
|
5005
5182
|
const source = unwrapExpression(expression.right);
|
|
5006
|
-
if (source.type ===
|
|
5183
|
+
if (source.type === AST_NODE_TYPES33.NewExpression) {
|
|
5007
5184
|
constructedFields += 1;
|
|
5008
5185
|
constructedFieldNames.add(storedField);
|
|
5009
|
-
} else if (source.type ===
|
|
5186
|
+
} else if (source.type === AST_NODE_TYPES33.Identifier) {
|
|
5010
5187
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
5011
5188
|
fields2.add(storedField);
|
|
5012
5189
|
storedFieldsFrom.set(source.name, fields2);
|
|
5013
|
-
} else if (source.type ===
|
|
5190
|
+
} else if (source.type === AST_NODE_TYPES33.MemberExpression && source.object.type === AST_NODE_TYPES33.Identifier) {
|
|
5014
5191
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
5015
5192
|
fields2.add(storedField);
|
|
5016
5193
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5045,7 +5222,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5045
5222
|
)) {
|
|
5046
5223
|
if (localBindings2.has(reference.name)) continue;
|
|
5047
5224
|
let fields2 = reference.fields;
|
|
5048
|
-
if (parameter.type ===
|
|
5225
|
+
if (parameter.type === AST_NODE_TYPES33.TSParameterProperty) {
|
|
5049
5226
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5050
5227
|
fields2 = [reference.name];
|
|
5051
5228
|
} else if (fields2.length === 0)
|
|
@@ -5068,8 +5245,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5068
5245
|
};
|
|
5069
5246
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5070
5247
|
let target = parameter;
|
|
5071
|
-
if (target.type ===
|
|
5072
|
-
if (target.type ===
|
|
5248
|
+
if (target.type === AST_NODE_TYPES33.AssignmentPattern) target = target.left;
|
|
5249
|
+
if (target.type === AST_NODE_TYPES33.ObjectPattern) {
|
|
5073
5250
|
return objectPatternCollaborators(target, declared);
|
|
5074
5251
|
}
|
|
5075
5252
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5079,10 +5256,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5079
5256
|
};
|
|
5080
5257
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5081
5258
|
let target = annotated;
|
|
5082
|
-
if (target.type ===
|
|
5259
|
+
if (target.type === AST_NODE_TYPES33.TSParameterProperty)
|
|
5083
5260
|
target = target.parameter;
|
|
5084
|
-
if (target.type ===
|
|
5085
|
-
if (target.type !==
|
|
5261
|
+
if (target.type === AST_NODE_TYPES33.AssignmentPattern) target = target.left;
|
|
5262
|
+
if (target.type !== AST_NODE_TYPES33.Identifier) return [];
|
|
5086
5263
|
const members = bagMemberTypes(
|
|
5087
5264
|
target.typeAnnotation?.typeAnnotation,
|
|
5088
5265
|
declared
|
|
@@ -5101,10 +5278,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5101
5278
|
};
|
|
5102
5279
|
var namedParameterCollaborator = (annotated) => {
|
|
5103
5280
|
let target = annotated;
|
|
5104
|
-
if (target.type ===
|
|
5281
|
+
if (target.type === AST_NODE_TYPES33.TSParameterProperty)
|
|
5105
5282
|
target = target.parameter;
|
|
5106
|
-
if (target.type ===
|
|
5107
|
-
if (target.type !==
|
|
5283
|
+
if (target.type === AST_NODE_TYPES33.AssignmentPattern) target = target.left;
|
|
5284
|
+
if (target.type !== AST_NODE_TYPES33.Identifier) return null;
|
|
5108
5285
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5109
5286
|
if (reference === null) return null;
|
|
5110
5287
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5116,12 +5293,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5116
5293
|
if (members === null) return [];
|
|
5117
5294
|
const collaborators = [];
|
|
5118
5295
|
for (const property of pattern.properties) {
|
|
5119
|
-
if (property.type !==
|
|
5296
|
+
if (property.type !== AST_NODE_TYPES33.Property || property.computed)
|
|
5120
5297
|
continue;
|
|
5121
|
-
if (property.key.type !==
|
|
5298
|
+
if (property.key.type !== AST_NODE_TYPES33.Identifier) continue;
|
|
5122
5299
|
const key = property.key.name;
|
|
5123
|
-
const bound = property.value.type ===
|
|
5124
|
-
if (bound.type !==
|
|
5300
|
+
const bound = property.value.type === AST_NODE_TYPES33.AssignmentPattern ? property.value.left : property.value;
|
|
5301
|
+
if (bound.type !== AST_NODE_TYPES33.Identifier) continue;
|
|
5125
5302
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5126
5303
|
const reference = members.get(key);
|
|
5127
5304
|
if (reference === void 0) continue;
|
|
@@ -5131,22 +5308,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5131
5308
|
};
|
|
5132
5309
|
var bagMemberTypes = (annotation, declared) => {
|
|
5133
5310
|
if (annotation === void 0) return null;
|
|
5134
|
-
if (annotation.type ===
|
|
5311
|
+
if (annotation.type === AST_NODE_TYPES33.TSTypeLiteral) {
|
|
5135
5312
|
return propertySignatureTypes(annotation.members);
|
|
5136
5313
|
}
|
|
5137
|
-
if (annotation.type !==
|
|
5314
|
+
if (annotation.type !== AST_NODE_TYPES33.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES33.Identifier) {
|
|
5138
5315
|
return null;
|
|
5139
5316
|
}
|
|
5140
5317
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5141
5318
|
};
|
|
5142
5319
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5143
|
-
if (node.type ===
|
|
5320
|
+
if (node.type === AST_NODE_TYPES33.CallExpression) {
|
|
5144
5321
|
const { callee } = node;
|
|
5145
|
-
if (callee.type ===
|
|
5322
|
+
if (callee.type === AST_NODE_TYPES33.Identifier)
|
|
5146
5323
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5147
|
-
return callee.type ===
|
|
5324
|
+
return callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES33.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
5148
5325
|
}
|
|
5149
|
-
return node.type ===
|
|
5326
|
+
return node.type === AST_NODE_TYPES33.TSTypeReference && node.typeName.type === AST_NODE_TYPES33.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
5150
5327
|
});
|
|
5151
5328
|
var subtreeHas = (root, found) => {
|
|
5152
5329
|
let hit = false;
|
|
@@ -5166,26 +5343,26 @@ var subtreeHas = (root, found) => {
|
|
|
5166
5343
|
};
|
|
5167
5344
|
var invokedInstanceField = (call) => {
|
|
5168
5345
|
let callee = unwrapExpression(call.callee);
|
|
5169
|
-
while (callee.type ===
|
|
5346
|
+
while (callee.type === AST_NODE_TYPES33.ChainExpression)
|
|
5170
5347
|
callee = unwrapExpression(callee.expression);
|
|
5171
5348
|
const direct = instanceField(callee);
|
|
5172
5349
|
if (direct !== null) return direct;
|
|
5173
|
-
return callee.type ===
|
|
5350
|
+
return callee.type === AST_NODE_TYPES33.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5174
5351
|
};
|
|
5175
5352
|
var instanceField = (candidate2) => {
|
|
5176
5353
|
let node = candidate2;
|
|
5177
|
-
while (node.type ===
|
|
5354
|
+
while (node.type === AST_NODE_TYPES33.ChainExpression || node.type === AST_NODE_TYPES33.TSAsExpression || node.type === AST_NODE_TYPES33.TSNonNullExpression || node.type === AST_NODE_TYPES33.TSSatisfiesExpression || node.type === AST_NODE_TYPES33.TSTypeAssertion)
|
|
5178
5355
|
node = node.expression;
|
|
5179
|
-
return node.type ===
|
|
5356
|
+
return node.type === AST_NODE_TYPES33.MemberExpression && node.object.type === AST_NODE_TYPES33.ThisExpression ? staticMemberName(node) : null;
|
|
5180
5357
|
};
|
|
5181
5358
|
function writtenInstanceField(node) {
|
|
5182
|
-
if (node.type ===
|
|
5359
|
+
if (node.type === AST_NODE_TYPES33.AssignmentExpression || node.type === AST_NODE_TYPES33.ForOfStatement || node.type === AST_NODE_TYPES33.ForInStatement)
|
|
5183
5360
|
return instanceField(node.left);
|
|
5184
|
-
if (node.type ===
|
|
5361
|
+
if (node.type === AST_NODE_TYPES33.UpdateExpression)
|
|
5185
5362
|
return instanceField(node.argument);
|
|
5186
|
-
if (node.type ===
|
|
5363
|
+
if (node.type === AST_NODE_TYPES33.UnaryExpression && node.operator === "delete")
|
|
5187
5364
|
return instanceField(node.argument);
|
|
5188
|
-
if (node.type ===
|
|
5365
|
+
if (node.type === AST_NODE_TYPES33.MemberExpression && isDestructuredWriteTarget(node))
|
|
5189
5366
|
return instanceField(node);
|
|
5190
5367
|
return null;
|
|
5191
5368
|
}
|
|
@@ -5194,39 +5371,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5194
5371
|
let target = access;
|
|
5195
5372
|
for (; ; ) {
|
|
5196
5373
|
const parent = target.parent;
|
|
5197
|
-
if (parent.type ===
|
|
5374
|
+
if (parent.type === AST_NODE_TYPES33.Property && parent.value === target && parent.parent.type === AST_NODE_TYPES33.ObjectPattern) {
|
|
5198
5375
|
target = parent.parent;
|
|
5199
5376
|
continue;
|
|
5200
5377
|
}
|
|
5201
|
-
if (parent.type ===
|
|
5378
|
+
if (parent.type === AST_NODE_TYPES33.ArrayPattern || parent.type === AST_NODE_TYPES33.ObjectPattern || parent.type === AST_NODE_TYPES33.RestElement && parent.argument === target || parent.type === AST_NODE_TYPES33.AssignmentPattern && parent.left === target) {
|
|
5202
5379
|
target = parent;
|
|
5203
5380
|
continue;
|
|
5204
5381
|
}
|
|
5205
|
-
return target !== access && (parent.type ===
|
|
5382
|
+
return target !== access && (parent.type === AST_NODE_TYPES33.AssignmentExpression || parent.type === AST_NODE_TYPES33.ForOfStatement || parent.type === AST_NODE_TYPES33.ForInStatement) && parent.left === target;
|
|
5206
5383
|
}
|
|
5207
5384
|
}
|
|
5208
5385
|
var behaviorallyInvokedFields = (body3) => {
|
|
5209
5386
|
const invoked = /* @__PURE__ */ new Set();
|
|
5210
5387
|
const visit = (current) => {
|
|
5211
|
-
if (current.type ===
|
|
5388
|
+
if (current.type === AST_NODE_TYPES33.ClassDeclaration || current.type === AST_NODE_TYPES33.ClassExpression || current.type === AST_NODE_TYPES33.FunctionDeclaration || current.type === AST_NODE_TYPES33.FunctionExpression)
|
|
5212
5389
|
return;
|
|
5213
|
-
if (current.type ===
|
|
5390
|
+
if (current.type === AST_NODE_TYPES33.CallExpression) {
|
|
5214
5391
|
const field = invokedInstanceField(current);
|
|
5215
5392
|
if (field !== null) invoked.add(field);
|
|
5216
5393
|
}
|
|
5217
5394
|
forEachOwnAstChild(current, visit);
|
|
5218
5395
|
};
|
|
5219
5396
|
for (const member3 of body3.body) {
|
|
5220
|
-
if (member3.type ===
|
|
5221
|
-
if (member3.type ===
|
|
5397
|
+
if (member3.type === AST_NODE_TYPES33.StaticBlock || member3.static) continue;
|
|
5398
|
+
if (member3.type === AST_NODE_TYPES33.MethodDefinition) {
|
|
5222
5399
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5223
5400
|
visit(member3.value.body);
|
|
5224
5401
|
continue;
|
|
5225
5402
|
}
|
|
5226
|
-
if (member3.type !==
|
|
5403
|
+
if (member3.type !== AST_NODE_TYPES33.PropertyDefinition || member3.value === null)
|
|
5227
5404
|
continue;
|
|
5228
5405
|
visit(
|
|
5229
|
-
member3.value.type ===
|
|
5406
|
+
member3.value.type === AST_NODE_TYPES33.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5230
5407
|
);
|
|
5231
5408
|
}
|
|
5232
5409
|
return invoked;
|
|
@@ -5246,8 +5423,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5246
5423
|
var fileInterfaceNames = (program) => {
|
|
5247
5424
|
const names = [];
|
|
5248
5425
|
for (const statement of program.body) {
|
|
5249
|
-
const declaration = statement.type ===
|
|
5250
|
-
if (declaration?.type ===
|
|
5426
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5427
|
+
if (declaration?.type === AST_NODE_TYPES33.TSInterfaceDeclaration)
|
|
5251
5428
|
names.push(declaration.id.name);
|
|
5252
5429
|
}
|
|
5253
5430
|
return names;
|
|
@@ -5255,22 +5432,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5255
5432
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5256
5433
|
const names = [];
|
|
5257
5434
|
function collectPublicCallable(member3) {
|
|
5258
|
-
if (member3.type ===
|
|
5435
|
+
if (member3.type === AST_NODE_TYPES33.PropertyDefinition) {
|
|
5259
5436
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5260
5437
|
return;
|
|
5261
|
-
if (member3.key.type ===
|
|
5262
|
-
if (member3.value?.type !==
|
|
5438
|
+
if (member3.key.type === AST_NODE_TYPES33.PrivateIdentifier) return;
|
|
5439
|
+
if (member3.value?.type !== AST_NODE_TYPES33.ArrowFunctionExpression && member3.value?.type !== AST_NODE_TYPES33.FunctionExpression && member3.typeAnnotation?.typeAnnotation.type !== AST_NODE_TYPES33.TSFunctionType && !(member3.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES33.TSTypeReference && member3.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES33.Identifier && functionAliases.has(
|
|
5263
5440
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5264
5441
|
)))
|
|
5265
5442
|
return;
|
|
5266
5443
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5267
5444
|
return;
|
|
5268
5445
|
}
|
|
5269
|
-
if (member3.type !==
|
|
5446
|
+
if (member3.type !== AST_NODE_TYPES33.MethodDefinition) return;
|
|
5270
5447
|
if (member3.kind !== "method" || member3.static) return;
|
|
5271
5448
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5272
5449
|
return;
|
|
5273
|
-
if (member3.key.type ===
|
|
5450
|
+
if (member3.key.type === AST_NODE_TYPES33.PrivateIdentifier) return;
|
|
5274
5451
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5275
5452
|
}
|
|
5276
5453
|
for (const member3 of body3.body) {
|
|
@@ -5281,13 +5458,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5281
5458
|
var isFluentConstructionObject = (node, getText) => {
|
|
5282
5459
|
if (node.id === null) return false;
|
|
5283
5460
|
const methods = node.body.body.filter(
|
|
5284
|
-
(member3) => member3.type ===
|
|
5461
|
+
(member3) => member3.type === AST_NODE_TYPES33.MethodDefinition && member3.kind === "method" && !member3.static && member3.accessibility !== "private" && member3.accessibility !== "protected" && member3.value.body !== null
|
|
5285
5462
|
);
|
|
5286
5463
|
if (methods.length === 0) return false;
|
|
5287
5464
|
return methods.every((member3) => {
|
|
5288
5465
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5289
5466
|
if (result === void 0) return false;
|
|
5290
|
-
const returnsOwnType = result.type ===
|
|
5467
|
+
const returnsOwnType = result.type === AST_NODE_TYPES33.TSTypeReference && result.typeName.type === AST_NODE_TYPES33.Identifier && result.typeName.name === node.id?.name;
|
|
5291
5468
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5292
5469
|
});
|
|
5293
5470
|
};
|
|
@@ -5295,10 +5472,10 @@ function localClassAbstractness(program) {
|
|
|
5295
5472
|
const classes = /* @__PURE__ */ new Map();
|
|
5296
5473
|
const parents = /* @__PURE__ */ new Map();
|
|
5297
5474
|
for (const statement of program.body) {
|
|
5298
|
-
const declaration = statement.type ===
|
|
5299
|
-
if (declaration?.type ===
|
|
5475
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration || statement.type === AST_NODE_TYPES33.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5476
|
+
if (declaration?.type === AST_NODE_TYPES33.ClassDeclaration && declaration.id !== null) {
|
|
5300
5477
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5301
|
-
if (declaration.superClass?.type ===
|
|
5478
|
+
if (declaration.superClass?.type === AST_NODE_TYPES33.Identifier) {
|
|
5302
5479
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5303
5480
|
}
|
|
5304
5481
|
}
|
|
@@ -5316,9 +5493,9 @@ function localClassAbstractness(program) {
|
|
|
5316
5493
|
return classes;
|
|
5317
5494
|
}
|
|
5318
5495
|
function declaredMemberName(member3) {
|
|
5319
|
-
if (!member3.computed && member3.key.type ===
|
|
5496
|
+
if (!member3.computed && member3.key.type === AST_NODE_TYPES33.Identifier)
|
|
5320
5497
|
return member3.key.name;
|
|
5321
|
-
if (member3.key.type ===
|
|
5498
|
+
if (member3.key.type === AST_NODE_TYPES33.Literal && typeof member3.key.value === "string")
|
|
5322
5499
|
return member3.key.value;
|
|
5323
5500
|
return null;
|
|
5324
5501
|
}
|
|
@@ -5327,35 +5504,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5327
5504
|
const parents = /* @__PURE__ */ new Map();
|
|
5328
5505
|
const functionAliases = localFunctionAliases(program);
|
|
5329
5506
|
function collectInterfaceSurface(statement) {
|
|
5330
|
-
const declaration = statement.type ===
|
|
5331
|
-
if (declaration?.type ===
|
|
5507
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5508
|
+
if (declaration?.type === AST_NODE_TYPES33.TSTypeAliasDeclaration) {
|
|
5332
5509
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5333
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5510
|
+
const parts = declaration.typeAnnotation.type === AST_NODE_TYPES33.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5334
5511
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5335
5512
|
for (const part of parts) {
|
|
5336
|
-
if (part.type ===
|
|
5513
|
+
if (part.type === AST_NODE_TYPES33.TSTypeReference && part.typeName.type === AST_NODE_TYPES33.Identifier) {
|
|
5337
5514
|
inherited.push(part.typeName.name);
|
|
5338
5515
|
continue;
|
|
5339
5516
|
}
|
|
5340
|
-
if (part.type ===
|
|
5517
|
+
if (part.type === AST_NODE_TYPES33.TSTypeReference) {
|
|
5341
5518
|
inherited.push("*");
|
|
5342
5519
|
continue;
|
|
5343
5520
|
}
|
|
5344
|
-
if (part.type !==
|
|
5521
|
+
if (part.type !== AST_NODE_TYPES33.TSTypeLiteral) continue;
|
|
5345
5522
|
addCallableMembers(part.members, callables2);
|
|
5346
5523
|
}
|
|
5347
5524
|
interfaces.set(declaration.id.name, callables2);
|
|
5348
5525
|
parents.set(declaration.id.name, inherited);
|
|
5349
5526
|
return;
|
|
5350
5527
|
}
|
|
5351
|
-
if (declaration?.type !==
|
|
5528
|
+
if (declaration?.type !== AST_NODE_TYPES33.TSInterfaceDeclaration) return;
|
|
5352
5529
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5353
5530
|
addCallableMembers(declaration.body.body, callables);
|
|
5354
5531
|
interfaces.set(declaration.id.name, callables);
|
|
5355
5532
|
parents.set(declaration.id.name, [
|
|
5356
5533
|
...parents.get(declaration.id.name) ?? [],
|
|
5357
5534
|
...declaration.extends.flatMap(
|
|
5358
|
-
(heritage) => heritage.expression.type ===
|
|
5535
|
+
(heritage) => heritage.expression.type === AST_NODE_TYPES33.Identifier ? [heritage.expression.name] : ["*"]
|
|
5359
5536
|
)
|
|
5360
5537
|
]);
|
|
5361
5538
|
}
|
|
@@ -5364,17 +5541,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5364
5541
|
}
|
|
5365
5542
|
function addCallableMembers(members, callables) {
|
|
5366
5543
|
for (const member3 of members) {
|
|
5367
|
-
if (member3.type !==
|
|
5544
|
+
if (member3.type !== AST_NODE_TYPES33.TSMethodSignature && member3.type !== AST_NODE_TYPES33.TSPropertySignature)
|
|
5368
5545
|
continue;
|
|
5369
5546
|
const name = declaredMemberName(member3);
|
|
5370
5547
|
if (name === null) continue;
|
|
5371
|
-
if (member3.type ===
|
|
5548
|
+
if (member3.type === AST_NODE_TYPES33.TSMethodSignature) {
|
|
5372
5549
|
callables.add(name);
|
|
5373
5550
|
continue;
|
|
5374
5551
|
}
|
|
5375
|
-
if (member3.type !==
|
|
5552
|
+
if (member3.type !== AST_NODE_TYPES33.TSPropertySignature) continue;
|
|
5376
5553
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5377
|
-
if (annotation?.type ===
|
|
5554
|
+
if (annotation?.type === AST_NODE_TYPES33.TSFunctionType || annotation?.type === AST_NODE_TYPES33.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES33.Identifier && functionAliases.has(annotation.typeName.name))
|
|
5378
5555
|
callables.add(name);
|
|
5379
5556
|
}
|
|
5380
5557
|
}
|
|
@@ -5404,7 +5581,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5404
5581
|
}
|
|
5405
5582
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5406
5583
|
if (node.superClass !== null) {
|
|
5407
|
-
if (node.superClass.type !==
|
|
5584
|
+
if (node.superClass.type !== AST_NODE_TYPES33.Identifier) return true;
|
|
5408
5585
|
const localAbstract = classes.get(node.superClass.name);
|
|
5409
5586
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5410
5587
|
}
|
|
@@ -5443,7 +5620,7 @@ var require_port_for_service_default = createRule({
|
|
|
5443
5620
|
if (node.abstract === true) return;
|
|
5444
5621
|
if (node.decorators.length > 0) return;
|
|
5445
5622
|
const ctor = node.body.body.find(
|
|
5446
|
-
(member3) => member3.type ===
|
|
5623
|
+
(member3) => member3.type === AST_NODE_TYPES33.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null && member3.value.body !== void 0
|
|
5447
5624
|
);
|
|
5448
5625
|
if (ctor === void 0) return;
|
|
5449
5626
|
const constructorFacts = readConstructor(
|
|
@@ -5493,7 +5670,7 @@ var require_port_for_service_default = createRule({
|
|
|
5493
5670
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5494
5671
|
const combined = /* @__PURE__ */ new Set();
|
|
5495
5672
|
for (const implementation of node.implements) {
|
|
5496
|
-
if (implementation.expression.type !==
|
|
5673
|
+
if (implementation.expression.type !== AST_NODE_TYPES33.Identifier)
|
|
5497
5674
|
return true;
|
|
5498
5675
|
const name = implementation.expression.name;
|
|
5499
5676
|
const localAbstract = classes.get(name);
|
|
@@ -5510,7 +5687,7 @@ function createServiceOperationResolver(program) {
|
|
|
5510
5687
|
let declaredTypes = null;
|
|
5511
5688
|
return (node) => {
|
|
5512
5689
|
const ctor = node.body.body.find(
|
|
5513
|
-
(member3) => member3.type ===
|
|
5690
|
+
(member3) => member3.type === AST_NODE_TYPES33.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5514
5691
|
);
|
|
5515
5692
|
if (ctor === void 0) return [];
|
|
5516
5693
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5528,7 +5705,7 @@ function createServiceOperationResolver(program) {
|
|
|
5528
5705
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5529
5706
|
forEachServiceCall(body3, (call) => {
|
|
5530
5707
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5531
|
-
if (call.callee.type ===
|
|
5708
|
+
if (call.callee.type === AST_NODE_TYPES33.MemberExpression && call.callee.object.type === AST_NODE_TYPES33.ThisExpression) {
|
|
5532
5709
|
const callee = staticMemberName(call.callee);
|
|
5533
5710
|
if (callee !== null) {
|
|
5534
5711
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5567,11 +5744,11 @@ function serviceOperationBodies(node) {
|
|
|
5567
5744
|
});
|
|
5568
5745
|
}
|
|
5569
5746
|
for (const member3 of node.body.body) {
|
|
5570
|
-
if (member3.type !==
|
|
5747
|
+
if (member3.type !== AST_NODE_TYPES33.MethodDefinition && member3.type !== AST_NODE_TYPES33.PropertyDefinition)
|
|
5571
5748
|
continue;
|
|
5572
|
-
if (member3.static || member3.decorators.length > 0 || member3.type ===
|
|
5749
|
+
if (member3.static || member3.decorators.length > 0 || member3.type === AST_NODE_TYPES33.MethodDefinition && member3.kind !== "method")
|
|
5573
5750
|
continue;
|
|
5574
|
-
if (member3.value?.type !==
|
|
5751
|
+
if (member3.value?.type !== AST_NODE_TYPES33.FunctionExpression && member3.value?.type !== AST_NODE_TYPES33.ArrowFunctionExpression)
|
|
5575
5752
|
continue;
|
|
5576
5753
|
const name = declaredMemberName(member3);
|
|
5577
5754
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5580,9 +5757,9 @@ function serviceOperationBodies(node) {
|
|
|
5580
5757
|
return bodies;
|
|
5581
5758
|
}
|
|
5582
5759
|
function forEachServiceCall(node, onCall) {
|
|
5583
|
-
if (node.type ===
|
|
5760
|
+
if (node.type === AST_NODE_TYPES33.FunctionDeclaration || node.type === AST_NODE_TYPES33.FunctionExpression || node.type === AST_NODE_TYPES33.ArrowFunctionExpression || node.type === AST_NODE_TYPES33.ClassDeclaration || node.type === AST_NODE_TYPES33.ClassExpression)
|
|
5584
5761
|
return;
|
|
5585
|
-
if (node.type ===
|
|
5762
|
+
if (node.type === AST_NODE_TYPES33.BlockStatement) {
|
|
5586
5763
|
for (const statement of node.body) {
|
|
5587
5764
|
forEachServiceCall(statement, onCall);
|
|
5588
5765
|
if (terminatesOperation(statement)) break;
|
|
@@ -5594,29 +5771,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5594
5771
|
forEachServiceCall(branch, onCall);
|
|
5595
5772
|
return;
|
|
5596
5773
|
}
|
|
5597
|
-
if (node.type ===
|
|
5774
|
+
if (node.type === AST_NODE_TYPES33.CallExpression) onCall(node);
|
|
5598
5775
|
forEachOwnAstChild(node, (child) => {
|
|
5599
5776
|
forEachServiceCall(child, onCall);
|
|
5600
5777
|
});
|
|
5601
5778
|
}
|
|
5602
5779
|
function literalExecutionBranch(node) {
|
|
5603
|
-
if (node.type ===
|
|
5780
|
+
if (node.type === AST_NODE_TYPES33.WhileStatement && node.test.type === AST_NODE_TYPES33.Literal && node.test.value === false)
|
|
5604
5781
|
return node.test;
|
|
5605
|
-
if ((node.type ===
|
|
5782
|
+
if ((node.type === AST_NODE_TYPES33.IfStatement || node.type === AST_NODE_TYPES33.ConditionalExpression) && node.test.type === AST_NODE_TYPES33.Literal && typeof node.test.value === "boolean") {
|
|
5606
5783
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5607
5784
|
}
|
|
5608
|
-
if (node.type !==
|
|
5785
|
+
if (node.type !== AST_NODE_TYPES33.LogicalExpression || node.left.type !== AST_NODE_TYPES33.Literal || typeof node.left.value !== "boolean")
|
|
5609
5786
|
return null;
|
|
5610
5787
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5611
5788
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5612
5789
|
return node.left;
|
|
5613
5790
|
}
|
|
5614
5791
|
function terminatesOperation(node) {
|
|
5615
|
-
if (node.type ===
|
|
5792
|
+
if (node.type === AST_NODE_TYPES33.ReturnStatement || node.type === AST_NODE_TYPES33.ThrowStatement)
|
|
5616
5793
|
return true;
|
|
5617
|
-
if (node.type ===
|
|
5794
|
+
if (node.type === AST_NODE_TYPES33.BlockStatement)
|
|
5618
5795
|
return node.body.some(terminatesOperation);
|
|
5619
|
-
if (node.type !==
|
|
5796
|
+
if (node.type !== AST_NODE_TYPES33.IfStatement) return false;
|
|
5620
5797
|
const branch = literalExecutionBranch(node);
|
|
5621
5798
|
if (branch !== null) return terminatesOperation(branch);
|
|
5622
5799
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5630,7 +5807,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5630
5807
|
const seen = /* @__PURE__ */ new Set();
|
|
5631
5808
|
function addImplementedContracts(current) {
|
|
5632
5809
|
for (const implementation of current.implements) {
|
|
5633
|
-
if (implementation.expression.type !==
|
|
5810
|
+
if (implementation.expression.type !== AST_NODE_TYPES33.Identifier)
|
|
5634
5811
|
return false;
|
|
5635
5812
|
const name = implementation.expression.name;
|
|
5636
5813
|
const surface = interfaces.get(name);
|
|
@@ -5653,7 +5830,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5653
5830
|
}
|
|
5654
5831
|
if (!addImplementedContracts(current)) return null;
|
|
5655
5832
|
if (current.superClass === null) continue;
|
|
5656
|
-
if (current.superClass.type !==
|
|
5833
|
+
if (current.superClass.type !== AST_NODE_TYPES33.Identifier) return null;
|
|
5657
5834
|
const base = classes.get(current.superClass.name);
|
|
5658
5835
|
if (base === void 0) return null;
|
|
5659
5836
|
pending.push(base);
|
|
@@ -5663,8 +5840,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5663
5840
|
function localClassDeclarations(program) {
|
|
5664
5841
|
const classes = /* @__PURE__ */ new Map();
|
|
5665
5842
|
for (const statement of program.body) {
|
|
5666
|
-
const declaration = statement.type ===
|
|
5667
|
-
if (declaration?.type ===
|
|
5843
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration || statement.type === AST_NODE_TYPES33.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5844
|
+
if (declaration?.type === AST_NODE_TYPES33.ClassDeclaration && declaration.id !== null)
|
|
5668
5845
|
classes.set(declaration.id.name, declaration);
|
|
5669
5846
|
}
|
|
5670
5847
|
return classes;
|
|
@@ -5672,13 +5849,13 @@ function localClassDeclarations(program) {
|
|
|
5672
5849
|
function abstractContractOperations(node, functionAliases) {
|
|
5673
5850
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5674
5851
|
for (const member3 of node.body.body) {
|
|
5675
|
-
if (member3.type !==
|
|
5852
|
+
if (member3.type !== AST_NODE_TYPES33.TSAbstractMethodDefinition && member3.type !== AST_NODE_TYPES33.TSAbstractPropertyDefinition)
|
|
5676
5853
|
continue;
|
|
5677
5854
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5678
5855
|
continue;
|
|
5679
|
-
if (member3.type ===
|
|
5856
|
+
if (member3.type === AST_NODE_TYPES33.TSAbstractPropertyDefinition) {
|
|
5680
5857
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5681
|
-
if (annotation?.type !==
|
|
5858
|
+
if (annotation?.type !== AST_NODE_TYPES33.TSFunctionType && !(annotation?.type === AST_NODE_TYPES33.TSTypeReference && annotation.typeName.type === AST_NODE_TYPES33.Identifier && functionAliases.has(annotation.typeName.name)))
|
|
5682
5859
|
continue;
|
|
5683
5860
|
}
|
|
5684
5861
|
const name = declaredMemberName(member3);
|
|
@@ -5814,7 +5991,7 @@ function isServiceRole(name, filename) {
|
|
|
5814
5991
|
}
|
|
5815
5992
|
|
|
5816
5993
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
5817
|
-
import { AST_NODE_TYPES as
|
|
5994
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
5818
5995
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
5819
5996
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
5820
5997
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -5866,7 +6043,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
5866
6043
|
]
|
|
5867
6044
|
};
|
|
5868
6045
|
function isEmptyObject(node) {
|
|
5869
|
-
return node.type ===
|
|
6046
|
+
return node.type === AST_NODE_TYPES34.ObjectExpression && node.properties.length === 0;
|
|
5870
6047
|
}
|
|
5871
6048
|
var no_conditional_empty_object_spread_default = createRule({
|
|
5872
6049
|
name: "no-conditional-empty-object-spread",
|
|
@@ -5887,13 +6064,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5887
6064
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
5888
6065
|
return {
|
|
5889
6066
|
SpreadElement(node) {
|
|
5890
|
-
if (node.parent.type !==
|
|
6067
|
+
if (node.parent.type !== AST_NODE_TYPES34.ObjectExpression || node.argument.type !== AST_NODE_TYPES34.ConditionalExpression)
|
|
5891
6068
|
return;
|
|
5892
6069
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
5893
6070
|
const conditional = node.argument;
|
|
5894
6071
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
5895
6072
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
5896
|
-
const canFix = populated.type ===
|
|
6073
|
+
const canFix = populated.type === AST_NODE_TYPES34.ObjectExpression && populated.properties.length > 0 && context.sourceCode.getCommentsInside(conditional).length === 0;
|
|
5897
6074
|
context.report({
|
|
5898
6075
|
node,
|
|
5899
6076
|
messageId: "avoid",
|
|
@@ -5910,8 +6087,8 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5910
6087
|
|
|
5911
6088
|
// src/rules/prefer-typed-reflection.ts
|
|
5912
6089
|
import {
|
|
5913
|
-
AST_NODE_TYPES as
|
|
5914
|
-
ASTUtils as
|
|
6090
|
+
AST_NODE_TYPES as AST_NODE_TYPES35,
|
|
6091
|
+
ASTUtils as ASTUtils22,
|
|
5915
6092
|
ESLintUtils as ESLintUtils7
|
|
5916
6093
|
} from "@typescript-eslint/utils";
|
|
5917
6094
|
import ts13 from "typescript";
|
|
@@ -5989,17 +6166,17 @@ var prefer_typed_reflection_default = createRule({
|
|
|
5989
6166
|
const services = ESLintUtils7.getParserServices(context);
|
|
5990
6167
|
if (!services.program) return {};
|
|
5991
6168
|
const checker = services.program.getTypeChecker();
|
|
5992
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
5993
|
-
const globalName = (node, name) => node.type ===
|
|
6169
|
+
const isReflect = (node) => globalName(node, "Reflect") || node.type === AST_NODE_TYPES35.MemberExpression && ASTUtils22.getPropertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
6170
|
+
const globalName = (node, name) => node.type === AST_NODE_TYPES35.Identifier && node.name === name && !ASTUtils22.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
5994
6171
|
const closedObject = (type) => {
|
|
5995
6172
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
5996
6173
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
5997
6174
|
};
|
|
5998
6175
|
const inspectGet = (node, type) => {
|
|
5999
6176
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
6000
|
-
return node.arguments.length === 2 && (staticString(key) !== null || key?.type ===
|
|
6177
|
+
return node.arguments.length === 2 && (staticString(key) !== null || key?.type === AST_NODE_TYPES35.Literal && typeof key.value === "number") && closedObject(type);
|
|
6001
6178
|
};
|
|
6002
|
-
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type ===
|
|
6179
|
+
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type === AST_NODE_TYPES35.ArrayExpression && knownType(type) && type.getCallSignatures().some(
|
|
6003
6180
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
6004
6181
|
(parameter) => knownType(
|
|
6005
6182
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -6010,25 +6187,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6010
6187
|
)
|
|
6011
6188
|
);
|
|
6012
6189
|
const getReplacement = (node, type, target) => {
|
|
6013
|
-
if (node.optional || node.callee.type !==
|
|
6190
|
+
if (node.optional || node.callee.type !== AST_NODE_TYPES35.MemberExpression || node.callee.optional || context.sourceCode.getCommentsInside(node).length > 0) return null;
|
|
6014
6191
|
let outer = node;
|
|
6015
|
-
while (outer.parent.type ===
|
|
6016
|
-
if (outer.parent.type ===
|
|
6192
|
+
while (outer.parent.type === AST_NODE_TYPES35.TSAsExpression || outer.parent.type === AST_NODE_TYPES35.TSTypeAssertion || outer.parent.type === AST_NODE_TYPES35.TSSatisfiesExpression || outer.parent.type === AST_NODE_TYPES35.TSNonNullExpression || outer.parent.type === AST_NODE_TYPES35.ChainExpression) outer = outer.parent;
|
|
6193
|
+
if (outer.parent.type === AST_NODE_TYPES35.UnaryExpression && outer.parent.operator === "delete" || outer.parent.type === AST_NODE_TYPES35.CallExpression && outer.parent.callee === outer || outer.parent.type === AST_NODE_TYPES35.TaggedTemplateExpression && outer.parent.tag === outer) return null;
|
|
6017
6194
|
const writtenKey = node.arguments[1];
|
|
6018
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6195
|
+
if (writtenKey === void 0 || writtenKey.type === AST_NODE_TYPES35.SpreadElement) return null;
|
|
6019
6196
|
const key = unwrapExpression(writtenKey);
|
|
6020
|
-
const name = staticString(key) ?? (key.type ===
|
|
6197
|
+
const name = staticString(key) ?? (key.type === AST_NODE_TYPES35.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
6021
6198
|
const members = type.isUnion() ? type.types : [type];
|
|
6022
6199
|
if (name === null || !members.every((member3) => (member3.flags & ts13.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
6023
6200
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
6024
6201
|
};
|
|
6025
6202
|
return {
|
|
6026
6203
|
CallExpression(node) {
|
|
6027
|
-
if (node.callee.type !==
|
|
6204
|
+
if (node.callee.type !== AST_NODE_TYPES35.MemberExpression || !isReflect(node.callee.object))
|
|
6028
6205
|
return;
|
|
6029
|
-
const method =
|
|
6206
|
+
const method = ASTUtils22.getPropertyName(node.callee);
|
|
6030
6207
|
const target = node.arguments[0];
|
|
6031
|
-
if (!target || target.type ===
|
|
6208
|
+
if (!target || target.type === AST_NODE_TYPES35.SpreadElement || method !== "get" && method !== "apply")
|
|
6032
6209
|
return;
|
|
6033
6210
|
const type = checker.getTypeAtLocation(
|
|
6034
6211
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6044,30 +6221,30 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6044
6221
|
|
|
6045
6222
|
// src/rules/no-broad-return-type.ts
|
|
6046
6223
|
import {
|
|
6047
|
-
AST_NODE_TYPES as
|
|
6224
|
+
AST_NODE_TYPES as AST_NODE_TYPES37,
|
|
6048
6225
|
ESLintUtils as ESLintUtils8
|
|
6049
6226
|
} from "@typescript-eslint/utils";
|
|
6050
6227
|
import ts14 from "typescript";
|
|
6051
6228
|
|
|
6052
6229
|
// src/rules/_unused-private-binding.ts
|
|
6053
|
-
import { AST_NODE_TYPES as
|
|
6230
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
6054
6231
|
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6055
6232
|
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6056
6233
|
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6057
6234
|
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
6058
6235
|
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
6059
|
-
const statement = declaration.type ===
|
|
6060
|
-
if (statement.parent.type ===
|
|
6061
|
-
if (statement.parent.type !==
|
|
6062
|
-
return sourceCode.ast.body.some((node) => node.type ===
|
|
6236
|
+
const statement = declaration.type === AST_NODE_TYPES36.VariableDeclarator ? declaration.parent : declaration;
|
|
6237
|
+
if (statement.parent.type === AST_NODE_TYPES36.ExportNamedDeclaration || statement.parent.type === AST_NODE_TYPES36.ExportDefaultDeclaration) return false;
|
|
6238
|
+
if (statement.parent.type !== AST_NODE_TYPES36.Program) return statement.parent.type === AST_NODE_TYPES36.BlockStatement;
|
|
6239
|
+
return sourceCode.ast.body.some((node) => node.type === AST_NODE_TYPES36.ImportDeclaration || node.type === AST_NODE_TYPES36.ExportNamedDeclaration || node.type === AST_NODE_TYPES36.ExportDefaultDeclaration || node.type === AST_NODE_TYPES36.ExportAllDeclaration);
|
|
6063
6240
|
}
|
|
6064
6241
|
function hasOnlyDirectFactoryUses(variable) {
|
|
6065
6242
|
return variable.references.every((reference) => {
|
|
6066
6243
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6067
6244
|
const identifier = reference.identifier;
|
|
6068
6245
|
const parent = identifier.parent;
|
|
6069
|
-
if (parent.type ===
|
|
6070
|
-
return parent.type ===
|
|
6246
|
+
if (parent.type === AST_NODE_TYPES36.CallExpression && parent.callee === identifier) return true;
|
|
6247
|
+
return parent.type === AST_NODE_TYPES36.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === AST_NODE_TYPES36.CallExpression && parent.parent.callee === parent;
|
|
6071
6248
|
});
|
|
6072
6249
|
}
|
|
6073
6250
|
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
@@ -6081,7 +6258,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6081
6258
|
const current = pending.pop();
|
|
6082
6259
|
if (current === void 0 || seen.has(current)) continue;
|
|
6083
6260
|
seen.add(current);
|
|
6084
|
-
if (current.type ===
|
|
6261
|
+
if (current.type === AST_NODE_TYPES36.Identifier || current.type === AST_NODE_TYPES36.JSXIdentifier) collected.add(current.name);
|
|
6085
6262
|
forEachOwnAstChild(current, (child) => {
|
|
6086
6263
|
pending.push(child);
|
|
6087
6264
|
}, (key) => key !== "tokens" && key !== "comments");
|
|
@@ -6092,7 +6269,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6092
6269
|
return names.has(name);
|
|
6093
6270
|
}
|
|
6094
6271
|
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6095
|
-
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !==
|
|
6272
|
+
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== AST_NODE_TYPES36.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
6096
6273
|
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6097
6274
|
}
|
|
6098
6275
|
|
|
@@ -6206,7 +6383,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6206
6383
|
known: false,
|
|
6207
6384
|
opaque: false
|
|
6208
6385
|
});
|
|
6209
|
-
if (node.body && node.body.type !==
|
|
6386
|
+
if (node.body && node.body.type !== AST_NODE_TYPES37.BlockStatement)
|
|
6210
6387
|
inspectReturn(node.body);
|
|
6211
6388
|
};
|
|
6212
6389
|
const leave = () => {
|
|
@@ -6214,7 +6391,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6214
6391
|
if (frame?.annotation && frame.known && !frame.opaque) {
|
|
6215
6392
|
const annotation = frame.annotation;
|
|
6216
6393
|
const node = frame.node;
|
|
6217
|
-
const canFix = node.type ===
|
|
6394
|
+
const canFix = node.type === AST_NODE_TYPES37.FunctionDeclaration && node.id !== null && isUnusedPrivateBinding(context.sourceCode, node, node.id, context.filename) && context.sourceCode.getCommentsInside(annotation).length === 0 && retainsNamedTypeUses(context.sourceCode, annotation);
|
|
6218
6395
|
context.report({ node: annotation, messageId: "avoid", fix: canFix ? (fixer) => fixer.replaceText(annotation, context.sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")) : null });
|
|
6219
6396
|
}
|
|
6220
6397
|
};
|
|
@@ -6234,49 +6411,49 @@ var no_broad_return_type_default = createRule({
|
|
|
6234
6411
|
|
|
6235
6412
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
6236
6413
|
import {
|
|
6237
|
-
AST_NODE_TYPES as
|
|
6238
|
-
ASTUtils as
|
|
6414
|
+
AST_NODE_TYPES as AST_NODE_TYPES39,
|
|
6415
|
+
ASTUtils as ASTUtils24,
|
|
6239
6416
|
ESLintUtils as ESLintUtils9
|
|
6240
6417
|
} from "@typescript-eslint/utils";
|
|
6241
6418
|
import ts15 from "typescript";
|
|
6242
6419
|
|
|
6243
6420
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
6244
6421
|
import {
|
|
6245
|
-
AST_NODE_TYPES as
|
|
6246
|
-
ASTUtils as
|
|
6422
|
+
AST_NODE_TYPES as AST_NODE_TYPES38,
|
|
6423
|
+
ASTUtils as ASTUtils23
|
|
6247
6424
|
} from "@typescript-eslint/utils";
|
|
6248
6425
|
function literalIdentityReduceFix(sourceCode, node) {
|
|
6249
|
-
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !==
|
|
6426
|
+
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !== AST_NODE_TYPES38.MemberExpression || node.callee.optional || ASTUtils23.getPropertyName(node.callee) !== "reduce")
|
|
6250
6427
|
return null;
|
|
6251
6428
|
const values = node.callee.object;
|
|
6252
|
-
if (values.type !==
|
|
6253
|
-
(element) => element?.type ===
|
|
6429
|
+
if (values.type !== AST_NODE_TYPES38.ArrayExpression || values.elements.length === 0 || !values.elements.every(
|
|
6430
|
+
(element) => element?.type === AST_NODE_TYPES38.Literal && typeof element.value === "string"
|
|
6254
6431
|
))
|
|
6255
6432
|
return null;
|
|
6256
6433
|
const statement = sourceCode.ast.body[0];
|
|
6257
|
-
if (statement?.type !==
|
|
6434
|
+
if (statement?.type !== AST_NODE_TYPES38.ExportNamedDeclaration || statement.declaration?.type !== AST_NODE_TYPES38.FunctionDeclaration)
|
|
6258
6435
|
return null;
|
|
6259
6436
|
const owner = statement.declaration;
|
|
6260
6437
|
if (owner.async || owner.declare || owner.generator || owner.typeParameters !== void 0 || owner.params.length !== 0 || owner.body.body.length !== 1 || !stringArray(owner.returnType?.typeAnnotation))
|
|
6261
6438
|
return null;
|
|
6262
6439
|
const returned2 = owner.body.body[0];
|
|
6263
|
-
if (returned2?.type !==
|
|
6440
|
+
if (returned2?.type !== AST_NODE_TYPES38.ReturnStatement || returned2.argument !== node || node.typeArguments?.params.length !== 1 || !stringArray(node.typeArguments.params[0]))
|
|
6264
6441
|
return null;
|
|
6265
6442
|
const [callback, seed] = node.arguments;
|
|
6266
|
-
if (seed?.type !==
|
|
6443
|
+
if (seed?.type !== AST_NODE_TYPES38.ArrayExpression || seed.elements.length !== 0 || callback?.type !== AST_NODE_TYPES38.ArrowFunctionExpression || callback.async || callback.typeParameters !== void 0 || callback.returnType !== void 0 || callback.params.length !== 2 || callback.body.type !== AST_NODE_TYPES38.ArrayExpression || callback.body.elements.length !== 2)
|
|
6267
6444
|
return null;
|
|
6268
6445
|
if (!identitySpread(sourceCode, callback)) return null;
|
|
6269
6446
|
return (fixer) => fixer.replaceText(node, sourceCode.getText(values));
|
|
6270
6447
|
}
|
|
6271
6448
|
function stringArray(node) {
|
|
6272
|
-
return node?.type ===
|
|
6449
|
+
return node?.type === AST_NODE_TYPES38.TSArrayType && node.elementType.type === AST_NODE_TYPES38.TSStringKeyword;
|
|
6273
6450
|
}
|
|
6274
6451
|
function identitySpread(sourceCode, callback) {
|
|
6275
6452
|
const [accumulator, item] = callback.params;
|
|
6276
|
-
if (accumulator?.type !==
|
|
6453
|
+
if (accumulator?.type !== AST_NODE_TYPES38.Identifier || item?.type !== AST_NODE_TYPES38.Identifier || accumulator.name === item.name || accumulator.optional || item.optional || accumulator.typeAnnotation !== void 0 || item.typeAnnotation !== void 0 || callback.body.type !== AST_NODE_TYPES38.ArrayExpression)
|
|
6277
6454
|
return false;
|
|
6278
6455
|
const [spread, appended] = callback.body.elements;
|
|
6279
|
-
if (spread?.type !==
|
|
6456
|
+
if (spread?.type !== AST_NODE_TYPES38.SpreadElement || spread.argument.type !== AST_NODE_TYPES38.Identifier || appended?.type !== AST_NODE_TYPES38.Identifier || spread.argument.name !== accumulator.name || appended.name !== item.name)
|
|
6280
6457
|
return false;
|
|
6281
6458
|
const bindings = sourceCode.getDeclaredVariables(callback);
|
|
6282
6459
|
const left = bindings.find(
|
|
@@ -6285,10 +6462,10 @@ function identitySpread(sourceCode, callback) {
|
|
|
6285
6462
|
const right = bindings.find(
|
|
6286
6463
|
(variable) => variable.identifiers.includes(item)
|
|
6287
6464
|
);
|
|
6288
|
-
return left !== void 0 && right !== void 0 &&
|
|
6465
|
+
return left !== void 0 && right !== void 0 && ASTUtils23.findVariable(
|
|
6289
6466
|
sourceCode.getScope(spread.argument),
|
|
6290
6467
|
spread.argument.name
|
|
6291
|
-
) === left &&
|
|
6468
|
+
) === left && ASTUtils23.findVariable(sourceCode.getScope(appended), appended.name) === right;
|
|
6292
6469
|
}
|
|
6293
6470
|
|
|
6294
6471
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
@@ -6384,19 +6561,19 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6384
6561
|
const checker = program.getTypeChecker();
|
|
6385
6562
|
return {
|
|
6386
6563
|
CallExpression(node) {
|
|
6387
|
-
if (node.callee.type !==
|
|
6388
|
-
|
|
6564
|
+
if (node.callee.type !== AST_NODE_TYPES39.MemberExpression || !["reduce", "reduceRight"].includes(
|
|
6565
|
+
ASTUtils24.getPropertyName(node.callee) ?? ""
|
|
6389
6566
|
) || node.arguments.length !== 2)
|
|
6390
6567
|
return;
|
|
6391
6568
|
const seed = node.arguments[1];
|
|
6392
|
-
const arraySeed = seed?.type ===
|
|
6393
|
-
const objectSeed = seed?.type ===
|
|
6569
|
+
const arraySeed = seed?.type === AST_NODE_TYPES39.ArrayExpression && seed.elements.length === 0;
|
|
6570
|
+
const objectSeed = seed?.type === AST_NODE_TYPES39.ObjectExpression && seed.properties.length === 0;
|
|
6394
6571
|
if (!arraySeed && !objectSeed) return;
|
|
6395
6572
|
const callback = node.arguments[0];
|
|
6396
|
-
if (!callback || callback.type !==
|
|
6573
|
+
if (!callback || callback.type !== AST_NODE_TYPES39.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES39.FunctionExpression)
|
|
6397
6574
|
return;
|
|
6398
6575
|
const parameter = callback.params[0];
|
|
6399
|
-
if (parameter?.type !==
|
|
6576
|
+
if (parameter?.type !== AST_NODE_TYPES39.Identifier) return;
|
|
6400
6577
|
const signature = checker.getResolvedSignature(
|
|
6401
6578
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
6402
6579
|
);
|
|
@@ -6407,51 +6584,51 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6407
6584
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
6408
6585
|
return;
|
|
6409
6586
|
const fix = literalIdentityReduceFix(context.sourceCode, node);
|
|
6410
|
-
const referencesAccumulator = (value) => value.type ===
|
|
6587
|
+
const referencesAccumulator = (value) => value.type === AST_NODE_TYPES39.Identifier && ASTUtils24.findVariable(
|
|
6411
6588
|
context.sourceCode.getScope(value),
|
|
6412
6589
|
value.name
|
|
6413
6590
|
) === accumulator;
|
|
6414
6591
|
const inspect = (current) => {
|
|
6415
6592
|
if (current !== callback.body && [
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6593
|
+
AST_NODE_TYPES39.ArrowFunctionExpression,
|
|
6594
|
+
AST_NODE_TYPES39.FunctionExpression,
|
|
6595
|
+
AST_NODE_TYPES39.FunctionDeclaration,
|
|
6596
|
+
AST_NODE_TYPES39.ClassDeclaration,
|
|
6597
|
+
AST_NODE_TYPES39.ClassExpression,
|
|
6598
|
+
AST_NODE_TYPES39.ForStatement,
|
|
6599
|
+
AST_NODE_TYPES39.ForInStatement,
|
|
6600
|
+
AST_NODE_TYPES39.ForOfStatement,
|
|
6601
|
+
AST_NODE_TYPES39.WhileStatement,
|
|
6602
|
+
AST_NODE_TYPES39.DoWhileStatement
|
|
6426
6603
|
].some((kind) => kind === current.type))
|
|
6427
6604
|
return;
|
|
6428
|
-
if (current.type ===
|
|
6605
|
+
if (current.type === AST_NODE_TYPES39.SpreadElement && (arraySeed && current.parent.type === AST_NODE_TYPES39.ArrayExpression || objectSeed && current.parent.type === AST_NODE_TYPES39.ObjectExpression) && referencesAccumulator(current.argument)) {
|
|
6429
6606
|
context.report({
|
|
6430
6607
|
node: current,
|
|
6431
6608
|
messageId: "copy",
|
|
6432
6609
|
fix
|
|
6433
6610
|
});
|
|
6434
6611
|
}
|
|
6435
|
-
if (current.type ===
|
|
6612
|
+
if (current.type === AST_NODE_TYPES39.CallExpression)
|
|
6436
6613
|
inspectCall(current);
|
|
6437
6614
|
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
6438
6615
|
};
|
|
6439
6616
|
const inspectCall = (current) => {
|
|
6440
|
-
if (current.callee.type !==
|
|
6617
|
+
if (current.callee.type !== AST_NODE_TYPES39.MemberExpression) return;
|
|
6441
6618
|
const member3 = current.callee;
|
|
6442
|
-
const name =
|
|
6619
|
+
const name = ASTUtils24.getPropertyName(member3);
|
|
6443
6620
|
const directCopy = arraySeed && name !== null && COPY_METHODS.has(name) && referencesAccumulator(member3.object);
|
|
6444
|
-
const globalArray = member3.object.type ===
|
|
6621
|
+
const globalArray = member3.object.type === AST_NODE_TYPES39.Identifier && member3.object.name === "Array" && !ASTUtils24.findVariable(
|
|
6445
6622
|
context.sourceCode.getScope(member3.object),
|
|
6446
6623
|
"Array"
|
|
6447
6624
|
)?.defs.length;
|
|
6448
6625
|
const fromCopy = arraySeed && name === "from" && globalArray && current.arguments[0] !== void 0 && referencesAccumulator(current.arguments[0]);
|
|
6449
|
-
const globalObject = member3.object.type ===
|
|
6626
|
+
const globalObject = member3.object.type === AST_NODE_TYPES39.Identifier && member3.object.name === "Object" && !ASTUtils24.findVariable(
|
|
6450
6627
|
context.sourceCode.getScope(member3.object),
|
|
6451
6628
|
"Object"
|
|
6452
6629
|
)?.defs.length;
|
|
6453
6630
|
const target = current.arguments[0];
|
|
6454
|
-
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type ===
|
|
6631
|
+
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type === AST_NODE_TYPES39.ObjectExpression && current.arguments.slice(1).some(referencesAccumulator);
|
|
6455
6632
|
if (directCopy || fromCopy || assignCopy)
|
|
6456
6633
|
context.report({ node: current, messageId: "copy" });
|
|
6457
6634
|
};
|
|
@@ -6462,7 +6639,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6462
6639
|
});
|
|
6463
6640
|
|
|
6464
6641
|
// src/rules/no-known-value-widening.ts
|
|
6465
|
-
import { AST_NODE_TYPES as
|
|
6642
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
|
|
6466
6643
|
import ts16 from "typescript";
|
|
6467
6644
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
6468
6645
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
@@ -6517,7 +6694,7 @@ var no_known_value_widening_default = createRule({
|
|
|
6517
6694
|
const checker = services.program.getTypeChecker();
|
|
6518
6695
|
return {
|
|
6519
6696
|
VariableDeclarator(node) {
|
|
6520
|
-
if (node.id.type !==
|
|
6697
|
+
if (node.id.type !== AST_NODE_TYPES40.Identifier || !node.id.typeAnnotation || node.init?.type !== AST_NODE_TYPES40.Identifier || node.parent.kind !== "const" || node.parent.parent.type === AST_NODE_TYPES40.ExportNamedDeclaration) return;
|
|
6521
6698
|
const source = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.init));
|
|
6522
6699
|
if (hasUnknownContract(source, checker)) return;
|
|
6523
6700
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.id.typeAnnotation.typeAnnotation));
|
|
@@ -6536,7 +6713,7 @@ var no_known_value_widening_default = createRule({
|
|
|
6536
6713
|
});
|
|
6537
6714
|
|
|
6538
6715
|
// src/rules/no-invalid-typed-mutation.ts
|
|
6539
|
-
import { ASTUtils as
|
|
6716
|
+
import { ASTUtils as ASTUtils25, AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
6540
6717
|
import { isObjectType, isTypeReference } from "ts-api-utils";
|
|
6541
6718
|
import ts17 from "typescript";
|
|
6542
6719
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
@@ -6644,7 +6821,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6644
6821
|
const target = node.arguments[0];
|
|
6645
6822
|
if (target === void 0) return;
|
|
6646
6823
|
invalidateNamespace(target);
|
|
6647
|
-
if (target.type !==
|
|
6824
|
+
if (target.type !== AST_NODE_TYPES41.Identifier) return;
|
|
6648
6825
|
const writes = mutationWrites(node, method.namespace, method.method);
|
|
6649
6826
|
if (writes !== void 0) candidates.push({ call: node, ...method, target, writes });
|
|
6650
6827
|
},
|
|
@@ -6655,9 +6832,9 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6655
6832
|
}
|
|
6656
6833
|
});
|
|
6657
6834
|
function localDataTarget(target, sourceCode) {
|
|
6658
|
-
const binding3 =
|
|
6835
|
+
const binding3 = ASTUtils25.findVariable(sourceCode.getScope(target), target.name);
|
|
6659
6836
|
const definition = binding3?.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
6660
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !==
|
|
6837
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !== AST_NODE_TYPES41.Identifier || definition.node.id.typeAnnotation === void 0 || definition.node.init?.type !== AST_NODE_TYPES41.ObjectExpression || definition.parent.parent.type === AST_NODE_TYPES41.ExportNamedDeclaration) return void 0;
|
|
6661
6838
|
const properties = plainProperties(definition.node.init);
|
|
6662
6839
|
if (properties === void 0) return void 0;
|
|
6663
6840
|
const scope = sourceCode.getScope(definition.node).variableScope;
|
|
@@ -6668,29 +6845,29 @@ function localDataTarget(target, sourceCode) {
|
|
|
6668
6845
|
return new Set(properties.map((property) => property.key));
|
|
6669
6846
|
}
|
|
6670
6847
|
function safeTargetUse(identifier, sourceCode) {
|
|
6671
|
-
if (identifier.type !==
|
|
6848
|
+
if (identifier.type !== AST_NODE_TYPES41.Identifier) return false;
|
|
6672
6849
|
const parent = identifier.parent;
|
|
6673
|
-
if (parent.type ===
|
|
6674
|
-
const key =
|
|
6850
|
+
if (parent.type === AST_NODE_TYPES41.MemberExpression && parent.object === identifier) {
|
|
6851
|
+
const key = ASTUtils25.getPropertyName(parent);
|
|
6675
6852
|
const use = outerExpression(parent);
|
|
6676
|
-
if (parent.optional || use.parent.type ===
|
|
6677
|
-
return key !== null && key !== "__proto__" && !(use.parent.type ===
|
|
6853
|
+
if (parent.optional || use.parent.type === AST_NODE_TYPES41.UnaryExpression && use.parent.operator === "delete") return false;
|
|
6854
|
+
return key !== null && key !== "__proto__" && !(use.parent.type === AST_NODE_TYPES41.CallExpression && use.parent.callee === use);
|
|
6678
6855
|
}
|
|
6679
|
-
if (parent.type !==
|
|
6856
|
+
if (parent.type !== AST_NODE_TYPES41.CallExpression || parent.arguments[0] !== identifier) return false;
|
|
6680
6857
|
const method = nativeMember(parent.callee, sourceCode);
|
|
6681
6858
|
if (method === void 0) return false;
|
|
6682
6859
|
const writes = mutationWrites(parent, method.namespace, method.method);
|
|
6683
|
-
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type ===
|
|
6860
|
+
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type === AST_NODE_TYPES41.ExpressionStatement);
|
|
6684
6861
|
}
|
|
6685
6862
|
function keepsMutableDescriptor(call, method) {
|
|
6686
6863
|
if (method !== "defineProperty") return true;
|
|
6687
6864
|
const descriptor = call.arguments[2];
|
|
6688
|
-
if (descriptor?.type !==
|
|
6865
|
+
if (descriptor?.type !== AST_NODE_TYPES41.ObjectExpression) return false;
|
|
6689
6866
|
const properties = plainProperties(descriptor);
|
|
6690
6867
|
return properties !== void 0 && properties.every((property) => {
|
|
6691
6868
|
if (property.key !== "writable" && property.key !== "configurable") return true;
|
|
6692
6869
|
const value = unwrapExpression(property.value);
|
|
6693
|
-
return value.type ===
|
|
6870
|
+
return value.type === AST_NODE_TYPES41.Literal && value.value === true;
|
|
6694
6871
|
});
|
|
6695
6872
|
}
|
|
6696
6873
|
function declaredTargetType(node, checker) {
|
|
@@ -6740,9 +6917,9 @@ function definiteSignatures(type, checker, seen) {
|
|
|
6740
6917
|
}
|
|
6741
6918
|
function nativeMember(node, sourceCode) {
|
|
6742
6919
|
const member3 = unwrapExpression(node);
|
|
6743
|
-
if (member3.type !==
|
|
6920
|
+
if (member3.type !== AST_NODE_TYPES41.MemberExpression || member3.optional) return void 0;
|
|
6744
6921
|
const namespace = nativeNamespace(member3.object, sourceCode);
|
|
6745
|
-
const method =
|
|
6922
|
+
const method = ASTUtils25.getPropertyName(member3);
|
|
6746
6923
|
if (namespace === void 0 || method === null) return void 0;
|
|
6747
6924
|
const supported2 = namespace === "Object" ? ["assign", "defineProperty", "defineProperties", "setPrototypeOf"] : ["set", "defineProperty", "setPrototypeOf"];
|
|
6748
6925
|
return supported2.includes(method) ? { namespace, method } : void 0;
|
|
@@ -6751,43 +6928,43 @@ function ordinaryNamespaceUse(node) {
|
|
|
6751
6928
|
const value = outerExpression(node);
|
|
6752
6929
|
const parent = value.parent;
|
|
6753
6930
|
if (parent === void 0) return false;
|
|
6754
|
-
return parent.type ===
|
|
6931
|
+
return parent.type === AST_NODE_TYPES41.MemberExpression && parent.object === value || parent.type === AST_NODE_TYPES41.UnaryExpression && parent.operator === "typeof" || parent.type === AST_NODE_TYPES41.TSTypeQuery || parent.type === AST_NODE_TYPES41.TSQualifiedName;
|
|
6755
6932
|
}
|
|
6756
6933
|
function replacementNamespace(node, sourceCode) {
|
|
6757
6934
|
const value = unwrapExpression(node);
|
|
6758
6935
|
if (nativeObjectPrototype(value, sourceCode)) return "ObjectPrototype";
|
|
6759
|
-
return nativeNamespace(value, sourceCode) ?? (value.type ===
|
|
6936
|
+
return nativeNamespace(value, sourceCode) ?? (value.type === AST_NODE_TYPES41.MemberExpression ? replacementNamespace(value.object, sourceCode) : void 0);
|
|
6760
6937
|
}
|
|
6761
6938
|
function nativeObjectPrototype(node, sourceCode) {
|
|
6762
6939
|
const value = unwrapExpression(node);
|
|
6763
|
-
return value.type ===
|
|
6940
|
+
return value.type === AST_NODE_TYPES41.MemberExpression && ASTUtils25.getPropertyName(value) === "prototype" && nativeNamespace(value.object, sourceCode) === "Object";
|
|
6764
6941
|
}
|
|
6765
6942
|
function nativeNamespace(node, sourceCode) {
|
|
6766
6943
|
const value = unwrapExpression(node);
|
|
6767
|
-
if (value.type ===
|
|
6768
|
-
const key =
|
|
6944
|
+
if (value.type === AST_NODE_TYPES41.MemberExpression && !value.optional && nativeGlobalReceiver(value.object, sourceCode)) {
|
|
6945
|
+
const key = ASTUtils25.getPropertyName(value);
|
|
6769
6946
|
if (key === "Object" || key === "Reflect") return key;
|
|
6770
6947
|
}
|
|
6771
|
-
if (value.type !==
|
|
6772
|
-
const binding3 =
|
|
6948
|
+
if (value.type !== AST_NODE_TYPES41.Identifier || value.name !== "Object" && value.name !== "Reflect") return void 0;
|
|
6949
|
+
const binding3 = ASTUtils25.findVariable(sourceCode.getScope(value), value.name);
|
|
6773
6950
|
return binding3 === null || binding3.defs.length === 0 ? value.name : void 0;
|
|
6774
6951
|
}
|
|
6775
6952
|
function nativeGlobalReceiver(node, sourceCode) {
|
|
6776
|
-
if (node.type !==
|
|
6777
|
-
const binding3 =
|
|
6953
|
+
if (node.type !== AST_NODE_TYPES41.Identifier || !["globalThis", "window", "self"].includes(node.name)) return false;
|
|
6954
|
+
const binding3 = ASTUtils25.findVariable(sourceCode.getScope(node), node.name);
|
|
6778
6955
|
return binding3 === null || binding3.defs.length === 0;
|
|
6779
6956
|
}
|
|
6780
6957
|
function mutationWrites(node, namespace, method) {
|
|
6781
6958
|
if (namespace === "Object" && method === "assign") {
|
|
6782
6959
|
const source = node.arguments[1];
|
|
6783
|
-
return node.arguments.length === 2 && source?.type ===
|
|
6960
|
+
return node.arguments.length === 2 && source?.type === AST_NODE_TYPES41.ObjectExpression ? plainProperties(source) : void 0;
|
|
6784
6961
|
}
|
|
6785
6962
|
if (node.arguments.length !== 3 || method !== "set" && method !== "defineProperty") return void 0;
|
|
6786
6963
|
const key = staticString(node.arguments[1]);
|
|
6787
6964
|
const value = node.arguments[2];
|
|
6788
|
-
if (key === null || value === void 0 || value.type ===
|
|
6965
|
+
if (key === null || value === void 0 || value.type === AST_NODE_TYPES41.SpreadElement) return void 0;
|
|
6789
6966
|
if (method === "set") return [{ key, value }];
|
|
6790
|
-
if (value.type !==
|
|
6967
|
+
if (value.type !== AST_NODE_TYPES41.ObjectExpression) return void 0;
|
|
6791
6968
|
const properties = plainProperties(value);
|
|
6792
6969
|
if (properties === void 0 || properties.some((property) => !["value", "configurable", "enumerable", "writable"].includes(property.key))) return void 0;
|
|
6793
6970
|
const payload = properties.find((property) => property.key === "value");
|
|
@@ -6797,8 +6974,8 @@ function plainProperties(node) {
|
|
|
6797
6974
|
const writes = [];
|
|
6798
6975
|
const names = /* @__PURE__ */ new Set();
|
|
6799
6976
|
for (const property of node.properties) {
|
|
6800
|
-
if (property.type !==
|
|
6801
|
-
const key =
|
|
6977
|
+
if (property.type !== AST_NODE_TYPES41.Property || property.kind !== "init" || property.method) return void 0;
|
|
6978
|
+
const key = ASTUtils25.getPropertyName(property);
|
|
6802
6979
|
if (key === null || key === "__proto__" || names.has(key)) return void 0;
|
|
6803
6980
|
names.add(key);
|
|
6804
6981
|
writes.push({ key, value: property.value });
|
|
@@ -6807,7 +6984,7 @@ function plainProperties(node) {
|
|
|
6807
6984
|
}
|
|
6808
6985
|
|
|
6809
6986
|
// src/rules/no-contradictory-type-predicate.ts
|
|
6810
|
-
import { ASTUtils as
|
|
6987
|
+
import { ASTUtils as ASTUtils27, AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
6811
6988
|
import ts20 from "typescript";
|
|
6812
6989
|
|
|
6813
6990
|
// src/rules/_has-separate-predicate-contract.ts
|
|
@@ -6823,7 +7000,7 @@ function hasSeparatePredicateContract(node, checker) {
|
|
|
6823
7000
|
}
|
|
6824
7001
|
|
|
6825
7002
|
// src/rules/_contradictory-array-predicate.ts
|
|
6826
|
-
import { AST_NODE_TYPES as
|
|
7003
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ASTUtils as ASTUtils26 } from "@typescript-eslint/utils";
|
|
6827
7004
|
import ts19 from "typescript";
|
|
6828
7005
|
import { isTypeReference as isTypeReference2 } from "ts-api-utils";
|
|
6829
7006
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
@@ -6836,12 +7013,12 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6836
7013
|
function matches(expression, parameter, input, target) {
|
|
6837
7014
|
if ((input.flags & ts19.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
6838
7015
|
const call = unwrapExpression(expression);
|
|
6839
|
-
if (call.type !==
|
|
7016
|
+
if (call.type !== AST_NODE_TYPES42.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
6840
7017
|
const argument = call.arguments[0];
|
|
6841
7018
|
const callee = unwrapExpression(call.callee);
|
|
6842
|
-
if (argument?.type !==
|
|
6843
|
-
const declared =
|
|
6844
|
-
if (declared === null || declared !==
|
|
7019
|
+
if (argument?.type !== AST_NODE_TYPES42.Identifier || callee.type !== AST_NODE_TYPES42.MemberExpression || callee.optional || ASTUtils26.getPropertyName(callee) !== "isArray" || callee.object.type !== AST_NODE_TYPES42.Identifier || callee.object.name !== "Array") return false;
|
|
7020
|
+
const declared = ASTUtils26.findVariable(sourceCode.getScope(parameter), parameter.name);
|
|
7021
|
+
if (declared === null || declared !== ASTUtils26.findVariable(sourceCode.getScope(argument), argument.name)) return false;
|
|
6845
7022
|
const binding3 = nativeBinding(callee.object, sourceCode);
|
|
6846
7023
|
if (binding3 === void 0 || !stableArray(binding3, sourceCode, stable2)) return false;
|
|
6847
7024
|
const signature = checker.getResolvedSignature(services.esTreeNodeToTSNodeMap.get(call));
|
|
@@ -6851,7 +7028,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6851
7028
|
return {
|
|
6852
7029
|
matches,
|
|
6853
7030
|
observeConstructor(member3) {
|
|
6854
|
-
const name =
|
|
7031
|
+
const name = ASTUtils26.getPropertyName(member3, sourceCode.getScope(member3));
|
|
6855
7032
|
if (name === "constructor" || name === null && member3.computed) constructorCapability = true;
|
|
6856
7033
|
},
|
|
6857
7034
|
stable() {
|
|
@@ -6865,7 +7042,7 @@ function plainPrimitiveArray(target, checker) {
|
|
|
6865
7042
|
return element !== void 0 && (element.flags & PRIMITIVE_ELEMENTS) !== 0 && (element.flags & (ts19.TypeFlags.Enum | ts19.TypeFlags.EnumLiteral | ts19.TypeFlags.Intersection)) === 0;
|
|
6866
7043
|
}
|
|
6867
7044
|
function nativeBinding(identifier, sourceCode) {
|
|
6868
|
-
const binding3 =
|
|
7045
|
+
const binding3 = ASTUtils26.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6869
7046
|
return binding3 !== null && binding3.defs.length === 0 ? binding3 : void 0;
|
|
6870
7047
|
}
|
|
6871
7048
|
function stableArray(binding3, sourceCode, cache) {
|
|
@@ -6892,8 +7069,8 @@ function typeOnlyReference2(reference) {
|
|
|
6892
7069
|
}
|
|
6893
7070
|
function ordinaryObjectUse(node) {
|
|
6894
7071
|
const member3 = node.parent;
|
|
6895
|
-
if (member3?.type !==
|
|
6896
|
-
const name =
|
|
7072
|
+
if (member3?.type !== AST_NODE_TYPES42.MemberExpression || member3.object !== node) return false;
|
|
7073
|
+
const name = ASTUtils26.getPropertyName(member3);
|
|
6897
7074
|
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
6898
7075
|
}
|
|
6899
7076
|
function ordinaryArrayReference(reference) {
|
|
@@ -6903,17 +7080,17 @@ function ordinaryArrayReference(reference) {
|
|
|
6903
7080
|
}
|
|
6904
7081
|
function ordinaryArrayUse(node) {
|
|
6905
7082
|
const member3 = node.parent;
|
|
6906
|
-
if (member3?.type ===
|
|
6907
|
-
if (member3?.type !==
|
|
6908
|
-
return member3.parent.type ===
|
|
7083
|
+
if (member3?.type === AST_NODE_TYPES42.TSTypeQuery) return true;
|
|
7084
|
+
if (member3?.type !== AST_NODE_TYPES42.MemberExpression || member3.object !== node || member3.optional || ASTUtils26.getPropertyName(member3) !== "isArray") return false;
|
|
7085
|
+
return member3.parent.type === AST_NODE_TYPES42.CallExpression && member3.parent.callee === member3 && !member3.parent.optional;
|
|
6909
7086
|
}
|
|
6910
7087
|
function ordinaryHostReference(reference) {
|
|
6911
7088
|
if (reference.isWrite()) return false;
|
|
6912
7089
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6913
7090
|
let node = reference.identifier;
|
|
6914
|
-
while (node.parent?.type ===
|
|
7091
|
+
while (node.parent?.type === AST_NODE_TYPES42.MemberExpression && node.parent.object === node) {
|
|
6915
7092
|
const member3 = node.parent;
|
|
6916
|
-
const name =
|
|
7093
|
+
const name = ASTUtils26.getPropertyName(member3);
|
|
6917
7094
|
if (name === null) return false;
|
|
6918
7095
|
if (name === "Array") return ordinaryArrayUse(member3);
|
|
6919
7096
|
if (name === "Reflect") return false;
|
|
@@ -6999,10 +7176,10 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
6999
7176
|
const pendingArrays = [];
|
|
7000
7177
|
function inspect(node) {
|
|
7001
7178
|
const annotation = node.returnType?.typeAnnotation;
|
|
7002
|
-
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !==
|
|
7179
|
+
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !== AST_NODE_TYPES43.TSTypePredicate || annotation.asserts || annotation.parameterName.type !== AST_NODE_TYPES43.Identifier || annotation.typeAnnotation === void 0) return;
|
|
7003
7180
|
const name = annotation.parameterName.name;
|
|
7004
7181
|
if (hasSeparatePredicateContract(services.esTreeNodeToTSNodeMap.get(node), checker)) return;
|
|
7005
|
-
const parameter = node.params.find((candidate2) => candidate2.type ===
|
|
7182
|
+
const parameter = node.params.find((candidate2) => candidate2.type === AST_NODE_TYPES43.Identifier && candidate2.name === name);
|
|
7006
7183
|
const expression = singleReturn(node);
|
|
7007
7184
|
if (parameter?.typeAnnotation === void 0 || expression === void 0) return;
|
|
7008
7185
|
const check = typeofCheck(expression);
|
|
@@ -7047,13 +7224,13 @@ function shallowRecordCheck(expression, parameter, input, target, sourceCode, ch
|
|
|
7047
7224
|
const value = unwrapExpression(expression);
|
|
7048
7225
|
const direct = typeofCheck(value);
|
|
7049
7226
|
if (direct !== void 0) return direct.kind === "object" && sameParameter(parameter, direct.parameter, sourceCode);
|
|
7050
|
-
if (value.type !==
|
|
7227
|
+
if (value.type !== AST_NODE_TYPES43.LogicalExpression || value.operator !== "&&") return false;
|
|
7051
7228
|
for (const [left, right] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7052
7229
|
const check = typeofCheck(left);
|
|
7053
7230
|
const excluded = unwrapExpression(right);
|
|
7054
|
-
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !==
|
|
7231
|
+
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !== AST_NODE_TYPES43.BinaryExpression || excluded.operator !== "!==" && excluded.operator !== "!=") continue;
|
|
7055
7232
|
for (const [tested, sentinel] of [[excluded.left, excluded.right], [excluded.right, excluded.left]]) {
|
|
7056
|
-
if (tested.type ===
|
|
7233
|
+
if (tested.type === AST_NODE_TYPES43.Identifier && sentinel.type === AST_NODE_TYPES43.Literal && sentinel.value === null && sameParameter(parameter, tested, sourceCode)) return true;
|
|
7057
7234
|
}
|
|
7058
7235
|
}
|
|
7059
7236
|
return false;
|
|
@@ -7086,17 +7263,17 @@ function literalKind(type, checker) {
|
|
|
7086
7263
|
}
|
|
7087
7264
|
function singleReturn(node) {
|
|
7088
7265
|
if (node.body === void 0) return void 0;
|
|
7089
|
-
if (node.body.type !==
|
|
7266
|
+
if (node.body.type !== AST_NODE_TYPES43.BlockStatement) return node.body;
|
|
7090
7267
|
const statement = node.body.body[0];
|
|
7091
|
-
return node.body.body.length === 1 && statement?.type ===
|
|
7268
|
+
return node.body.body.length === 1 && statement?.type === AST_NODE_TYPES43.ReturnStatement && statement.argument !== null ? statement.argument : void 0;
|
|
7092
7269
|
}
|
|
7093
7270
|
function typeofCheck(expression) {
|
|
7094
7271
|
const value = unwrapExpression(expression);
|
|
7095
|
-
if (value.type !==
|
|
7272
|
+
if (value.type !== AST_NODE_TYPES43.BinaryExpression || value.operator !== "===" && value.operator !== "==") return void 0;
|
|
7096
7273
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7097
7274
|
const operand = unwrapExpression(tested);
|
|
7098
7275
|
const kind = staticString(expected);
|
|
7099
|
-
if (operand.type !==
|
|
7276
|
+
if (operand.type !== AST_NODE_TYPES43.UnaryExpression || operand.operator !== "typeof" || operand.argument.type !== AST_NODE_TYPES43.Identifier || kind === null || !isRuntimeKind(kind)) continue;
|
|
7100
7277
|
return { parameter: operand.argument, kind };
|
|
7101
7278
|
}
|
|
7102
7279
|
return void 0;
|
|
@@ -7105,8 +7282,8 @@ function isRuntimeKind(value) {
|
|
|
7105
7282
|
return RUNTIME_KINDS.has(value);
|
|
7106
7283
|
}
|
|
7107
7284
|
function sameParameter(declared, tested, sourceCode) {
|
|
7108
|
-
const parameter =
|
|
7109
|
-
return parameter !== null && parameter ===
|
|
7285
|
+
const parameter = ASTUtils27.findVariable(sourceCode.getScope(declared), declared.name);
|
|
7286
|
+
return parameter !== null && parameter === ASTUtils27.findVariable(sourceCode.getScope(tested), tested.name);
|
|
7110
7287
|
}
|
|
7111
7288
|
function inputKinds(type, checker) {
|
|
7112
7289
|
if ((type.flags & ts20.TypeFlags.Unknown) !== 0) return /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
@@ -7150,62 +7327,6 @@ import ts22 from "typescript";
|
|
|
7150
7327
|
// src/rules/_uuid-predicate-witness.ts
|
|
7151
7328
|
import { AST_NODE_TYPES as AST_NODE_TYPES44, ASTUtils as ASTUtils28 } from "@typescript-eslint/utils";
|
|
7152
7329
|
import ts21 from "typescript";
|
|
7153
|
-
|
|
7154
|
-
// src/rules/_native-runtime-unchanged.ts
|
|
7155
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES43, ASTUtils as ASTUtils27 } from "@typescript-eslint/utils";
|
|
7156
|
-
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
7157
|
-
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
7158
|
-
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
7159
|
-
const index = runtimeIndex(sourceCode);
|
|
7160
|
-
const cached = index.results.get(name);
|
|
7161
|
-
if (cached !== void 0) return cached;
|
|
7162
|
-
const changed = index.nodes.some((node) => node.type === AST_NODE_TYPES43.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === AST_NODE_TYPES43.Literal && "regex" in node) || index.references.some((node) => unsafeReference(node, sourceCode, name));
|
|
7163
|
-
index.results.set(name, !changed);
|
|
7164
|
-
return !changed;
|
|
7165
|
-
}
|
|
7166
|
-
function runtimeIndex(sourceCode) {
|
|
7167
|
-
const cached = INDEXES.get(sourceCode);
|
|
7168
|
-
if (cached !== void 0) return cached;
|
|
7169
|
-
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false).map((reference) => reference.identifier)) ?? [];
|
|
7170
|
-
const nodes = [];
|
|
7171
|
-
const pending = [sourceCode.ast];
|
|
7172
|
-
while (pending.length > 0) {
|
|
7173
|
-
const node = pending.pop();
|
|
7174
|
-
if (node === void 0) continue;
|
|
7175
|
-
nodes.push(node);
|
|
7176
|
-
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
7177
|
-
pending.push(child);
|
|
7178
|
-
});
|
|
7179
|
-
}
|
|
7180
|
-
const index = { references, nodes, results: /* @__PURE__ */ new Map() };
|
|
7181
|
-
INDEXES.set(sourceCode, index);
|
|
7182
|
-
return index;
|
|
7183
|
-
}
|
|
7184
|
-
function unsafeReference(node, sourceCode, name) {
|
|
7185
|
-
if (!ambient(node, sourceCode)) return false;
|
|
7186
|
-
if (node.name === "eval" || node.name === "Function") return true;
|
|
7187
|
-
if (node.name === name) return !nativeRead(node, name);
|
|
7188
|
-
if (!GLOBAL_OBJECTS2.has(node.name)) return false;
|
|
7189
|
-
const value = outerExpression(node);
|
|
7190
|
-
const property = value.parent;
|
|
7191
|
-
if (property?.type !== AST_NODE_TYPES43.MemberExpression || property.object !== value) return true;
|
|
7192
|
-
const key = staticPropertyName(property, sourceCode);
|
|
7193
|
-
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
7194
|
-
return key === name && !nativeRead(property, name);
|
|
7195
|
-
}
|
|
7196
|
-
function ambient(node, sourceCode) {
|
|
7197
|
-
const variable = ASTUtils27.findVariable(sourceCode.getScope(node), node.name);
|
|
7198
|
-
return variable === null || variable.defs.length === 0;
|
|
7199
|
-
}
|
|
7200
|
-
function nativeRead(node, name) {
|
|
7201
|
-
const value = outerExpression(node);
|
|
7202
|
-
const parent = value.parent;
|
|
7203
|
-
if (parent?.type === AST_NODE_TYPES43.UnaryExpression && parent.operator === "typeof") return true;
|
|
7204
|
-
if (name !== "Error") return false;
|
|
7205
|
-
return parent?.type === AST_NODE_TYPES43.NewExpression && parent.callee === value || parent?.type === AST_NODE_TYPES43.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
7206
|
-
}
|
|
7207
|
-
|
|
7208
|
-
// src/rules/_uuid-predicate-witness.ts
|
|
7209
7330
|
function uuidPredicateWitness(expression, parameter, sourceCode, services) {
|
|
7210
7331
|
const success = unwrapExpression(expression);
|
|
7211
7332
|
if (!member(success, "success")) return void 0;
|
|
@@ -11438,14 +11559,21 @@ function canAutofixNextConfigLiteral(sourceCode) {
|
|
|
11438
11559
|
// src/rules/no-dangerously-allow-svg.ts
|
|
11439
11560
|
var NEXT_CONFIG_RE = /(?:^|\/)next\.config\.[cm]?[jt]s$/;
|
|
11440
11561
|
var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
11441
|
-
summary: "
|
|
11442
|
-
rationale: "SVG
|
|
11443
|
-
remediation: "
|
|
11562
|
+
summary: "Require an explicit hardening policy for Next Image SVG delivery",
|
|
11563
|
+
rationale: "SVG can contain scripts and other active content. This organizational rule requires a recognized explicit script-blocking sandbox CSP when SVG delivery is enabled, with attachment disposition. It does not establish that framework defaults are missing or that a reported configuration is exploitable.",
|
|
11564
|
+
remediation: "Disable dangerouslyAllowSVG, or configure an explicit literal image contentSecurityPolicy such as `script-src 'none'; sandbox;` and keep attachment disposition. Verify effective headers and defaults against the application's pinned Next version.",
|
|
11444
11565
|
category: "security",
|
|
11445
11566
|
autofix: "safe",
|
|
11567
|
+
references: [
|
|
11568
|
+
"https://www.w3.org/TR/2026/WD-CSP3-20261027/#parse-serialized-policy",
|
|
11569
|
+
"https://github.com/vercel/next.js/blob/v16.4.3/packages/next/src/shared/lib/image-config.ts#L255"
|
|
11570
|
+
],
|
|
11446
11571
|
limitations: [
|
|
11447
11572
|
"Automatic boolean changes are withheld when the module contains explicit TypeScript or JSDoc contracts; those contracts can constrain an aliased property to literal true. Plain objects and as const inference remain fixable.",
|
|
11448
|
-
"
|
|
11573
|
+
"This rule does not resolve the installed Next version or evaluate effective response headers. The inspected Next 16.4.3 defaults already block scripts, apply sandbox, and use attachment disposition. A report for omitted explicit CSP is a policy finding, not proof of XSS.",
|
|
11574
|
+
"Omitted contentDispositionType is treated as attachment. Older or customized runtime defaults are not established by this source-only check.",
|
|
11575
|
+
"Only a bounded literal CSP subset is recognized: the first script-src must contain only 'none', and the first sandbox must have no tokens. Directive names and separators use CSP ASCII syntax. Valid policy lists, default-src fallbacks and other equivalent policies are not proved; omitted, dynamic or unrecognized explicit policies can still report. This is not a general CSP validator or proof of runtime security.",
|
|
11576
|
+
"Automatic fixes disable SVG opt-in to satisfy this policy; recognized hardened configurations are preserved. Only literal effective properties of a directly exported object, unescaped const alias, or isolated module.exports object are analyzed. Wrappers, factories, spreads, dynamic computed keys and mutations are not inferred."
|
|
11449
11577
|
],
|
|
11450
11578
|
examples: [
|
|
11451
11579
|
{
|
|
@@ -11459,7 +11587,7 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11459
11587
|
},
|
|
11460
11588
|
{
|
|
11461
11589
|
id: "svg-enabled",
|
|
11462
|
-
title: "
|
|
11590
|
+
title: "SVG opt-in requires explicit hardening under this policy",
|
|
11463
11591
|
outcome: "match",
|
|
11464
11592
|
files: [{ path: "next.config.mjs", source: "export default { images: { dangerouslyAllowSVG: true } };\n" }],
|
|
11465
11593
|
focusPath: "next.config.mjs",
|
|
@@ -11468,12 +11596,34 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11468
11596
|
},
|
|
11469
11597
|
{
|
|
11470
11598
|
id: "safe-autofix",
|
|
11471
|
-
title: "
|
|
11599
|
+
title: "Disable SVG delivery to satisfy this policy",
|
|
11472
11600
|
outcome: "match",
|
|
11473
11601
|
files: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: true } };" }],
|
|
11474
11602
|
fixedFiles: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: false } };" }],
|
|
11475
11603
|
focusPath: "next.config.ts",
|
|
11476
11604
|
expectedCount: 1
|
|
11605
|
+
},
|
|
11606
|
+
{
|
|
11607
|
+
id: "svg-explicit-hardening",
|
|
11608
|
+
scenarioId: "explicit-hardening",
|
|
11609
|
+
title: "Allow SVG delivery with explicit hardening",
|
|
11610
|
+
outcome: "no-match",
|
|
11611
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'none'; sandbox;" } };
|
|
11612
|
+
` }],
|
|
11613
|
+
focusPath: "next.config.mjs",
|
|
11614
|
+
expectedCount: 0,
|
|
11615
|
+
public: true
|
|
11616
|
+
},
|
|
11617
|
+
{
|
|
11618
|
+
id: "svg-unsafe-first-directive",
|
|
11619
|
+
scenarioId: "explicit-hardening",
|
|
11620
|
+
title: "A later duplicate cannot replace the effective policy",
|
|
11621
|
+
outcome: "match",
|
|
11622
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'unsafe-inline'; script-src 'none'; sandbox;" } };
|
|
11623
|
+
` }],
|
|
11624
|
+
focusPath: "next.config.mjs",
|
|
11625
|
+
expectedCount: 1,
|
|
11626
|
+
public: true
|
|
11477
11627
|
}
|
|
11478
11628
|
]
|
|
11479
11629
|
};
|
|
@@ -11483,12 +11633,16 @@ function literalString2(node) {
|
|
|
11483
11633
|
return null;
|
|
11484
11634
|
}
|
|
11485
11635
|
function hasHardenedSvgPolicy(policy) {
|
|
11486
|
-
const directives =
|
|
11487
|
-
const
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11636
|
+
const directives = /* @__PURE__ */ new Map();
|
|
11637
|
+
for (const part of policy.split(";")) {
|
|
11638
|
+
const [name, ...values] = part.split(/[\t\n\f\r ]+/u).filter(Boolean);
|
|
11639
|
+
if (name === void 0 || !/^[A-Za-z0-9-]+$/u.test(name)) continue;
|
|
11640
|
+
const key = name.toLowerCase();
|
|
11641
|
+
if (!directives.has(key)) directives.set(key, values);
|
|
11642
|
+
}
|
|
11643
|
+
const scriptSource = directives.get("script-src");
|
|
11644
|
+
const sandbox = directives.get("sandbox");
|
|
11645
|
+
return scriptSource?.length === 1 && scriptSource[0]?.toLowerCase() === "'none'" && sandbox?.length === 0;
|
|
11492
11646
|
}
|
|
11493
11647
|
var no_dangerously_allow_svg_default = createRule({
|
|
11494
11648
|
name: "no-dangerously-allow-svg",
|
|
@@ -11499,7 +11653,7 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
11499
11653
|
docs: { description: NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION.summary },
|
|
11500
11654
|
schema: [],
|
|
11501
11655
|
messages: {
|
|
11502
|
-
noDangerouslyAllowSvg: "
|
|
11656
|
+
noDangerouslyAllowSvg: "SVG opt-in requires a recognized explicit script-blocking sandbox CSP and attachment disposition under this policy."
|
|
11503
11657
|
}
|
|
11504
11658
|
},
|
|
11505
11659
|
defaultOptions: [],
|
|
@@ -17836,7 +17990,7 @@ var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
|
17836
17990
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
17837
17991
|
remediation: "Move the request into a client module and call that abstraction from application code.",
|
|
17838
17992
|
category: "architecture",
|
|
17839
|
-
limitations: ["Tests, client-layer paths, constructed handoffs, and pre-signed URL transfers are excluded. Configure the same literal Next.js basePath here and on prefer-server-actions so one rule owns each internal mutation.", "Effect and pre-signed-transfer exemptions use recognized syntax and naming conventions, not complete React or URL provenance. Those conservative exclusions are recall limitations, not evidence that every excluded request satisfies transport policy."],
|
|
17993
|
+
limitations: ["Tests, client-layer paths, constructed handoffs, and pre-signed URL transfers are excluded. Configure the same literal Next.js basePath here and on prefer-server-actions so one rule owns each internal mutation.", "Effect and pre-signed-transfer exemptions use recognized syntax and naming conventions, not complete React or URL provenance. Those conservative exclusions are recall limitations, not evidence that every excluded request satisfies transport policy.", "Unshadowed native members and bounded stable const aliases or single-property destructuring are recognized. Visible writes, callable escapes, whole-global escapes and mutation capabilities anywhere in the file invalidate that proof, including earlier captures. Known unrelated global member writes and typeof global checks do not. Static constructor members and destructuring projections invalidate the proof; indirect reflection, external monkeypatches and arbitrary forwarding functions are not inferred."],
|
|
17840
17994
|
examples: [
|
|
17841
17995
|
{ id: "client-call", title: "Use a client abstraction", outcome: "no-match", files: [{ path: "src/routes/handler.ts", source: "const response = await billingClient.getInvoice(id);" }], focusPath: "src/routes/handler.ts", expectedCount: 0, public: true },
|
|
17842
17996
|
{ id: "raw-fetch", title: "Do not call global fetch here", outcome: "match", files: [{ path: "src/routes/handler.ts", source: "const response = await fetch('/api/invoices');" }], focusPath: "src/routes/handler.ts", expectedCount: 1, public: true }
|
|
@@ -17857,11 +18011,6 @@ var DEFAULT_ALLOW = [
|
|
|
17857
18011
|
"[\\\\/][^\\\\/]*(?:Client|client)\\.[cm]?[jt]sx?$"
|
|
17858
18012
|
];
|
|
17859
18013
|
var NON_PRODUCTION_TREE_RE = /[\\/](playwright|cypress|__testfixtures__)[\\/]/;
|
|
17860
|
-
var GLOBAL_RECEIVERS3 = /* @__PURE__ */ new Set([
|
|
17861
|
-
"globalThis",
|
|
17862
|
-
"window",
|
|
17863
|
-
"self"
|
|
17864
|
-
]);
|
|
17865
18014
|
var PRESIGNED_URL_NAME_RE = /(?:pre-?signed|signed|upload|download)Url$/i;
|
|
17866
18015
|
var INTERNAL_MUTATION_METHODS = /* @__PURE__ */ new Set([
|
|
17867
18016
|
"POST",
|
|
@@ -17885,23 +18034,13 @@ var BASE_PATH_RE = /^\/(?!$)(?!.*[?#])(?:[^/]+\/)*[^/]+$/u;
|
|
|
17885
18034
|
function isValidBasePath(basePath) {
|
|
17886
18035
|
return BASE_PATH_RE.test(basePath) && !basePath.split("/").some((segment) => segment === "." || segment === "..");
|
|
17887
18036
|
}
|
|
17888
|
-
function isGlobalFetchCall(node, resolvesToGlobal) {
|
|
17889
|
-
const callee = unwrapExpression(node.callee);
|
|
17890
|
-
if (callee.type === "Identifier") {
|
|
17891
|
-
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
17892
|
-
}
|
|
17893
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "fetch" && callee.object.type === "Identifier") {
|
|
17894
|
-
return GLOBAL_RECEIVERS3.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
17895
|
-
}
|
|
17896
|
-
return false;
|
|
17897
|
-
}
|
|
17898
18037
|
function isConstructedArgumentHandoff(node, resolvesToGlobal) {
|
|
17899
18038
|
const [first] = node.arguments;
|
|
17900
18039
|
return node.arguments.length === 1 && first !== void 0 && first.type === AST_NODE_TYPES98.NewExpression && first.callee.type === AST_NODE_TYPES98.Identifier && (first.callee.name === "URL" || first.callee.name === "Request") && resolvesToGlobal(first.callee);
|
|
17901
18040
|
}
|
|
17902
18041
|
function effectOwns(node) {
|
|
17903
18042
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17904
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES98.Identifier) return false;
|
|
18043
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES98.Identifier || unwrappedNodeCallee.name !== "fetch") return false;
|
|
17905
18044
|
const method = readDirectMethod(node);
|
|
17906
18045
|
if (method !== null && method !== "GET") return false;
|
|
17907
18046
|
const first = node.arguments[0];
|
|
@@ -18038,7 +18177,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18038
18177
|
}
|
|
18039
18178
|
function serverActionOwns(node) {
|
|
18040
18179
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
18041
|
-
if (unwrappedNodeCallee.type !== AST_NODE_TYPES98.Identifier || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
18180
|
+
if (unwrappedNodeCallee.type !== AST_NODE_TYPES98.Identifier || unwrappedNodeCallee.name !== "fetch" || !resolvesToGlobal(unwrappedNodeCallee) || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
18042
18181
|
return false;
|
|
18043
18182
|
}
|
|
18044
18183
|
const url = node.arguments[0];
|
|
@@ -18095,7 +18234,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18095
18234
|
}
|
|
18096
18235
|
return {
|
|
18097
18236
|
CallExpression(node) {
|
|
18098
|
-
if (!
|
|
18237
|
+
if (!nativeFetchReference(unwrapExpression(node.callee), context.sourceCode)) {
|
|
18099
18238
|
return;
|
|
18100
18239
|
}
|
|
18101
18240
|
if (isPresignedUrlTransfer(node) || isConstructedArgumentHandoff(node, resolvesToGlobal) || effectOwns(node) || serverActionOwns(node)) {
|
|
@@ -32785,6 +32924,7 @@ var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
|
32785
32924
|
limitations: [
|
|
32786
32925
|
"Signal presence establishes an explicit cancellation path, not a guaranteed timeout. Literal null, global undefined, and void 0 do not provide a signal. Erased TypeScript wrappers preserve the same analysis. Unknown spreads and dynamic values are not inferred. Forwarded Request objects retain their signal unless an init explicitly resets it to null.",
|
|
32787
32926
|
"Unshadowed native fetch members and bounded stable const aliases or destructuring are recognized. Reassigned, defaulted and unknown aliases and arbitrary forwarding functions are excluded.",
|
|
32927
|
+
"Visible writes, callable escapes, whole-global escapes and mutation capabilities anywhere in the file invalidate native fetch identity, including earlier captures. Known unrelated global member writes and typeof global checks do not. Static constructor members and destructuring projections invalidate the proof; indirect reflection and external monkeypatches are not inferred.",
|
|
32788
32928
|
"Accessors and unproved prototypes are excluded because native option conversion can attach or replace a signal before it is read."
|
|
32789
32929
|
],
|
|
32790
32930
|
examples: [
|
|
@@ -32831,7 +32971,7 @@ function emptySignal(expression, resolvesToGlobal) {
|
|
|
32831
32971
|
}
|
|
32832
32972
|
return null;
|
|
32833
32973
|
}
|
|
32834
|
-
function initSignalState(init, resolvesToGlobal) {
|
|
32974
|
+
function initSignalState(init, resolvesToGlobal, sourceCode) {
|
|
32835
32975
|
init = unwrapExpression(init);
|
|
32836
32976
|
if (init.type !== AST_NODE_TYPES159.ObjectExpression) return "unknown";
|
|
32837
32977
|
let state = "absent";
|
|
@@ -32841,12 +32981,12 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
32841
32981
|
continue;
|
|
32842
32982
|
}
|
|
32843
32983
|
if (prop.kind !== "init" || hasUnprovedPrototype(prop)) return "unknown";
|
|
32844
|
-
const
|
|
32845
|
-
if (
|
|
32984
|
+
const name = staticPropertyName(prop, sourceCode);
|
|
32985
|
+
if (name === "signal") {
|
|
32846
32986
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
32847
|
-
} else if (!prop.computed &&
|
|
32987
|
+
} else if (!prop.computed && name === "__proto__" && state === "absent") {
|
|
32848
32988
|
state = "unknown";
|
|
32849
|
-
} else if (prop.computed &&
|
|
32989
|
+
} else if (prop.computed && name === null) {
|
|
32850
32990
|
state = "unknown";
|
|
32851
32991
|
}
|
|
32852
32992
|
}
|
|
@@ -32924,7 +33064,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32924
33064
|
return "unknown";
|
|
32925
33065
|
}
|
|
32926
33066
|
}
|
|
32927
|
-
return initSignalState(definition.node.init, resolvesToGlobal);
|
|
33067
|
+
return initSignalState(definition.node.init, resolvesToGlobal, context.sourceCode);
|
|
32928
33068
|
}
|
|
32929
33069
|
function isForwardedRequest(argument) {
|
|
32930
33070
|
let value = unwrapExpression(argument);
|
|
@@ -32952,7 +33092,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32952
33092
|
}
|
|
32953
33093
|
const [first, rawInit] = node.arguments;
|
|
32954
33094
|
const init = rawInit === void 0 ? void 0 : unwrapExpression(rawInit);
|
|
32955
|
-
const state = init === void 0 ? "unknown" : init.type === AST_NODE_TYPES159.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal);
|
|
33095
|
+
const state = init === void 0 ? "unknown" : init.type === AST_NODE_TYPES159.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal, context.sourceCode);
|
|
32956
33096
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first) && state !== "null")) {
|
|
32957
33097
|
return;
|
|
32958
33098
|
}
|