@sarj/eslint-plugin 16.36.6 → 16.38.50
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 +908 -761
- package/dist/index.js +902 -755
- package/dist/rule-examples.cjs +168 -44
- package/dist/rule-examples.js +168 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -678,41 +678,230 @@ var no_mutating_input_with_result_default = createRule({
|
|
|
678
678
|
});
|
|
679
679
|
|
|
680
680
|
// src/rules/no-negative-only-http-status-assertion.ts
|
|
681
|
-
var
|
|
681
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
682
682
|
|
|
683
683
|
// src/rules/_native-fetch-reference.ts
|
|
684
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
685
|
+
|
|
686
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
687
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
688
|
+
|
|
689
|
+
// src/rules/_stable-value-binding.ts
|
|
684
690
|
var import_utils5 = require("@typescript-eslint/utils");
|
|
691
|
+
function typeOnlyReference(reference) {
|
|
692
|
+
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
693
|
+
let current = outerExpression(reference.identifier);
|
|
694
|
+
while (current.parent?.type === import_utils5.AST_NODE_TYPES.TSQualifiedName && current.parent.left === current) {
|
|
695
|
+
current = current.parent;
|
|
696
|
+
}
|
|
697
|
+
return current.parent?.type === import_utils5.AST_NODE_TYPES.TSTypeQuery && current.parent.exprName === current;
|
|
698
|
+
}
|
|
699
|
+
function stableValueBinding(variable, acceptRead) {
|
|
700
|
+
let initializer;
|
|
701
|
+
return variable.references.every((reference) => {
|
|
702
|
+
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
703
|
+
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
704
|
+
initializer = reference.identifier;
|
|
705
|
+
return true;
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/rules/_static-string.ts
|
|
710
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
711
|
+
function staticString(node) {
|
|
712
|
+
if (node === void 0) return null;
|
|
713
|
+
const value = unwrapExpression(node);
|
|
714
|
+
if (value.type === import_utils6.AST_NODE_TYPES.Literal && typeof value.value === "string") return value.value;
|
|
715
|
+
return value.type === import_utils6.AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
716
|
+
}
|
|
717
|
+
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
718
|
+
function scopedStaticString(node, sourceCode) {
|
|
719
|
+
let value = unwrapExpression(node);
|
|
720
|
+
if (value.type !== import_utils6.AST_NODE_TYPES.Identifier) return staticString(value);
|
|
721
|
+
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
722
|
+
if (values === void 0) {
|
|
723
|
+
values = /* @__PURE__ */ new WeakMap();
|
|
724
|
+
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
725
|
+
}
|
|
726
|
+
const seen = /* @__PURE__ */ new Set();
|
|
727
|
+
const pending = [];
|
|
728
|
+
let result = null;
|
|
729
|
+
while (value.type === import_utils6.AST_NODE_TYPES.Identifier) {
|
|
730
|
+
const binding3 = import_utils6.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
731
|
+
if (binding3 === null || seen.has(binding3)) break;
|
|
732
|
+
if (values.has(binding3)) {
|
|
733
|
+
result = values.get(binding3) ?? null;
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
seen.add(binding3);
|
|
737
|
+
pending.push(binding3);
|
|
738
|
+
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
739
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== import_utils6.AST_NODE_TYPES.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
740
|
+
value = unwrapExpression(definition.node.init);
|
|
741
|
+
if (value.type !== import_utils6.AST_NODE_TYPES.Identifier) result = staticString(value);
|
|
742
|
+
}
|
|
743
|
+
for (const binding3 of pending) values.set(binding3, result);
|
|
744
|
+
return result;
|
|
745
|
+
}
|
|
746
|
+
function staticPropertyName(node, sourceCode) {
|
|
747
|
+
const direct = import_utils6.ASTUtils.getPropertyName(node);
|
|
748
|
+
if (direct !== null || !node.computed) return direct;
|
|
749
|
+
const key = node.type === import_utils6.AST_NODE_TYPES.MemberExpression ? node.property : node.key;
|
|
750
|
+
return scopedStaticString(key, sourceCode);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
754
|
+
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
755
|
+
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
756
|
+
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
757
|
+
const index = runtimeIndex(sourceCode);
|
|
758
|
+
const cached = index.results.get(name);
|
|
759
|
+
if (cached !== void 0) return cached;
|
|
760
|
+
const changed = index.nodes.some((node) => node.type === import_utils7.AST_NODE_TYPES.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "fetch" && node.type === import_utils7.AST_NODE_TYPES.Property && node.parent.type === import_utils7.AST_NODE_TYPES.ObjectPattern && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === import_utils7.AST_NODE_TYPES.Literal && "regex" in node) || index.references.some((reference) => (name !== "fetch" || !typeOnlyReference(reference)) && unsafeReference(reference.identifier, sourceCode, name, index));
|
|
761
|
+
index.results.set(name, !changed);
|
|
762
|
+
return !changed;
|
|
763
|
+
}
|
|
764
|
+
function runtimeIndex(sourceCode) {
|
|
765
|
+
const cached = INDEXES.get(sourceCode);
|
|
766
|
+
if (cached !== void 0) return cached;
|
|
767
|
+
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false)) ?? [];
|
|
768
|
+
const nodes = [];
|
|
769
|
+
const pending = [sourceCode.ast];
|
|
770
|
+
while (pending.length > 0) {
|
|
771
|
+
const node = pending.pop();
|
|
772
|
+
if (node === void 0) continue;
|
|
773
|
+
nodes.push(node);
|
|
774
|
+
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
775
|
+
pending.push(child);
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
const index = { references, nodes, results: /* @__PURE__ */ new Map(), fetchAliases: /* @__PURE__ */ new Map() };
|
|
779
|
+
INDEXES.set(sourceCode, index);
|
|
780
|
+
return index;
|
|
781
|
+
}
|
|
782
|
+
function unsafeReference(node, sourceCode, name, index) {
|
|
783
|
+
if (!ambient(node, sourceCode)) return false;
|
|
784
|
+
if (node.name === "eval" || node.name === "Function") return true;
|
|
785
|
+
if (node.name === name) return name === "fetch" ? !fetchRead(node, sourceCode, index) : !nativeRead(node, name);
|
|
786
|
+
if (!GLOBAL_OBJECTS.has(node.name)) return false;
|
|
787
|
+
const value = outerExpression(node);
|
|
788
|
+
const property = value.parent;
|
|
789
|
+
if (name === "fetch" && property?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && property.operator === "typeof") return false;
|
|
790
|
+
if (property?.type !== import_utils7.AST_NODE_TYPES.MemberExpression || property.object !== value) {
|
|
791
|
+
return name !== "fetch" || !fetchProjection(value, sourceCode, index);
|
|
792
|
+
}
|
|
793
|
+
const key = staticPropertyName(property, sourceCode);
|
|
794
|
+
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
795
|
+
if (name === "fetch" && GLOBAL_OBJECTS.has(key)) return true;
|
|
796
|
+
return key === name && !(name === "fetch" ? fetchRead(property, sourceCode, index) : nativeRead(property, name));
|
|
797
|
+
}
|
|
798
|
+
function ambient(node, sourceCode) {
|
|
799
|
+
const variable = import_utils7.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
800
|
+
return variable === null || variable.defs.length === 0;
|
|
801
|
+
}
|
|
802
|
+
function fetchUse(node, sourceCode) {
|
|
803
|
+
const value = outerExpression(node);
|
|
804
|
+
const parent = value.parent;
|
|
805
|
+
if (parent?.type === import_utils7.AST_NODE_TYPES.CallExpression && parent.callee === value || parent?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
806
|
+
if (parent?.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator || parent.init !== value || parent.id.type !== import_utils7.AST_NODE_TYPES.Identifier) return false;
|
|
807
|
+
return stableConstBinding(parent.id, sourceCode) ?? false;
|
|
808
|
+
}
|
|
809
|
+
function stableConstBinding(node, sourceCode) {
|
|
810
|
+
const binding3 = import_utils7.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
811
|
+
if (binding3 === null || binding3.defs.length !== 1) return null;
|
|
812
|
+
const [definition] = binding3.defs;
|
|
813
|
+
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && definition.parent.parent.type !== import_utils7.AST_NODE_TYPES.ExportNamedDeclaration && !binding3.references.some((reference) => reference.isWrite() && reference.init !== true) ? binding3 : null;
|
|
814
|
+
}
|
|
815
|
+
function fetchRead(node, sourceCode, index) {
|
|
816
|
+
const use = fetchUse(node, sourceCode);
|
|
817
|
+
return use === true || use !== false && fetchAliasRead(use, sourceCode, index);
|
|
818
|
+
}
|
|
819
|
+
function fetchAliasRead(binding3, sourceCode, index) {
|
|
820
|
+
const pending = [binding3];
|
|
821
|
+
const visited = [];
|
|
822
|
+
let safe = true;
|
|
823
|
+
while (pending.length > 0 && safe) {
|
|
824
|
+
const current = pending.pop();
|
|
825
|
+
if (current === void 0) continue;
|
|
826
|
+
const cached = index.fetchAliases.get(current);
|
|
827
|
+
if (cached === "safe") continue;
|
|
828
|
+
if (cached !== void 0) {
|
|
829
|
+
safe = false;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
index.fetchAliases.set(current, "visiting");
|
|
833
|
+
visited.push(current);
|
|
834
|
+
const captures = fetchAliasCaptures(current, sourceCode);
|
|
835
|
+
if (captures === false) {
|
|
836
|
+
safe = false;
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
for (const captured of captures) pending.push(captured);
|
|
840
|
+
}
|
|
841
|
+
for (const current of visited) index.fetchAliases.set(current, safe ? "safe" : "unsafe");
|
|
842
|
+
return safe;
|
|
843
|
+
}
|
|
844
|
+
function fetchAliasCaptures(binding3, sourceCode) {
|
|
845
|
+
const captures = [];
|
|
846
|
+
for (const reference of binding3.references) {
|
|
847
|
+
if (reference.isValueReference === false || reference.init === true || typeOnlyReference(reference)) continue;
|
|
848
|
+
const use = fetchUse(reference.identifier, sourceCode);
|
|
849
|
+
if (use === false) return false;
|
|
850
|
+
if (use !== true) captures.push(use);
|
|
851
|
+
}
|
|
852
|
+
return captures;
|
|
853
|
+
}
|
|
854
|
+
function fetchProjection(node, sourceCode, index) {
|
|
855
|
+
const declaration = node.parent;
|
|
856
|
+
if (declaration?.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils7.AST_NODE_TYPES.ObjectPattern || declaration.id.properties.length !== 1) return false;
|
|
857
|
+
const [property] = declaration.id.properties;
|
|
858
|
+
if (property?.type !== import_utils7.AST_NODE_TYPES.Property || staticPropertyName(property, sourceCode) !== "fetch" || property.value.type !== import_utils7.AST_NODE_TYPES.Identifier) return false;
|
|
859
|
+
const binding3 = stableConstBinding(property.value, sourceCode);
|
|
860
|
+
return binding3 !== null && fetchAliasRead(binding3, sourceCode, index);
|
|
861
|
+
}
|
|
862
|
+
function nativeRead(node, name) {
|
|
863
|
+
const value = outerExpression(node);
|
|
864
|
+
const parent = value.parent;
|
|
865
|
+
if (parent?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
866
|
+
if (name !== "Error") return false;
|
|
867
|
+
return parent?.type === import_utils7.AST_NODE_TYPES.NewExpression && parent.callee === value || parent?.type === import_utils7.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/rules/_native-fetch-reference.ts
|
|
685
871
|
var GLOBAL_RECEIVERS = /* @__PURE__ */ new Set(["globalThis", "self", "window"]);
|
|
686
|
-
function nativeFetchReference(node, sourceCode
|
|
872
|
+
function nativeFetchReference(node, sourceCode) {
|
|
873
|
+
return lexicalFetchReference(node, sourceCode) && nativeRuntimeUnchanged(sourceCode, "fetch");
|
|
874
|
+
}
|
|
875
|
+
function lexicalFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
687
876
|
const expression = unwrapExpression(node);
|
|
688
|
-
if (expression.type ===
|
|
689
|
-
return
|
|
877
|
+
if (expression.type === import_utils8.AST_NODE_TYPES.MemberExpression) {
|
|
878
|
+
return staticPropertyName(expression, sourceCode) === "fetch" && globalReceiver(expression.object, sourceCode);
|
|
690
879
|
}
|
|
691
|
-
if (expression.type !==
|
|
692
|
-
const binding3 =
|
|
880
|
+
if (expression.type !== import_utils8.AST_NODE_TYPES.Identifier) return false;
|
|
881
|
+
const binding3 = import_utils8.ASTUtils.findVariable(sourceCode.getScope(expression), expression.name);
|
|
693
882
|
if (binding3 === null || binding3.defs.length === 0) return expression.name === "fetch";
|
|
694
883
|
if (seen.has(binding3) || seen.size >= 8 || binding3.defs.length !== 1 || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
695
884
|
seen.add(binding3);
|
|
696
885
|
const [definition] = binding3.defs;
|
|
697
886
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null) return false;
|
|
698
|
-
if (definition.node.id.type ===
|
|
699
|
-
return
|
|
887
|
+
if (definition.node.id.type === import_utils8.AST_NODE_TYPES.Identifier) {
|
|
888
|
+
return lexicalFetchReference(definition.node.init, sourceCode, seen);
|
|
700
889
|
}
|
|
701
|
-
return definition.node.id.type ===
|
|
890
|
+
return definition.node.id.type === import_utils8.AST_NODE_TYPES.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === import_utils8.AST_NODE_TYPES.Property && staticPropertyName(property, sourceCode) === "fetch" && property.value.type === import_utils8.AST_NODE_TYPES.Identifier && import_utils8.ASTUtils.findVariable(sourceCode.getScope(property.value), property.value.name) === binding3);
|
|
702
891
|
}
|
|
703
892
|
function globalReceiver(node, sourceCode) {
|
|
704
893
|
const receiver = unwrapExpression(node);
|
|
705
|
-
return receiver.type ===
|
|
894
|
+
return receiver.type === import_utils8.AST_NODE_TYPES.Identifier && GLOBAL_RECEIVERS.has(receiver.name) && !import_utils8.ASTUtils.findVariable(sourceCode.getScope(receiver), receiver.name)?.defs.length;
|
|
706
895
|
}
|
|
707
896
|
|
|
708
897
|
// src/rules/_test-mock-provenance.ts
|
|
709
|
-
var
|
|
898
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
710
899
|
function importedTestMockNamespace(source, identifier) {
|
|
711
|
-
const binding3 =
|
|
900
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
712
901
|
const importedBinding = runtimeImportBinding(binding3);
|
|
713
|
-
if (importedBinding === null || importedBinding.specifier.type !==
|
|
902
|
+
if (importedBinding === null || importedBinding.specifier.type !== import_utils9.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
714
903
|
const specifier = importedBinding.specifier;
|
|
715
|
-
const imported = specifier.imported.type ===
|
|
904
|
+
const imported = specifier.imported.type === import_utils9.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
716
905
|
const module2 = importedBinding.module;
|
|
717
906
|
if (module2 === "vitest" && (imported === "vi" || imported === "vitest")) return "vitest";
|
|
718
907
|
if (module2 === "@jest/globals" && imported === "jest") return "jest";
|
|
@@ -720,12 +909,12 @@ function importedTestMockNamespace(source, identifier) {
|
|
|
720
909
|
}
|
|
721
910
|
function isUnshadowedTestMockGlobal(source, identifier) {
|
|
722
911
|
if (identifier.name !== "vi" && identifier.name !== "jest") return false;
|
|
723
|
-
const binding3 =
|
|
912
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
724
913
|
return binding3 === null || binding3.defs.length === 0 && !binding3.references.some((reference) => reference.isWrite());
|
|
725
914
|
}
|
|
726
915
|
var TEST_FRAMEWORK_MODULES = /* @__PURE__ */ new Set(["@jest/globals", "@playwright/test", "bun:test", "node:test", "vitest"]);
|
|
727
916
|
function runtimeTestFrameworkName(source, identifier, kind) {
|
|
728
|
-
const binding3 =
|
|
917
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
729
918
|
if (binding3 === null || binding3.defs.length === 0) {
|
|
730
919
|
return binding3?.references.some((reference) => reference.isWrite()) ? null : identifier.name;
|
|
731
920
|
}
|
|
@@ -733,22 +922,22 @@ function runtimeTestFrameworkName(source, identifier, kind) {
|
|
|
733
922
|
if (importedBinding === null) return null;
|
|
734
923
|
const { specifier, module: module2 } = importedBinding;
|
|
735
924
|
const isNodeAssertion = kind === "assertion" && (module2 === "node:assert" || module2 === "node:assert/strict");
|
|
736
|
-
if (specifier.type ===
|
|
925
|
+
if (specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier) {
|
|
737
926
|
if (isNodeAssertion) return "assert";
|
|
738
927
|
if (!TEST_FRAMEWORK_MODULES.has(module2)) return null;
|
|
739
|
-
const imported = specifier.imported.type ===
|
|
928
|
+
const imported = specifier.imported.type === import_utils9.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
740
929
|
return imported;
|
|
741
930
|
}
|
|
742
931
|
if (isNodeAssertion) return "assert";
|
|
743
|
-
return kind === "test" && module2 === "node:test" && specifier.type ===
|
|
932
|
+
return kind === "test" && module2 === "node:test" && specifier.type === import_utils9.AST_NODE_TYPES.ImportDefaultSpecifier ? "test" : null;
|
|
744
933
|
}
|
|
745
934
|
function runtimeImportBinding(binding3) {
|
|
746
935
|
if (binding3?.defs.length !== 1) return null;
|
|
747
936
|
const definition = binding3.defs[0];
|
|
748
|
-
if (definition?.type !== "ImportBinding" || definition.parent.type !==
|
|
937
|
+
if (definition?.type !== "ImportBinding" || definition.parent.type !== import_utils9.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type") return null;
|
|
749
938
|
const specifier = definition.node;
|
|
750
|
-
if (specifier.type !==
|
|
751
|
-
if (specifier.type ===
|
|
939
|
+
if (specifier.type !== import_utils9.AST_NODE_TYPES.ImportSpecifier && specifier.type !== import_utils9.AST_NODE_TYPES.ImportDefaultSpecifier && specifier.type !== import_utils9.AST_NODE_TYPES.ImportNamespaceSpecifier) return null;
|
|
940
|
+
if (specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") return null;
|
|
752
941
|
return { module: definition.parent.source.value, specifier };
|
|
753
942
|
}
|
|
754
943
|
function vitestFixtureTestName(source, identifier) {
|
|
@@ -756,24 +945,24 @@ function vitestFixtureTestName(source, identifier) {
|
|
|
756
945
|
}
|
|
757
946
|
function fixtureTestName(node, source, seen) {
|
|
758
947
|
node = unwrapExpression(node);
|
|
759
|
-
if (node.type ===
|
|
948
|
+
if (node.type === import_utils9.AST_NODE_TYPES.CallExpression) {
|
|
760
949
|
const callee = unwrapExpression(node.callee);
|
|
761
|
-
return !node.optional && callee.type ===
|
|
950
|
+
return !node.optional && callee.type === import_utils9.AST_NODE_TYPES.MemberExpression && !callee.optional && import_utils9.ASTUtils.getPropertyName(callee) === "extend" && node.arguments.length > 0 && !node.arguments.some((argument) => argument.type === import_utils9.AST_NODE_TYPES.SpreadElement) ? fixtureTestName(callee.object, source, seen) : null;
|
|
762
951
|
}
|
|
763
|
-
if (node.type !==
|
|
764
|
-
const binding3 =
|
|
952
|
+
if (node.type !== import_utils9.AST_NODE_TYPES.Identifier) return null;
|
|
953
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
765
954
|
if (binding3 === null || seen.has(binding3) || !unchangedFixtureApi(binding3)) return null;
|
|
766
955
|
seen.add(binding3);
|
|
767
956
|
const imported = runtimeImportBinding(binding3);
|
|
768
|
-
if (imported?.module === "vitest" && imported.specifier.type ===
|
|
957
|
+
if (imported?.module === "vitest" && imported.specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier) {
|
|
769
958
|
const name = imported.specifier.imported;
|
|
770
|
-
const value = name.type ===
|
|
959
|
+
const value = name.type === import_utils9.AST_NODE_TYPES.Identifier ? name.name : name.value;
|
|
771
960
|
return value === "test" || value === "it" ? value : null;
|
|
772
961
|
}
|
|
773
962
|
const definition = binding3.defs[0];
|
|
774
|
-
if (binding3.defs.length !== 1 || definition?.node.type !==
|
|
963
|
+
if (binding3.defs.length !== 1 || definition?.node.type !== import_utils9.AST_NODE_TYPES.VariableDeclarator || definition.node.id.type !== import_utils9.AST_NODE_TYPES.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0]) return null;
|
|
775
964
|
const initializer = unwrapExpression(definition.node.init);
|
|
776
|
-
return initializer.type ===
|
|
965
|
+
return initializer.type === import_utils9.AST_NODE_TYPES.CallExpression ? fixtureTestName(initializer, source, seen) : null;
|
|
777
966
|
}
|
|
778
967
|
var FIXTURE_API_STABILITY = /* @__PURE__ */ new WeakMap();
|
|
779
968
|
function unchangedFixtureApi(binding3) {
|
|
@@ -783,9 +972,9 @@ function unchangedFixtureApi(binding3) {
|
|
|
783
972
|
if (reference.isWrite()) return reference.init === true;
|
|
784
973
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
785
974
|
let use = outerExpression(reference.identifier);
|
|
786
|
-
while (use.parent?.type ===
|
|
975
|
+
while (use.parent?.type === import_utils9.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = outerExpression(use.parent);
|
|
787
976
|
const parent = use.parent;
|
|
788
|
-
return parent?.type ===
|
|
977
|
+
return parent?.type === import_utils9.AST_NODE_TYPES.CallExpression && parent.callee === use || parent?.type === import_utils9.AST_NODE_TYPES.ExportSpecifier || parent?.type === import_utils9.AST_NODE_TYPES.ExportDefaultDeclaration || parent?.type === import_utils9.AST_NODE_TYPES.TSTypeQuery || parent?.type === import_utils9.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof";
|
|
789
978
|
});
|
|
790
979
|
FIXTURE_API_STABILITY.set(binding3, unchanged);
|
|
791
980
|
return unchanged;
|
|
@@ -815,72 +1004,72 @@ var NO_NEGATIVE_ONLY_HTTP_STATUS_ASSERTION_DOCUMENTATION = {
|
|
|
815
1004
|
]
|
|
816
1005
|
};
|
|
817
1006
|
function statusAssertion(source, call) {
|
|
818
|
-
if (call.arguments.length !== 1 || call.arguments[0]?.type !==
|
|
819
|
-
const matcher =
|
|
1007
|
+
if (call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils10.AST_NODE_TYPES.Literal || typeof call.arguments[0].value !== "number" || call.callee.type !== import_utils10.AST_NODE_TYPES.MemberExpression) return null;
|
|
1008
|
+
const matcher = import_utils10.ASTUtils.getPropertyName(call.callee);
|
|
820
1009
|
if (matcher === null) return null;
|
|
821
1010
|
let object = unwrapExpression(call.callee.object);
|
|
822
|
-
const negative = object.type ===
|
|
823
|
-
if (negative && object.type ===
|
|
824
|
-
if (object.type !==
|
|
1011
|
+
const negative = object.type === import_utils10.AST_NODE_TYPES.MemberExpression && import_utils10.ASTUtils.getPropertyName(object) === "not";
|
|
1012
|
+
if (negative && object.type === import_utils10.AST_NODE_TYPES.MemberExpression) object = unwrapExpression(object.object);
|
|
1013
|
+
if (object.type !== import_utils10.AST_NODE_TYPES.CallExpression || object.arguments.length !== 1 || object.callee.type !== import_utils10.AST_NODE_TYPES.Identifier || runtimeTestFrameworkName(source, object.callee, "assertion") !== "expect") return null;
|
|
825
1014
|
const argument = object.arguments[0];
|
|
826
|
-
const response = argument === void 0 || argument.type ===
|
|
1015
|
+
const response = argument === void 0 || argument.type === import_utils10.AST_NODE_TYPES.SpreadElement ? null : fetchResponse(source, argument);
|
|
827
1016
|
return response === null ? null : { response, expected: call.arguments[0].value, matcher, negative };
|
|
828
1017
|
}
|
|
829
1018
|
function fetchResponse(source, value) {
|
|
830
1019
|
const node = unwrapExpression(value);
|
|
831
|
-
if (node.type !==
|
|
1020
|
+
if (node.type !== import_utils10.AST_NODE_TYPES.MemberExpression || import_utils10.ASTUtils.getPropertyName(node) !== "status" || node.object.type !== import_utils10.AST_NODE_TYPES.Identifier) return null;
|
|
832
1021
|
return responseBinding(source, node.object);
|
|
833
1022
|
}
|
|
834
1023
|
function responseBinding(source, node, seen = /* @__PURE__ */ new Set()) {
|
|
835
|
-
const variable =
|
|
1024
|
+
const variable = import_utils10.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
836
1025
|
const definition = variable?.defs[0]?.node;
|
|
837
1026
|
if (variable?.defs.length !== 1 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
838
1027
|
seen.add(variable);
|
|
839
1028
|
const parameter = variable.defs[0];
|
|
840
|
-
if (parameter?.type === "Parameter" && parameter.name.type ===
|
|
1029
|
+
if (parameter?.type === "Parameter" && parameter.name.type === import_utils10.AST_NODE_TYPES.Identifier) {
|
|
841
1030
|
const annotation = parameter.name.typeAnnotation?.typeAnnotation;
|
|
842
|
-
return annotation?.type ===
|
|
1031
|
+
return annotation?.type === import_utils10.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils10.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Response" && (import_utils10.ASTUtils.findVariable(source.getScope(annotation.typeName), "Response")?.defs.length ?? 0) === 0 ? variable : null;
|
|
843
1032
|
}
|
|
844
|
-
if (definition?.type !==
|
|
1033
|
+
if (definition?.type !== import_utils10.AST_NODE_TYPES.VariableDeclarator || definition.parent.kind !== "const" || definition.init === null) return null;
|
|
845
1034
|
let initial = unwrapExpression(definition.init);
|
|
846
|
-
if (initial.type ===
|
|
847
|
-
if (initial.type ===
|
|
1035
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.AwaitExpression) initial = unwrapExpression(initial.argument);
|
|
1036
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.Identifier) return responseBinding(source, initial, seen);
|
|
848
1037
|
return nativeResponse(initial, source) ? variable : null;
|
|
849
1038
|
}
|
|
850
1039
|
function nativeResponse(initial, source) {
|
|
851
|
-
if (initial.type ===
|
|
852
|
-
if (initial.type ===
|
|
853
|
-
if (initial.type !==
|
|
1040
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.NewExpression && initial.callee.type === import_utils10.AST_NODE_TYPES.Identifier && initial.callee.name === "Response" && (import_utils10.ASTUtils.findVariable(source.getScope(initial.callee), "Response")?.defs.length ?? 0) === 0) return true;
|
|
1041
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.CallExpression && nativeFetchReference(initial.callee, source)) return true;
|
|
1042
|
+
if (initial.type !== import_utils10.AST_NODE_TYPES.CallExpression || initial.callee.type !== import_utils10.AST_NODE_TYPES.Identifier) return false;
|
|
854
1043
|
const callee = initial.callee;
|
|
855
|
-
const binding3 =
|
|
1044
|
+
const binding3 = import_utils10.ASTUtils.findVariable(source.getScope(callee), callee.name);
|
|
856
1045
|
if ((binding3?.defs.length ?? 0) === 0) return callee.name === "fetch";
|
|
857
1046
|
const imported = binding3?.defs[0];
|
|
858
|
-
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !==
|
|
1047
|
+
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !== import_utils10.AST_NODE_TYPES.ImportDeclaration || imported.parent.importKind === "type" || !FETCH_MODULES.has(imported.parent.source.value)) return false;
|
|
859
1048
|
const specifier = imported.node;
|
|
860
|
-
if (specifier.type ===
|
|
861
|
-
if (specifier.type !==
|
|
862
|
-
const importedName7 = specifier.imported.type ===
|
|
1049
|
+
if (specifier.type === import_utils10.AST_NODE_TYPES.ImportDefaultSpecifier) return imported.parent.source.value === "node-fetch";
|
|
1050
|
+
if (specifier.type !== import_utils10.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type") return false;
|
|
1051
|
+
const importedName7 = specifier.imported.type === import_utils10.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
863
1052
|
return importedName7 === "fetch";
|
|
864
1053
|
}
|
|
865
1054
|
function enclosingTest(source, node) {
|
|
866
1055
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
867
|
-
if (current.type ===
|
|
868
|
-
if (current.type !==
|
|
1056
|
+
if (current.type === import_utils10.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
1057
|
+
if (current.type !== import_utils10.AST_NODE_TYPES.ArrowFunctionExpression && current.type !== import_utils10.AST_NODE_TYPES.FunctionExpression) continue;
|
|
869
1058
|
const registration2 = directArgumentCall(current);
|
|
870
1059
|
const callee = registration2?.callee;
|
|
871
|
-
if (callee?.type !==
|
|
1060
|
+
if (callee?.type !== import_utils10.AST_NODE_TYPES.Identifier) return null;
|
|
872
1061
|
const name = runtimeTestFrameworkName(source, callee, "test") ?? vitestFixtureTestName(source, callee);
|
|
873
1062
|
return name === "test" || name === "it" ? current : null;
|
|
874
1063
|
}
|
|
875
1064
|
return null;
|
|
876
1065
|
}
|
|
877
1066
|
function hasExactStatus(source, test, response) {
|
|
878
|
-
if (test.body.type !==
|
|
1067
|
+
if (test.body.type !== import_utils10.AST_NODE_TYPES.BlockStatement) return false;
|
|
879
1068
|
return test.body.body.some((statement) => {
|
|
880
|
-
if (statement.type !==
|
|
1069
|
+
if (statement.type !== import_utils10.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
881
1070
|
let expression = unwrapExpression(statement.expression);
|
|
882
|
-
if (expression.type ===
|
|
883
|
-
if (expression.type !==
|
|
1071
|
+
if (expression.type === import_utils10.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1072
|
+
if (expression.type !== import_utils10.AST_NODE_TYPES.CallExpression) return false;
|
|
884
1073
|
const assertion = statusAssertion(source, expression);
|
|
885
1074
|
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;
|
|
886
1075
|
});
|
|
@@ -911,7 +1100,7 @@ var no_negative_only_http_status_assertion_default = createRule({
|
|
|
911
1100
|
});
|
|
912
1101
|
|
|
913
1102
|
// src/rules/prefer-test-fixture-reuse.ts
|
|
914
|
-
var
|
|
1103
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
915
1104
|
var MAX_DEPTH = 8;
|
|
916
1105
|
var FRAMEWORKS = /* @__PURE__ */ new Set(["vitest", "@playwright/test"]);
|
|
917
1106
|
var TEST_MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "sequential"]);
|
|
@@ -933,24 +1122,24 @@ var PREFER_TEST_FIXTURE_REUSE_DOCUMENTATION = {
|
|
|
933
1122
|
]
|
|
934
1123
|
};
|
|
935
1124
|
function stableBinding(source, identifier) {
|
|
936
|
-
const variable =
|
|
1125
|
+
const variable = import_utils11.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
937
1126
|
if (variable?.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
938
1127
|
return variable;
|
|
939
1128
|
}
|
|
940
1129
|
function constructorBinding(source, node, depth = 0) {
|
|
941
1130
|
node = unwrapExpression(node);
|
|
942
|
-
if (node.type !==
|
|
1131
|
+
if (node.type !== import_utils11.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
943
1132
|
const variable = stableBinding(source, node);
|
|
944
1133
|
const definition = variable?.defs[0];
|
|
945
1134
|
if (variable === null || definition === void 0) return null;
|
|
946
1135
|
if (definition.type === "ClassName") return variable;
|
|
947
|
-
if (definition.type === "ImportBinding" && definition.parent.type ===
|
|
948
|
-
if (definition.node.type ===
|
|
1136
|
+
if (definition.type === "ImportBinding" && definition.parent.type === import_utils11.AST_NODE_TYPES.ImportDeclaration && definition.parent.importKind !== "type" && (definition.node.type !== import_utils11.AST_NODE_TYPES.ImportSpecifier || definition.node.importKind !== "type")) return variable;
|
|
1137
|
+
if (definition.node.type === import_utils11.AST_NODE_TYPES.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);
|
|
949
1138
|
return null;
|
|
950
1139
|
}
|
|
951
1140
|
function fixtureApi(source, expression, depth = 0) {
|
|
952
1141
|
const node = unwrapExpression(expression);
|
|
953
|
-
if (node.type !==
|
|
1142
|
+
if (node.type !== import_utils11.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
954
1143
|
const variable = stableBinding(source, node);
|
|
955
1144
|
const definition = variable?.defs[0];
|
|
956
1145
|
if (variable === null || definition === void 0) return null;
|
|
@@ -962,35 +1151,35 @@ function fixtureApi(source, expression, depth = 0) {
|
|
|
962
1151
|
}
|
|
963
1152
|
function importedFixtureApi(variable) {
|
|
964
1153
|
const definition = variable.defs[0];
|
|
965
|
-
if (definition?.type === "ImportBinding" && definition.parent.type ===
|
|
1154
|
+
if (definition?.type === "ImportBinding" && definition.parent.type === import_utils11.AST_NODE_TYPES.ImportDeclaration && FRAMEWORKS.has(definition.parent.source.value) && definition.parent.importKind !== "type" && definition.node.type === import_utils11.AST_NODE_TYPES.ImportSpecifier && definition.node.importKind !== "type") {
|
|
966
1155
|
const imported = definition.node.imported;
|
|
967
|
-
const name = imported.type ===
|
|
1156
|
+
const name = imported.type === import_utils11.AST_NODE_TYPES.Identifier ? imported.name : imported.value;
|
|
968
1157
|
return name === "test" || name === "it";
|
|
969
1158
|
}
|
|
970
1159
|
return false;
|
|
971
1160
|
}
|
|
972
1161
|
function fixtureExtension(declaration, before) {
|
|
973
|
-
if (declaration.type !==
|
|
1162
|
+
if (declaration.type !== import_utils11.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= before) return null;
|
|
974
1163
|
const initial = unwrapExpression(declaration.init);
|
|
975
|
-
if (initial.type !==
|
|
1164
|
+
if (initial.type !== import_utils11.AST_NODE_TYPES.CallExpression || initial.optional || initial.arguments.length !== 1 || initial.callee.type !== import_utils11.AST_NODE_TYPES.MemberExpression || initial.callee.optional || import_utils11.ASTUtils.getPropertyName(initial.callee) !== "extend") return null;
|
|
976
1165
|
const declarations = initial.arguments[0];
|
|
977
|
-
if (declarations?.type !==
|
|
1166
|
+
if (declarations?.type !== import_utils11.AST_NODE_TYPES.ObjectExpression || declarations.properties.some((property) => property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed || property.kind !== "init")) return null;
|
|
978
1167
|
return { receiver: initial.callee.object, declarations };
|
|
979
1168
|
}
|
|
980
1169
|
function fixtureApiStable(variable) {
|
|
981
1170
|
return !variable.references.some((reference) => {
|
|
982
1171
|
if (reference.isWrite() || reference.isTypeReference && !reference.isValueReference) return false;
|
|
983
1172
|
let use = reference.identifier;
|
|
984
|
-
while (use.parent?.type ===
|
|
985
|
-
return use.parent?.type !==
|
|
1173
|
+
while (use.parent?.type === import_utils11.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = use.parent;
|
|
1174
|
+
return use.parent?.type !== import_utils11.AST_NODE_TYPES.CallExpression || use.parent.callee !== use;
|
|
986
1175
|
});
|
|
987
1176
|
}
|
|
988
1177
|
function fixtureConstructors(source, declarations, inherited) {
|
|
989
1178
|
const result = new Map(inherited);
|
|
990
1179
|
for (const property of declarations.properties) {
|
|
991
|
-
if (property.type !==
|
|
992
|
-
const name =
|
|
993
|
-
if (name === null || property.value.type ===
|
|
1180
|
+
if (property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed || property.value.type === import_utils11.AST_NODE_TYPES.AssignmentPattern) continue;
|
|
1181
|
+
const name = import_utils11.ASTUtils.getPropertyName(property);
|
|
1182
|
+
if (name === null || property.value.type === import_utils11.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) continue;
|
|
994
1183
|
const constructor = fixtureConstructor(source, property.value);
|
|
995
1184
|
if (constructor === null) result.delete(name);
|
|
996
1185
|
else result.set(name, constructor);
|
|
@@ -999,24 +1188,24 @@ function fixtureConstructors(source, declarations, inherited) {
|
|
|
999
1188
|
}
|
|
1000
1189
|
function fixtureConstructor(source, value) {
|
|
1001
1190
|
value = unwrapExpression(value);
|
|
1002
|
-
if (value.type !==
|
|
1191
|
+
if (value.type !== import_utils11.AST_NODE_TYPES.ArrowFunctionExpression && value.type !== import_utils11.AST_NODE_TYPES.FunctionExpression) return newConstructor(source, value);
|
|
1003
1192
|
const use = value.params[1];
|
|
1004
|
-
if (use?.type !==
|
|
1193
|
+
if (use?.type !== import_utils11.AST_NODE_TYPES.Identifier) return null;
|
|
1005
1194
|
const binding3 = stableBinding(source, use);
|
|
1006
|
-
const calls = scopeNodes(value.body, source).filter((node) => node.type ===
|
|
1195
|
+
const calls = scopeNodes(value.body, source).filter((node) => node.type === import_utils11.AST_NODE_TYPES.CallExpression && !node.optional && node.arguments.length === 1 && node.callee.type === import_utils11.AST_NODE_TYPES.Identifier && stableBinding(source, node.callee) === binding3);
|
|
1007
1196
|
if (calls.length !== 1 || binding3 === null) return null;
|
|
1008
1197
|
const argument = calls[0]?.arguments[0];
|
|
1009
|
-
return argument === void 0 || argument.type ===
|
|
1198
|
+
return argument === void 0 || argument.type === import_utils11.AST_NODE_TYPES.SpreadElement ? null : newConstructor(source, argument);
|
|
1010
1199
|
}
|
|
1011
1200
|
function newConstructor(source, expression) {
|
|
1012
1201
|
const value = unwrapExpression(expression);
|
|
1013
|
-
if (value.type ===
|
|
1014
|
-
if (value.type !==
|
|
1202
|
+
if (value.type === import_utils11.AST_NODE_TYPES.NewExpression) return constructorBinding(source, value.callee);
|
|
1203
|
+
if (value.type !== import_utils11.AST_NODE_TYPES.Identifier) return null;
|
|
1015
1204
|
const variable = stableBinding(source, value);
|
|
1016
1205
|
const declaration = variable?.defs[0]?.node;
|
|
1017
|
-
if (declaration?.type !==
|
|
1206
|
+
if (declaration?.type !== import_utils11.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= value.range[0]) return null;
|
|
1018
1207
|
const initial = unwrapExpression(declaration.init);
|
|
1019
|
-
return initial.type ===
|
|
1208
|
+
return initial.type === import_utils11.AST_NODE_TYPES.NewExpression ? constructorBinding(source, initial.callee) : null;
|
|
1020
1209
|
}
|
|
1021
1210
|
function scopeNodes(root, source) {
|
|
1022
1211
|
const result = [];
|
|
@@ -1025,7 +1214,7 @@ function scopeNodes(root, source) {
|
|
|
1025
1214
|
const node = pending.pop();
|
|
1026
1215
|
if (node === void 0) continue;
|
|
1027
1216
|
result.push(node);
|
|
1028
|
-
if (node !== root && (node.type ===
|
|
1217
|
+
if (node !== root && (node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils11.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils11.AST_NODE_TYPES.ClassExpression)) continue;
|
|
1029
1218
|
for (const key of source.visitorKeys[node.type] ?? []) {
|
|
1030
1219
|
const value = Reflect.get(node, key);
|
|
1031
1220
|
if (Array.isArray(value)) pending.push(...value.filter(isNode2));
|
|
@@ -1039,13 +1228,13 @@ function isNode2(value) {
|
|
|
1039
1228
|
}
|
|
1040
1229
|
function testApiCallee(expression) {
|
|
1041
1230
|
let node = unwrapExpression(expression);
|
|
1042
|
-
while (node.type ===
|
|
1231
|
+
while (node.type === import_utils11.AST_NODE_TYPES.MemberExpression && !node.optional && TEST_MODIFIERS.has(import_utils11.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
1043
1232
|
return node;
|
|
1044
1233
|
}
|
|
1045
1234
|
function requestingFunction(node) {
|
|
1046
1235
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
1047
|
-
if (current.type ===
|
|
1048
|
-
if (current.type ===
|
|
1236
|
+
if (current.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils11.AST_NODE_TYPES.FunctionExpression) return current;
|
|
1237
|
+
if (current.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
1049
1238
|
}
|
|
1050
1239
|
return null;
|
|
1051
1240
|
}
|
|
@@ -1067,13 +1256,13 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1067
1256
|
const call = functionNode === null ? null : directArgumentCall(functionNode);
|
|
1068
1257
|
if (functionNode === null || call === null) return;
|
|
1069
1258
|
const parameter = functionNode.params[0];
|
|
1070
|
-
if (parameter?.type !==
|
|
1259
|
+
if (parameter?.type !== import_utils11.AST_NODE_TYPES.ObjectPattern) return;
|
|
1071
1260
|
const entries = fixtureApi(context.sourceCode, testApiCallee(call.callee));
|
|
1072
1261
|
const constructor = constructorBinding(context.sourceCode, node.callee);
|
|
1073
1262
|
if (entries === null || constructor === null) return;
|
|
1074
1263
|
for (const property of parameter.properties) {
|
|
1075
|
-
if (property.type !==
|
|
1076
|
-
const name =
|
|
1264
|
+
if (property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed) continue;
|
|
1265
|
+
const name = import_utils11.ASTUtils.getPropertyName(property);
|
|
1077
1266
|
if (name !== null && entries.get(name) === constructor) {
|
|
1078
1267
|
context.report({ node, messageId: "reuseFixture", data: { fixture: name } });
|
|
1079
1268
|
return;
|
|
@@ -1085,7 +1274,7 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1085
1274
|
});
|
|
1086
1275
|
|
|
1087
1276
|
// src/rules/no-return-disposed-resource.ts
|
|
1088
|
-
var
|
|
1277
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
1089
1278
|
var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
1090
1279
|
defaultLevel: "warning",
|
|
1091
1280
|
summary: "Do not return a resource whose using declaration disposes it before the caller receives it.",
|
|
@@ -1105,16 +1294,16 @@ var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
|
1105
1294
|
};
|
|
1106
1295
|
function owningFunction(node) {
|
|
1107
1296
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
1108
|
-
if (current.type ===
|
|
1297
|
+
if (current.type === import_utils12.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils12.AST_NODE_TYPES.FunctionExpression || current.type === import_utils12.AST_NODE_TYPES.ArrowFunctionExpression) return current;
|
|
1109
1298
|
}
|
|
1110
1299
|
return null;
|
|
1111
1300
|
}
|
|
1112
1301
|
function resourceOwner(source, value, seen = /* @__PURE__ */ new Set()) {
|
|
1113
1302
|
const node = unwrapExpression(value);
|
|
1114
|
-
if (node.type !==
|
|
1115
|
-
const variable =
|
|
1303
|
+
if (node.type !== import_utils12.AST_NODE_TYPES.Identifier) return null;
|
|
1304
|
+
const variable = import_utils12.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
1116
1305
|
const definition = variable?.defs[0];
|
|
1117
|
-
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !==
|
|
1306
|
+
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !== import_utils12.AST_NODE_TYPES.VariableDeclarator) return null;
|
|
1118
1307
|
const declaration = definition.node;
|
|
1119
1308
|
if (declaration.parent.kind === "using" || declaration.parent.kind === "await using") return declaration;
|
|
1120
1309
|
if (declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= node.range[0]) return null;
|
|
@@ -1143,7 +1332,7 @@ var no_return_disposed_resource_default = createRule({
|
|
|
1143
1332
|
});
|
|
1144
1333
|
|
|
1145
1334
|
// src/rules/require-jwt-lifetime.ts
|
|
1146
|
-
var
|
|
1335
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
1147
1336
|
var REQUIRE_JWT_LIFETIME_DOCUMENTATION = {
|
|
1148
1337
|
defaultLevel: "warning",
|
|
1149
1338
|
summary: "Require an expiration claim or a maximum token age when returning a verified JWT.",
|
|
@@ -1171,36 +1360,36 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1171
1360
|
function inspect(input) {
|
|
1172
1361
|
if (input === null) return;
|
|
1173
1362
|
let node = unwrapExpression(input);
|
|
1174
|
-
if (node.type ===
|
|
1175
|
-
if (node.type !==
|
|
1363
|
+
if (node.type === import_utils13.AST_NODE_TYPES.AwaitExpression) node = unwrapExpression(node.argument);
|
|
1364
|
+
if (node.type !== import_utils13.AST_NODE_TYPES.CallExpression || !isVerifier(node.callee)) return;
|
|
1176
1365
|
if (!missingLifetime(node.arguments[2])) return;
|
|
1177
1366
|
context.report({ node, messageId: "lifetime" });
|
|
1178
1367
|
}
|
|
1179
1368
|
function isVerifier(node) {
|
|
1180
1369
|
node = unwrapExpression(node);
|
|
1181
|
-
if (node.type ===
|
|
1182
|
-
const variable =
|
|
1370
|
+
if (node.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
1371
|
+
const variable = import_utils13.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1183
1372
|
const declaration = variable?.defs[0]?.node;
|
|
1184
|
-
return variable?.defs.length === 1 && declaration?.type ===
|
|
1373
|
+
return variable?.defs.length === 1 && declaration?.type === import_utils13.AST_NODE_TYPES.ImportSpecifier && declaration.parent.type === import_utils13.AST_NODE_TYPES.ImportDeclaration && declaration.importKind !== "type" && declaration.parent.importKind !== "type" && declaration.parent.source.value === "jose" && declaration.imported.type === import_utils13.AST_NODE_TYPES.Identifier && declaration.imported.name === "jwtVerify";
|
|
1185
1374
|
}
|
|
1186
|
-
if (node.type !==
|
|
1187
|
-
const definition =
|
|
1188
|
-
return definition?.type ===
|
|
1375
|
+
if (node.type !== import_utils13.AST_NODE_TYPES.MemberExpression || import_utils13.ASTUtils.getPropertyName(node) !== "jwtVerify" || node.object.type !== import_utils13.AST_NODE_TYPES.Identifier) return false;
|
|
1376
|
+
const definition = import_utils13.ASTUtils.findVariable(sourceCode.getScope(node.object), node.object.name)?.defs[0]?.node;
|
|
1377
|
+
return definition?.type === import_utils13.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && definition.parent.source.value === "jose";
|
|
1189
1378
|
}
|
|
1190
1379
|
function missingLifetime(options) {
|
|
1191
1380
|
if (options === void 0) return true;
|
|
1192
|
-
if (options.type !==
|
|
1193
|
-
return !options.properties.some((property) => property.type ===
|
|
1381
|
+
if (options.type !== import_utils13.AST_NODE_TYPES.ObjectExpression || options.properties.some((property) => property.type !== import_utils13.AST_NODE_TYPES.Property || property.computed)) return false;
|
|
1382
|
+
return !options.properties.some((property) => property.type === import_utils13.AST_NODE_TYPES.Property && lifetimeProperty(property));
|
|
1194
1383
|
}
|
|
1195
1384
|
function lifetimeProperty(property) {
|
|
1196
|
-
const name = property.key.type ===
|
|
1385
|
+
const name = property.key.type === import_utils13.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils13.AST_NODE_TYPES.Literal ? property.key.value : null;
|
|
1197
1386
|
if (name === "maxTokenAge") {
|
|
1198
|
-
if (property.value.type !==
|
|
1387
|
+
if (property.value.type !== import_utils13.AST_NODE_TYPES.Literal) return true;
|
|
1199
1388
|
return typeof property.value.value === "number" && Number.isFinite(property.value.value) || typeof property.value.value === "string" && property.value.value.trim() !== "";
|
|
1200
1389
|
}
|
|
1201
1390
|
if (name !== "requiredClaims") return false;
|
|
1202
|
-
if (property.value.type !==
|
|
1203
|
-
return property.value.elements.some((element) => element?.type ===
|
|
1391
|
+
if (property.value.type !== import_utils13.AST_NODE_TYPES.ArrayExpression || property.value.elements.some((element) => element?.type !== import_utils13.AST_NODE_TYPES.Literal)) return true;
|
|
1392
|
+
return property.value.elements.some((element) => element?.type === import_utils13.AST_NODE_TYPES.Literal && element.value === "exp");
|
|
1204
1393
|
}
|
|
1205
1394
|
return {
|
|
1206
1395
|
ReturnStatement(node) {
|
|
@@ -1214,7 +1403,7 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1214
1403
|
});
|
|
1215
1404
|
|
|
1216
1405
|
// src/rules/no-discarded-validation-result.ts
|
|
1217
|
-
var
|
|
1406
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
1218
1407
|
|
|
1219
1408
|
// src/rules/_zod.ts
|
|
1220
1409
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
@@ -1250,52 +1439,52 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1250
1439
|
function schema(node, depth = 0) {
|
|
1251
1440
|
if (depth > 24) return null;
|
|
1252
1441
|
node = unwrapExpression(node);
|
|
1253
|
-
if (node.type ===
|
|
1254
|
-
const variable =
|
|
1442
|
+
if (node.type === import_utils14.AST_NODE_TYPES.Identifier) {
|
|
1443
|
+
const variable = import_utils14.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1255
1444
|
const definition = variable?.defs[0]?.node;
|
|
1256
1445
|
if (variable?.defs.length !== 1) return null;
|
|
1257
|
-
if (definition?.type ===
|
|
1258
|
-
if (definition?.type ===
|
|
1259
|
-
if (definition?.type ===
|
|
1446
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.ImportSpecifier && definition.parent.type === import_utils14.AST_NODE_TYPES.ImportDeclaration && definition.importKind !== "type" && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1447
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1448
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.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);
|
|
1260
1449
|
return null;
|
|
1261
1450
|
}
|
|
1262
|
-
if (node.type ===
|
|
1451
|
+
if (node.type === import_utils14.AST_NODE_TYPES.MemberExpression) {
|
|
1263
1452
|
const owner2 = schema(node.object, depth + 1);
|
|
1264
1453
|
return owner2;
|
|
1265
1454
|
}
|
|
1266
|
-
if (node.type !==
|
|
1455
|
+
if (node.type !== import_utils14.AST_NODE_TYPES.CallExpression) return null;
|
|
1267
1456
|
const owner = schema(node.callee, depth + 1);
|
|
1268
1457
|
if (owner === null) return null;
|
|
1269
|
-
const invokedChange = node.callee.type ===
|
|
1270
|
-
const coerced = node.callee.type ===
|
|
1458
|
+
const invokedChange = node.callee.type === import_utils14.AST_NODE_TYPES.MemberExpression && CHANGING.has(import_utils14.ASTUtils.getPropertyName(node.callee) ?? "");
|
|
1459
|
+
const coerced = node.callee.type === import_utils14.AST_NODE_TYPES.MemberExpression && coercionNamespace(node.callee.object);
|
|
1271
1460
|
const changedArgument = node.arguments.some((argument) => {
|
|
1272
|
-
if (argument.type ===
|
|
1273
|
-
if (argument.type ===
|
|
1461
|
+
if (argument.type === import_utils14.AST_NODE_TYPES.ArrayExpression) return argument.elements.some((element) => element !== null && schema(element, depth + 1)?.changed === true);
|
|
1462
|
+
if (argument.type === import_utils14.AST_NODE_TYPES.ObjectExpression) return argument.properties.some((property) => property.type === import_utils14.AST_NODE_TYPES.Property && schema(property.value, depth + 1)?.changed === true);
|
|
1274
1463
|
return schema(argument, depth + 1)?.changed === true;
|
|
1275
1464
|
});
|
|
1276
1465
|
return { changed: owner.changed || invokedChange || coerced || changedArgument };
|
|
1277
1466
|
}
|
|
1278
1467
|
function coercionNamespace(node) {
|
|
1279
1468
|
let namespace = false;
|
|
1280
|
-
if (node.type ===
|
|
1469
|
+
if (node.type === import_utils14.AST_NODE_TYPES.MemberExpression && import_utils14.ASTUtils.getPropertyName(node) === "coerce") {
|
|
1281
1470
|
namespace = true;
|
|
1282
1471
|
node = node.object;
|
|
1283
1472
|
}
|
|
1284
|
-
if (node.type !==
|
|
1285
|
-
const variable =
|
|
1473
|
+
if (node.type !== import_utils14.AST_NODE_TYPES.Identifier) return false;
|
|
1474
|
+
const variable = import_utils14.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1286
1475
|
const definition = variable?.defs[0]?.node;
|
|
1287
|
-
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !==
|
|
1288
|
-
if (definition.type ===
|
|
1289
|
-
if (definition.type !==
|
|
1290
|
-
const name = definition.imported.type ===
|
|
1476
|
+
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !== import_utils14.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return false;
|
|
1477
|
+
if (definition.type === import_utils14.AST_NODE_TYPES.ImportNamespaceSpecifier) return namespace;
|
|
1478
|
+
if (definition.type !== import_utils14.AST_NODE_TYPES.ImportSpecifier || definition.importKind === "type") return false;
|
|
1479
|
+
const name = definition.imported.type === import_utils14.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value;
|
|
1291
1480
|
return namespace ? name === "z" : name === "coerce";
|
|
1292
1481
|
}
|
|
1293
1482
|
return {
|
|
1294
1483
|
ExpressionStatement(statement) {
|
|
1295
1484
|
let expression = unwrapExpression(statement.expression);
|
|
1296
|
-
if (expression.type ===
|
|
1297
|
-
if (expression.type !==
|
|
1298
|
-
const method =
|
|
1485
|
+
if (expression.type === import_utils14.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1486
|
+
if (expression.type !== import_utils14.AST_NODE_TYPES.CallExpression || expression.callee.type !== import_utils14.AST_NODE_TYPES.MemberExpression) return;
|
|
1487
|
+
const method = import_utils14.ASTUtils.getPropertyName(expression.callee);
|
|
1299
1488
|
if (!(/* @__PURE__ */ new Set(["parse", "parseAsync", "safeParse", "safeParseAsync"])).has(method ?? "")) return;
|
|
1300
1489
|
const owner = schema(expression.callee.object);
|
|
1301
1490
|
if (owner !== null && (owner.changed || method?.startsWith("safe") === true)) context.report({ node: expression, messageId: "discarded" });
|
|
@@ -1305,7 +1494,7 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1305
1494
|
});
|
|
1306
1495
|
|
|
1307
1496
|
// src/rules/production-derived-test-cases.ts
|
|
1308
|
-
var
|
|
1497
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
1309
1498
|
var MEMBERSHIP = /(?:^|_)(?:ALLOWED|ELIGIBLE|REQUIRED|SUPPORTED)(?:_|$)/u;
|
|
1310
1499
|
var SUPPORT_PATH = /(?:^|[/_.-])(?:tests?|fixtures?|fakes?|mocks?|stubs?|__tests__)(?:[/_.-]|$)/u;
|
|
1311
1500
|
var PRODUCTION_DERIVED_TEST_CASES_DOCUMENTATION = {
|
|
@@ -1340,52 +1529,52 @@ var production_derived_test_cases_default = createRule({
|
|
|
1340
1529
|
const tables = [];
|
|
1341
1530
|
const asserted = /* @__PURE__ */ new Set();
|
|
1342
1531
|
function binding3(node) {
|
|
1343
|
-
return
|
|
1532
|
+
return import_utils15.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1344
1533
|
}
|
|
1345
1534
|
function importedName7(node, module2) {
|
|
1346
1535
|
const variable = binding3(node);
|
|
1347
1536
|
const specifier = variable?.defs[0]?.node;
|
|
1348
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1349
|
-
return specifier.imported.type ===
|
|
1537
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils15.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils15.AST_NODE_TYPES.ImportDeclaration || specifier.parent.importKind === "type" || specifier.parent.source.value !== module2 || variable.references.some((reference) => reference.isWrite())) return null;
|
|
1538
|
+
return specifier.imported.type === import_utils15.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1350
1539
|
}
|
|
1351
1540
|
function production(node) {
|
|
1352
1541
|
node = unwrapExpression(node);
|
|
1353
|
-
if (node.type !==
|
|
1542
|
+
if (node.type !== import_utils15.AST_NODE_TYPES.Identifier) return null;
|
|
1354
1543
|
const variable = binding3(node);
|
|
1355
1544
|
const specifier = variable?.defs[0]?.node;
|
|
1356
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1357
|
-
const name = specifier.imported.type ===
|
|
1545
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils15.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils15.AST_NODE_TYPES.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;
|
|
1546
|
+
const name = specifier.imported.type === import_utils15.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1358
1547
|
return MEMBERSHIP.test(name) && !name.endsWith("REGISTRY") ? variable : null;
|
|
1359
1548
|
}
|
|
1360
1549
|
function runner(node) {
|
|
1361
1550
|
node = unwrapExpression(node);
|
|
1362
|
-
while (node.type ===
|
|
1363
|
-
if (node.type !==
|
|
1551
|
+
while (node.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["only", "skip", "concurrent", "sequential"].includes(import_utils15.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
1552
|
+
if (node.type !== import_utils15.AST_NODE_TYPES.Identifier) return false;
|
|
1364
1553
|
const name = importedName7(node, "vitest");
|
|
1365
1554
|
return name === "test" || name === "it" || vitestFixtureTestName(sourceCode, node) !== null;
|
|
1366
1555
|
}
|
|
1367
1556
|
function caseTable(node) {
|
|
1368
|
-
return node.type ===
|
|
1557
|
+
return node.type === import_utils15.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["each", "for"].includes(import_utils15.ASTUtils.getPropertyName(node.callee) ?? "") && runner(node.callee.object);
|
|
1369
1558
|
}
|
|
1370
1559
|
function literalTable(node, seen = /* @__PURE__ */ new Set()) {
|
|
1371
1560
|
node = unwrapExpression(node);
|
|
1372
1561
|
if (seen.has(node)) return false;
|
|
1373
1562
|
seen.add(node);
|
|
1374
|
-
if (node.type ===
|
|
1563
|
+
if (node.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
1375
1564
|
const variable = binding3(node);
|
|
1376
1565
|
const definition = variable?.defs[0]?.node;
|
|
1377
|
-
return variable?.defs.length === 1 && definition?.type ===
|
|
1566
|
+
return variable?.defs.length === 1 && definition?.type === import_utils15.AST_NODE_TYPES.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 === import_utils15.AST_NODE_TYPES.CallExpression && (caseTable(reference.identifier.parent) || reference.identifier.parent.callee.type === import_utils15.AST_NODE_TYPES.Identifier && importedName7(reference.identifier.parent.callee, "vitest") === "expect" || reference.identifier.parent.callee.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["toEqual", "toStrictEqual"].includes(import_utils15.ASTUtils.getPropertyName(reference.identifier.parent.callee) ?? ""))) && literalTable(definition.init, seen);
|
|
1378
1567
|
}
|
|
1379
|
-
return node.type ===
|
|
1568
|
+
return node.type === import_utils15.AST_NODE_TYPES.ArrayExpression && node.elements.every((element) => element?.type === import_utils15.AST_NODE_TYPES.Literal && !("regex" in element));
|
|
1380
1569
|
}
|
|
1381
1570
|
function unconditional(node) {
|
|
1382
1571
|
const statement = node.parent;
|
|
1383
|
-
if (statement.type !==
|
|
1384
|
-
if (statement.parent.type ===
|
|
1572
|
+
if (statement.type !== import_utils15.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
1573
|
+
if (statement.parent.type === import_utils15.AST_NODE_TYPES.Program) return true;
|
|
1385
1574
|
const block = statement.parent;
|
|
1386
|
-
if (block.type !==
|
|
1575
|
+
if (block.type !== import_utils15.AST_NODE_TYPES.BlockStatement || block.parent.type !== import_utils15.AST_NODE_TYPES.ArrowFunctionExpression && block.parent.type !== import_utils15.AST_NODE_TYPES.FunctionExpression) return false;
|
|
1387
1576
|
const call = block.parent.parent;
|
|
1388
|
-
return call.type ===
|
|
1577
|
+
return call.type === import_utils15.AST_NODE_TYPES.CallExpression && runner(call.callee);
|
|
1389
1578
|
}
|
|
1390
1579
|
return {
|
|
1391
1580
|
CallExpression(node) {
|
|
@@ -1393,9 +1582,9 @@ var production_derived_test_cases_default = createRule({
|
|
|
1393
1582
|
const variable2 = production(node.arguments[0]);
|
|
1394
1583
|
if (variable2 !== null) tables.push({ node, variable: variable2 });
|
|
1395
1584
|
}
|
|
1396
|
-
if (node.callee.type !==
|
|
1585
|
+
if (node.callee.type !== import_utils15.AST_NODE_TYPES.MemberExpression || !["toEqual", "toStrictEqual"].includes(import_utils15.ASTUtils.getPropertyName(node.callee) ?? "") || node.arguments.length !== 1 || node.arguments[0] === void 0 || !literalTable(node.arguments[0]) || !unconditional(node)) return;
|
|
1397
1586
|
const expect = node.callee.object;
|
|
1398
|
-
if (expect.type !==
|
|
1587
|
+
if (expect.type !== import_utils15.AST_NODE_TYPES.CallExpression || expect.callee.type !== import_utils15.AST_NODE_TYPES.Identifier || importedName7(expect.callee, "vitest") !== "expect" || expect.arguments.length !== 1 || expect.arguments[0] === void 0) return;
|
|
1399
1588
|
const variable = production(expect.arguments[0]);
|
|
1400
1589
|
if (variable !== null) asserted.add(variable);
|
|
1401
1590
|
},
|
|
@@ -1407,14 +1596,14 @@ var production_derived_test_cases_default = createRule({
|
|
|
1407
1596
|
});
|
|
1408
1597
|
|
|
1409
1598
|
// src/rules/require-constrained-schema-integer.ts
|
|
1410
|
-
var
|
|
1599
|
+
var import_utils16 = require("@typescript-eslint/utils");
|
|
1411
1600
|
var FIELD_MINIMUMS = /* @__PURE__ */ new Map([["limit", 1], ["version", 0]]);
|
|
1412
1601
|
var NUMBER_FACTORIES = /* @__PURE__ */ new Set(["number", "int", "int32", "uint32"]);
|
|
1413
1602
|
var PRESERVING = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta", "max", "lte", "lt", "finite", "safe", "multipleOf"]);
|
|
1414
1603
|
function numericLiteral(node) {
|
|
1415
1604
|
node = unwrapExpression(node);
|
|
1416
|
-
if (node.type ===
|
|
1417
|
-
if (node.type ===
|
|
1605
|
+
if (node.type === import_utils16.AST_NODE_TYPES.Literal && typeof node.value === "number") return node.value;
|
|
1606
|
+
if (node.type === import_utils16.AST_NODE_TYPES.UnaryExpression && (node.operator === "-" || node.operator === "+")) {
|
|
1418
1607
|
const value = numericLiteral(node.argument);
|
|
1419
1608
|
return value === null ? null : node.operator === "-" ? -value : value;
|
|
1420
1609
|
}
|
|
@@ -1451,35 +1640,35 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1451
1640
|
const sourceCode = context.sourceCode;
|
|
1452
1641
|
function factory(node) {
|
|
1453
1642
|
node = unwrapExpression(node);
|
|
1454
|
-
if (node.type ===
|
|
1643
|
+
if (node.type === import_utils16.AST_NODE_TYPES.Identifier) {
|
|
1455
1644
|
const definition2 = imported(node);
|
|
1456
|
-
return definition2?.type ===
|
|
1645
|
+
return definition2?.type === import_utils16.AST_NODE_TYPES.ImportSpecifier ? definition2.imported.type === import_utils16.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value : null;
|
|
1457
1646
|
}
|
|
1458
|
-
if (node.type !==
|
|
1647
|
+
if (node.type !== import_utils16.AST_NODE_TYPES.MemberExpression) return null;
|
|
1459
1648
|
let receiver = unwrapExpression(node.object);
|
|
1460
|
-
if (receiver.type ===
|
|
1461
|
-
if (receiver.type !==
|
|
1649
|
+
if (receiver.type === import_utils16.AST_NODE_TYPES.MemberExpression && import_utils16.ASTUtils.getPropertyName(receiver) === "coerce") receiver = unwrapExpression(receiver.object);
|
|
1650
|
+
if (receiver.type !== import_utils16.AST_NODE_TYPES.Identifier) return null;
|
|
1462
1651
|
const definition = imported(receiver);
|
|
1463
|
-
if (definition === null || definition.type ===
|
|
1464
|
-
return
|
|
1652
|
+
if (definition === null || definition.type === import_utils16.AST_NODE_TYPES.ImportSpecifier && (definition.imported.type === import_utils16.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z") return null;
|
|
1653
|
+
return import_utils16.ASTUtils.getPropertyName(node);
|
|
1465
1654
|
}
|
|
1466
1655
|
function imported(identifier) {
|
|
1467
|
-
const variable =
|
|
1656
|
+
const variable = import_utils16.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
1468
1657
|
const definition = variable?.defs[0]?.node;
|
|
1469
|
-
if (variable?.defs.length !== 1 || definition?.type !==
|
|
1470
|
-
return definition.type ===
|
|
1658
|
+
if (variable?.defs.length !== 1 || definition?.type !== import_utils16.AST_NODE_TYPES.ImportSpecifier && definition?.type !== import_utils16.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils16.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1659
|
+
return definition.type === import_utils16.AST_NODE_TYPES.ImportSpecifier && definition.importKind === "type" ? null : definition;
|
|
1471
1660
|
}
|
|
1472
1661
|
function constrained(value, minimum) {
|
|
1473
1662
|
const calls = [];
|
|
1474
1663
|
value = unwrapExpression(value);
|
|
1475
|
-
while (value.type ===
|
|
1664
|
+
while (value.type === import_utils16.AST_NODE_TYPES.CallExpression) {
|
|
1476
1665
|
const name = factory(value.callee);
|
|
1477
1666
|
if (name !== null) {
|
|
1478
1667
|
return chainContract(name, calls, minimum);
|
|
1479
1668
|
}
|
|
1480
1669
|
const callee = unwrapExpression(value.callee);
|
|
1481
|
-
if (callee.type !==
|
|
1482
|
-
const method =
|
|
1670
|
+
if (callee.type !== import_utils16.AST_NODE_TYPES.MemberExpression) return null;
|
|
1671
|
+
const method = import_utils16.ASTUtils.getPropertyName(callee);
|
|
1483
1672
|
if (method === null) return null;
|
|
1484
1673
|
calls.push({ method, call: value });
|
|
1485
1674
|
value = unwrapExpression(callee.object);
|
|
@@ -1504,7 +1693,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1504
1693
|
}
|
|
1505
1694
|
function lowerBound(call, minimum, exclusive) {
|
|
1506
1695
|
const argument = call.arguments[0];
|
|
1507
|
-
if (argument === void 0 || argument.type ===
|
|
1696
|
+
if (argument === void 0 || argument.type === import_utils16.AST_NODE_TYPES.SpreadElement) return null;
|
|
1508
1697
|
const bound = numericLiteral(argument);
|
|
1509
1698
|
return bound === null || bound >= minimum - (exclusive ? 1 : 0);
|
|
1510
1699
|
}
|
|
@@ -1513,10 +1702,10 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1513
1702
|
const name = factory(node.callee);
|
|
1514
1703
|
if (name === null || !["object", "strictObject", "looseObject"].includes(name) || node.arguments.length !== 1) return;
|
|
1515
1704
|
const shape = node.arguments[0];
|
|
1516
|
-
if (shape?.type !==
|
|
1705
|
+
if (shape?.type !== import_utils16.AST_NODE_TYPES.ObjectExpression) return;
|
|
1517
1706
|
for (const property of shape.properties) {
|
|
1518
|
-
if (property.type !==
|
|
1519
|
-
const field =
|
|
1707
|
+
if (property.type !== import_utils16.AST_NODE_TYPES.Property || property.computed || property.kind !== "init" || property.method) continue;
|
|
1708
|
+
const field = import_utils16.ASTUtils.getPropertyName(property);
|
|
1520
1709
|
const minimum = field === null ? void 0 : FIELD_MINIMUMS.get(field);
|
|
1521
1710
|
if (minimum === void 0 || field === null || constrained(property.value, minimum) !== false) continue;
|
|
1522
1711
|
context.report({ node: property, messageId: "constrainInteger", data: { field, minimum } });
|
|
@@ -1527,7 +1716,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1527
1716
|
});
|
|
1528
1717
|
|
|
1529
1718
|
// src/rules/no-generic-json-parser.ts
|
|
1530
|
-
var
|
|
1719
|
+
var import_utils17 = require("@typescript-eslint/utils");
|
|
1531
1720
|
var OPEN_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "json", "record", "partialRecord"]);
|
|
1532
1721
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta"]);
|
|
1533
1722
|
var NO_GENERIC_JSON_PARSER_DOCUMENTATION = {
|
|
@@ -1560,60 +1749,60 @@ var no_generic_json_parser_default = createRule({
|
|
|
1560
1749
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1561
1750
|
const sourceCode = context.sourceCode;
|
|
1562
1751
|
function binding3(node) {
|
|
1563
|
-
return
|
|
1752
|
+
return import_utils17.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1564
1753
|
}
|
|
1565
1754
|
function initializer(node) {
|
|
1566
1755
|
const variable = binding3(node);
|
|
1567
1756
|
const definition = variable?.defs[0];
|
|
1568
|
-
if (variable?.defs.length !== 1 || definition?.node.type !==
|
|
1757
|
+
if (variable?.defs.length !== 1 || definition?.node.type !== import_utils17.AST_NODE_TYPES.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;
|
|
1569
1758
|
return definition.node.init;
|
|
1570
1759
|
}
|
|
1571
1760
|
function parser(node, seen = /* @__PURE__ */ new Set(), awaited = false) {
|
|
1572
1761
|
node = unwrapExpression(node);
|
|
1573
1762
|
if (seen.has(node)) return null;
|
|
1574
1763
|
seen.add(node);
|
|
1575
|
-
if (node.type ===
|
|
1576
|
-
if (node.type ===
|
|
1764
|
+
if (node.type === import_utils17.AST_NODE_TYPES.AwaitExpression) return parser(node.argument, seen, true);
|
|
1765
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1577
1766
|
const value = initializer(node);
|
|
1578
1767
|
return value === null ? null : parser(value, seen, awaited);
|
|
1579
1768
|
}
|
|
1580
|
-
if (node.type !==
|
|
1581
|
-
if (
|
|
1769
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.CallExpression || node.callee.type !== import_utils17.AST_NODE_TYPES.MemberExpression || !["parse", "parseAsync"].includes(import_utils17.ASTUtils.getPropertyName(node.callee) ?? "")) return null;
|
|
1770
|
+
if (import_utils17.ASTUtils.getPropertyName(node.callee) === "parseAsync" && !awaited) return null;
|
|
1582
1771
|
return openSchema(node.callee.object) ? node : null;
|
|
1583
1772
|
}
|
|
1584
1773
|
function openSchema(node, seen = /* @__PURE__ */ new Set()) {
|
|
1585
1774
|
node = unwrapExpression(node);
|
|
1586
1775
|
if (seen.has(node)) return false;
|
|
1587
1776
|
seen.add(node);
|
|
1588
|
-
if (node.type ===
|
|
1777
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1589
1778
|
const value = initializer(node);
|
|
1590
1779
|
return value !== null && openSchema(value, seen);
|
|
1591
1780
|
}
|
|
1592
|
-
if (node.type !==
|
|
1781
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.CallExpression) return false;
|
|
1593
1782
|
const name = factory(node.callee);
|
|
1594
1783
|
if (name !== null) return OPEN_FACTORIES.has(name);
|
|
1595
1784
|
const callee = unwrapExpression(node.callee);
|
|
1596
|
-
return callee.type ===
|
|
1785
|
+
return callee.type === import_utils17.AST_NODE_TYPES.MemberExpression && WRAPPERS.has(import_utils17.ASTUtils.getPropertyName(callee) ?? "") && openSchema(callee.object, seen);
|
|
1597
1786
|
}
|
|
1598
1787
|
function factory(node) {
|
|
1599
1788
|
node = unwrapExpression(node);
|
|
1600
|
-
if (node.type ===
|
|
1789
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1601
1790
|
const definition2 = binding3(node)?.defs[0]?.node;
|
|
1602
|
-
if (definition2?.type !==
|
|
1603
|
-
return definition2.imported.type ===
|
|
1791
|
+
if (definition2?.type !== import_utils17.AST_NODE_TYPES.ImportSpecifier || definition2.parent.type !== import_utils17.AST_NODE_TYPES.ImportDeclaration || definition2.importKind === "type" || definition2.parent.importKind === "type" || !isZodModule(definition2.parent.source.value)) return null;
|
|
1792
|
+
return definition2.imported.type === import_utils17.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value;
|
|
1604
1793
|
}
|
|
1605
|
-
if (node.type !==
|
|
1794
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.MemberExpression) return null;
|
|
1606
1795
|
const receiver = unwrapExpression(node.object);
|
|
1607
|
-
if (receiver.type !==
|
|
1796
|
+
if (receiver.type !== import_utils17.AST_NODE_TYPES.Identifier) return null;
|
|
1608
1797
|
const definition = binding3(receiver)?.defs[0]?.node;
|
|
1609
|
-
if (definition === void 0 || definition.type !==
|
|
1610
|
-
if (definition.type ===
|
|
1611
|
-
return
|
|
1798
|
+
if (definition === void 0 || definition.type !== import_utils17.AST_NODE_TYPES.ImportSpecifier && definition.type !== import_utils17.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils17.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1799
|
+
if (definition.type === import_utils17.AST_NODE_TYPES.ImportSpecifier && (definition.importKind === "type" || (definition.imported.type === import_utils17.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z")) return null;
|
|
1800
|
+
return import_utils17.ASTUtils.getPropertyName(node);
|
|
1612
1801
|
}
|
|
1613
1802
|
const reported = /* @__PURE__ */ new Set();
|
|
1614
1803
|
return {
|
|
1615
1804
|
MemberExpression(node) {
|
|
1616
|
-
const field =
|
|
1805
|
+
const field = import_utils17.ASTUtils.getPropertyName(node);
|
|
1617
1806
|
if (field === null) return;
|
|
1618
1807
|
const call = parser(node.object);
|
|
1619
1808
|
if (call === null || reported.has(call)) return;
|
|
@@ -1625,7 +1814,7 @@ var no_generic_json_parser_default = createRule({
|
|
|
1625
1814
|
});
|
|
1626
1815
|
|
|
1627
1816
|
// src/rules/no-redundant-local-alias.ts
|
|
1628
|
-
var
|
|
1817
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
1629
1818
|
var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
1630
1819
|
defaultLevel: "warning",
|
|
1631
1820
|
summary: "Pass the original local into an object field instead of creating a single-use rename.",
|
|
@@ -1644,7 +1833,7 @@ var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
|
1644
1833
|
function stableSource(variable, alias) {
|
|
1645
1834
|
const definition = variable.defs[0];
|
|
1646
1835
|
if (variable.defs.length !== 1 || definition === void 0 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
1647
|
-
return definition.type === "Parameter" || definition.node.type ===
|
|
1836
|
+
return definition.type === "Parameter" || definition.node.type === import_utils18.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < alias.range[0];
|
|
1648
1837
|
}
|
|
1649
1838
|
var no_redundant_local_alias_default = createRule({
|
|
1650
1839
|
name: "no-redundant-local-alias",
|
|
@@ -1660,18 +1849,18 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1660
1849
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1661
1850
|
return {
|
|
1662
1851
|
VariableDeclarator(node) {
|
|
1663
|
-
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !==
|
|
1852
|
+
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !== import_utils18.AST_NODE_TYPES.Identifier || node.id.typeAnnotation !== void 0 || node.init?.type !== import_utils18.AST_NODE_TYPES.Identifier) return;
|
|
1664
1853
|
const scope = context.sourceCode.getScope(node);
|
|
1665
1854
|
if (scope.variableScope.type !== "function") return;
|
|
1666
|
-
const target =
|
|
1667
|
-
const source =
|
|
1855
|
+
const target = import_utils18.ASTUtils.findVariable(scope, node.id.name);
|
|
1856
|
+
const source = import_utils18.ASTUtils.findVariable(scope, node.init.name);
|
|
1668
1857
|
if (target === null || source === null || !stableSource(source, node)) return;
|
|
1669
1858
|
const reads = target.references.filter((reference) => reference.isRead());
|
|
1670
1859
|
if (reads.length !== 1 || target.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
1671
1860
|
const read = reads[0];
|
|
1672
1861
|
if (read === void 0 || read.from.variableScope !== scope.variableScope) return;
|
|
1673
1862
|
const property = read.identifier.parent;
|
|
1674
|
-
if (property.type !==
|
|
1863
|
+
if (property.type !== import_utils18.AST_NODE_TYPES.Property || !property.shorthand || property.value !== read.identifier || property.parent.type !== import_utils18.AST_NODE_TYPES.ObjectExpression || property.computed || property.method || property.kind !== "init") return;
|
|
1675
1864
|
context.report({ node, messageId: "redundantAlias", data: { source: node.init.name, target: node.id.name } });
|
|
1676
1865
|
}
|
|
1677
1866
|
};
|
|
@@ -1679,10 +1868,10 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1679
1868
|
});
|
|
1680
1869
|
|
|
1681
1870
|
// src/rules/no-test-comments.ts
|
|
1682
|
-
var
|
|
1871
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
1683
1872
|
|
|
1684
1873
|
// src/rules/_comments.ts
|
|
1685
|
-
var
|
|
1874
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
1686
1875
|
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/;
|
|
1687
1876
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
1688
1877
|
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/;
|
|
@@ -1768,10 +1957,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
1768
1957
|
var NARRATION_MIN_CONTENT = 1;
|
|
1769
1958
|
var TOKEN_PLURAL_MIN = 4;
|
|
1770
1959
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1960
|
+
import_utils19.AST_NODE_TYPES.ExpressionStatement,
|
|
1961
|
+
import_utils19.AST_NODE_TYPES.ReturnStatement,
|
|
1962
|
+
import_utils19.AST_NODE_TYPES.ThrowStatement,
|
|
1963
|
+
import_utils19.AST_NODE_TYPES.VariableDeclaration
|
|
1775
1964
|
]);
|
|
1776
1965
|
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;
|
|
1777
1966
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -1830,12 +2019,12 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
1830
2019
|
function restatableStatementNodeBelow(comment, sourceCode) {
|
|
1831
2020
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
1832
2021
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
1833
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
2022
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils19.AST_NODE_TYPES.Program; node = node.parent) {
|
|
1834
2023
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
1835
2024
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
1836
2025
|
return null;
|
|
1837
2026
|
}
|
|
1838
|
-
if (node.type ===
|
|
2027
|
+
if (node.type === import_utils19.AST_NODE_TYPES.VariableDeclaration && isTrivialInitializer(node)) {
|
|
1839
2028
|
return null;
|
|
1840
2029
|
}
|
|
1841
2030
|
return node;
|
|
@@ -1845,8 +2034,8 @@ function restatableStatementNodeBelow(comment, sourceCode) {
|
|
|
1845
2034
|
function isTrivialInitializer(node) {
|
|
1846
2035
|
return node.declarations.every((declarator) => {
|
|
1847
2036
|
const init = declarator.init;
|
|
1848
|
-
if (init == null || init.type ===
|
|
1849
|
-
return init.type ===
|
|
2037
|
+
if (init == null || init.type === import_utils19.AST_NODE_TYPES.Literal) return true;
|
|
2038
|
+
return init.type === import_utils19.AST_NODE_TYPES.ArrayExpression && init.elements.length === 0 || init.type === import_utils19.AST_NODE_TYPES.ObjectExpression && init.properties.length === 0;
|
|
1850
2039
|
});
|
|
1851
2040
|
}
|
|
1852
2041
|
function restatesStatementHead(body3, statement) {
|
|
@@ -1873,7 +2062,7 @@ function headTokens(source) {
|
|
|
1873
2062
|
}
|
|
1874
2063
|
|
|
1875
2064
|
// src/rules/_comment-edits.ts
|
|
1876
|
-
var
|
|
2065
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
1877
2066
|
function physicalLineEnd(text, offset) {
|
|
1878
2067
|
const newline = text.indexOf("\n", offset);
|
|
1879
2068
|
return newline < 0 ? text.length : newline;
|
|
@@ -2000,7 +2189,7 @@ var no_test_comments_default = createRule({
|
|
|
2000
2189
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2001
2190
|
const filename = scopedFilename(context);
|
|
2002
2191
|
const unambiguous = /(?:^|\/)(?:tests?|__tests__|fixtures|__fixtures__|__mocks__)\//u.test(filename) || /\.(?:test|spec|e2e|integration)\.[cm]?[jt]sx?$/u.test(filename);
|
|
2003
|
-
const framework = context.sourceCode.ast.body.some((statement) => statement.type ===
|
|
2192
|
+
const framework = context.sourceCode.ast.body.some((statement) => statement.type === import_utils21.AST_NODE_TYPES.ImportDeclaration && statement.importKind !== "type" && (statement.specifiers.length === 0 || statement.specifiers.some((specifier) => specifier.type !== import_utils21.AST_NODE_TYPES.ImportSpecifier || specifier.importKind !== "type")) && ["vitest", "@jest/globals", "@playwright/test", "bun:test", "node:test"].includes(statement.source.value));
|
|
2004
2193
|
if (!unambiguous && !framework) return {};
|
|
2005
2194
|
return {
|
|
2006
2195
|
Program() {
|
|
@@ -2050,14 +2239,14 @@ var no_test_comments_default = createRule({
|
|
|
2050
2239
|
});
|
|
2051
2240
|
|
|
2052
2241
|
// src/rules/no-mutating-container-transform.ts
|
|
2053
|
-
var
|
|
2242
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
2054
2243
|
var MUTATORS = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
2055
2244
|
var PRIMITIVES = /* @__PURE__ */ new Set([
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2245
|
+
import_utils22.AST_NODE_TYPES.TSStringKeyword,
|
|
2246
|
+
import_utils22.AST_NODE_TYPES.TSNumberKeyword,
|
|
2247
|
+
import_utils22.AST_NODE_TYPES.TSBooleanKeyword,
|
|
2248
|
+
import_utils22.AST_NODE_TYPES.TSBigIntKeyword,
|
|
2249
|
+
import_utils22.AST_NODE_TYPES.TSSymbolKeyword
|
|
2061
2250
|
]);
|
|
2062
2251
|
var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
2063
2252
|
defaultLevel: "warning",
|
|
@@ -2076,27 +2265,27 @@ var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
|
2076
2265
|
]
|
|
2077
2266
|
};
|
|
2078
2267
|
function arrayElement(node, sourceCode) {
|
|
2079
|
-
if (node.type ===
|
|
2080
|
-
if (node.type ===
|
|
2268
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSArrayType) return node.elementType;
|
|
2269
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && (node.typeName.name === "Array" || node.typeName.name === "ReadonlyArray") && (import_utils22.ASTUtils.findVariable(sourceCode.getScope(node.typeName), node.typeName.name)?.defs.length ?? 0) === 0 && node.typeArguments?.params.length === 1) return node.typeArguments.params[0] ?? null;
|
|
2081
2270
|
return null;
|
|
2082
2271
|
}
|
|
2083
2272
|
function returnsArray(node, sourceCode) {
|
|
2084
2273
|
let annotation = node.returnType?.typeAnnotation;
|
|
2085
|
-
if (annotation?.type ===
|
|
2274
|
+
if (annotation?.type === import_utils22.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Promise" && (import_utils22.ASTUtils.findVariable(sourceCode.getScope(annotation.typeName), "Promise")?.defs.length ?? 0) === 0 && annotation.typeArguments?.params.length === 1) annotation = annotation.typeArguments.params[0];
|
|
2086
2275
|
return annotation !== void 0 && arrayElement(annotation, sourceCode) !== null;
|
|
2087
2276
|
}
|
|
2088
2277
|
function supported(statements) {
|
|
2089
2278
|
return statements.every((statement) => {
|
|
2090
2279
|
switch (statement.type) {
|
|
2091
|
-
case
|
|
2092
|
-
case
|
|
2093
|
-
case
|
|
2094
|
-
case
|
|
2095
|
-
case
|
|
2280
|
+
case import_utils22.AST_NODE_TYPES.ExpressionStatement:
|
|
2281
|
+
case import_utils22.AST_NODE_TYPES.VariableDeclaration:
|
|
2282
|
+
case import_utils22.AST_NODE_TYPES.ReturnStatement:
|
|
2283
|
+
case import_utils22.AST_NODE_TYPES.ThrowStatement:
|
|
2284
|
+
case import_utils22.AST_NODE_TYPES.EmptyStatement:
|
|
2096
2285
|
return true;
|
|
2097
|
-
case
|
|
2286
|
+
case import_utils22.AST_NODE_TYPES.BlockStatement:
|
|
2098
2287
|
return supported(statement.body);
|
|
2099
|
-
case
|
|
2288
|
+
case import_utils22.AST_NODE_TYPES.IfStatement:
|
|
2100
2289
|
return supported([statement.consequent]) && (statement.alternate === null || supported([statement.alternate]));
|
|
2101
2290
|
default:
|
|
2102
2291
|
return false;
|
|
@@ -2117,13 +2306,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2117
2306
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2118
2307
|
const sourceCode = context.sourceCode;
|
|
2119
2308
|
function binding3(node) {
|
|
2120
|
-
return node.type ===
|
|
2309
|
+
return node.type === import_utils22.AST_NODE_TYPES.Identifier ? import_utils22.ASTUtils.findVariable(sourceCode.getScope(node), node.name) : null;
|
|
2121
2310
|
}
|
|
2122
2311
|
function inspect(node) {
|
|
2123
|
-
if (node.body?.type !==
|
|
2312
|
+
if (node.body?.type !== import_utils22.AST_NODE_TYPES.BlockStatement || !returnsArray(node, sourceCode) || !supported(node.body.body)) return;
|
|
2124
2313
|
const initial = /* @__PURE__ */ new Map();
|
|
2125
2314
|
for (const parameter of node.params) {
|
|
2126
|
-
if (parameter.type !==
|
|
2315
|
+
if (parameter.type !== import_utils22.AST_NODE_TYPES.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
2127
2316
|
const element = arrayElement(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
2128
2317
|
const variable = binding3(parameter);
|
|
2129
2318
|
if (element !== null && PRIMITIVES.has(element.type) && variable !== null) initial.set(variable, parameter.name);
|
|
@@ -2136,26 +2325,26 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2136
2325
|
}
|
|
2137
2326
|
function expression(current, state) {
|
|
2138
2327
|
switch (current.type) {
|
|
2139
|
-
case
|
|
2140
|
-
case
|
|
2141
|
-
case
|
|
2328
|
+
case import_utils22.AST_NODE_TYPES.FunctionExpression:
|
|
2329
|
+
case import_utils22.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
2330
|
+
case import_utils22.AST_NODE_TYPES.ClassExpression:
|
|
2142
2331
|
return;
|
|
2143
|
-
case
|
|
2332
|
+
case import_utils22.AST_NODE_TYPES.AssignmentExpression:
|
|
2144
2333
|
assignment(current, state);
|
|
2145
2334
|
return;
|
|
2146
|
-
case
|
|
2335
|
+
case import_utils22.AST_NODE_TYPES.LogicalExpression:
|
|
2147
2336
|
logical(current, state);
|
|
2148
2337
|
return;
|
|
2149
|
-
case
|
|
2338
|
+
case import_utils22.AST_NODE_TYPES.ConditionalExpression:
|
|
2150
2339
|
conditional(current, state);
|
|
2151
2340
|
return;
|
|
2152
|
-
case
|
|
2341
|
+
case import_utils22.AST_NODE_TYPES.UpdateExpression:
|
|
2153
2342
|
write(current.argument, state);
|
|
2154
2343
|
break;
|
|
2155
|
-
case
|
|
2344
|
+
case import_utils22.AST_NODE_TYPES.UnaryExpression:
|
|
2156
2345
|
if (current.operator === "delete") write(current.argument, state);
|
|
2157
2346
|
break;
|
|
2158
|
-
case
|
|
2347
|
+
case import_utils22.AST_NODE_TYPES.CallExpression:
|
|
2159
2348
|
mutationCall(current, state);
|
|
2160
2349
|
break;
|
|
2161
2350
|
default:
|
|
@@ -2175,13 +2364,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2175
2364
|
function logical(current, state) {
|
|
2176
2365
|
expression(current.left, state);
|
|
2177
2366
|
const left = unwrapExpression(current.left);
|
|
2178
|
-
if (left.type ===
|
|
2367
|
+
if (left.type === import_utils22.AST_NODE_TYPES.Literal && (current.operator === "&&" && !left.value || current.operator === "||" && !!left.value || current.operator === "??" && left.value !== null)) return;
|
|
2179
2368
|
expression(current.right, state);
|
|
2180
2369
|
}
|
|
2181
2370
|
function conditional(current, state) {
|
|
2182
2371
|
expression(current.test, state);
|
|
2183
2372
|
const test = unwrapExpression(current.test);
|
|
2184
|
-
if (test.type ===
|
|
2373
|
+
if (test.type === import_utils22.AST_NODE_TYPES.Literal) {
|
|
2185
2374
|
expression(test.value ? current.consequent : current.alternate, state);
|
|
2186
2375
|
return;
|
|
2187
2376
|
}
|
|
@@ -2189,13 +2378,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2189
2378
|
expression(current.alternate, state);
|
|
2190
2379
|
}
|
|
2191
2380
|
function mutationCall(current, state) {
|
|
2192
|
-
if (current.callee.type !==
|
|
2381
|
+
if (current.callee.type !== import_utils22.AST_NODE_TYPES.MemberExpression || !MUTATORS.has(import_utils22.ASTUtils.getPropertyName(current.callee) ?? "")) return;
|
|
2193
2382
|
const parameter = origin(current.callee.object, state);
|
|
2194
2383
|
if (parameter !== void 0 && first === null) first = { node: current, parameter };
|
|
2195
2384
|
}
|
|
2196
2385
|
function write(target, state) {
|
|
2197
2386
|
target = unwrapExpression(target);
|
|
2198
|
-
if (target.type !==
|
|
2387
|
+
if (target.type !== import_utils22.AST_NODE_TYPES.MemberExpression || !target.computed && import_utils22.ASTUtils.getPropertyName(target) !== "length") return;
|
|
2199
2388
|
const parameter = origin(target.object, state);
|
|
2200
2389
|
if (parameter !== void 0 && first === null) first = { node: target, parameter };
|
|
2201
2390
|
}
|
|
@@ -2205,18 +2394,18 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2205
2394
|
}
|
|
2206
2395
|
function statement(current, state) {
|
|
2207
2396
|
switch (current.type) {
|
|
2208
|
-
case
|
|
2397
|
+
case import_utils22.AST_NODE_TYPES.BlockStatement:
|
|
2209
2398
|
return statements(current.body, state);
|
|
2210
|
-
case
|
|
2399
|
+
case import_utils22.AST_NODE_TYPES.IfStatement:
|
|
2211
2400
|
return branch(current, state);
|
|
2212
|
-
case
|
|
2401
|
+
case import_utils22.AST_NODE_TYPES.VariableDeclaration:
|
|
2213
2402
|
declarations(current, state);
|
|
2214
2403
|
return false;
|
|
2215
|
-
case
|
|
2216
|
-
case
|
|
2404
|
+
case import_utils22.AST_NODE_TYPES.ReturnStatement:
|
|
2405
|
+
case import_utils22.AST_NODE_TYPES.ThrowStatement:
|
|
2217
2406
|
if (current.argument !== null) expression(current.argument, state);
|
|
2218
2407
|
return true;
|
|
2219
|
-
case
|
|
2408
|
+
case import_utils22.AST_NODE_TYPES.ExpressionStatement:
|
|
2220
2409
|
expression(current.expression, state);
|
|
2221
2410
|
return false;
|
|
2222
2411
|
default:
|
|
@@ -2225,7 +2414,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2225
2414
|
}
|
|
2226
2415
|
function branch(current, state) {
|
|
2227
2416
|
expression(current.test, state);
|
|
2228
|
-
if (current.test.type ===
|
|
2417
|
+
if (current.test.type === import_utils22.AST_NODE_TYPES.Literal) return current.test.value ? statements([current.consequent], state) : current.alternate !== null && statements([current.alternate], state);
|
|
2229
2418
|
const left = new Map(state);
|
|
2230
2419
|
const right = new Map(state);
|
|
2231
2420
|
const leftEnds = statements([current.consequent], left);
|
|
@@ -2257,7 +2446,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2257
2446
|
});
|
|
2258
2447
|
|
|
2259
2448
|
// src/rules/no-redundant-consumer-union.ts
|
|
2260
|
-
var
|
|
2449
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
2261
2450
|
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
2262
2451
|
|
|
2263
2452
|
// src/rules/_checked-native-source.ts
|
|
@@ -2368,11 +2557,11 @@ function finiteMember(member3, checker) {
|
|
|
2368
2557
|
}
|
|
2369
2558
|
|
|
2370
2559
|
// src/rules/_private-consumer-fix.ts
|
|
2371
|
-
var
|
|
2560
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
2372
2561
|
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
2373
2562
|
|
|
2374
2563
|
// src/rules/_type-binding.ts
|
|
2375
|
-
var
|
|
2564
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
2376
2565
|
function typeBinding(source, identifier) {
|
|
2377
2566
|
let scope = source.getScope(identifier);
|
|
2378
2567
|
while (scope !== null) {
|
|
@@ -2398,12 +2587,12 @@ function retainsNamedTypeUses(source, removed) {
|
|
|
2398
2587
|
function publicTypeUse(identifier) {
|
|
2399
2588
|
let node = identifier;
|
|
2400
2589
|
while (node.parent) {
|
|
2401
|
-
if (node.type ===
|
|
2402
|
-
if (node.type ===
|
|
2403
|
-
return node.parent.type ===
|
|
2590
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils23.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils23.AST_NODE_TYPES.TSAsExpression || node.type === import_utils23.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
2591
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
2592
|
+
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2404
2593
|
}
|
|
2405
|
-
if (node.type ===
|
|
2406
|
-
return node.parent.type ===
|
|
2594
|
+
if (node.type === import_utils23.AST_NODE_TYPES.ExportSpecifier) {
|
|
2595
|
+
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2407
2596
|
}
|
|
2408
2597
|
node = node.parent;
|
|
2409
2598
|
}
|
|
@@ -2417,8 +2606,8 @@ function insideTypeRange(node, range) {
|
|
|
2417
2606
|
var UNSAFE = import_typescript3.default.TypeFlags.Any | import_typescript3.default.TypeFlags.Unknown | import_typescript3.default.TypeFlags.Never | import_typescript3.default.TypeFlags.TypeParameter | import_typescript3.default.TypeFlags.Conditional | import_typescript3.default.TypeFlags.IndexedAccess | import_typescript3.default.TypeFlags.Substitution;
|
|
2418
2607
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
2419
2608
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
2420
|
-
const owner = node.type ===
|
|
2421
|
-
if (owner.type !==
|
|
2609
|
+
const owner = node.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
2610
|
+
if (owner.type !== import_utils24.AST_NODE_TYPES.FunctionDeclaration && owner.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator) return false;
|
|
2422
2611
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
2423
2612
|
if (!binding3) return false;
|
|
2424
2613
|
const checker = services.program.getTypeChecker();
|
|
@@ -2436,7 +2625,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
2436
2625
|
continue;
|
|
2437
2626
|
}
|
|
2438
2627
|
const call = reference.identifier.parent;
|
|
2439
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2628
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils24.AST_NODE_TYPES.CallExpression || call.callee !== reference.identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils24.AST_NODE_TYPES.Identifier) return false;
|
|
2440
2629
|
const argument = services.esTreeNodeToTSNodeMap.get(call.arguments[0]);
|
|
2441
2630
|
const type = checker.getTypeAtLocation(argument);
|
|
2442
2631
|
if (!knownArgument(type, argument, fields2, checker) || !checker.isTypeAssignableTo(type, original)) return false;
|
|
@@ -2491,7 +2680,7 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
2491
2680
|
}
|
|
2492
2681
|
|
|
2493
2682
|
// src/rules/_private-scalar-consumer.ts
|
|
2494
|
-
var
|
|
2683
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2495
2684
|
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
2496
2685
|
|
|
2497
2686
|
// src/rules/_scalar-parameter-view.ts
|
|
@@ -2637,31 +2826,11 @@ function intrinsicAttribute(attribute, view) {
|
|
|
2637
2826
|
return import_typescript5.default.isJsxAttribute(attribute) && import_typescript5.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
2638
2827
|
}
|
|
2639
2828
|
|
|
2640
|
-
// src/rules/_stable-value-binding.ts
|
|
2641
|
-
var import_utils22 = require("@typescript-eslint/utils");
|
|
2642
|
-
function typeOnlyReference(reference) {
|
|
2643
|
-
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
2644
|
-
let current = outerExpression(reference.identifier);
|
|
2645
|
-
while (current.parent?.type === import_utils22.AST_NODE_TYPES.TSQualifiedName && current.parent.left === current) {
|
|
2646
|
-
current = current.parent;
|
|
2647
|
-
}
|
|
2648
|
-
return current.parent?.type === import_utils22.AST_NODE_TYPES.TSTypeQuery && current.parent.exprName === current;
|
|
2649
|
-
}
|
|
2650
|
-
function stableValueBinding(variable, acceptRead) {
|
|
2651
|
-
let initializer;
|
|
2652
|
-
return variable.references.every((reference) => {
|
|
2653
|
-
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
2654
|
-
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
2655
|
-
initializer = reference.identifier;
|
|
2656
|
-
return true;
|
|
2657
|
-
});
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
2829
|
// src/rules/_private-scalar-consumer.ts
|
|
2661
2830
|
function directEval(node) {
|
|
2662
2831
|
let callee = unwrapExpression(node.callee);
|
|
2663
|
-
while (callee.type ===
|
|
2664
|
-
return callee.type ===
|
|
2832
|
+
while (callee.type === import_utils25.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
2833
|
+
return callee.type === import_utils25.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
2665
2834
|
}
|
|
2666
2835
|
function primitiveKeyword(node) {
|
|
2667
2836
|
return node !== void 0 && (node.kind === import_typescript6.default.SyntaxKind.StringKeyword || node.kind === import_typescript6.default.SyntaxKind.NumberKeyword || node.kind === import_typescript6.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript6.default.SyntaxKind.BigIntKeyword);
|
|
@@ -2672,7 +2841,7 @@ function nullishPrimitiveUnion(node) {
|
|
|
2672
2841
|
function consumerAnnotation(node) {
|
|
2673
2842
|
if (node.params.length !== 1) return void 0;
|
|
2674
2843
|
const parameter = node.params[0];
|
|
2675
|
-
return parameter?.type ===
|
|
2844
|
+
return parameter?.type === import_utils25.AST_NODE_TYPES.Identifier || parameter?.type === import_utils25.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
2676
2845
|
}
|
|
2677
2846
|
function exportedSymbols(source, checker) {
|
|
2678
2847
|
const symbol = checker.getSymbolAtLocation(source);
|
|
@@ -2703,12 +2872,12 @@ function independentSignature(native) {
|
|
|
2703
2872
|
return parameter !== void 0 && parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!import_typescript6.default.isIdentifier(parameter.name) || parameter.name.text !== "this");
|
|
2704
2873
|
}
|
|
2705
2874
|
function callableBinding(node, sourceCode) {
|
|
2706
|
-
if (node.type ===
|
|
2707
|
-
if (node.parent.type !==
|
|
2875
|
+
if (node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
2876
|
+
if (node.parent.type !== import_utils25.AST_NODE_TYPES.Program) return void 0;
|
|
2708
2877
|
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
2709
2878
|
}
|
|
2710
2879
|
const declaration = node.parent;
|
|
2711
|
-
if (declaration.type !==
|
|
2880
|
+
if (declaration.type !== import_utils25.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils25.AST_NODE_TYPES.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== import_utils25.AST_NODE_TYPES.Program) return void 0;
|
|
2712
2881
|
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
2713
2882
|
}
|
|
2714
2883
|
function directCalls(binding3) {
|
|
@@ -2716,7 +2885,7 @@ function directCalls(binding3) {
|
|
|
2716
2885
|
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
2717
2886
|
const identifier = reference.identifier;
|
|
2718
2887
|
const call = identifier.parent;
|
|
2719
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2888
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils25.AST_NODE_TYPES.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils25.AST_NODE_TYPES.Identifier) return false;
|
|
2720
2889
|
calls += 1;
|
|
2721
2890
|
return true;
|
|
2722
2891
|
});
|
|
@@ -2727,6 +2896,7 @@ function directCalls(binding3) {
|
|
|
2727
2896
|
var CONFIG = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
2728
2897
|
var EXAMPLE = 'export {}; interface Animal {readonly name: string} interface Dog extends Animal {readonly breed: string} export type KeptDog = Dog; const dog: Dog = {name: "Ada", breed: "Collie"}; function label(value: Dog | Animal): string {return value.name;} label(dog);';
|
|
2729
2898
|
var NULLABLE_EXAMPLE = EXAMPLE.replace("readonly name: string", "readonly name: string | null").replace("return value.name;", "return value.name ?? '';");
|
|
2899
|
+
var OPTIONAL_EXAMPLE = EXAMPLE.replace("readonly breed: string", "readonly breed?: string");
|
|
2730
2900
|
var NO_REDUNDANT_CONSUMER_UNION_DOCUMENTATION = {
|
|
2731
2901
|
defaultLevel: "warning",
|
|
2732
2902
|
summary: "Keep the covering object contract in a private scalar consumer union.",
|
|
@@ -2738,12 +2908,14 @@ var NO_REDUNDANT_CONSUMER_UNION_DOCUMENTATION = {
|
|
|
2738
2908
|
"Automatic fixes additionally require every existing identifier caller to be natively assignable to the original contract, without Any, unknown, error or unresolved types on the relevant surface. Comments inside the annotation and TypeScript suppression directives keep the finding manual. Removed named types/imports must retain an independent top-level exported type-alias or direct type-export read. Other removable annotations/assertions, the covering annotation and own-definition/self references cannot keep one another live; otherwise simultaneous fixes can introduce unused-type errors. The exact authored covering type and terminator token sequence are retained; edits that would merge distinct CR and LF terminators remain manual; no producer, call or function body is rewritten.",
|
|
2739
2909
|
"Only an inline binary parameter union in a strict module's top-level private scalar consumer is supported. Exactly one parameter, an explicit broad primitive return annotation, a single pure returned scalar expression and direct identifier-argument callers are required. Type queries or type-only exports of the callable, public APIs, callbacks, contextual signatures, overloads, generics, decorators, async functions, direct eval and fresh-object callers prevent findings.",
|
|
2740
2910
|
"Both alternatives must have complete ordinary finite structural surfaces consisting only of explicitly readonly broad string, number, boolean or bigint properties, optionally paired directly with null or undefined in an exact two-part union. Required and optional nullable fields may be read under the same native coverage proof. Every field must have one actual declaration origin throughout each alternative's inheritance/intersection graph. Shared ancestors retain that origin; repeated merged fields, explicit overrides and independently declared overlapping fields abstain, including valid compatible declarations. This excludes recovered conflicting properties without claiming whole-source health. Aliases, imports, re-exports and ordinary inheritance are resolved by the parser-owned TypeScript checker. Any, unknown, missing imports, open/generic/mapped/indexed types, classes, brands, literal discriminants, methods, properties with scalar type aliases, parenthesized or more complex property unions, callbacks and recursive or nested object fields are unsupported.",
|
|
2741
|
-
"Reports
|
|
2911
|
+
"Reports proper native assignability, where covered is assignable to covering and the reverse is false, or mutual native assignability with a strict smaller declared covering surface and only optional covered-only members. Every covering member, including optional members, must exist in the covered type's enumerated declared surface. Otherwise an existing identifier may carry an incompatible extra field and be rejected after simplification; implicit Object members containing Any cannot replace explicit declared coverage or the native Optional requirement. The covering type must declare every read field and a read required field; an all-optional reduced contract can reject existing callers. Identical alternatives and primitive/top/bottom redundancy remain upstream-owned; equal-key and incomparable mutually assignable structures are excluded. The mutual case additionally requires inline contracts or locally bound interfaces/type aliases whose alias and heritage references can be traced through the parser-owned type scope. Merged interface fragments must all resolve to the reference's same native symbol; mixed exported/local recovery abstains. Imported, global and qualified-namespace references in that path abstain; proper one-way coverage retains its existing alias/import support.",
|
|
2742
2912
|
"General union simplification can change Extract, conditional types, in-narrowing, fresh-literal checking and public presentation. Those contexts are excluded even when ordinary assignment succeeds. Flat destructuring counts every bound field as read; whole-object escape, mutation, helpers, closures, reflection, serialization, dynamic reads, implicit Object capabilities and JSX prevent findings. Imported Python protocol assignability is not approximated by this rule."
|
|
2743
2913
|
],
|
|
2744
2914
|
examples: [
|
|
2745
2915
|
{ id: "covered-alternative", title: "The private consumer needs the covering Animal contract", outcome: "match", files: [{ path: "src/case.ts", source: EXAMPLE }, CONFIG], focusPath: "src/case.ts", expectedCount: 1, public: true, fixedFiles: [{ path: "src/case.ts", source: EXAMPLE.replace("Dog | Animal", "Animal") }] },
|
|
2746
2916
|
{ id: "public-contract", title: "A public union retains its observable alternatives", outcome: "no-match", files: [{ path: "src/case.ts", source: EXAMPLE.replace("function label", "export function label") }, CONFIG], focusPath: "src/case.ts", expectedCount: 0, public: true },
|
|
2917
|
+
{ id: "optional-covered-alternative", scenarioId: "optional-readonly-contract", title: "An unread optional breed retains the smaller Animal surface", outcome: "match", files: [{ path: "src/case.ts", source: OPTIONAL_EXAMPLE }, CONFIG], focusPath: "src/case.ts", expectedCount: 1, public: true, fixedFiles: [{ path: "src/case.ts", source: OPTIONAL_EXAMPLE.replace("Dog | Animal", "Animal") }] },
|
|
2918
|
+
{ id: "optional-public-contract", scenarioId: "optional-readonly-contract", title: "A public optional union retains its observable alternatives", outcome: "no-match", files: [{ path: "src/case.ts", source: OPTIONAL_EXAMPLE.replace("function label", "export function label") }, CONFIG], focusPath: "src/case.ts", expectedCount: 0, public: true },
|
|
2747
2919
|
{ id: "nullable-covered-alternative", scenarioId: "nullable-readonly-contract", title: "A nullable name retains the covering Animal contract", outcome: "match", files: [{ path: "src/case.ts", source: NULLABLE_EXAMPLE }, CONFIG], focusPath: "src/case.ts", expectedCount: 1, public: true, fixedFiles: [{ path: "src/case.ts", source: NULLABLE_EXAMPLE.replace("Dog | Animal", "Animal") }] },
|
|
2748
2920
|
{ id: "nullable-domain-contract", scenarioId: "nullable-readonly-contract", title: "A literal breed keeps the authored domain contract", outcome: "no-match", files: [{ path: "src/case.ts", source: NULLABLE_EXAMPLE.replace("readonly breed: string", "readonly breed: 'Collie'") }, CONFIG], focusPath: "src/case.ts", expectedCount: 0, public: true }
|
|
2749
2921
|
]
|
|
@@ -2758,6 +2930,68 @@ function scalarFields(type, checker) {
|
|
|
2758
2930
|
}
|
|
2759
2931
|
return fields2.size ? fields2 : null;
|
|
2760
2932
|
}
|
|
2933
|
+
function localContractBindings(roots, source, services) {
|
|
2934
|
+
const pending = [...roots];
|
|
2935
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2936
|
+
for (let index = 0; index < pending.length; index++) {
|
|
2937
|
+
const node = pending[index];
|
|
2938
|
+
if (!node || visited.has(node)) continue;
|
|
2939
|
+
visited.add(node);
|
|
2940
|
+
const references = localContractReferences(node, source, services);
|
|
2941
|
+
if (references === null) return false;
|
|
2942
|
+
pending.push(...references);
|
|
2943
|
+
}
|
|
2944
|
+
return true;
|
|
2945
|
+
}
|
|
2946
|
+
function localContractReferences(node, source, services) {
|
|
2947
|
+
switch (node.type) {
|
|
2948
|
+
case import_utils26.AST_NODE_TYPES.TSTypeLiteral:
|
|
2949
|
+
return [];
|
|
2950
|
+
case import_utils26.AST_NODE_TYPES.TSIntersectionType:
|
|
2951
|
+
return node.types;
|
|
2952
|
+
case import_utils26.AST_NODE_TYPES.TSTypeReference:
|
|
2953
|
+
return !node.typeArguments && node.typeName.type === import_utils26.AST_NODE_TYPES.Identifier ? [node.typeName] : null;
|
|
2954
|
+
case import_utils26.AST_NODE_TYPES.Identifier:
|
|
2955
|
+
return localBindingReferences(node, source, services);
|
|
2956
|
+
default:
|
|
2957
|
+
return null;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
function localBindingReferences(identifier, source, services) {
|
|
2961
|
+
const definitions2 = typeBinding(source, identifier)?.defs.filter((definition) => definition.isTypeDefinition).map((definition) => definition.node);
|
|
2962
|
+
if (!definitions2?.length || !definitions2.every(moduleTypeDeclaration)) return null;
|
|
2963
|
+
const first = definitions2[0];
|
|
2964
|
+
if (definitions2.length === 1 && first?.type === import_utils26.AST_NODE_TYPES.TSTypeAliasDeclaration && !first.typeParameters) return [first.typeAnnotation];
|
|
2965
|
+
const interfaces = definitions2.filter((definition) => definition.type === import_utils26.AST_NODE_TYPES.TSInterfaceDeclaration);
|
|
2966
|
+
if (interfaces.length !== definitions2.length || interfaces.some((declaration) => declaration.typeParameters)) return null;
|
|
2967
|
+
if (interfaces.length > 1) {
|
|
2968
|
+
const checker = services.program.getTypeChecker();
|
|
2969
|
+
const symbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(identifier));
|
|
2970
|
+
if (!symbol || interfaces.some((declaration) => checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(declaration.id)) !== symbol)) return null;
|
|
2971
|
+
}
|
|
2972
|
+
const bases = interfaces.flatMap((declaration) => declaration.extends.map((base) => base.expression));
|
|
2973
|
+
return bases.every((base) => base.type === import_utils26.AST_NODE_TYPES.Identifier) ? bases : null;
|
|
2974
|
+
}
|
|
2975
|
+
function moduleTypeDeclaration(node) {
|
|
2976
|
+
const parent = node.parent;
|
|
2977
|
+
if (parent?.type === import_utils26.AST_NODE_TYPES.Program) return true;
|
|
2978
|
+
if (parent?.type !== import_utils26.AST_NODE_TYPES.ExportNamedDeclaration && parent?.type !== import_utils26.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
2979
|
+
return parent.parent.type === import_utils26.AST_NODE_TYPES.Program;
|
|
2980
|
+
}
|
|
2981
|
+
function coveringAlternative(leftNode, rightNode, checker, fieldsOf, reads) {
|
|
2982
|
+
const left = checker.getTypeFromTypeNode(leftNode);
|
|
2983
|
+
const right = checker.getTypeFromTypeNode(rightNode);
|
|
2984
|
+
const leftFields = fieldsOf(left);
|
|
2985
|
+
const rightFields = fieldsOf(right);
|
|
2986
|
+
if (!leftFields || !rightFields) return null;
|
|
2987
|
+
const forward = checker.isTypeAssignableTo(left, right);
|
|
2988
|
+
const reverse = checker.isTypeAssignableTo(right, left);
|
|
2989
|
+
const mutual = forward && reverse;
|
|
2990
|
+
if (!forward && !reverse || mutual && leftFields.size === rightFields.size) return null;
|
|
2991
|
+
const [covered2, covering, coveredFields, coveringFields] = forward && (!reverse || leftFields.size > rightFields.size) ? [leftNode, rightNode, leftFields, rightFields] : [rightNode, leftNode, rightFields, leftFields];
|
|
2992
|
+
if ([...coveringFields.keys()].some((key) => !coveredFields.has(key)) || mutual && [...coveredFields].some(([key, required]) => required && !coveringFields.has(key)) || [...reads].some((key) => !coveringFields.has(key)) || ![...reads].some((key) => coveringFields.get(key))) return null;
|
|
2993
|
+
return { covered: covered2, covering, mutual };
|
|
2994
|
+
}
|
|
2761
2995
|
function privateUnionFix(sourceCode, services, proof) {
|
|
2762
2996
|
const covering = services.tsNodeToESTreeNodeMap.get(proof.covering);
|
|
2763
2997
|
if (!validConsumerFixCalls(proof.candidate, proof.parameter, sourceCode, services)) return null;
|
|
@@ -2777,7 +3011,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2777
3011
|
let dynamic = false;
|
|
2778
3012
|
const remember = (node) => {
|
|
2779
3013
|
const annotation = consumerAnnotation(node);
|
|
2780
|
-
if (annotation?.type ===
|
|
3014
|
+
if (annotation?.type === import_utils26.AST_NODE_TYPES.TSUnionType && annotation.types.length === 2) candidates.push(node);
|
|
2781
3015
|
};
|
|
2782
3016
|
return {
|
|
2783
3017
|
FunctionDeclaration: remember,
|
|
@@ -2787,7 +3021,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2787
3021
|
},
|
|
2788
3022
|
"Program:exit"() {
|
|
2789
3023
|
if (dynamic || !candidates.length) return;
|
|
2790
|
-
const services =
|
|
3024
|
+
const services = import_utils26.ESLintUtils.getParserServices(context);
|
|
2791
3025
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2792
3026
|
if (!source) return;
|
|
2793
3027
|
const checker = services.program.getTypeChecker();
|
|
@@ -2808,17 +3042,11 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2808
3042
|
const leftNode = annotation.types[0];
|
|
2809
3043
|
const rightNode = annotation.types[1];
|
|
2810
3044
|
if (!leftNode || !rightNode) continue;
|
|
2811
|
-
const
|
|
2812
|
-
|
|
2813
|
-
const leftFields = fieldsOf(left);
|
|
2814
|
-
const rightFields = fieldsOf(right);
|
|
2815
|
-
if (!leftFields || !rightFields) continue;
|
|
2816
|
-
const forward = checker.isTypeAssignableTo(left, right);
|
|
2817
|
-
const reverse = checker.isTypeAssignableTo(right, left);
|
|
2818
|
-
if (forward === reverse) continue;
|
|
2819
|
-
const [coveredNode, coveringNode, coveredFields, coveringFields] = forward ? [leftNode, rightNode, leftFields, rightFields] : [rightNode, leftNode, rightFields, leftFields];
|
|
2820
|
-
if ([...coveringFields.keys()].some((key) => !coveredFields.has(key)) || [...consumer.reads].some((key) => !coveringFields.has(key)) || ![...consumer.reads].some((key) => coveringFields.get(key))) continue;
|
|
3045
|
+
const coverage = coveringAlternative(leftNode, rightNode, checker, fieldsOf, consumer.reads);
|
|
3046
|
+
if (!coverage) continue;
|
|
2821
3047
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
3048
|
+
if (coverage.mutual && (reportNode.type !== import_utils26.AST_NODE_TYPES.TSUnionType || !localContractBindings(reportNode.types, context.sourceCode, services))) continue;
|
|
3049
|
+
const { covered: coveredNode, covering: coveringNode } = coverage;
|
|
2822
3050
|
const fix = privateUnionFix(context.sourceCode, services, {
|
|
2823
3051
|
candidate: candidate2,
|
|
2824
3052
|
parameter: consumer.parameter,
|
|
@@ -2835,7 +3063,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2835
3063
|
});
|
|
2836
3064
|
|
|
2837
3065
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
2838
|
-
var
|
|
3066
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
2839
3067
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
2840
3068
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
2841
3069
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
@@ -2886,7 +3114,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2886
3114
|
const candidates = [];
|
|
2887
3115
|
let dynamic = false;
|
|
2888
3116
|
const remember = (node) => {
|
|
2889
|
-
if (consumerAnnotation(node)?.type ===
|
|
3117
|
+
if (consumerAnnotation(node)?.type === import_utils27.AST_NODE_TYPES.TSTypeLiteral) candidates.push(node);
|
|
2890
3118
|
};
|
|
2891
3119
|
return {
|
|
2892
3120
|
FunctionDeclaration: remember,
|
|
@@ -2896,7 +3124,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2896
3124
|
},
|
|
2897
3125
|
"Program:exit"() {
|
|
2898
3126
|
if (dynamic || !candidates.length) return;
|
|
2899
|
-
const services =
|
|
3127
|
+
const services = import_utils27.ESLintUtils.getParserServices(context);
|
|
2900
3128
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2901
3129
|
if (!source) return;
|
|
2902
3130
|
const checker = services.program.getTypeChecker();
|
|
@@ -2920,7 +3148,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2920
3148
|
});
|
|
2921
3149
|
|
|
2922
3150
|
// src/rules/no-excess-jsx-props.ts
|
|
2923
|
-
var
|
|
3151
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
2924
3152
|
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
2925
3153
|
|
|
2926
3154
|
// src/rules/_ordinary-object-effects.ts
|
|
@@ -3262,11 +3490,11 @@ var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3262
3490
|
function plainLiteralFields(node) {
|
|
3263
3491
|
const fields2 = /* @__PURE__ */ new Map();
|
|
3264
3492
|
for (const property of node.properties) {
|
|
3265
|
-
if (property.type !==
|
|
3493
|
+
if (property.type !== import_utils28.AST_NODE_TYPES.Property || property.kind !== "init") return null;
|
|
3266
3494
|
const key = property.key;
|
|
3267
3495
|
let name;
|
|
3268
|
-
if (!property.computed && key.type ===
|
|
3269
|
-
else if (key.type ===
|
|
3496
|
+
if (!property.computed && key.type === import_utils28.AST_NODE_TYPES.Identifier) name = key.name;
|
|
3497
|
+
else if (key.type === import_utils28.AST_NODE_TYPES.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
3270
3498
|
else return null;
|
|
3271
3499
|
if (name === "__proto__") return null;
|
|
3272
3500
|
fields2.set(name, property);
|
|
@@ -3378,35 +3606,35 @@ function localObjectFields(symbol, source, proof) {
|
|
|
3378
3606
|
if (!native || native.getSourceFile() !== source || !initializer || !import_typescript10.default.isObjectLiteralExpression(initializer)) return null;
|
|
3379
3607
|
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
3380
3608
|
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
3381
|
-
if (declaration.type !==
|
|
3609
|
+
if (declaration.type !== import_utils28.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.id.type !== import_utils28.AST_NODE_TYPES.Identifier || literal2.type !== import_utils28.AST_NODE_TYPES.ObjectExpression || declaration.parent.parent.type === import_utils28.AST_NODE_TYPES.ExportNamedDeclaration) return null;
|
|
3382
3610
|
const fields2 = plainLiteralFields(literal2);
|
|
3383
3611
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3384
3612
|
if (!fields2 || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
3385
3613
|
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
3386
3614
|
const member3 = reference.identifier.parent;
|
|
3387
|
-
return member3.type ===
|
|
3615
|
+
return member3.type === import_utils28.AST_NODE_TYPES.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields2);
|
|
3388
3616
|
})) return null;
|
|
3389
3617
|
return fields2;
|
|
3390
3618
|
}
|
|
3391
3619
|
function staticMemberKey(member3) {
|
|
3392
3620
|
const property = member3.property;
|
|
3393
|
-
return !member3.computed && property.type ===
|
|
3621
|
+
return !member3.computed && property.type === import_utils28.AST_NODE_TYPES.Identifier ? property.name : property.type === import_utils28.AST_NODE_TYPES.Literal && (typeof property.value === "string" || typeof property.value === "number") ? String(property.value) : void 0;
|
|
3394
3622
|
}
|
|
3395
3623
|
function readonlyFieldValue(member3, fields2) {
|
|
3396
3624
|
const key = staticMemberKey(member3);
|
|
3397
3625
|
if (key === void 0 || !fields2.has(key)) return false;
|
|
3398
3626
|
const parent = member3.parent;
|
|
3399
|
-
if (parent.type ===
|
|
3627
|
+
if (parent.type === import_utils28.AST_NODE_TYPES.Property && parent.value === member3 && parent.parent.type === import_utils28.AST_NODE_TYPES.ObjectExpression) {
|
|
3400
3628
|
const object = parent.parent;
|
|
3401
3629
|
const owner = object.parent;
|
|
3402
|
-
return owner.type ===
|
|
3630
|
+
return owner.type === import_utils28.AST_NODE_TYPES.JSXSpreadAttribute && owner.argument === object || owner.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && owner.init === object;
|
|
3403
3631
|
}
|
|
3404
|
-
return parent.type ===
|
|
3632
|
+
return parent.type === import_utils28.AST_NODE_TYPES.JSXExpressionContainer && parent.expression === member3 || parent.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && parent.init === member3;
|
|
3405
3633
|
}
|
|
3406
3634
|
function privateElementDeclaration(opening) {
|
|
3407
3635
|
const value = outerExpression(opening.parent);
|
|
3408
3636
|
const declaration = value.parent;
|
|
3409
|
-
return declaration.type ===
|
|
3637
|
+
return declaration.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && declaration.init === value && declaration.id.type === import_utils28.AST_NODE_TYPES.Identifier && declaration.parent.kind === "const" && declaration.parent.parent.type !== import_utils28.AST_NODE_TYPES.ExportNamedDeclaration ? declaration : null;
|
|
3410
3638
|
}
|
|
3411
3639
|
function closedElementValue(opening, declaration, fields2, reads, proof) {
|
|
3412
3640
|
if (!proof.staticScope || !closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
@@ -3432,10 +3660,10 @@ function closedInvocation(node, proof) {
|
|
|
3432
3660
|
}
|
|
3433
3661
|
function independentInvocation(scope, proof) {
|
|
3434
3662
|
const block = scope.block;
|
|
3435
|
-
if (block.type !==
|
|
3663
|
+
if (block.type !== import_utils28.AST_NODE_TYPES.ArrowFunctionExpression && block.type !== import_utils28.AST_NODE_TYPES.FunctionDeclaration && block.type !== import_utils28.AST_NODE_TYPES.FunctionExpression) return false;
|
|
3436
3664
|
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3437
3665
|
for (const parameter of block.params) {
|
|
3438
|
-
if (parameter.type !==
|
|
3666
|
+
if (parameter.type !== import_utils28.AST_NODE_TYPES.Identifier || parameter.name === "this") return false;
|
|
3439
3667
|
const binding3 = scope.set.get(parameter.name);
|
|
3440
3668
|
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3441
3669
|
}
|
|
@@ -3443,16 +3671,16 @@ function independentInvocation(scope, proof) {
|
|
|
3443
3671
|
if (typeOnlyReference(reference)) return true;
|
|
3444
3672
|
const value = outerExpression(reference.identifier);
|
|
3445
3673
|
const parent = value.parent;
|
|
3446
|
-
const read = parent?.type ===
|
|
3674
|
+
const read = parent?.type === import_utils28.AST_NODE_TYPES.MemberExpression && parent.object === value ? parent : value;
|
|
3447
3675
|
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
3448
3676
|
});
|
|
3449
3677
|
}
|
|
3450
3678
|
function consumedElementRead(node, fields2, reads) {
|
|
3451
3679
|
const identifier = outerExpression(node);
|
|
3452
3680
|
const props = identifier.parent;
|
|
3453
|
-
if (!props || props.type !==
|
|
3681
|
+
if (!props || props.type !== import_utils28.AST_NODE_TYPES.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
3454
3682
|
const member3 = props.parent;
|
|
3455
|
-
if (member3.type !==
|
|
3683
|
+
if (member3.type !== import_utils28.AST_NODE_TYPES.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
3456
3684
|
const key = staticMemberKey(member3);
|
|
3457
3685
|
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields2);
|
|
3458
3686
|
}
|
|
@@ -3480,7 +3708,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3480
3708
|
const evaluate = (node, declaration, fields2) => {
|
|
3481
3709
|
const keys = [...fields2.keys()];
|
|
3482
3710
|
const opening = node.parent;
|
|
3483
|
-
services ??=
|
|
3711
|
+
services ??= import_utils28.ESLintUtils.getParserServices(context);
|
|
3484
3712
|
standardJSX ??= supportedJSX(services.program.getCompilerOptions(), context.sourceCode.getAllComments());
|
|
3485
3713
|
if (!standardJSX) return;
|
|
3486
3714
|
const checker = services.program.getTypeChecker();
|
|
@@ -3513,9 +3741,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3513
3741
|
};
|
|
3514
3742
|
return {
|
|
3515
3743
|
JSXSpreadAttribute(node) {
|
|
3516
|
-
if (node.argument.type !==
|
|
3744
|
+
if (node.argument.type !== import_utils28.AST_NODE_TYPES.ObjectExpression) return;
|
|
3517
3745
|
const opening = node.parent;
|
|
3518
|
-
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !==
|
|
3746
|
+
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== import_utils28.AST_NODE_TYPES.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
3519
3747
|
const declaration = privateElementDeclaration(opening);
|
|
3520
3748
|
if (!declaration) return;
|
|
3521
3749
|
const fields2 = literalFields(node.argument);
|
|
@@ -3527,7 +3755,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3527
3755
|
},
|
|
3528
3756
|
"Program:exit"() {
|
|
3529
3757
|
if (!candidates.length) return;
|
|
3530
|
-
services =
|
|
3758
|
+
services = import_utils28.ESLintUtils.getParserServices(context);
|
|
3531
3759
|
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
3532
3760
|
for (const { node, declaration, fields: fields2 } of candidates) evaluate(node, declaration, fields2);
|
|
3533
3761
|
}
|
|
@@ -3536,7 +3764,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3536
3764
|
});
|
|
3537
3765
|
|
|
3538
3766
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3539
|
-
var
|
|
3767
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
3540
3768
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3541
3769
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3542
3770
|
defaultLevel: "warning",
|
|
@@ -3600,19 +3828,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3600
3828
|
});
|
|
3601
3829
|
function hasUseServerDirective(program) {
|
|
3602
3830
|
for (const statement of program.body) {
|
|
3603
|
-
if (statement.type !==
|
|
3831
|
+
if (statement.type !== import_utils29.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0) return false;
|
|
3604
3832
|
if (statement.directive === "use server") return true;
|
|
3605
3833
|
}
|
|
3606
3834
|
return false;
|
|
3607
3835
|
}
|
|
3608
3836
|
function isTypeOnly(node) {
|
|
3609
3837
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3610
|
-
(specifier) => specifier.type ===
|
|
3838
|
+
(specifier) => specifier.type === import_utils29.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3611
3839
|
);
|
|
3612
3840
|
}
|
|
3613
3841
|
|
|
3614
3842
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3615
|
-
var
|
|
3843
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3616
3844
|
|
|
3617
3845
|
// src/rules/_secret-names.ts
|
|
3618
3846
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -3756,54 +3984,10 @@ function isAuthSecretName(identifier) {
|
|
|
3756
3984
|
return hasApiKey(tokens);
|
|
3757
3985
|
}
|
|
3758
3986
|
|
|
3759
|
-
// src/rules/_static-string.ts
|
|
3760
|
-
var import_utils28 = require("@typescript-eslint/utils");
|
|
3761
|
-
function staticString(node) {
|
|
3762
|
-
if (node === void 0) return null;
|
|
3763
|
-
const value = unwrapExpression(node);
|
|
3764
|
-
if (value.type === import_utils28.AST_NODE_TYPES.Literal && typeof value.value === "string") return value.value;
|
|
3765
|
-
return value.type === import_utils28.AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
3766
|
-
}
|
|
3767
|
-
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
3768
|
-
function scopedStaticString(node, sourceCode) {
|
|
3769
|
-
let value = unwrapExpression(node);
|
|
3770
|
-
if (value.type !== import_utils28.AST_NODE_TYPES.Identifier) return staticString(value);
|
|
3771
|
-
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
3772
|
-
if (values === void 0) {
|
|
3773
|
-
values = /* @__PURE__ */ new WeakMap();
|
|
3774
|
-
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
3775
|
-
}
|
|
3776
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3777
|
-
const pending = [];
|
|
3778
|
-
let result = null;
|
|
3779
|
-
while (value.type === import_utils28.AST_NODE_TYPES.Identifier) {
|
|
3780
|
-
const binding3 = import_utils28.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
3781
|
-
if (binding3 === null || seen.has(binding3)) break;
|
|
3782
|
-
if (values.has(binding3)) {
|
|
3783
|
-
result = values.get(binding3) ?? null;
|
|
3784
|
-
break;
|
|
3785
|
-
}
|
|
3786
|
-
seen.add(binding3);
|
|
3787
|
-
pending.push(binding3);
|
|
3788
|
-
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
3789
|
-
if (definition?.type !== "Variable" || definition.node.id.type !== import_utils28.AST_NODE_TYPES.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
3790
|
-
value = unwrapExpression(definition.node.init);
|
|
3791
|
-
if (value.type !== import_utils28.AST_NODE_TYPES.Identifier) result = staticString(value);
|
|
3792
|
-
}
|
|
3793
|
-
for (const binding3 of pending) values.set(binding3, result);
|
|
3794
|
-
return result;
|
|
3795
|
-
}
|
|
3796
|
-
function staticPropertyName(node, sourceCode) {
|
|
3797
|
-
const direct = import_utils28.ASTUtils.getPropertyName(node);
|
|
3798
|
-
if (direct !== null || !node.computed) return direct;
|
|
3799
|
-
const key = node.type === import_utils28.AST_NODE_TYPES.MemberExpression ? node.property : node.key;
|
|
3800
|
-
return scopedStaticString(key, sourceCode);
|
|
3801
|
-
}
|
|
3802
|
-
|
|
3803
3987
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3804
3988
|
var STORAGE_NAMES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
3805
3989
|
var METADATA_WORDS = /* @__PURE__ */ new Set(["page", "cursor", "next", "hint", "expires", "expiry", "expiration"]);
|
|
3806
|
-
var
|
|
3990
|
+
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
3807
3991
|
var NO_CREDENTIAL_IN_BROWSER_STORAGE_DOCUMENTATION = {
|
|
3808
3992
|
defaultLevel: "warning",
|
|
3809
3993
|
summary: "Do not write credential-named values to browser storage or script-readable cookies.",
|
|
@@ -3861,7 +4045,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3861
4045
|
return {
|
|
3862
4046
|
CallExpression(node) {
|
|
3863
4047
|
const callee = unwrapExpression(node.callee);
|
|
3864
|
-
if (callee.type !==
|
|
4048
|
+
if (callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils30.AST_NODE_TYPES.Identifier || callee.property.name !== "setItem" || !isStorage(sourceCode, callee.object)) {
|
|
3865
4049
|
return;
|
|
3866
4050
|
}
|
|
3867
4051
|
const [key] = node.arguments;
|
|
@@ -3869,12 +4053,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3869
4053
|
},
|
|
3870
4054
|
AssignmentExpression(node) {
|
|
3871
4055
|
const target = node.left;
|
|
3872
|
-
if (target.type !==
|
|
4056
|
+
if (target.type !== import_utils30.AST_NODE_TYPES.MemberExpression) return;
|
|
3873
4057
|
if (isStorage(sourceCode, target.object)) {
|
|
3874
4058
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
3875
4059
|
return;
|
|
3876
4060
|
}
|
|
3877
|
-
if (!target.computed && target.property.type ===
|
|
4061
|
+
if (!target.computed && target.property.type === import_utils30.AST_NODE_TYPES.Identifier && target.property.name === "cookie" && globalMemberName(sourceCode, target.object) === "document") {
|
|
3878
4062
|
report2(node, cookieName(node.right));
|
|
3879
4063
|
}
|
|
3880
4064
|
}
|
|
@@ -3887,34 +4071,34 @@ function isStorage(sourceCode, node) {
|
|
|
3887
4071
|
}
|
|
3888
4072
|
function globalMemberName(sourceCode, node) {
|
|
3889
4073
|
const value = unwrapExpression(node);
|
|
3890
|
-
if (value.type ===
|
|
3891
|
-
if (value.type ===
|
|
4074
|
+
if (value.type === import_utils30.AST_NODE_TYPES.Identifier) return isUnshadowed(sourceCode, value) ? value.name : null;
|
|
4075
|
+
if (value.type === import_utils30.AST_NODE_TYPES.MemberExpression && !value.computed && value.object.type === import_utils30.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(value.object.name) && value.property.type === import_utils30.AST_NODE_TYPES.Identifier && isUnshadowed(sourceCode, value.object)) {
|
|
3892
4076
|
return value.property.name;
|
|
3893
4077
|
}
|
|
3894
4078
|
return null;
|
|
3895
4079
|
}
|
|
3896
4080
|
function isUnshadowed(sourceCode, node) {
|
|
3897
|
-
const variable =
|
|
4081
|
+
const variable = import_utils30.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3898
4082
|
return variable === null || variable.defs.length === 0;
|
|
3899
4083
|
}
|
|
3900
4084
|
function storedPropertyKey(sourceCode, target) {
|
|
3901
|
-
if (!target.computed) return target.property.type ===
|
|
4085
|
+
if (!target.computed) return target.property.type === import_utils30.AST_NODE_TYPES.Identifier ? target.property.name : null;
|
|
3902
4086
|
return scopedStaticString(target.property, sourceCode);
|
|
3903
4087
|
}
|
|
3904
4088
|
function cookieName(value) {
|
|
3905
4089
|
let expression = unwrapExpression(value);
|
|
3906
|
-
while (expression.type ===
|
|
4090
|
+
while (expression.type === import_utils30.AST_NODE_TYPES.BinaryExpression && expression.operator === "+") {
|
|
3907
4091
|
expression = unwrapExpression(expression.left);
|
|
3908
4092
|
}
|
|
3909
4093
|
let text = null;
|
|
3910
|
-
if (expression.type ===
|
|
3911
|
-
if (expression.type ===
|
|
4094
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.Literal && typeof expression.value === "string") text = expression.value;
|
|
4095
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.TemplateLiteral) text = expression.quasis[0]?.value.cooked ?? null;
|
|
3912
4096
|
if (text === null || !text.includes("=")) return null;
|
|
3913
4097
|
return text.slice(0, text.indexOf("=")).trim();
|
|
3914
4098
|
}
|
|
3915
4099
|
|
|
3916
4100
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
3917
|
-
var
|
|
4101
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3918
4102
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
3919
4103
|
var NUMBER_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat"]);
|
|
3920
4104
|
var SEARCH_PARAM_TYPES = /* @__PURE__ */ new Set(["URLSearchParams", "ReadonlyURLSearchParams"]);
|
|
@@ -3971,7 +4155,7 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
3971
4155
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context)) return {};
|
|
3972
4156
|
let services;
|
|
3973
4157
|
try {
|
|
3974
|
-
services =
|
|
4158
|
+
services = import_utils31.ESLintUtils.getParserServices(context);
|
|
3975
4159
|
} catch {
|
|
3976
4160
|
services = null;
|
|
3977
4161
|
}
|
|
@@ -3993,27 +4177,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
3993
4177
|
}
|
|
3994
4178
|
});
|
|
3995
4179
|
function isNumericParser(sourceCode, callee) {
|
|
3996
|
-
if (callee.type ===
|
|
4180
|
+
if (callee.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
3997
4181
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
3998
4182
|
}
|
|
3999
|
-
return callee.type ===
|
|
4183
|
+
return callee.type === import_utils31.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils31.AST_NODE_TYPES.Identifier && callee.object.name === "Number" && callee.property.type === import_utils31.AST_NODE_TYPES.Identifier && NUMBER_PARSERS.has(callee.property.name) && isUnshadowedGlobal(sourceCode, callee.object);
|
|
4000
4184
|
}
|
|
4001
4185
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4002
|
-
const variable =
|
|
4186
|
+
const variable = import_utils31.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4003
4187
|
return variable === null || variable.defs.length === 0;
|
|
4004
4188
|
}
|
|
4005
4189
|
function searchParamGetCall(argument) {
|
|
4006
4190
|
let value = unwrapExpression(argument);
|
|
4007
|
-
if (value.type ===
|
|
4008
|
-
if (value.type ===
|
|
4009
|
-
if (value.type ===
|
|
4010
|
-
if (value.type !==
|
|
4191
|
+
if (value.type === import_utils31.AST_NODE_TYPES.AwaitExpression) value = unwrapExpression(value.argument);
|
|
4192
|
+
if (value.type === import_utils31.AST_NODE_TYPES.LogicalExpression && value.operator === "??") value = unwrapExpression(value.left);
|
|
4193
|
+
if (value.type === import_utils31.AST_NODE_TYPES.ChainExpression) value = value.expression;
|
|
4194
|
+
if (value.type !== import_utils31.AST_NODE_TYPES.CallExpression || value.callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression || value.callee.computed || value.callee.property.type !== import_utils31.AST_NODE_TYPES.Identifier || value.callee.property.name !== "get") {
|
|
4011
4195
|
return null;
|
|
4012
4196
|
}
|
|
4013
4197
|
return value;
|
|
4014
4198
|
}
|
|
4015
4199
|
function isSearchParamReceiver(call, services) {
|
|
4016
|
-
if (call.callee.type !==
|
|
4200
|
+
if (call.callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression) return false;
|
|
4017
4201
|
const checker = services.program.getTypeChecker();
|
|
4018
4202
|
const type = checker.getNonNullableType(
|
|
4019
4203
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4025,7 +4209,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4025
4209
|
// package.json
|
|
4026
4210
|
var package_default = {
|
|
4027
4211
|
name: "@sarj/eslint-plugin",
|
|
4028
|
-
version: "16.
|
|
4212
|
+
version: "16.38.50",
|
|
4029
4213
|
packageManager: "npm@12.2.1",
|
|
4030
4214
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4031
4215
|
type: "module",
|
|
@@ -4147,11 +4331,11 @@ var package_default = {
|
|
|
4147
4331
|
};
|
|
4148
4332
|
|
|
4149
4333
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4150
|
-
var
|
|
4334
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4151
4335
|
var ts12 = __toESM(require("typescript"), 1);
|
|
4152
4336
|
|
|
4153
4337
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4154
|
-
var
|
|
4338
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4155
4339
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
4156
4340
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
4157
4341
|
const source = call.getSourceFile();
|
|
@@ -4225,7 +4409,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4225
4409
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4226
4410
|
rejected.expression.expression.getStart()
|
|
4227
4411
|
);
|
|
4228
|
-
return identifier?.type ===
|
|
4412
|
+
return identifier?.type === import_utils32.AST_NODE_TYPES.Identifier && identifier.name === "TypeError" && (import_utils32.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
4229
4413
|
}
|
|
4230
4414
|
function exactConstruction(node, consumer, implementation) {
|
|
4231
4415
|
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4591,7 +4775,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4591
4775
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
4592
4776
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
4593
4777
|
return {};
|
|
4594
|
-
const services =
|
|
4778
|
+
const services = import_utils33.ESLintUtils.getParserServices(context);
|
|
4595
4779
|
const checker = services.program.getTypeChecker();
|
|
4596
4780
|
function inspect(node) {
|
|
4597
4781
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -4606,7 +4790,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4606
4790
|
return;
|
|
4607
4791
|
const parameters = signature.getParameters();
|
|
4608
4792
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4609
|
-
if (argument.type !==
|
|
4793
|
+
if (argument.type !== import_utils33.AST_NODE_TYPES.NewExpression) continue;
|
|
4610
4794
|
const parameter = parameters[index];
|
|
4611
4795
|
if (parameter === void 0) continue;
|
|
4612
4796
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4653,18 +4837,18 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4653
4837
|
});
|
|
4654
4838
|
|
|
4655
4839
|
// src/rules/require-explicit-service-contract.ts
|
|
4656
|
-
var
|
|
4840
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
4657
4841
|
|
|
4658
4842
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4659
|
-
var
|
|
4843
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4660
4844
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4661
4845
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4662
4846
|
return null;
|
|
4663
4847
|
const [contractStatement, worker, classStatement, factoryStatement] = sourceCode.ast.body;
|
|
4664
|
-
const contract = contractStatement?.type ===
|
|
4665
|
-
const implementation = classStatement?.type ===
|
|
4666
|
-
const factory = factoryStatement?.type ===
|
|
4667
|
-
if (contract?.type !==
|
|
4848
|
+
const contract = contractStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? contractStatement.declaration : null;
|
|
4849
|
+
const implementation = classStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? classStatement.declaration : classStatement;
|
|
4850
|
+
const factory = factoryStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? factoryStatement.declaration : null;
|
|
4851
|
+
if (contract?.type !== import_utils34.AST_NODE_TYPES.TSTypeAliasDeclaration || worker?.type !== import_utils34.AST_NODE_TYPES.TSInterfaceDeclaration || implementation?.type !== import_utils34.AST_NODE_TYPES.ClassDeclaration || implementation !== candidate2 || !ordinaryClass(implementation) || !ordinaryFactory(factory))
|
|
4668
4852
|
return null;
|
|
4669
4853
|
const operation2 = contractOperation(contract);
|
|
4670
4854
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4683,17 +4867,17 @@ function ordinaryClass(node) {
|
|
|
4683
4867
|
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;
|
|
4684
4868
|
}
|
|
4685
4869
|
function ordinaryFactory(node) {
|
|
4686
|
-
return node?.type ===
|
|
4870
|
+
return node?.type === import_utils34.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && !node.declare && !node.async && !node.generator && node.typeParameters === void 0 && node.params.length === 1 && node.body.body.length === 1;
|
|
4687
4871
|
}
|
|
4688
4872
|
function interfaceOperation(node) {
|
|
4689
4873
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4690
4874
|
}
|
|
4691
4875
|
function contractOperation(node) {
|
|
4692
|
-
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type ===
|
|
4876
|
+
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type === import_utils34.AST_NODE_TYPES.TSTypeLiteral ? singletonOperation(node.typeAnnotation.members) : null;
|
|
4693
4877
|
}
|
|
4694
4878
|
function singletonOperation(members) {
|
|
4695
4879
|
const member3 = members[0];
|
|
4696
|
-
return members.length === 1 && member3?.type ===
|
|
4880
|
+
return members.length === 1 && member3?.type === import_utils34.AST_NODE_TYPES.TSMethodSignature && member3.kind === "method" && !member3.computed && !member3.optional && member3.key.type === import_utils34.AST_NODE_TYPES.Identifier && member3.params.length === 0 && member3.typeParameters === void 0 && member3.returnType?.typeAnnotation.type === import_utils34.AST_NODE_TYPES.TSVoidKeyword ? member3.key.name : null;
|
|
4697
4881
|
}
|
|
4698
4882
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4699
4883
|
const names = declarations.flatMap(
|
|
@@ -4704,7 +4888,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4704
4888
|
);
|
|
4705
4889
|
}
|
|
4706
4890
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4707
|
-
const binding3 =
|
|
4891
|
+
const binding3 = import_utils34.ASTUtils.findVariable(
|
|
4708
4892
|
sourceCode.getScope(reference),
|
|
4709
4893
|
reference.name
|
|
4710
4894
|
);
|
|
@@ -4712,45 +4896,45 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
4712
4896
|
}
|
|
4713
4897
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
4714
4898
|
const constructor = implementation.body.body[0];
|
|
4715
|
-
if (constructor?.type !==
|
|
4899
|
+
if (constructor?.type !== import_utils34.AST_NODE_TYPES.MethodDefinition || constructor.value.type !== import_utils34.AST_NODE_TYPES.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)
|
|
4716
4900
|
return null;
|
|
4717
4901
|
const property = constructor.value.params[0];
|
|
4718
|
-
if (property?.type !==
|
|
4902
|
+
if (property?.type !== import_utils34.AST_NODE_TYPES.TSParameterProperty || property.accessibility !== "private" || !property.readonly || property.override || property.decorators.length !== 0 || property.parameter.type !== import_utils34.AST_NODE_TYPES.Identifier || property.parameter.optional || !typeReference(sourceCode, property.parameter.typeAnnotation, worker))
|
|
4719
4903
|
return null;
|
|
4720
4904
|
return property.parameter.name;
|
|
4721
4905
|
}
|
|
4722
4906
|
function typeReference(sourceCode, annotation, declaration) {
|
|
4723
4907
|
const type = annotation?.typeAnnotation;
|
|
4724
|
-
return type?.type ===
|
|
4908
|
+
return type?.type === import_utils34.AST_NODE_TYPES.TSTypeReference && type.typeArguments === void 0 && type.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && sameBinding(sourceCode, type.typeName, declaration);
|
|
4725
4909
|
}
|
|
4726
4910
|
function forwardsOperation(implementation, field, operation2) {
|
|
4727
4911
|
const method = implementation.body.body[1];
|
|
4728
|
-
if (method?.type !==
|
|
4912
|
+
if (method?.type !== import_utils34.AST_NODE_TYPES.MethodDefinition || method.kind !== "method" || method.value.type !== import_utils34.AST_NODE_TYPES.FunctionExpression || method.computed || method.static || method.optional || method.override || method.decorators.length !== 0 || method.accessibility !== void 0 && method.accessibility !== "public" || method.key.type !== import_utils34.AST_NODE_TYPES.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 !== import_utils34.AST_NODE_TYPES.TSVoidKeyword)
|
|
4729
4913
|
return false;
|
|
4730
4914
|
const statement = method.value.body.body[0];
|
|
4731
|
-
const call = statement?.type ===
|
|
4732
|
-
return call?.type ===
|
|
4915
|
+
const call = statement?.type === import_utils34.AST_NODE_TYPES.ExpressionStatement ? statement.expression : null;
|
|
4916
|
+
return call?.type === import_utils34.AST_NODE_TYPES.CallExpression && !call.optional && call.typeArguments === void 0 && call.arguments.length === 0 && forwardedMember(call.callee, field, operation2);
|
|
4733
4917
|
}
|
|
4734
4918
|
function forwardedMember(node, field, operation2) {
|
|
4735
|
-
if (node.type !==
|
|
4919
|
+
if (node.type !== import_utils34.AST_NODE_TYPES.MemberExpression || node.computed || node.optional || node.property.type !== import_utils34.AST_NODE_TYPES.Identifier || node.property.name !== operation2)
|
|
4736
4920
|
return false;
|
|
4737
4921
|
const receiver = node.object;
|
|
4738
|
-
return receiver.type ===
|
|
4922
|
+
return receiver.type === import_utils34.AST_NODE_TYPES.MemberExpression && !receiver.computed && !receiver.optional && receiver.object.type === import_utils34.AST_NODE_TYPES.ThisExpression && receiver.property.type === import_utils34.AST_NODE_TYPES.Identifier && receiver.property.name === field;
|
|
4739
4923
|
}
|
|
4740
4924
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
4741
4925
|
const parameter = factory.params[0];
|
|
4742
|
-
if (parameter?.type !==
|
|
4926
|
+
if (parameter?.type !== import_utils34.AST_NODE_TYPES.Identifier || parameter.optional || !typeReference(sourceCode, parameter.typeAnnotation, worker) || !typeReference(sourceCode, factory.returnType, contract))
|
|
4743
4927
|
return false;
|
|
4744
4928
|
const statement = factory.body.body[0];
|
|
4745
|
-
const constructed = statement?.type ===
|
|
4746
|
-
if (constructed?.type !==
|
|
4929
|
+
const constructed = statement?.type === import_utils34.AST_NODE_TYPES.ReturnStatement ? statement.argument : null;
|
|
4930
|
+
if (constructed?.type !== import_utils34.AST_NODE_TYPES.NewExpression || constructed.typeArguments !== void 0 || constructed.callee.type !== import_utils34.AST_NODE_TYPES.Identifier || !sameBinding(sourceCode, constructed.callee, implementation) || constructed.arguments.length !== 1)
|
|
4747
4931
|
return false;
|
|
4748
4932
|
const argument = constructed.arguments[0];
|
|
4749
|
-
return argument?.type ===
|
|
4933
|
+
return argument?.type === import_utils34.AST_NODE_TYPES.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
4750
4934
|
}
|
|
4751
4935
|
|
|
4752
4936
|
// src/rules/require-port-for-service.ts
|
|
4753
|
-
var
|
|
4937
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4754
4938
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
4755
4939
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
4756
4940
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -4834,50 +5018,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
4834
5018
|
"||="
|
|
4835
5019
|
]);
|
|
4836
5020
|
var staticMemberName = (member3) => {
|
|
4837
|
-
if (member3.property.type ===
|
|
5021
|
+
if (member3.property.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier)
|
|
4838
5022
|
return `#${member3.property.name}`;
|
|
4839
|
-
return
|
|
5023
|
+
return import_utils35.ASTUtils.getPropertyName(member3);
|
|
4840
5024
|
};
|
|
4841
5025
|
var detachedValueExports = (program) => {
|
|
4842
5026
|
const names = /* @__PURE__ */ new Set();
|
|
4843
5027
|
for (const statement of program.body) {
|
|
4844
|
-
if (statement.type ===
|
|
5028
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
4845
5029
|
for (const specifier of statement.specifiers) {
|
|
4846
5030
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
4847
5031
|
}
|
|
4848
|
-
} else if (statement.type ===
|
|
5032
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4849
5033
|
names.add(statement.declaration.name);
|
|
4850
|
-
} else if (statement.type ===
|
|
5034
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4851
5035
|
names.add(statement.expression.name);
|
|
4852
5036
|
}
|
|
4853
5037
|
}
|
|
4854
5038
|
return names;
|
|
4855
5039
|
};
|
|
4856
|
-
var isExportedClass = (node, detached) => node.parent.type ===
|
|
5040
|
+
var isExportedClass = (node, detached) => node.parent.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
4857
5041
|
var createExportedServiceClassResolver = (program) => {
|
|
4858
5042
|
const detached = detachedValueExports(program);
|
|
4859
5043
|
return (node) => isExportedClass(node, detached);
|
|
4860
5044
|
};
|
|
4861
5045
|
var readTypeReference = (annotation) => {
|
|
4862
|
-
if (annotation?.type ===
|
|
5046
|
+
if (annotation?.type === import_utils35.AST_NODE_TYPES.TSUnionType) {
|
|
4863
5047
|
const members = annotation.types.filter(
|
|
4864
|
-
(member3) => member3.type !==
|
|
5048
|
+
(member3) => member3.type !== import_utils35.AST_NODE_TYPES.TSUndefinedKeyword && member3.type !== import_utils35.AST_NODE_TYPES.TSNullKeyword
|
|
4865
5049
|
);
|
|
4866
5050
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
4867
5051
|
}
|
|
4868
|
-
if (annotation === void 0 || annotation.type !==
|
|
5052
|
+
if (annotation === void 0 || annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference)
|
|
4869
5053
|
return null;
|
|
4870
5054
|
const { typeName } = annotation;
|
|
4871
|
-
const rightmost = typeName.type ===
|
|
5055
|
+
const rightmost = typeName.type === import_utils35.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils35.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
4872
5056
|
if (rightmost === null) return null;
|
|
4873
5057
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
4874
5058
|
};
|
|
4875
|
-
var qualifiedName = (name) => name.type ===
|
|
5059
|
+
var qualifiedName = (name) => name.type === import_utils35.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils35.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
4876
5060
|
var propertySignatureTypes = (members) => {
|
|
4877
5061
|
const types = /* @__PURE__ */ new Map();
|
|
4878
5062
|
for (const member3 of members) {
|
|
4879
|
-
if (member3.type !==
|
|
4880
|
-
if (member3.computed || member3.key.type !==
|
|
5063
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5064
|
+
if (member3.computed || member3.key.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
4881
5065
|
continue;
|
|
4882
5066
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
4883
5067
|
if (reference === null) continue;
|
|
@@ -4889,18 +5073,18 @@ var fileTypeIndex = (program) => {
|
|
|
4889
5073
|
const objects = /* @__PURE__ */ new Map();
|
|
4890
5074
|
const functionAliases = localFunctionAliases(program);
|
|
4891
5075
|
function collectDeclaredType(statement) {
|
|
4892
|
-
const declaration = statement.type ===
|
|
4893
|
-
if (declaration?.type ===
|
|
5076
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5077
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
4894
5078
|
objects.set(
|
|
4895
5079
|
declaration.id.name,
|
|
4896
5080
|
propertySignatureTypes(declaration.body.body)
|
|
4897
5081
|
);
|
|
4898
5082
|
return;
|
|
4899
5083
|
}
|
|
4900
|
-
if (declaration?.type !==
|
|
5084
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) return;
|
|
4901
5085
|
const aliased = declaration.typeAnnotation;
|
|
4902
|
-
const literals = aliased.type ===
|
|
4903
|
-
(part) => part.type ===
|
|
5086
|
+
const literals = aliased.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter(
|
|
5087
|
+
(part) => part.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral
|
|
4904
5088
|
) : [];
|
|
4905
5089
|
if (literals.length === 0) return;
|
|
4906
5090
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -4920,12 +5104,12 @@ function localFunctionAliases(program) {
|
|
|
4920
5104
|
const names = /* @__PURE__ */ new Set();
|
|
4921
5105
|
const parents = /* @__PURE__ */ new Map();
|
|
4922
5106
|
for (const statement of program.body) {
|
|
4923
|
-
const declaration = statement.type ===
|
|
4924
|
-
if (declaration?.type !==
|
|
5107
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5108
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
4925
5109
|
const annotation = declaration.typeAnnotation;
|
|
4926
|
-
if (annotation.type ===
|
|
5110
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSFunctionType || annotation.type === import_utils35.AST_NODE_TYPES.TSConstructorType)
|
|
4927
5111
|
names.add(declaration.id.name);
|
|
4928
|
-
if (annotation.type ===
|
|
5112
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
4929
5113
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
4930
5114
|
}
|
|
4931
5115
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -4961,32 +5145,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
4961
5145
|
function scanStoredFields(body4) {
|
|
4962
5146
|
const pending = [...body4.body];
|
|
4963
5147
|
function recordStoredField(current) {
|
|
4964
|
-
if (current.type ===
|
|
5148
|
+
if (current.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils35.AST_NODE_TYPES.ClassExpression || current.type === import_utils35.AST_NODE_TYPES.ClassDeclaration)
|
|
4965
5149
|
return;
|
|
4966
|
-
if (current.type ===
|
|
5150
|
+
if (current.type === import_utils35.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
4967
5151
|
localBindings2.add(current.id.name);
|
|
4968
|
-
const expression = current.type ===
|
|
5152
|
+
const expression = current.type === import_utils35.AST_NODE_TYPES.AssignmentExpression ? current : null;
|
|
4969
5153
|
const storedField = writtenInstanceField(current);
|
|
4970
5154
|
if (storedField !== null) {
|
|
4971
5155
|
if (writtenFieldNames.has(storedField))
|
|
4972
5156
|
unstableFieldNames.add(storedField);
|
|
4973
5157
|
writtenFieldNames.add(storedField);
|
|
4974
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5158
|
+
if (expression?.operator !== "=" || expression.parent.type !== import_utils35.AST_NODE_TYPES.ExpressionStatement || expression.parent.parent !== body4)
|
|
4975
5159
|
unstableFieldNames.add(storedField);
|
|
4976
5160
|
}
|
|
4977
|
-
if (expression?.type !==
|
|
5161
|
+
if (expression?.type !== import_utils35.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils35.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils35.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
4978
5162
|
enqueueChildren(current);
|
|
4979
5163
|
return;
|
|
4980
5164
|
}
|
|
4981
5165
|
const source = unwrapExpression(expression.right);
|
|
4982
|
-
if (source.type ===
|
|
5166
|
+
if (source.type === import_utils35.AST_NODE_TYPES.NewExpression) {
|
|
4983
5167
|
constructedFields += 1;
|
|
4984
5168
|
constructedFieldNames.add(storedField);
|
|
4985
|
-
} else if (source.type ===
|
|
5169
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4986
5170
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
4987
5171
|
fields2.add(storedField);
|
|
4988
5172
|
storedFieldsFrom.set(source.name, fields2);
|
|
4989
|
-
} else if (source.type ===
|
|
5173
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4990
5174
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
4991
5175
|
fields2.add(storedField);
|
|
4992
5176
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5021,7 +5205,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5021
5205
|
)) {
|
|
5022
5206
|
if (localBindings2.has(reference.name)) continue;
|
|
5023
5207
|
let fields2 = reference.fields;
|
|
5024
|
-
if (parameter.type ===
|
|
5208
|
+
if (parameter.type === import_utils35.AST_NODE_TYPES.TSParameterProperty) {
|
|
5025
5209
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5026
5210
|
fields2 = [reference.name];
|
|
5027
5211
|
} else if (fields2.length === 0)
|
|
@@ -5044,8 +5228,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5044
5228
|
};
|
|
5045
5229
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5046
5230
|
let target = parameter;
|
|
5047
|
-
if (target.type ===
|
|
5048
|
-
if (target.type ===
|
|
5231
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5232
|
+
if (target.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5049
5233
|
return objectPatternCollaborators(target, declared);
|
|
5050
5234
|
}
|
|
5051
5235
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5055,10 +5239,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5055
5239
|
};
|
|
5056
5240
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5057
5241
|
let target = annotated;
|
|
5058
|
-
if (target.type ===
|
|
5242
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5059
5243
|
target = target.parameter;
|
|
5060
|
-
if (target.type ===
|
|
5061
|
-
if (target.type !==
|
|
5244
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5245
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return [];
|
|
5062
5246
|
const members = bagMemberTypes(
|
|
5063
5247
|
target.typeAnnotation?.typeAnnotation,
|
|
5064
5248
|
declared
|
|
@@ -5077,10 +5261,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5077
5261
|
};
|
|
5078
5262
|
var namedParameterCollaborator = (annotated) => {
|
|
5079
5263
|
let target = annotated;
|
|
5080
|
-
if (target.type ===
|
|
5264
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5081
5265
|
target = target.parameter;
|
|
5082
|
-
if (target.type ===
|
|
5083
|
-
if (target.type !==
|
|
5266
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5267
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5084
5268
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5085
5269
|
if (reference === null) return null;
|
|
5086
5270
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5092,12 +5276,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5092
5276
|
if (members === null) return [];
|
|
5093
5277
|
const collaborators = [];
|
|
5094
5278
|
for (const property of pattern.properties) {
|
|
5095
|
-
if (property.type !==
|
|
5279
|
+
if (property.type !== import_utils35.AST_NODE_TYPES.Property || property.computed)
|
|
5096
5280
|
continue;
|
|
5097
|
-
if (property.key.type !==
|
|
5281
|
+
if (property.key.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5098
5282
|
const key = property.key.name;
|
|
5099
|
-
const bound = property.value.type ===
|
|
5100
|
-
if (bound.type !==
|
|
5283
|
+
const bound = property.value.type === import_utils35.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
5284
|
+
if (bound.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5101
5285
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5102
5286
|
const reference = members.get(key);
|
|
5103
5287
|
if (reference === void 0) continue;
|
|
@@ -5107,22 +5291,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5107
5291
|
};
|
|
5108
5292
|
var bagMemberTypes = (annotation, declared) => {
|
|
5109
5293
|
if (annotation === void 0) return null;
|
|
5110
|
-
if (annotation.type ===
|
|
5294
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5111
5295
|
return propertySignatureTypes(annotation.members);
|
|
5112
5296
|
}
|
|
5113
|
-
if (annotation.type !==
|
|
5297
|
+
if (annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5114
5298
|
return null;
|
|
5115
5299
|
}
|
|
5116
5300
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5117
5301
|
};
|
|
5118
5302
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5119
|
-
if (node.type ===
|
|
5303
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5120
5304
|
const { callee } = node;
|
|
5121
|
-
if (callee.type ===
|
|
5305
|
+
if (callee.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5122
5306
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5123
|
-
return callee.type ===
|
|
5307
|
+
return callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils35.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
5124
5308
|
}
|
|
5125
|
-
return node.type ===
|
|
5309
|
+
return node.type === import_utils35.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils35.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
5126
5310
|
});
|
|
5127
5311
|
var subtreeHas = (root, found) => {
|
|
5128
5312
|
let hit = false;
|
|
@@ -5142,26 +5326,26 @@ var subtreeHas = (root, found) => {
|
|
|
5142
5326
|
};
|
|
5143
5327
|
var invokedInstanceField = (call) => {
|
|
5144
5328
|
let callee = unwrapExpression(call.callee);
|
|
5145
|
-
while (callee.type ===
|
|
5329
|
+
while (callee.type === import_utils35.AST_NODE_TYPES.ChainExpression)
|
|
5146
5330
|
callee = unwrapExpression(callee.expression);
|
|
5147
5331
|
const direct = instanceField(callee);
|
|
5148
5332
|
if (direct !== null) return direct;
|
|
5149
|
-
return callee.type ===
|
|
5333
|
+
return callee.type === import_utils35.AST_NODE_TYPES.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5150
5334
|
};
|
|
5151
5335
|
var instanceField = (candidate2) => {
|
|
5152
5336
|
let node = candidate2;
|
|
5153
|
-
while (node.type ===
|
|
5337
|
+
while (node.type === import_utils35.AST_NODE_TYPES.ChainExpression || node.type === import_utils35.AST_NODE_TYPES.TSAsExpression || node.type === import_utils35.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils35.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils35.AST_NODE_TYPES.TSTypeAssertion)
|
|
5154
5338
|
node = node.expression;
|
|
5155
|
-
return node.type ===
|
|
5339
|
+
return node.type === import_utils35.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils35.AST_NODE_TYPES.ThisExpression ? staticMemberName(node) : null;
|
|
5156
5340
|
};
|
|
5157
5341
|
function writtenInstanceField(node) {
|
|
5158
|
-
if (node.type ===
|
|
5342
|
+
if (node.type === import_utils35.AST_NODE_TYPES.AssignmentExpression || node.type === import_utils35.AST_NODE_TYPES.ForOfStatement || node.type === import_utils35.AST_NODE_TYPES.ForInStatement)
|
|
5159
5343
|
return instanceField(node.left);
|
|
5160
|
-
if (node.type ===
|
|
5344
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UpdateExpression)
|
|
5161
5345
|
return instanceField(node.argument);
|
|
5162
|
-
if (node.type ===
|
|
5346
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UnaryExpression && node.operator === "delete")
|
|
5163
5347
|
return instanceField(node.argument);
|
|
5164
|
-
if (node.type ===
|
|
5348
|
+
if (node.type === import_utils35.AST_NODE_TYPES.MemberExpression && isDestructuredWriteTarget(node))
|
|
5165
5349
|
return instanceField(node);
|
|
5166
5350
|
return null;
|
|
5167
5351
|
}
|
|
@@ -5170,39 +5354,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5170
5354
|
let target = access;
|
|
5171
5355
|
for (; ; ) {
|
|
5172
5356
|
const parent = target.parent;
|
|
5173
|
-
if (parent.type ===
|
|
5357
|
+
if (parent.type === import_utils35.AST_NODE_TYPES.Property && parent.value === target && parent.parent.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5174
5358
|
target = parent.parent;
|
|
5175
5359
|
continue;
|
|
5176
5360
|
}
|
|
5177
|
-
if (parent.type ===
|
|
5361
|
+
if (parent.type === import_utils35.AST_NODE_TYPES.ArrayPattern || parent.type === import_utils35.AST_NODE_TYPES.ObjectPattern || parent.type === import_utils35.AST_NODE_TYPES.RestElement && parent.argument === target || parent.type === import_utils35.AST_NODE_TYPES.AssignmentPattern && parent.left === target) {
|
|
5178
5362
|
target = parent;
|
|
5179
5363
|
continue;
|
|
5180
5364
|
}
|
|
5181
|
-
return target !== access && (parent.type ===
|
|
5365
|
+
return target !== access && (parent.type === import_utils35.AST_NODE_TYPES.AssignmentExpression || parent.type === import_utils35.AST_NODE_TYPES.ForOfStatement || parent.type === import_utils35.AST_NODE_TYPES.ForInStatement) && parent.left === target;
|
|
5182
5366
|
}
|
|
5183
5367
|
}
|
|
5184
5368
|
var behaviorallyInvokedFields = (body3) => {
|
|
5185
5369
|
const invoked = /* @__PURE__ */ new Set();
|
|
5186
5370
|
const visit = (current) => {
|
|
5187
|
-
if (current.type ===
|
|
5371
|
+
if (current.type === import_utils35.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils35.AST_NODE_TYPES.ClassExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils35.AST_NODE_TYPES.FunctionExpression)
|
|
5188
5372
|
return;
|
|
5189
|
-
if (current.type ===
|
|
5373
|
+
if (current.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5190
5374
|
const field = invokedInstanceField(current);
|
|
5191
5375
|
if (field !== null) invoked.add(field);
|
|
5192
5376
|
}
|
|
5193
5377
|
forEachOwnAstChild(current, visit);
|
|
5194
5378
|
};
|
|
5195
5379
|
for (const member3 of body3.body) {
|
|
5196
|
-
if (member3.type ===
|
|
5197
|
-
if (member3.type ===
|
|
5380
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.StaticBlock || member3.static) continue;
|
|
5381
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition) {
|
|
5198
5382
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5199
5383
|
visit(member3.value.body);
|
|
5200
5384
|
continue;
|
|
5201
5385
|
}
|
|
5202
|
-
if (member3.type !==
|
|
5386
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition || member3.value === null)
|
|
5203
5387
|
continue;
|
|
5204
5388
|
visit(
|
|
5205
|
-
member3.value.type ===
|
|
5389
|
+
member3.value.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5206
5390
|
);
|
|
5207
5391
|
}
|
|
5208
5392
|
return invoked;
|
|
@@ -5222,8 +5406,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5222
5406
|
var fileInterfaceNames = (program) => {
|
|
5223
5407
|
const names = [];
|
|
5224
5408
|
for (const statement of program.body) {
|
|
5225
|
-
const declaration = statement.type ===
|
|
5226
|
-
if (declaration?.type ===
|
|
5409
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5410
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration)
|
|
5227
5411
|
names.push(declaration.id.name);
|
|
5228
5412
|
}
|
|
5229
5413
|
return names;
|
|
@@ -5231,22 +5415,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5231
5415
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5232
5416
|
const names = [];
|
|
5233
5417
|
function collectPublicCallable(member3) {
|
|
5234
|
-
if (member3.type ===
|
|
5418
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.PropertyDefinition) {
|
|
5235
5419
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5236
5420
|
return;
|
|
5237
|
-
if (member3.key.type ===
|
|
5238
|
-
if (member3.value?.type !==
|
|
5421
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5422
|
+
if (member3.value?.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression && member3.value?.type !== import_utils35.AST_NODE_TYPES.FunctionExpression && member3.typeAnnotation?.typeAnnotation.type !== import_utils35.AST_NODE_TYPES.TSFunctionType && !(member3.typeAnnotation?.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSTypeReference && member3.typeAnnotation.typeAnnotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(
|
|
5239
5423
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5240
5424
|
)))
|
|
5241
5425
|
return;
|
|
5242
5426
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5243
5427
|
return;
|
|
5244
5428
|
}
|
|
5245
|
-
if (member3.type !==
|
|
5429
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition) return;
|
|
5246
5430
|
if (member3.kind !== "method" || member3.static) return;
|
|
5247
5431
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5248
5432
|
return;
|
|
5249
|
-
if (member3.key.type ===
|
|
5433
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5250
5434
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5251
5435
|
}
|
|
5252
5436
|
for (const member3 of body3.body) {
|
|
@@ -5257,13 +5441,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5257
5441
|
var isFluentConstructionObject = (node, getText) => {
|
|
5258
5442
|
if (node.id === null) return false;
|
|
5259
5443
|
const methods = node.body.body.filter(
|
|
5260
|
-
(member3) => member3.type ===
|
|
5444
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "method" && !member3.static && member3.accessibility !== "private" && member3.accessibility !== "protected" && member3.value.body !== null
|
|
5261
5445
|
);
|
|
5262
5446
|
if (methods.length === 0) return false;
|
|
5263
5447
|
return methods.every((member3) => {
|
|
5264
5448
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5265
5449
|
if (result === void 0) return false;
|
|
5266
|
-
const returnsOwnType = result.type ===
|
|
5450
|
+
const returnsOwnType = result.type === import_utils35.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
5267
5451
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5268
5452
|
});
|
|
5269
5453
|
};
|
|
@@ -5271,10 +5455,10 @@ function localClassAbstractness(program) {
|
|
|
5271
5455
|
const classes = /* @__PURE__ */ new Map();
|
|
5272
5456
|
const parents = /* @__PURE__ */ new Map();
|
|
5273
5457
|
for (const statement of program.body) {
|
|
5274
|
-
const declaration = statement.type ===
|
|
5275
|
-
if (declaration?.type ===
|
|
5458
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5459
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
5276
5460
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5277
|
-
if (declaration.superClass?.type ===
|
|
5461
|
+
if (declaration.superClass?.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5278
5462
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5279
5463
|
}
|
|
5280
5464
|
}
|
|
@@ -5292,9 +5476,9 @@ function localClassAbstractness(program) {
|
|
|
5292
5476
|
return classes;
|
|
5293
5477
|
}
|
|
5294
5478
|
function declaredMemberName(member3) {
|
|
5295
|
-
if (!member3.computed && member3.key.type ===
|
|
5479
|
+
if (!member3.computed && member3.key.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5296
5480
|
return member3.key.name;
|
|
5297
|
-
if (member3.key.type ===
|
|
5481
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.Literal && typeof member3.key.value === "string")
|
|
5298
5482
|
return member3.key.value;
|
|
5299
5483
|
return null;
|
|
5300
5484
|
}
|
|
@@ -5303,35 +5487,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5303
5487
|
const parents = /* @__PURE__ */ new Map();
|
|
5304
5488
|
const functionAliases = localFunctionAliases(program);
|
|
5305
5489
|
function collectInterfaceSurface(statement) {
|
|
5306
|
-
const declaration = statement.type ===
|
|
5307
|
-
if (declaration?.type ===
|
|
5490
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5491
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
5308
5492
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5309
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5493
|
+
const parts = declaration.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5310
5494
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5311
5495
|
for (const part of parts) {
|
|
5312
|
-
if (part.type ===
|
|
5496
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5313
5497
|
inherited.push(part.typeName.name);
|
|
5314
5498
|
continue;
|
|
5315
5499
|
}
|
|
5316
|
-
if (part.type ===
|
|
5500
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference) {
|
|
5317
5501
|
inherited.push("*");
|
|
5318
5502
|
continue;
|
|
5319
5503
|
}
|
|
5320
|
-
if (part.type !==
|
|
5504
|
+
if (part.type !== import_utils35.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
5321
5505
|
addCallableMembers(part.members, callables2);
|
|
5322
5506
|
}
|
|
5323
5507
|
interfaces.set(declaration.id.name, callables2);
|
|
5324
5508
|
parents.set(declaration.id.name, inherited);
|
|
5325
5509
|
return;
|
|
5326
5510
|
}
|
|
5327
|
-
if (declaration?.type !==
|
|
5511
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) return;
|
|
5328
5512
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5329
5513
|
addCallableMembers(declaration.body.body, callables);
|
|
5330
5514
|
interfaces.set(declaration.id.name, callables);
|
|
5331
5515
|
parents.set(declaration.id.name, [
|
|
5332
5516
|
...parents.get(declaration.id.name) ?? [],
|
|
5333
5517
|
...declaration.extends.flatMap(
|
|
5334
|
-
(heritage) => heritage.expression.type ===
|
|
5518
|
+
(heritage) => heritage.expression.type === import_utils35.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
5335
5519
|
)
|
|
5336
5520
|
]);
|
|
5337
5521
|
}
|
|
@@ -5340,17 +5524,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5340
5524
|
}
|
|
5341
5525
|
function addCallableMembers(members, callables) {
|
|
5342
5526
|
for (const member3 of members) {
|
|
5343
|
-
if (member3.type !==
|
|
5527
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature)
|
|
5344
5528
|
continue;
|
|
5345
5529
|
const name = declaredMemberName(member3);
|
|
5346
5530
|
if (name === null) continue;
|
|
5347
|
-
if (member3.type ===
|
|
5531
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSMethodSignature) {
|
|
5348
5532
|
callables.add(name);
|
|
5349
5533
|
continue;
|
|
5350
5534
|
}
|
|
5351
|
-
if (member3.type !==
|
|
5535
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5352
5536
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5353
|
-
if (annotation?.type ===
|
|
5537
|
+
if (annotation?.type === import_utils35.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name))
|
|
5354
5538
|
callables.add(name);
|
|
5355
5539
|
}
|
|
5356
5540
|
}
|
|
@@ -5380,7 +5564,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5380
5564
|
}
|
|
5381
5565
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5382
5566
|
if (node.superClass !== null) {
|
|
5383
|
-
if (node.superClass.type !==
|
|
5567
|
+
if (node.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return true;
|
|
5384
5568
|
const localAbstract = classes.get(node.superClass.name);
|
|
5385
5569
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5386
5570
|
}
|
|
@@ -5419,7 +5603,7 @@ var require_port_for_service_default = createRule({
|
|
|
5419
5603
|
if (node.abstract === true) return;
|
|
5420
5604
|
if (node.decorators.length > 0) return;
|
|
5421
5605
|
const ctor = node.body.body.find(
|
|
5422
|
-
(member3) => member3.type ===
|
|
5606
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null && member3.value.body !== void 0
|
|
5423
5607
|
);
|
|
5424
5608
|
if (ctor === void 0) return;
|
|
5425
5609
|
const constructorFacts = readConstructor(
|
|
@@ -5469,7 +5653,7 @@ var require_port_for_service_default = createRule({
|
|
|
5469
5653
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5470
5654
|
const combined = /* @__PURE__ */ new Set();
|
|
5471
5655
|
for (const implementation of node.implements) {
|
|
5472
|
-
if (implementation.expression.type !==
|
|
5656
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5473
5657
|
return true;
|
|
5474
5658
|
const name = implementation.expression.name;
|
|
5475
5659
|
const localAbstract = classes.get(name);
|
|
@@ -5486,7 +5670,7 @@ function createServiceOperationResolver(program) {
|
|
|
5486
5670
|
let declaredTypes = null;
|
|
5487
5671
|
return (node) => {
|
|
5488
5672
|
const ctor = node.body.body.find(
|
|
5489
|
-
(member3) => member3.type ===
|
|
5673
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5490
5674
|
);
|
|
5491
5675
|
if (ctor === void 0) return [];
|
|
5492
5676
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5504,7 +5688,7 @@ function createServiceOperationResolver(program) {
|
|
|
5504
5688
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5505
5689
|
forEachServiceCall(body3, (call) => {
|
|
5506
5690
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5507
|
-
if (call.callee.type ===
|
|
5691
|
+
if (call.callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && call.callee.object.type === import_utils35.AST_NODE_TYPES.ThisExpression) {
|
|
5508
5692
|
const callee = staticMemberName(call.callee);
|
|
5509
5693
|
if (callee !== null) {
|
|
5510
5694
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5543,11 +5727,11 @@ function serviceOperationBodies(node) {
|
|
|
5543
5727
|
});
|
|
5544
5728
|
}
|
|
5545
5729
|
for (const member3 of node.body.body) {
|
|
5546
|
-
if (member3.type !==
|
|
5730
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition)
|
|
5547
5731
|
continue;
|
|
5548
|
-
if (member3.static || member3.decorators.length > 0 || member3.type ===
|
|
5732
|
+
if (member3.static || member3.decorators.length > 0 || member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind !== "method")
|
|
5549
5733
|
continue;
|
|
5550
|
-
if (member3.value?.type !==
|
|
5734
|
+
if (member3.value?.type !== import_utils35.AST_NODE_TYPES.FunctionExpression && member3.value?.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
5551
5735
|
continue;
|
|
5552
5736
|
const name = declaredMemberName(member3);
|
|
5553
5737
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5556,9 +5740,9 @@ function serviceOperationBodies(node) {
|
|
|
5556
5740
|
return bodies;
|
|
5557
5741
|
}
|
|
5558
5742
|
function forEachServiceCall(node, onCall) {
|
|
5559
|
-
if (node.type ===
|
|
5743
|
+
if (node.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils35.AST_NODE_TYPES.FunctionExpression || node.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils35.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils35.AST_NODE_TYPES.ClassExpression)
|
|
5560
5744
|
return;
|
|
5561
|
-
if (node.type ===
|
|
5745
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement) {
|
|
5562
5746
|
for (const statement of node.body) {
|
|
5563
5747
|
forEachServiceCall(statement, onCall);
|
|
5564
5748
|
if (terminatesOperation(statement)) break;
|
|
@@ -5570,29 +5754,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5570
5754
|
forEachServiceCall(branch, onCall);
|
|
5571
5755
|
return;
|
|
5572
5756
|
}
|
|
5573
|
-
if (node.type ===
|
|
5757
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) onCall(node);
|
|
5574
5758
|
forEachOwnAstChild(node, (child) => {
|
|
5575
5759
|
forEachServiceCall(child, onCall);
|
|
5576
5760
|
});
|
|
5577
5761
|
}
|
|
5578
5762
|
function literalExecutionBranch(node) {
|
|
5579
|
-
if (node.type ===
|
|
5763
|
+
if (node.type === import_utils35.AST_NODE_TYPES.WhileStatement && node.test.type === import_utils35.AST_NODE_TYPES.Literal && node.test.value === false)
|
|
5580
5764
|
return node.test;
|
|
5581
|
-
if ((node.type ===
|
|
5765
|
+
if ((node.type === import_utils35.AST_NODE_TYPES.IfStatement || node.type === import_utils35.AST_NODE_TYPES.ConditionalExpression) && node.test.type === import_utils35.AST_NODE_TYPES.Literal && typeof node.test.value === "boolean") {
|
|
5582
5766
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5583
5767
|
}
|
|
5584
|
-
if (node.type !==
|
|
5768
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.LogicalExpression || node.left.type !== import_utils35.AST_NODE_TYPES.Literal || typeof node.left.value !== "boolean")
|
|
5585
5769
|
return null;
|
|
5586
5770
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5587
5771
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5588
5772
|
return node.left;
|
|
5589
5773
|
}
|
|
5590
5774
|
function terminatesOperation(node) {
|
|
5591
|
-
if (node.type ===
|
|
5775
|
+
if (node.type === import_utils35.AST_NODE_TYPES.ReturnStatement || node.type === import_utils35.AST_NODE_TYPES.ThrowStatement)
|
|
5592
5776
|
return true;
|
|
5593
|
-
if (node.type ===
|
|
5777
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement)
|
|
5594
5778
|
return node.body.some(terminatesOperation);
|
|
5595
|
-
if (node.type !==
|
|
5779
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.IfStatement) return false;
|
|
5596
5780
|
const branch = literalExecutionBranch(node);
|
|
5597
5781
|
if (branch !== null) return terminatesOperation(branch);
|
|
5598
5782
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5606,7 +5790,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5606
5790
|
const seen = /* @__PURE__ */ new Set();
|
|
5607
5791
|
function addImplementedContracts(current) {
|
|
5608
5792
|
for (const implementation of current.implements) {
|
|
5609
|
-
if (implementation.expression.type !==
|
|
5793
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5610
5794
|
return false;
|
|
5611
5795
|
const name = implementation.expression.name;
|
|
5612
5796
|
const surface = interfaces.get(name);
|
|
@@ -5629,7 +5813,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5629
5813
|
}
|
|
5630
5814
|
if (!addImplementedContracts(current)) return null;
|
|
5631
5815
|
if (current.superClass === null) continue;
|
|
5632
|
-
if (current.superClass.type !==
|
|
5816
|
+
if (current.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5633
5817
|
const base = classes.get(current.superClass.name);
|
|
5634
5818
|
if (base === void 0) return null;
|
|
5635
5819
|
pending.push(base);
|
|
@@ -5639,8 +5823,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5639
5823
|
function localClassDeclarations(program) {
|
|
5640
5824
|
const classes = /* @__PURE__ */ new Map();
|
|
5641
5825
|
for (const statement of program.body) {
|
|
5642
|
-
const declaration = statement.type ===
|
|
5643
|
-
if (declaration?.type ===
|
|
5826
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5827
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null)
|
|
5644
5828
|
classes.set(declaration.id.name, declaration);
|
|
5645
5829
|
}
|
|
5646
5830
|
return classes;
|
|
@@ -5648,13 +5832,13 @@ function localClassDeclarations(program) {
|
|
|
5648
5832
|
function abstractContractOperations(node, functionAliases) {
|
|
5649
5833
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5650
5834
|
for (const member3 of node.body.body) {
|
|
5651
|
-
if (member3.type !==
|
|
5835
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractMethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition)
|
|
5652
5836
|
continue;
|
|
5653
5837
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5654
5838
|
continue;
|
|
5655
|
-
if (member3.type ===
|
|
5839
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition) {
|
|
5656
5840
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5657
|
-
if (annotation?.type !==
|
|
5841
|
+
if (annotation?.type !== import_utils35.AST_NODE_TYPES.TSFunctionType && !(annotation?.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)))
|
|
5658
5842
|
continue;
|
|
5659
5843
|
}
|
|
5660
5844
|
const name = declaredMemberName(member3);
|
|
@@ -5790,7 +5974,7 @@ function isServiceRole(name, filename) {
|
|
|
5790
5974
|
}
|
|
5791
5975
|
|
|
5792
5976
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
5793
|
-
var
|
|
5977
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5794
5978
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
5795
5979
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
5796
5980
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -5842,7 +6026,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
5842
6026
|
]
|
|
5843
6027
|
};
|
|
5844
6028
|
function isEmptyObject(node) {
|
|
5845
|
-
return node.type ===
|
|
6029
|
+
return node.type === import_utils37.AST_NODE_TYPES.ObjectExpression && node.properties.length === 0;
|
|
5846
6030
|
}
|
|
5847
6031
|
var no_conditional_empty_object_spread_default = createRule({
|
|
5848
6032
|
name: "no-conditional-empty-object-spread",
|
|
@@ -5863,13 +6047,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5863
6047
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
5864
6048
|
return {
|
|
5865
6049
|
SpreadElement(node) {
|
|
5866
|
-
if (node.parent.type !==
|
|
6050
|
+
if (node.parent.type !== import_utils37.AST_NODE_TYPES.ObjectExpression || node.argument.type !== import_utils37.AST_NODE_TYPES.ConditionalExpression)
|
|
5867
6051
|
return;
|
|
5868
6052
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
5869
6053
|
const conditional = node.argument;
|
|
5870
6054
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
5871
6055
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
5872
|
-
const canFix = populated.type ===
|
|
6056
|
+
const canFix = populated.type === import_utils37.AST_NODE_TYPES.ObjectExpression && populated.properties.length > 0 && context.sourceCode.getCommentsInside(conditional).length === 0;
|
|
5873
6057
|
context.report({
|
|
5874
6058
|
node,
|
|
5875
6059
|
messageId: "avoid",
|
|
@@ -5885,7 +6069,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5885
6069
|
});
|
|
5886
6070
|
|
|
5887
6071
|
// src/rules/prefer-typed-reflection.ts
|
|
5888
|
-
var
|
|
6072
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5889
6073
|
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
5890
6074
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
5891
6075
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
@@ -5958,20 +6142,20 @@ var prefer_typed_reflection_default = createRule({
|
|
|
5958
6142
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
5959
6143
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
5960
6144
|
return {};
|
|
5961
|
-
const services =
|
|
6145
|
+
const services = import_utils38.ESLintUtils.getParserServices(context);
|
|
5962
6146
|
if (!services.program) return {};
|
|
5963
6147
|
const checker = services.program.getTypeChecker();
|
|
5964
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
5965
|
-
const globalName = (node, name) => node.type ===
|
|
6148
|
+
const isReflect = (node) => globalName(node, "Reflect") || node.type === import_utils38.AST_NODE_TYPES.MemberExpression && import_utils38.ASTUtils.getPropertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
6149
|
+
const globalName = (node, name) => node.type === import_utils38.AST_NODE_TYPES.Identifier && node.name === name && !import_utils38.ASTUtils.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
5966
6150
|
const closedObject = (type) => {
|
|
5967
6151
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
5968
6152
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
5969
6153
|
};
|
|
5970
6154
|
const inspectGet = (node, type) => {
|
|
5971
6155
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
5972
|
-
return node.arguments.length === 2 && (staticString(key) !== null || key?.type ===
|
|
6156
|
+
return node.arguments.length === 2 && (staticString(key) !== null || key?.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number") && closedObject(type);
|
|
5973
6157
|
};
|
|
5974
|
-
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type ===
|
|
6158
|
+
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type === import_utils38.AST_NODE_TYPES.ArrayExpression && knownType(type) && type.getCallSignatures().some(
|
|
5975
6159
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
5976
6160
|
(parameter) => knownType(
|
|
5977
6161
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -5982,25 +6166,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
5982
6166
|
)
|
|
5983
6167
|
);
|
|
5984
6168
|
const getReplacement = (node, type, target) => {
|
|
5985
|
-
if (node.optional || node.callee.type !==
|
|
6169
|
+
if (node.optional || node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || node.callee.optional || context.sourceCode.getCommentsInside(node).length > 0) return null;
|
|
5986
6170
|
let outer = node;
|
|
5987
|
-
while (outer.parent.type ===
|
|
5988
|
-
if (outer.parent.type ===
|
|
6171
|
+
while (outer.parent.type === import_utils38.AST_NODE_TYPES.TSAsExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.TSTypeAssertion || outer.parent.type === import_utils38.AST_NODE_TYPES.TSSatisfiesExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.TSNonNullExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.ChainExpression) outer = outer.parent;
|
|
6172
|
+
if (outer.parent.type === import_utils38.AST_NODE_TYPES.UnaryExpression && outer.parent.operator === "delete" || outer.parent.type === import_utils38.AST_NODE_TYPES.CallExpression && outer.parent.callee === outer || outer.parent.type === import_utils38.AST_NODE_TYPES.TaggedTemplateExpression && outer.parent.tag === outer) return null;
|
|
5989
6173
|
const writtenKey = node.arguments[1];
|
|
5990
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6174
|
+
if (writtenKey === void 0 || writtenKey.type === import_utils38.AST_NODE_TYPES.SpreadElement) return null;
|
|
5991
6175
|
const key = unwrapExpression(writtenKey);
|
|
5992
|
-
const name = staticString(key) ?? (key.type ===
|
|
6176
|
+
const name = staticString(key) ?? (key.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
5993
6177
|
const members = type.isUnion() ? type.types : [type];
|
|
5994
6178
|
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
5995
6179
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
5996
6180
|
};
|
|
5997
6181
|
return {
|
|
5998
6182
|
CallExpression(node) {
|
|
5999
|
-
if (node.callee.type !==
|
|
6183
|
+
if (node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || !isReflect(node.callee.object))
|
|
6000
6184
|
return;
|
|
6001
|
-
const method =
|
|
6185
|
+
const method = import_utils38.ASTUtils.getPropertyName(node.callee);
|
|
6002
6186
|
const target = node.arguments[0];
|
|
6003
|
-
if (!target || target.type ===
|
|
6187
|
+
if (!target || target.type === import_utils38.AST_NODE_TYPES.SpreadElement || method !== "get" && method !== "apply")
|
|
6004
6188
|
return;
|
|
6005
6189
|
const type = checker.getTypeAtLocation(
|
|
6006
6190
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6015,28 +6199,28 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6015
6199
|
});
|
|
6016
6200
|
|
|
6017
6201
|
// src/rules/no-broad-return-type.ts
|
|
6018
|
-
var
|
|
6202
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
6019
6203
|
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
6020
6204
|
|
|
6021
6205
|
// src/rules/_unused-private-binding.ts
|
|
6022
|
-
var
|
|
6206
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6023
6207
|
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6024
6208
|
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6025
6209
|
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6026
6210
|
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;
|
|
6027
6211
|
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
6028
|
-
const statement = declaration.type ===
|
|
6029
|
-
if (statement.parent.type ===
|
|
6030
|
-
if (statement.parent.type !==
|
|
6031
|
-
return sourceCode.ast.body.some((node) => node.type ===
|
|
6212
|
+
const statement = declaration.type === import_utils39.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
6213
|
+
if (statement.parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
6214
|
+
if (statement.parent.type !== import_utils39.AST_NODE_TYPES.Program) return statement.parent.type === import_utils39.AST_NODE_TYPES.BlockStatement;
|
|
6215
|
+
return sourceCode.ast.body.some((node) => node.type === import_utils39.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportAllDeclaration);
|
|
6032
6216
|
}
|
|
6033
6217
|
function hasOnlyDirectFactoryUses(variable) {
|
|
6034
6218
|
return variable.references.every((reference) => {
|
|
6035
6219
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6036
6220
|
const identifier = reference.identifier;
|
|
6037
6221
|
const parent = identifier.parent;
|
|
6038
|
-
if (parent.type ===
|
|
6039
|
-
return parent.type ===
|
|
6222
|
+
if (parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
6223
|
+
return parent.type === import_utils39.AST_NODE_TYPES.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent;
|
|
6040
6224
|
});
|
|
6041
6225
|
}
|
|
6042
6226
|
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
@@ -6050,7 +6234,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6050
6234
|
const current = pending.pop();
|
|
6051
6235
|
if (current === void 0 || seen.has(current)) continue;
|
|
6052
6236
|
seen.add(current);
|
|
6053
|
-
if (current.type ===
|
|
6237
|
+
if (current.type === import_utils39.AST_NODE_TYPES.Identifier || current.type === import_utils39.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
6054
6238
|
forEachOwnAstChild(current, (child) => {
|
|
6055
6239
|
pending.push(child);
|
|
6056
6240
|
}, (key) => key !== "tokens" && key !== "comments");
|
|
@@ -6061,7 +6245,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6061
6245
|
return names.has(name);
|
|
6062
6246
|
}
|
|
6063
6247
|
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6064
|
-
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !==
|
|
6248
|
+
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== import_utils39.AST_NODE_TYPES.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
6065
6249
|
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6066
6250
|
}
|
|
6067
6251
|
|
|
@@ -6150,7 +6334,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6150
6334
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6151
6335
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6152
6336
|
return {};
|
|
6153
|
-
const services =
|
|
6337
|
+
const services = import_utils40.ESLintUtils.getParserServices(context);
|
|
6154
6338
|
if (!services.program) return {};
|
|
6155
6339
|
const checker = services.program.getTypeChecker();
|
|
6156
6340
|
const frames = [];
|
|
@@ -6175,7 +6359,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6175
6359
|
known: false,
|
|
6176
6360
|
opaque: false
|
|
6177
6361
|
});
|
|
6178
|
-
if (node.body && node.body.type !==
|
|
6362
|
+
if (node.body && node.body.type !== import_utils40.AST_NODE_TYPES.BlockStatement)
|
|
6179
6363
|
inspectReturn(node.body);
|
|
6180
6364
|
};
|
|
6181
6365
|
const leave = () => {
|
|
@@ -6183,7 +6367,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6183
6367
|
if (frame?.annotation && frame.known && !frame.opaque) {
|
|
6184
6368
|
const annotation = frame.annotation;
|
|
6185
6369
|
const node = frame.node;
|
|
6186
|
-
const canFix = node.type ===
|
|
6370
|
+
const canFix = node.type === import_utils40.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && isUnusedPrivateBinding(context.sourceCode, node, node.id, context.filename) && context.sourceCode.getCommentsInside(annotation).length === 0 && retainsNamedTypeUses(context.sourceCode, annotation);
|
|
6187
6371
|
context.report({ node: annotation, messageId: "avoid", fix: canFix ? (fixer) => fixer.replaceText(annotation, context.sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")) : null });
|
|
6188
6372
|
}
|
|
6189
6373
|
};
|
|
@@ -6202,43 +6386,43 @@ var no_broad_return_type_default = createRule({
|
|
|
6202
6386
|
});
|
|
6203
6387
|
|
|
6204
6388
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
6205
|
-
var
|
|
6389
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6206
6390
|
var import_typescript14 = __toESM(require("typescript"), 1);
|
|
6207
6391
|
|
|
6208
6392
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
6209
|
-
var
|
|
6393
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6210
6394
|
function literalIdentityReduceFix(sourceCode, node) {
|
|
6211
|
-
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !==
|
|
6395
|
+
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !== import_utils41.AST_NODE_TYPES.MemberExpression || node.callee.optional || import_utils41.ASTUtils.getPropertyName(node.callee) !== "reduce")
|
|
6212
6396
|
return null;
|
|
6213
6397
|
const values = node.callee.object;
|
|
6214
|
-
if (values.type !==
|
|
6215
|
-
(element) => element?.type ===
|
|
6398
|
+
if (values.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || values.elements.length === 0 || !values.elements.every(
|
|
6399
|
+
(element) => element?.type === import_utils41.AST_NODE_TYPES.Literal && typeof element.value === "string"
|
|
6216
6400
|
))
|
|
6217
6401
|
return null;
|
|
6218
6402
|
const statement = sourceCode.ast.body[0];
|
|
6219
|
-
if (statement?.type !==
|
|
6403
|
+
if (statement?.type !== import_utils41.AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration?.type !== import_utils41.AST_NODE_TYPES.FunctionDeclaration)
|
|
6220
6404
|
return null;
|
|
6221
6405
|
const owner = statement.declaration;
|
|
6222
6406
|
if (owner.async || owner.declare || owner.generator || owner.typeParameters !== void 0 || owner.params.length !== 0 || owner.body.body.length !== 1 || !stringArray(owner.returnType?.typeAnnotation))
|
|
6223
6407
|
return null;
|
|
6224
6408
|
const returned2 = owner.body.body[0];
|
|
6225
|
-
if (returned2?.type !==
|
|
6409
|
+
if (returned2?.type !== import_utils41.AST_NODE_TYPES.ReturnStatement || returned2.argument !== node || node.typeArguments?.params.length !== 1 || !stringArray(node.typeArguments.params[0]))
|
|
6226
6410
|
return null;
|
|
6227
6411
|
const [callback, seed] = node.arguments;
|
|
6228
|
-
if (seed?.type !==
|
|
6412
|
+
if (seed?.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || seed.elements.length !== 0 || callback?.type !== import_utils41.AST_NODE_TYPES.ArrowFunctionExpression || callback.async || callback.typeParameters !== void 0 || callback.returnType !== void 0 || callback.params.length !== 2 || callback.body.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || callback.body.elements.length !== 2)
|
|
6229
6413
|
return null;
|
|
6230
6414
|
if (!identitySpread(sourceCode, callback)) return null;
|
|
6231
6415
|
return (fixer) => fixer.replaceText(node, sourceCode.getText(values));
|
|
6232
6416
|
}
|
|
6233
6417
|
function stringArray(node) {
|
|
6234
|
-
return node?.type ===
|
|
6418
|
+
return node?.type === import_utils41.AST_NODE_TYPES.TSArrayType && node.elementType.type === import_utils41.AST_NODE_TYPES.TSStringKeyword;
|
|
6235
6419
|
}
|
|
6236
6420
|
function identitySpread(sourceCode, callback) {
|
|
6237
6421
|
const [accumulator, item] = callback.params;
|
|
6238
|
-
if (accumulator?.type !==
|
|
6422
|
+
if (accumulator?.type !== import_utils41.AST_NODE_TYPES.Identifier || item?.type !== import_utils41.AST_NODE_TYPES.Identifier || accumulator.name === item.name || accumulator.optional || item.optional || accumulator.typeAnnotation !== void 0 || item.typeAnnotation !== void 0 || callback.body.type !== import_utils41.AST_NODE_TYPES.ArrayExpression)
|
|
6239
6423
|
return false;
|
|
6240
6424
|
const [spread, appended] = callback.body.elements;
|
|
6241
|
-
if (spread?.type !==
|
|
6425
|
+
if (spread?.type !== import_utils41.AST_NODE_TYPES.SpreadElement || spread.argument.type !== import_utils41.AST_NODE_TYPES.Identifier || appended?.type !== import_utils41.AST_NODE_TYPES.Identifier || spread.argument.name !== accumulator.name || appended.name !== item.name)
|
|
6242
6426
|
return false;
|
|
6243
6427
|
const bindings = sourceCode.getDeclaredVariables(callback);
|
|
6244
6428
|
const left = bindings.find(
|
|
@@ -6247,10 +6431,10 @@ function identitySpread(sourceCode, callback) {
|
|
|
6247
6431
|
const right = bindings.find(
|
|
6248
6432
|
(variable) => variable.identifiers.includes(item)
|
|
6249
6433
|
);
|
|
6250
|
-
return left !== void 0 && right !== void 0 &&
|
|
6434
|
+
return left !== void 0 && right !== void 0 && import_utils41.ASTUtils.findVariable(
|
|
6251
6435
|
sourceCode.getScope(spread.argument),
|
|
6252
6436
|
spread.argument.name
|
|
6253
|
-
) === left &&
|
|
6437
|
+
) === left && import_utils41.ASTUtils.findVariable(sourceCode.getScope(appended), appended.name) === right;
|
|
6254
6438
|
}
|
|
6255
6439
|
|
|
6256
6440
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
@@ -6340,25 +6524,25 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6340
6524
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6341
6525
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6342
6526
|
return {};
|
|
6343
|
-
const services =
|
|
6527
|
+
const services = import_utils42.ESLintUtils.getParserServices(context);
|
|
6344
6528
|
const program = services.program;
|
|
6345
6529
|
if (program === null) return {};
|
|
6346
6530
|
const checker = program.getTypeChecker();
|
|
6347
6531
|
return {
|
|
6348
6532
|
CallExpression(node) {
|
|
6349
|
-
if (node.callee.type !==
|
|
6350
|
-
|
|
6533
|
+
if (node.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression || !["reduce", "reduceRight"].includes(
|
|
6534
|
+
import_utils42.ASTUtils.getPropertyName(node.callee) ?? ""
|
|
6351
6535
|
) || node.arguments.length !== 2)
|
|
6352
6536
|
return;
|
|
6353
6537
|
const seed = node.arguments[1];
|
|
6354
|
-
const arraySeed = seed?.type ===
|
|
6355
|
-
const objectSeed = seed?.type ===
|
|
6538
|
+
const arraySeed = seed?.type === import_utils42.AST_NODE_TYPES.ArrayExpression && seed.elements.length === 0;
|
|
6539
|
+
const objectSeed = seed?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && seed.properties.length === 0;
|
|
6356
6540
|
if (!arraySeed && !objectSeed) return;
|
|
6357
6541
|
const callback = node.arguments[0];
|
|
6358
|
-
if (!callback || callback.type !==
|
|
6542
|
+
if (!callback || callback.type !== import_utils42.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils42.AST_NODE_TYPES.FunctionExpression)
|
|
6359
6543
|
return;
|
|
6360
6544
|
const parameter = callback.params[0];
|
|
6361
|
-
if (parameter?.type !==
|
|
6545
|
+
if (parameter?.type !== import_utils42.AST_NODE_TYPES.Identifier) return;
|
|
6362
6546
|
const signature = checker.getResolvedSignature(
|
|
6363
6547
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
6364
6548
|
);
|
|
@@ -6369,51 +6553,51 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6369
6553
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
6370
6554
|
return;
|
|
6371
6555
|
const fix = literalIdentityReduceFix(context.sourceCode, node);
|
|
6372
|
-
const referencesAccumulator = (value) => value.type ===
|
|
6556
|
+
const referencesAccumulator = (value) => value.type === import_utils42.AST_NODE_TYPES.Identifier && import_utils42.ASTUtils.findVariable(
|
|
6373
6557
|
context.sourceCode.getScope(value),
|
|
6374
6558
|
value.name
|
|
6375
6559
|
) === accumulator;
|
|
6376
6560
|
const inspect = (current) => {
|
|
6377
6561
|
if (current !== callback.body && [
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6562
|
+
import_utils42.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6563
|
+
import_utils42.AST_NODE_TYPES.FunctionExpression,
|
|
6564
|
+
import_utils42.AST_NODE_TYPES.FunctionDeclaration,
|
|
6565
|
+
import_utils42.AST_NODE_TYPES.ClassDeclaration,
|
|
6566
|
+
import_utils42.AST_NODE_TYPES.ClassExpression,
|
|
6567
|
+
import_utils42.AST_NODE_TYPES.ForStatement,
|
|
6568
|
+
import_utils42.AST_NODE_TYPES.ForInStatement,
|
|
6569
|
+
import_utils42.AST_NODE_TYPES.ForOfStatement,
|
|
6570
|
+
import_utils42.AST_NODE_TYPES.WhileStatement,
|
|
6571
|
+
import_utils42.AST_NODE_TYPES.DoWhileStatement
|
|
6388
6572
|
].some((kind) => kind === current.type))
|
|
6389
6573
|
return;
|
|
6390
|
-
if (current.type ===
|
|
6574
|
+
if (current.type === import_utils42.AST_NODE_TYPES.SpreadElement && (arraySeed && current.parent.type === import_utils42.AST_NODE_TYPES.ArrayExpression || objectSeed && current.parent.type === import_utils42.AST_NODE_TYPES.ObjectExpression) && referencesAccumulator(current.argument)) {
|
|
6391
6575
|
context.report({
|
|
6392
6576
|
node: current,
|
|
6393
6577
|
messageId: "copy",
|
|
6394
6578
|
fix
|
|
6395
6579
|
});
|
|
6396
6580
|
}
|
|
6397
|
-
if (current.type ===
|
|
6581
|
+
if (current.type === import_utils42.AST_NODE_TYPES.CallExpression)
|
|
6398
6582
|
inspectCall(current);
|
|
6399
6583
|
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
6400
6584
|
};
|
|
6401
6585
|
const inspectCall = (current) => {
|
|
6402
|
-
if (current.callee.type !==
|
|
6586
|
+
if (current.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression) return;
|
|
6403
6587
|
const member3 = current.callee;
|
|
6404
|
-
const name =
|
|
6588
|
+
const name = import_utils42.ASTUtils.getPropertyName(member3);
|
|
6405
6589
|
const directCopy = arraySeed && name !== null && COPY_METHODS.has(name) && referencesAccumulator(member3.object);
|
|
6406
|
-
const globalArray = member3.object.type ===
|
|
6590
|
+
const globalArray = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Array" && !import_utils42.ASTUtils.findVariable(
|
|
6407
6591
|
context.sourceCode.getScope(member3.object),
|
|
6408
6592
|
"Array"
|
|
6409
6593
|
)?.defs.length;
|
|
6410
6594
|
const fromCopy = arraySeed && name === "from" && globalArray && current.arguments[0] !== void 0 && referencesAccumulator(current.arguments[0]);
|
|
6411
|
-
const globalObject = member3.object.type ===
|
|
6595
|
+
const globalObject = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Object" && !import_utils42.ASTUtils.findVariable(
|
|
6412
6596
|
context.sourceCode.getScope(member3.object),
|
|
6413
6597
|
"Object"
|
|
6414
6598
|
)?.defs.length;
|
|
6415
6599
|
const target = current.arguments[0];
|
|
6416
|
-
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type ===
|
|
6600
|
+
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && current.arguments.slice(1).some(referencesAccumulator);
|
|
6417
6601
|
if (directCopy || fromCopy || assignCopy)
|
|
6418
6602
|
context.report({ node: current, messageId: "copy" });
|
|
6419
6603
|
};
|
|
@@ -6424,7 +6608,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6424
6608
|
});
|
|
6425
6609
|
|
|
6426
6610
|
// src/rules/no-known-value-widening.ts
|
|
6427
|
-
var
|
|
6611
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6428
6612
|
var import_typescript15 = __toESM(require("typescript"), 1);
|
|
6429
6613
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
6430
6614
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
@@ -6474,12 +6658,12 @@ var no_known_value_widening_default = createRule({
|
|
|
6474
6658
|
create(context) {
|
|
6475
6659
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6476
6660
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap) return {};
|
|
6477
|
-
const services =
|
|
6661
|
+
const services = import_utils43.ESLintUtils.getParserServices(context);
|
|
6478
6662
|
if (services.program === null) return {};
|
|
6479
6663
|
const checker = services.program.getTypeChecker();
|
|
6480
6664
|
return {
|
|
6481
6665
|
VariableDeclarator(node) {
|
|
6482
|
-
if (node.id.type !==
|
|
6666
|
+
if (node.id.type !== import_utils43.AST_NODE_TYPES.Identifier || !node.id.typeAnnotation || node.init?.type !== import_utils43.AST_NODE_TYPES.Identifier || node.parent.kind !== "const" || node.parent.parent.type === import_utils43.AST_NODE_TYPES.ExportNamedDeclaration) return;
|
|
6483
6667
|
const source = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.init));
|
|
6484
6668
|
if (hasUnknownContract(source, checker)) return;
|
|
6485
6669
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.id.typeAnnotation.typeAnnotation));
|
|
@@ -6498,7 +6682,7 @@ var no_known_value_widening_default = createRule({
|
|
|
6498
6682
|
});
|
|
6499
6683
|
|
|
6500
6684
|
// src/rules/no-invalid-typed-mutation.ts
|
|
6501
|
-
var
|
|
6685
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6502
6686
|
var import_ts_api_utils = require("ts-api-utils");
|
|
6503
6687
|
var import_typescript16 = __toESM(require("typescript"), 1);
|
|
6504
6688
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
@@ -6535,7 +6719,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6535
6719
|
defaultOptions: [],
|
|
6536
6720
|
create(context) {
|
|
6537
6721
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
6538
|
-
const services =
|
|
6722
|
+
const services = import_utils44.ESLintUtils.getParserServices(context);
|
|
6539
6723
|
const checker = services.program.getTypeChecker();
|
|
6540
6724
|
const candidates = [];
|
|
6541
6725
|
const replaced = /* @__PURE__ */ new Set();
|
|
@@ -6606,7 +6790,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6606
6790
|
const target = node.arguments[0];
|
|
6607
6791
|
if (target === void 0) return;
|
|
6608
6792
|
invalidateNamespace(target);
|
|
6609
|
-
if (target.type !==
|
|
6793
|
+
if (target.type !== import_utils44.AST_NODE_TYPES.Identifier) return;
|
|
6610
6794
|
const writes = mutationWrites(node, method.namespace, method.method);
|
|
6611
6795
|
if (writes !== void 0) candidates.push({ call: node, ...method, target, writes });
|
|
6612
6796
|
},
|
|
@@ -6617,9 +6801,9 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6617
6801
|
}
|
|
6618
6802
|
});
|
|
6619
6803
|
function localDataTarget(target, sourceCode) {
|
|
6620
|
-
const binding3 =
|
|
6804
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(target), target.name);
|
|
6621
6805
|
const definition = binding3?.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
6622
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !==
|
|
6806
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !== import_utils44.AST_NODE_TYPES.Identifier || definition.node.id.typeAnnotation === void 0 || definition.node.init?.type !== import_utils44.AST_NODE_TYPES.ObjectExpression || definition.parent.parent.type === import_utils44.AST_NODE_TYPES.ExportNamedDeclaration) return void 0;
|
|
6623
6807
|
const properties = plainProperties(definition.node.init);
|
|
6624
6808
|
if (properties === void 0) return void 0;
|
|
6625
6809
|
const scope = sourceCode.getScope(definition.node).variableScope;
|
|
@@ -6630,29 +6814,29 @@ function localDataTarget(target, sourceCode) {
|
|
|
6630
6814
|
return new Set(properties.map((property) => property.key));
|
|
6631
6815
|
}
|
|
6632
6816
|
function safeTargetUse(identifier, sourceCode) {
|
|
6633
|
-
if (identifier.type !==
|
|
6817
|
+
if (identifier.type !== import_utils44.AST_NODE_TYPES.Identifier) return false;
|
|
6634
6818
|
const parent = identifier.parent;
|
|
6635
|
-
if (parent.type ===
|
|
6636
|
-
const key =
|
|
6819
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.MemberExpression && parent.object === identifier) {
|
|
6820
|
+
const key = import_utils44.ASTUtils.getPropertyName(parent);
|
|
6637
6821
|
const use = outerExpression(parent);
|
|
6638
|
-
if (parent.optional || use.parent.type ===
|
|
6639
|
-
return key !== null && key !== "__proto__" && !(use.parent.type ===
|
|
6822
|
+
if (parent.optional || use.parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && use.parent.operator === "delete") return false;
|
|
6823
|
+
return key !== null && key !== "__proto__" && !(use.parent.type === import_utils44.AST_NODE_TYPES.CallExpression && use.parent.callee === use);
|
|
6640
6824
|
}
|
|
6641
|
-
if (parent.type !==
|
|
6825
|
+
if (parent.type !== import_utils44.AST_NODE_TYPES.CallExpression || parent.arguments[0] !== identifier) return false;
|
|
6642
6826
|
const method = nativeMember(parent.callee, sourceCode);
|
|
6643
6827
|
if (method === void 0) return false;
|
|
6644
6828
|
const writes = mutationWrites(parent, method.namespace, method.method);
|
|
6645
|
-
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type ===
|
|
6829
|
+
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type === import_utils44.AST_NODE_TYPES.ExpressionStatement);
|
|
6646
6830
|
}
|
|
6647
6831
|
function keepsMutableDescriptor(call, method) {
|
|
6648
6832
|
if (method !== "defineProperty") return true;
|
|
6649
6833
|
const descriptor = call.arguments[2];
|
|
6650
|
-
if (descriptor?.type !==
|
|
6834
|
+
if (descriptor?.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return false;
|
|
6651
6835
|
const properties = plainProperties(descriptor);
|
|
6652
6836
|
return properties !== void 0 && properties.every((property) => {
|
|
6653
6837
|
if (property.key !== "writable" && property.key !== "configurable") return true;
|
|
6654
6838
|
const value = unwrapExpression(property.value);
|
|
6655
|
-
return value.type ===
|
|
6839
|
+
return value.type === import_utils44.AST_NODE_TYPES.Literal && value.value === true;
|
|
6656
6840
|
});
|
|
6657
6841
|
}
|
|
6658
6842
|
function declaredTargetType(node, checker) {
|
|
@@ -6702,9 +6886,9 @@ function definiteSignatures(type, checker, seen) {
|
|
|
6702
6886
|
}
|
|
6703
6887
|
function nativeMember(node, sourceCode) {
|
|
6704
6888
|
const member3 = unwrapExpression(node);
|
|
6705
|
-
if (member3.type !==
|
|
6889
|
+
if (member3.type !== import_utils44.AST_NODE_TYPES.MemberExpression || member3.optional) return void 0;
|
|
6706
6890
|
const namespace = nativeNamespace(member3.object, sourceCode);
|
|
6707
|
-
const method =
|
|
6891
|
+
const method = import_utils44.ASTUtils.getPropertyName(member3);
|
|
6708
6892
|
if (namespace === void 0 || method === null) return void 0;
|
|
6709
6893
|
const supported2 = namespace === "Object" ? ["assign", "defineProperty", "defineProperties", "setPrototypeOf"] : ["set", "defineProperty", "setPrototypeOf"];
|
|
6710
6894
|
return supported2.includes(method) ? { namespace, method } : void 0;
|
|
@@ -6713,43 +6897,43 @@ function ordinaryNamespaceUse(node) {
|
|
|
6713
6897
|
const value = outerExpression(node);
|
|
6714
6898
|
const parent = value.parent;
|
|
6715
6899
|
if (parent === void 0) return false;
|
|
6716
|
-
return parent.type ===
|
|
6900
|
+
return parent.type === import_utils44.AST_NODE_TYPES.MemberExpression && parent.object === value || parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" || parent.type === import_utils44.AST_NODE_TYPES.TSTypeQuery || parent.type === import_utils44.AST_NODE_TYPES.TSQualifiedName;
|
|
6717
6901
|
}
|
|
6718
6902
|
function replacementNamespace(node, sourceCode) {
|
|
6719
6903
|
const value = unwrapExpression(node);
|
|
6720
6904
|
if (nativeObjectPrototype(value, sourceCode)) return "ObjectPrototype";
|
|
6721
|
-
return nativeNamespace(value, sourceCode) ?? (value.type ===
|
|
6905
|
+
return nativeNamespace(value, sourceCode) ?? (value.type === import_utils44.AST_NODE_TYPES.MemberExpression ? replacementNamespace(value.object, sourceCode) : void 0);
|
|
6722
6906
|
}
|
|
6723
6907
|
function nativeObjectPrototype(node, sourceCode) {
|
|
6724
6908
|
const value = unwrapExpression(node);
|
|
6725
|
-
return value.type ===
|
|
6909
|
+
return value.type === import_utils44.AST_NODE_TYPES.MemberExpression && import_utils44.ASTUtils.getPropertyName(value) === "prototype" && nativeNamespace(value.object, sourceCode) === "Object";
|
|
6726
6910
|
}
|
|
6727
6911
|
function nativeNamespace(node, sourceCode) {
|
|
6728
6912
|
const value = unwrapExpression(node);
|
|
6729
|
-
if (value.type ===
|
|
6730
|
-
const key =
|
|
6913
|
+
if (value.type === import_utils44.AST_NODE_TYPES.MemberExpression && !value.optional && nativeGlobalReceiver(value.object, sourceCode)) {
|
|
6914
|
+
const key = import_utils44.ASTUtils.getPropertyName(value);
|
|
6731
6915
|
if (key === "Object" || key === "Reflect") return key;
|
|
6732
6916
|
}
|
|
6733
|
-
if (value.type !==
|
|
6734
|
-
const binding3 =
|
|
6917
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.Identifier || value.name !== "Object" && value.name !== "Reflect") return void 0;
|
|
6918
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
6735
6919
|
return binding3 === null || binding3.defs.length === 0 ? value.name : void 0;
|
|
6736
6920
|
}
|
|
6737
6921
|
function nativeGlobalReceiver(node, sourceCode) {
|
|
6738
|
-
if (node.type !==
|
|
6739
|
-
const binding3 =
|
|
6922
|
+
if (node.type !== import_utils44.AST_NODE_TYPES.Identifier || !["globalThis", "window", "self"].includes(node.name)) return false;
|
|
6923
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
6740
6924
|
return binding3 === null || binding3.defs.length === 0;
|
|
6741
6925
|
}
|
|
6742
6926
|
function mutationWrites(node, namespace, method) {
|
|
6743
6927
|
if (namespace === "Object" && method === "assign") {
|
|
6744
6928
|
const source = node.arguments[1];
|
|
6745
|
-
return node.arguments.length === 2 && source?.type ===
|
|
6929
|
+
return node.arguments.length === 2 && source?.type === import_utils44.AST_NODE_TYPES.ObjectExpression ? plainProperties(source) : void 0;
|
|
6746
6930
|
}
|
|
6747
6931
|
if (node.arguments.length !== 3 || method !== "set" && method !== "defineProperty") return void 0;
|
|
6748
6932
|
const key = staticString(node.arguments[1]);
|
|
6749
6933
|
const value = node.arguments[2];
|
|
6750
|
-
if (key === null || value === void 0 || value.type ===
|
|
6934
|
+
if (key === null || value === void 0 || value.type === import_utils44.AST_NODE_TYPES.SpreadElement) return void 0;
|
|
6751
6935
|
if (method === "set") return [{ key, value }];
|
|
6752
|
-
if (value.type !==
|
|
6936
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return void 0;
|
|
6753
6937
|
const properties = plainProperties(value);
|
|
6754
6938
|
if (properties === void 0 || properties.some((property) => !["value", "configurable", "enumerable", "writable"].includes(property.key))) return void 0;
|
|
6755
6939
|
const payload = properties.find((property) => property.key === "value");
|
|
@@ -6759,8 +6943,8 @@ function plainProperties(node) {
|
|
|
6759
6943
|
const writes = [];
|
|
6760
6944
|
const names = /* @__PURE__ */ new Set();
|
|
6761
6945
|
for (const property of node.properties) {
|
|
6762
|
-
if (property.type !==
|
|
6763
|
-
const key =
|
|
6946
|
+
if (property.type !== import_utils44.AST_NODE_TYPES.Property || property.kind !== "init" || property.method) return void 0;
|
|
6947
|
+
const key = import_utils44.ASTUtils.getPropertyName(property);
|
|
6764
6948
|
if (key === null || key === "__proto__" || names.has(key)) return void 0;
|
|
6765
6949
|
names.add(key);
|
|
6766
6950
|
writes.push({ key, value: property.value });
|
|
@@ -6769,7 +6953,7 @@ function plainProperties(node) {
|
|
|
6769
6953
|
}
|
|
6770
6954
|
|
|
6771
6955
|
// src/rules/no-contradictory-type-predicate.ts
|
|
6772
|
-
var
|
|
6956
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6773
6957
|
var import_typescript19 = __toESM(require("typescript"), 1);
|
|
6774
6958
|
|
|
6775
6959
|
// src/rules/_has-separate-predicate-contract.ts
|
|
@@ -6785,7 +6969,7 @@ function hasSeparatePredicateContract(node, checker) {
|
|
|
6785
6969
|
}
|
|
6786
6970
|
|
|
6787
6971
|
// src/rules/_contradictory-array-predicate.ts
|
|
6788
|
-
var
|
|
6972
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6789
6973
|
var import_typescript18 = __toESM(require("typescript"), 1);
|
|
6790
6974
|
var import_ts_api_utils2 = require("ts-api-utils");
|
|
6791
6975
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
@@ -6798,12 +6982,12 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6798
6982
|
function matches(expression, parameter, input, target) {
|
|
6799
6983
|
if ((input.flags & import_typescript18.default.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
6800
6984
|
const call = unwrapExpression(expression);
|
|
6801
|
-
if (call.type !==
|
|
6985
|
+
if (call.type !== import_utils45.AST_NODE_TYPES.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
6802
6986
|
const argument = call.arguments[0];
|
|
6803
6987
|
const callee = unwrapExpression(call.callee);
|
|
6804
|
-
if (argument?.type !==
|
|
6805
|
-
const declared =
|
|
6806
|
-
if (declared === null || declared !==
|
|
6988
|
+
if (argument?.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.optional || import_utils45.ASTUtils.getPropertyName(callee) !== "isArray" || callee.object.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.object.name !== "Array") return false;
|
|
6989
|
+
const declared = import_utils45.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name);
|
|
6990
|
+
if (declared === null || declared !== import_utils45.ASTUtils.findVariable(sourceCode.getScope(argument), argument.name)) return false;
|
|
6807
6991
|
const binding3 = nativeBinding(callee.object, sourceCode);
|
|
6808
6992
|
if (binding3 === void 0 || !stableArray(binding3, sourceCode, stable2)) return false;
|
|
6809
6993
|
const signature = checker.getResolvedSignature(services.esTreeNodeToTSNodeMap.get(call));
|
|
@@ -6813,7 +6997,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6813
6997
|
return {
|
|
6814
6998
|
matches,
|
|
6815
6999
|
observeConstructor(member3) {
|
|
6816
|
-
const name =
|
|
7000
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3, sourceCode.getScope(member3));
|
|
6817
7001
|
if (name === "constructor" || name === null && member3.computed) constructorCapability = true;
|
|
6818
7002
|
},
|
|
6819
7003
|
stable() {
|
|
@@ -6827,7 +7011,7 @@ function plainPrimitiveArray(target, checker) {
|
|
|
6827
7011
|
return element !== void 0 && (element.flags & PRIMITIVE_ELEMENTS) !== 0 && (element.flags & (import_typescript18.default.TypeFlags.Enum | import_typescript18.default.TypeFlags.EnumLiteral | import_typescript18.default.TypeFlags.Intersection)) === 0;
|
|
6828
7012
|
}
|
|
6829
7013
|
function nativeBinding(identifier, sourceCode) {
|
|
6830
|
-
const binding3 =
|
|
7014
|
+
const binding3 = import_utils45.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6831
7015
|
return binding3 !== null && binding3.defs.length === 0 ? binding3 : void 0;
|
|
6832
7016
|
}
|
|
6833
7017
|
function stableArray(binding3, sourceCode, cache) {
|
|
@@ -6854,8 +7038,8 @@ function typeOnlyReference2(reference) {
|
|
|
6854
7038
|
}
|
|
6855
7039
|
function ordinaryObjectUse(node) {
|
|
6856
7040
|
const member3 = node.parent;
|
|
6857
|
-
if (member3?.type !==
|
|
6858
|
-
const name =
|
|
7041
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node) return false;
|
|
7042
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6859
7043
|
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
6860
7044
|
}
|
|
6861
7045
|
function ordinaryArrayReference(reference) {
|
|
@@ -6865,17 +7049,17 @@ function ordinaryArrayReference(reference) {
|
|
|
6865
7049
|
}
|
|
6866
7050
|
function ordinaryArrayUse(node) {
|
|
6867
7051
|
const member3 = node.parent;
|
|
6868
|
-
if (member3?.type ===
|
|
6869
|
-
if (member3?.type !==
|
|
6870
|
-
return member3.parent.type ===
|
|
7052
|
+
if (member3?.type === import_utils45.AST_NODE_TYPES.TSTypeQuery) return true;
|
|
7053
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node || member3.optional || import_utils45.ASTUtils.getPropertyName(member3) !== "isArray") return false;
|
|
7054
|
+
return member3.parent.type === import_utils45.AST_NODE_TYPES.CallExpression && member3.parent.callee === member3 && !member3.parent.optional;
|
|
6871
7055
|
}
|
|
6872
7056
|
function ordinaryHostReference(reference) {
|
|
6873
7057
|
if (reference.isWrite()) return false;
|
|
6874
7058
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6875
7059
|
let node = reference.identifier;
|
|
6876
|
-
while (node.parent?.type ===
|
|
7060
|
+
while (node.parent?.type === import_utils45.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
6877
7061
|
const member3 = node.parent;
|
|
6878
|
-
const name =
|
|
7062
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6879
7063
|
if (name === null) return false;
|
|
6880
7064
|
if (name === "Array") return ordinaryArrayUse(member3);
|
|
6881
7065
|
if (name === "Reflect") return false;
|
|
@@ -6955,16 +7139,16 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
6955
7139
|
defaultOptions: [],
|
|
6956
7140
|
create(context) {
|
|
6957
7141
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
6958
|
-
const services =
|
|
7142
|
+
const services = import_utils46.ESLintUtils.getParserServices(context);
|
|
6959
7143
|
const checker = services.program.getTypeChecker();
|
|
6960
7144
|
const uncheckedArray = contradictoryArrayPredicate(context.sourceCode, services);
|
|
6961
7145
|
const pendingArrays = [];
|
|
6962
7146
|
function inspect(node) {
|
|
6963
7147
|
const annotation = node.returnType?.typeAnnotation;
|
|
6964
|
-
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !==
|
|
7148
|
+
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !== import_utils46.AST_NODE_TYPES.TSTypePredicate || annotation.asserts || annotation.parameterName.type !== import_utils46.AST_NODE_TYPES.Identifier || annotation.typeAnnotation === void 0) return;
|
|
6965
7149
|
const name = annotation.parameterName.name;
|
|
6966
7150
|
if (hasSeparatePredicateContract(services.esTreeNodeToTSNodeMap.get(node), checker)) return;
|
|
6967
|
-
const parameter = node.params.find((candidate2) => candidate2.type ===
|
|
7151
|
+
const parameter = node.params.find((candidate2) => candidate2.type === import_utils46.AST_NODE_TYPES.Identifier && candidate2.name === name);
|
|
6968
7152
|
const expression = singleReturn(node);
|
|
6969
7153
|
if (parameter?.typeAnnotation === void 0 || expression === void 0) return;
|
|
6970
7154
|
const check = typeofCheck(expression);
|
|
@@ -7009,13 +7193,13 @@ function shallowRecordCheck(expression, parameter, input, target, sourceCode, ch
|
|
|
7009
7193
|
const value = unwrapExpression(expression);
|
|
7010
7194
|
const direct = typeofCheck(value);
|
|
7011
7195
|
if (direct !== void 0) return direct.kind === "object" && sameParameter(parameter, direct.parameter, sourceCode);
|
|
7012
|
-
if (value.type !==
|
|
7196
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.LogicalExpression || value.operator !== "&&") return false;
|
|
7013
7197
|
for (const [left, right] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7014
7198
|
const check = typeofCheck(left);
|
|
7015
7199
|
const excluded = unwrapExpression(right);
|
|
7016
|
-
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !==
|
|
7200
|
+
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || excluded.operator !== "!==" && excluded.operator !== "!=") continue;
|
|
7017
7201
|
for (const [tested, sentinel] of [[excluded.left, excluded.right], [excluded.right, excluded.left]]) {
|
|
7018
|
-
if (tested.type ===
|
|
7202
|
+
if (tested.type === import_utils46.AST_NODE_TYPES.Identifier && sentinel.type === import_utils46.AST_NODE_TYPES.Literal && sentinel.value === null && sameParameter(parameter, tested, sourceCode)) return true;
|
|
7019
7203
|
}
|
|
7020
7204
|
}
|
|
7021
7205
|
return false;
|
|
@@ -7048,17 +7232,17 @@ function literalKind(type, checker) {
|
|
|
7048
7232
|
}
|
|
7049
7233
|
function singleReturn(node) {
|
|
7050
7234
|
if (node.body === void 0) return void 0;
|
|
7051
|
-
if (node.body.type !==
|
|
7235
|
+
if (node.body.type !== import_utils46.AST_NODE_TYPES.BlockStatement) return node.body;
|
|
7052
7236
|
const statement = node.body.body[0];
|
|
7053
|
-
return node.body.body.length === 1 && statement?.type ===
|
|
7237
|
+
return node.body.body.length === 1 && statement?.type === import_utils46.AST_NODE_TYPES.ReturnStatement && statement.argument !== null ? statement.argument : void 0;
|
|
7054
7238
|
}
|
|
7055
7239
|
function typeofCheck(expression) {
|
|
7056
7240
|
const value = unwrapExpression(expression);
|
|
7057
|
-
if (value.type !==
|
|
7241
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || value.operator !== "===" && value.operator !== "==") return void 0;
|
|
7058
7242
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7059
7243
|
const operand = unwrapExpression(tested);
|
|
7060
7244
|
const kind = staticString(expected);
|
|
7061
|
-
if (operand.type !==
|
|
7245
|
+
if (operand.type !== import_utils46.AST_NODE_TYPES.UnaryExpression || operand.operator !== "typeof" || operand.argument.type !== import_utils46.AST_NODE_TYPES.Identifier || kind === null || !isRuntimeKind(kind)) continue;
|
|
7062
7246
|
return { parameter: operand.argument, kind };
|
|
7063
7247
|
}
|
|
7064
7248
|
return void 0;
|
|
@@ -7067,8 +7251,8 @@ function isRuntimeKind(value) {
|
|
|
7067
7251
|
return RUNTIME_KINDS.has(value);
|
|
7068
7252
|
}
|
|
7069
7253
|
function sameParameter(declared, tested, sourceCode) {
|
|
7070
|
-
const parameter =
|
|
7071
|
-
return parameter !== null && parameter ===
|
|
7254
|
+
const parameter = import_utils46.ASTUtils.findVariable(sourceCode.getScope(declared), declared.name);
|
|
7255
|
+
return parameter !== null && parameter === import_utils46.ASTUtils.findVariable(sourceCode.getScope(tested), tested.name);
|
|
7072
7256
|
}
|
|
7073
7257
|
function inputKinds(type, checker) {
|
|
7074
7258
|
if ((type.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
@@ -7112,62 +7296,6 @@ var import_typescript21 = __toESM(require("typescript"), 1);
|
|
|
7112
7296
|
// src/rules/_uuid-predicate-witness.ts
|
|
7113
7297
|
var import_utils47 = require("@typescript-eslint/utils");
|
|
7114
7298
|
var import_typescript20 = __toESM(require("typescript"), 1);
|
|
7115
|
-
|
|
7116
|
-
// src/rules/_native-runtime-unchanged.ts
|
|
7117
|
-
var import_utils46 = require("@typescript-eslint/utils");
|
|
7118
|
-
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
7119
|
-
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
7120
|
-
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
7121
|
-
const index = runtimeIndex(sourceCode);
|
|
7122
|
-
const cached = index.results.get(name);
|
|
7123
|
-
if (cached !== void 0) return cached;
|
|
7124
|
-
const changed = index.nodes.some((node) => node.type === import_utils46.AST_NODE_TYPES.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === import_utils46.AST_NODE_TYPES.Literal && "regex" in node) || index.references.some((node) => unsafeReference(node, sourceCode, name));
|
|
7125
|
-
index.results.set(name, !changed);
|
|
7126
|
-
return !changed;
|
|
7127
|
-
}
|
|
7128
|
-
function runtimeIndex(sourceCode) {
|
|
7129
|
-
const cached = INDEXES.get(sourceCode);
|
|
7130
|
-
if (cached !== void 0) return cached;
|
|
7131
|
-
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false).map((reference) => reference.identifier)) ?? [];
|
|
7132
|
-
const nodes = [];
|
|
7133
|
-
const pending = [sourceCode.ast];
|
|
7134
|
-
while (pending.length > 0) {
|
|
7135
|
-
const node = pending.pop();
|
|
7136
|
-
if (node === void 0) continue;
|
|
7137
|
-
nodes.push(node);
|
|
7138
|
-
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
7139
|
-
pending.push(child);
|
|
7140
|
-
});
|
|
7141
|
-
}
|
|
7142
|
-
const index = { references, nodes, results: /* @__PURE__ */ new Map() };
|
|
7143
|
-
INDEXES.set(sourceCode, index);
|
|
7144
|
-
return index;
|
|
7145
|
-
}
|
|
7146
|
-
function unsafeReference(node, sourceCode, name) {
|
|
7147
|
-
if (!ambient(node, sourceCode)) return false;
|
|
7148
|
-
if (node.name === "eval" || node.name === "Function") return true;
|
|
7149
|
-
if (node.name === name) return !nativeRead(node, name);
|
|
7150
|
-
if (!GLOBAL_OBJECTS2.has(node.name)) return false;
|
|
7151
|
-
const value = outerExpression(node);
|
|
7152
|
-
const property = value.parent;
|
|
7153
|
-
if (property?.type !== import_utils46.AST_NODE_TYPES.MemberExpression || property.object !== value) return true;
|
|
7154
|
-
const key = staticPropertyName(property, sourceCode);
|
|
7155
|
-
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
7156
|
-
return key === name && !nativeRead(property, name);
|
|
7157
|
-
}
|
|
7158
|
-
function ambient(node, sourceCode) {
|
|
7159
|
-
const variable = import_utils46.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
7160
|
-
return variable === null || variable.defs.length === 0;
|
|
7161
|
-
}
|
|
7162
|
-
function nativeRead(node, name) {
|
|
7163
|
-
const value = outerExpression(node);
|
|
7164
|
-
const parent = value.parent;
|
|
7165
|
-
if (parent?.type === import_utils46.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
7166
|
-
if (name !== "Error") return false;
|
|
7167
|
-
return parent?.type === import_utils46.AST_NODE_TYPES.NewExpression && parent.callee === value || parent?.type === import_utils46.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
7168
|
-
}
|
|
7169
|
-
|
|
7170
|
-
// src/rules/_uuid-predicate-witness.ts
|
|
7171
7299
|
function uuidPredicateWitness(expression, parameter, sourceCode, services) {
|
|
7172
7300
|
const success = unwrapExpression(expression);
|
|
7173
7301
|
if (!member(success, "success")) return void 0;
|
|
@@ -11392,14 +11520,21 @@ function canAutofixNextConfigLiteral(sourceCode) {
|
|
|
11392
11520
|
// src/rules/no-dangerously-allow-svg.ts
|
|
11393
11521
|
var NEXT_CONFIG_RE = /(?:^|\/)next\.config\.[cm]?[jt]s$/;
|
|
11394
11522
|
var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
11395
|
-
summary: "
|
|
11396
|
-
rationale: "SVG
|
|
11397
|
-
remediation: "
|
|
11523
|
+
summary: "Require an explicit hardening policy for Next Image SVG delivery",
|
|
11524
|
+
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.",
|
|
11525
|
+
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.",
|
|
11398
11526
|
category: "security",
|
|
11399
11527
|
autofix: "safe",
|
|
11528
|
+
references: [
|
|
11529
|
+
"https://www.w3.org/TR/2026/WD-CSP3-20261027/#parse-serialized-policy",
|
|
11530
|
+
"https://github.com/vercel/next.js/blob/v16.4.3/packages/next/src/shared/lib/image-config.ts#L255"
|
|
11531
|
+
],
|
|
11400
11532
|
limitations: [
|
|
11401
11533
|
"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.",
|
|
11402
|
-
"
|
|
11534
|
+
"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.",
|
|
11535
|
+
"Omitted contentDispositionType is treated as attachment. Older or customized runtime defaults are not established by this source-only check.",
|
|
11536
|
+
"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.",
|
|
11537
|
+
"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."
|
|
11403
11538
|
],
|
|
11404
11539
|
examples: [
|
|
11405
11540
|
{
|
|
@@ -11413,7 +11548,7 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11413
11548
|
},
|
|
11414
11549
|
{
|
|
11415
11550
|
id: "svg-enabled",
|
|
11416
|
-
title: "
|
|
11551
|
+
title: "SVG opt-in requires explicit hardening under this policy",
|
|
11417
11552
|
outcome: "match",
|
|
11418
11553
|
files: [{ path: "next.config.mjs", source: "export default { images: { dangerouslyAllowSVG: true } };\n" }],
|
|
11419
11554
|
focusPath: "next.config.mjs",
|
|
@@ -11422,12 +11557,34 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11422
11557
|
},
|
|
11423
11558
|
{
|
|
11424
11559
|
id: "safe-autofix",
|
|
11425
|
-
title: "
|
|
11560
|
+
title: "Disable SVG delivery to satisfy this policy",
|
|
11426
11561
|
outcome: "match",
|
|
11427
11562
|
files: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: true } };" }],
|
|
11428
11563
|
fixedFiles: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: false } };" }],
|
|
11429
11564
|
focusPath: "next.config.ts",
|
|
11430
11565
|
expectedCount: 1
|
|
11566
|
+
},
|
|
11567
|
+
{
|
|
11568
|
+
id: "svg-explicit-hardening",
|
|
11569
|
+
scenarioId: "explicit-hardening",
|
|
11570
|
+
title: "Allow SVG delivery with explicit hardening",
|
|
11571
|
+
outcome: "no-match",
|
|
11572
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'none'; sandbox;" } };
|
|
11573
|
+
` }],
|
|
11574
|
+
focusPath: "next.config.mjs",
|
|
11575
|
+
expectedCount: 0,
|
|
11576
|
+
public: true
|
|
11577
|
+
},
|
|
11578
|
+
{
|
|
11579
|
+
id: "svg-unsafe-first-directive",
|
|
11580
|
+
scenarioId: "explicit-hardening",
|
|
11581
|
+
title: "A later duplicate cannot replace the effective policy",
|
|
11582
|
+
outcome: "match",
|
|
11583
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'unsafe-inline'; script-src 'none'; sandbox;" } };
|
|
11584
|
+
` }],
|
|
11585
|
+
focusPath: "next.config.mjs",
|
|
11586
|
+
expectedCount: 1,
|
|
11587
|
+
public: true
|
|
11431
11588
|
}
|
|
11432
11589
|
]
|
|
11433
11590
|
};
|
|
@@ -11437,12 +11594,16 @@ function literalString2(node) {
|
|
|
11437
11594
|
return null;
|
|
11438
11595
|
}
|
|
11439
11596
|
function hasHardenedSvgPolicy(policy) {
|
|
11440
|
-
const directives =
|
|
11441
|
-
const
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11597
|
+
const directives = /* @__PURE__ */ new Map();
|
|
11598
|
+
for (const part of policy.split(";")) {
|
|
11599
|
+
const [name, ...values] = part.split(/[\t\n\f\r ]+/u).filter(Boolean);
|
|
11600
|
+
if (name === void 0 || !/^[A-Za-z0-9-]+$/u.test(name)) continue;
|
|
11601
|
+
const key = name.toLowerCase();
|
|
11602
|
+
if (!directives.has(key)) directives.set(key, values);
|
|
11603
|
+
}
|
|
11604
|
+
const scriptSource = directives.get("script-src");
|
|
11605
|
+
const sandbox = directives.get("sandbox");
|
|
11606
|
+
return scriptSource?.length === 1 && scriptSource[0]?.toLowerCase() === "'none'" && sandbox?.length === 0;
|
|
11446
11607
|
}
|
|
11447
11608
|
var no_dangerously_allow_svg_default = createRule({
|
|
11448
11609
|
name: "no-dangerously-allow-svg",
|
|
@@ -11453,7 +11614,7 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
11453
11614
|
docs: { description: NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION.summary },
|
|
11454
11615
|
schema: [],
|
|
11455
11616
|
messages: {
|
|
11456
|
-
noDangerouslyAllowSvg: "
|
|
11617
|
+
noDangerouslyAllowSvg: "SVG opt-in requires a recognized explicit script-blocking sandbox CSP and attachment disposition under this policy."
|
|
11457
11618
|
}
|
|
11458
11619
|
},
|
|
11459
11620
|
defaultOptions: [],
|
|
@@ -17749,7 +17910,7 @@ var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
|
17749
17910
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
17750
17911
|
remediation: "Move the request into a client module and call that abstraction from application code.",
|
|
17751
17912
|
category: "architecture",
|
|
17752
|
-
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."],
|
|
17913
|
+
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."],
|
|
17753
17914
|
examples: [
|
|
17754
17915
|
{ 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 },
|
|
17755
17916
|
{ 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 }
|
|
@@ -17770,11 +17931,6 @@ var DEFAULT_ALLOW = [
|
|
|
17770
17931
|
"[\\\\/][^\\\\/]*(?:Client|client)\\.[cm]?[jt]sx?$"
|
|
17771
17932
|
];
|
|
17772
17933
|
var NON_PRODUCTION_TREE_RE = /[\\/](playwright|cypress|__testfixtures__)[\\/]/;
|
|
17773
|
-
var GLOBAL_RECEIVERS3 = /* @__PURE__ */ new Set([
|
|
17774
|
-
"globalThis",
|
|
17775
|
-
"window",
|
|
17776
|
-
"self"
|
|
17777
|
-
]);
|
|
17778
17934
|
var PRESIGNED_URL_NAME_RE = /(?:pre-?signed|signed|upload|download)Url$/i;
|
|
17779
17935
|
var INTERNAL_MUTATION_METHODS = /* @__PURE__ */ new Set([
|
|
17780
17936
|
"POST",
|
|
@@ -17798,23 +17954,13 @@ var BASE_PATH_RE = /^\/(?!$)(?!.*[?#])(?:[^/]+\/)*[^/]+$/u;
|
|
|
17798
17954
|
function isValidBasePath(basePath) {
|
|
17799
17955
|
return BASE_PATH_RE.test(basePath) && !basePath.split("/").some((segment) => segment === "." || segment === "..");
|
|
17800
17956
|
}
|
|
17801
|
-
function isGlobalFetchCall(node, resolvesToGlobal) {
|
|
17802
|
-
const callee = unwrapExpression(node.callee);
|
|
17803
|
-
if (callee.type === "Identifier") {
|
|
17804
|
-
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
17805
|
-
}
|
|
17806
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "fetch" && callee.object.type === "Identifier") {
|
|
17807
|
-
return GLOBAL_RECEIVERS3.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
17808
|
-
}
|
|
17809
|
-
return false;
|
|
17810
|
-
}
|
|
17811
17957
|
function isConstructedArgumentHandoff(node, resolvesToGlobal) {
|
|
17812
17958
|
const [first] = node.arguments;
|
|
17813
17959
|
return node.arguments.length === 1 && first !== void 0 && first.type === import_utils108.AST_NODE_TYPES.NewExpression && first.callee.type === import_utils108.AST_NODE_TYPES.Identifier && (first.callee.name === "URL" || first.callee.name === "Request") && resolvesToGlobal(first.callee);
|
|
17814
17960
|
}
|
|
17815
17961
|
function effectOwns(node) {
|
|
17816
17962
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17817
|
-
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier) return false;
|
|
17963
|
+
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || unwrappedNodeCallee.name !== "fetch") return false;
|
|
17818
17964
|
const method = readDirectMethod(node);
|
|
17819
17965
|
if (method !== null && method !== "GET") return false;
|
|
17820
17966
|
const first = node.arguments[0];
|
|
@@ -17951,7 +18097,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
17951
18097
|
}
|
|
17952
18098
|
function serverActionOwns(node) {
|
|
17953
18099
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17954
|
-
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
18100
|
+
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || unwrappedNodeCallee.name !== "fetch" || !resolvesToGlobal(unwrappedNodeCallee) || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
17955
18101
|
return false;
|
|
17956
18102
|
}
|
|
17957
18103
|
const url = node.arguments[0];
|
|
@@ -18008,7 +18154,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18008
18154
|
}
|
|
18009
18155
|
return {
|
|
18010
18156
|
CallExpression(node) {
|
|
18011
|
-
if (!
|
|
18157
|
+
if (!nativeFetchReference(unwrapExpression(node.callee), context.sourceCode)) {
|
|
18012
18158
|
return;
|
|
18013
18159
|
}
|
|
18014
18160
|
if (isPresignedUrlTransfer(node) || isConstructedArgumentHandoff(node, resolvesToGlobal) || effectOwns(node) || serverActionOwns(node)) {
|
|
@@ -32630,6 +32776,7 @@ var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
|
32630
32776
|
limitations: [
|
|
32631
32777
|
"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.",
|
|
32632
32778
|
"Unshadowed native fetch members and bounded stable const aliases or destructuring are recognized. Reassigned, defaulted and unknown aliases and arbitrary forwarding functions are excluded.",
|
|
32779
|
+
"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.",
|
|
32633
32780
|
"Accessors and unproved prototypes are excluded because native option conversion can attach or replace a signal before it is read."
|
|
32634
32781
|
],
|
|
32635
32782
|
examples: [
|
|
@@ -32676,7 +32823,7 @@ function emptySignal(expression, resolvesToGlobal) {
|
|
|
32676
32823
|
}
|
|
32677
32824
|
return null;
|
|
32678
32825
|
}
|
|
32679
|
-
function initSignalState(init, resolvesToGlobal) {
|
|
32826
|
+
function initSignalState(init, resolvesToGlobal, sourceCode) {
|
|
32680
32827
|
init = unwrapExpression(init);
|
|
32681
32828
|
if (init.type !== import_utils176.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
32682
32829
|
let state = "absent";
|
|
@@ -32686,12 +32833,12 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
32686
32833
|
continue;
|
|
32687
32834
|
}
|
|
32688
32835
|
if (prop.kind !== "init" || hasUnprovedPrototype(prop)) return "unknown";
|
|
32689
|
-
const
|
|
32690
|
-
if (
|
|
32836
|
+
const name = staticPropertyName(prop, sourceCode);
|
|
32837
|
+
if (name === "signal") {
|
|
32691
32838
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
32692
|
-
} else if (!prop.computed &&
|
|
32839
|
+
} else if (!prop.computed && name === "__proto__" && state === "absent") {
|
|
32693
32840
|
state = "unknown";
|
|
32694
|
-
} else if (prop.computed &&
|
|
32841
|
+
} else if (prop.computed && name === null) {
|
|
32695
32842
|
state = "unknown";
|
|
32696
32843
|
}
|
|
32697
32844
|
}
|
|
@@ -32769,7 +32916,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32769
32916
|
return "unknown";
|
|
32770
32917
|
}
|
|
32771
32918
|
}
|
|
32772
|
-
return initSignalState(definition.node.init, resolvesToGlobal);
|
|
32919
|
+
return initSignalState(definition.node.init, resolvesToGlobal, context.sourceCode);
|
|
32773
32920
|
}
|
|
32774
32921
|
function isForwardedRequest(argument) {
|
|
32775
32922
|
let value = unwrapExpression(argument);
|
|
@@ -32797,7 +32944,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32797
32944
|
}
|
|
32798
32945
|
const [first, rawInit] = node.arguments;
|
|
32799
32946
|
const init = rawInit === void 0 ? void 0 : unwrapExpression(rawInit);
|
|
32800
|
-
const state = init === void 0 ? "unknown" : init.type === import_utils176.AST_NODE_TYPES.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal);
|
|
32947
|
+
const state = init === void 0 ? "unknown" : init.type === import_utils176.AST_NODE_TYPES.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal, context.sourceCode);
|
|
32801
32948
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first) && state !== "null")) {
|
|
32802
32949
|
return;
|
|
32803
32950
|
}
|