@sarj/eslint-plugin 16.36.7 → 16.38.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +907 -767
- package/dist/index.js +901 -761
- package/dist/rule-examples.cjs +168 -44
- package/dist/rule-examples.js +168 -44
- package/package.json +1 -1
package/dist/index.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) {
|
|
@@ -2384,26 +2573,78 @@ function typeBinding(source, identifier) {
|
|
|
2384
2573
|
}
|
|
2385
2574
|
return null;
|
|
2386
2575
|
}
|
|
2576
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
2387
2577
|
function retainsNamedTypeUses(source, removed) {
|
|
2388
2578
|
const manager = source.scopeManager;
|
|
2389
2579
|
if (manager === null) return false;
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2580
|
+
const index = referenceIndex(source, manager);
|
|
2581
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
2582
|
+
if (!reference.isRead()) continue;
|
|
2392
2583
|
const binding3 = reference.resolved;
|
|
2393
2584
|
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
2394
|
-
if (binding3.defs.length === 0)
|
|
2395
|
-
|
|
2396
|
-
|
|
2585
|
+
if (binding3.defs.length === 0) continue;
|
|
2586
|
+
const reads = publicReadExtents(index, binding3);
|
|
2587
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
2588
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
2589
|
+
}
|
|
2590
|
+
return true;
|
|
2591
|
+
}
|
|
2592
|
+
function referenceIndex(source, manager) {
|
|
2593
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
2594
|
+
if (cached?.manager === manager) return cached;
|
|
2595
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
2596
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
2597
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
2598
|
+
REFERENCE_INDEXES.set(source, index);
|
|
2599
|
+
return index;
|
|
2600
|
+
}
|
|
2601
|
+
function* referencesWithin(references, removed) {
|
|
2602
|
+
let low = 0;
|
|
2603
|
+
let high = references.length;
|
|
2604
|
+
while (low < high) {
|
|
2605
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
2606
|
+
const reference = references[middle];
|
|
2607
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
2608
|
+
else low = middle + 1;
|
|
2609
|
+
}
|
|
2610
|
+
for (let index = low; index < references.length; index++) {
|
|
2611
|
+
const reference = references[index];
|
|
2612
|
+
if (reference === void 0) continue;
|
|
2613
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
2614
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
function publicReadExtents(index, binding3) {
|
|
2618
|
+
const cached = index.publicReads.get(binding3);
|
|
2619
|
+
if (cached !== void 0) return cached;
|
|
2620
|
+
let type = null;
|
|
2621
|
+
let value = null;
|
|
2622
|
+
let both = null;
|
|
2623
|
+
for (const retained of binding3.references) {
|
|
2624
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
2625
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
2626
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
2627
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
2628
|
+
}
|
|
2629
|
+
const result = { type, value, both };
|
|
2630
|
+
index.publicReads.set(binding3, result);
|
|
2631
|
+
return result;
|
|
2632
|
+
}
|
|
2633
|
+
function extendExtent(extent, identifier) {
|
|
2634
|
+
return {
|
|
2635
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
2636
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
2637
|
+
};
|
|
2397
2638
|
}
|
|
2398
2639
|
function publicTypeUse(identifier) {
|
|
2399
2640
|
let node = identifier;
|
|
2400
2641
|
while (node.parent) {
|
|
2401
|
-
if (node.type ===
|
|
2402
|
-
if (node.type ===
|
|
2403
|
-
return node.parent.type ===
|
|
2642
|
+
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;
|
|
2643
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
2644
|
+
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
2645
|
}
|
|
2405
|
-
if (node.type ===
|
|
2406
|
-
return node.parent.type ===
|
|
2646
|
+
if (node.type === import_utils23.AST_NODE_TYPES.ExportSpecifier) {
|
|
2647
|
+
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
2648
|
}
|
|
2408
2649
|
node = node.parent;
|
|
2409
2650
|
}
|
|
@@ -2417,8 +2658,8 @@ function insideTypeRange(node, range) {
|
|
|
2417
2658
|
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
2659
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
2419
2660
|
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 !==
|
|
2661
|
+
const owner = node.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
2662
|
+
if (owner.type !== import_utils24.AST_NODE_TYPES.FunctionDeclaration && owner.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator) return false;
|
|
2422
2663
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
2423
2664
|
if (!binding3) return false;
|
|
2424
2665
|
const checker = services.program.getTypeChecker();
|
|
@@ -2436,7 +2677,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
2436
2677
|
continue;
|
|
2437
2678
|
}
|
|
2438
2679
|
const call = reference.identifier.parent;
|
|
2439
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2680
|
+
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
2681
|
const argument = services.esTreeNodeToTSNodeMap.get(call.arguments[0]);
|
|
2441
2682
|
const type = checker.getTypeAtLocation(argument);
|
|
2442
2683
|
if (!knownArgument(type, argument, fields2, checker) || !checker.isTypeAssignableTo(type, original)) return false;
|
|
@@ -2491,7 +2732,7 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
2491
2732
|
}
|
|
2492
2733
|
|
|
2493
2734
|
// src/rules/_private-scalar-consumer.ts
|
|
2494
|
-
var
|
|
2735
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2495
2736
|
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
2496
2737
|
|
|
2497
2738
|
// src/rules/_scalar-parameter-view.ts
|
|
@@ -2637,31 +2878,11 @@ function intrinsicAttribute(attribute, view) {
|
|
|
2637
2878
|
return import_typescript5.default.isJsxAttribute(attribute) && import_typescript5.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
2638
2879
|
}
|
|
2639
2880
|
|
|
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
2881
|
// src/rules/_private-scalar-consumer.ts
|
|
2661
2882
|
function directEval(node) {
|
|
2662
2883
|
let callee = unwrapExpression(node.callee);
|
|
2663
|
-
while (callee.type ===
|
|
2664
|
-
return callee.type ===
|
|
2884
|
+
while (callee.type === import_utils25.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
2885
|
+
return callee.type === import_utils25.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
2665
2886
|
}
|
|
2666
2887
|
function primitiveKeyword(node) {
|
|
2667
2888
|
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 +2893,7 @@ function nullishPrimitiveUnion(node) {
|
|
|
2672
2893
|
function consumerAnnotation(node) {
|
|
2673
2894
|
if (node.params.length !== 1) return void 0;
|
|
2674
2895
|
const parameter = node.params[0];
|
|
2675
|
-
return parameter?.type ===
|
|
2896
|
+
return parameter?.type === import_utils25.AST_NODE_TYPES.Identifier || parameter?.type === import_utils25.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
2676
2897
|
}
|
|
2677
2898
|
function exportedSymbols(source, checker) {
|
|
2678
2899
|
const symbol = checker.getSymbolAtLocation(source);
|
|
@@ -2703,12 +2924,12 @@ function independentSignature(native) {
|
|
|
2703
2924
|
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
2925
|
}
|
|
2705
2926
|
function callableBinding(node, sourceCode) {
|
|
2706
|
-
if (node.type ===
|
|
2707
|
-
if (node.parent.type !==
|
|
2927
|
+
if (node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
2928
|
+
if (node.parent.type !== import_utils25.AST_NODE_TYPES.Program) return void 0;
|
|
2708
2929
|
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
2709
2930
|
}
|
|
2710
2931
|
const declaration = node.parent;
|
|
2711
|
-
if (declaration.type !==
|
|
2932
|
+
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
2933
|
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
2713
2934
|
}
|
|
2714
2935
|
function directCalls(binding3) {
|
|
@@ -2716,7 +2937,7 @@ function directCalls(binding3) {
|
|
|
2716
2937
|
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
2717
2938
|
const identifier = reference.identifier;
|
|
2718
2939
|
const call = identifier.parent;
|
|
2719
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2940
|
+
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
2941
|
calls += 1;
|
|
2721
2942
|
return true;
|
|
2722
2943
|
});
|
|
@@ -2776,13 +2997,13 @@ function localContractBindings(roots, source, services) {
|
|
|
2776
2997
|
}
|
|
2777
2998
|
function localContractReferences(node, source, services) {
|
|
2778
2999
|
switch (node.type) {
|
|
2779
|
-
case
|
|
3000
|
+
case import_utils26.AST_NODE_TYPES.TSTypeLiteral:
|
|
2780
3001
|
return [];
|
|
2781
|
-
case
|
|
3002
|
+
case import_utils26.AST_NODE_TYPES.TSIntersectionType:
|
|
2782
3003
|
return node.types;
|
|
2783
|
-
case
|
|
2784
|
-
return !node.typeArguments && node.typeName.type ===
|
|
2785
|
-
case
|
|
3004
|
+
case import_utils26.AST_NODE_TYPES.TSTypeReference:
|
|
3005
|
+
return !node.typeArguments && node.typeName.type === import_utils26.AST_NODE_TYPES.Identifier ? [node.typeName] : null;
|
|
3006
|
+
case import_utils26.AST_NODE_TYPES.Identifier:
|
|
2786
3007
|
return localBindingReferences(node, source, services);
|
|
2787
3008
|
default:
|
|
2788
3009
|
return null;
|
|
@@ -2792,8 +3013,8 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2792
3013
|
const definitions2 = typeBinding(source, identifier)?.defs.filter((definition) => definition.isTypeDefinition).map((definition) => definition.node);
|
|
2793
3014
|
if (!definitions2?.length || !definitions2.every(moduleTypeDeclaration)) return null;
|
|
2794
3015
|
const first = definitions2[0];
|
|
2795
|
-
if (definitions2.length === 1 && first?.type ===
|
|
2796
|
-
const interfaces = definitions2.filter((definition) => definition.type ===
|
|
3016
|
+
if (definitions2.length === 1 && first?.type === import_utils26.AST_NODE_TYPES.TSTypeAliasDeclaration && !first.typeParameters) return [first.typeAnnotation];
|
|
3017
|
+
const interfaces = definitions2.filter((definition) => definition.type === import_utils26.AST_NODE_TYPES.TSInterfaceDeclaration);
|
|
2797
3018
|
if (interfaces.length !== definitions2.length || interfaces.some((declaration) => declaration.typeParameters)) return null;
|
|
2798
3019
|
if (interfaces.length > 1) {
|
|
2799
3020
|
const checker = services.program.getTypeChecker();
|
|
@@ -2801,13 +3022,13 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2801
3022
|
if (!symbol || interfaces.some((declaration) => checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(declaration.id)) !== symbol)) return null;
|
|
2802
3023
|
}
|
|
2803
3024
|
const bases = interfaces.flatMap((declaration) => declaration.extends.map((base) => base.expression));
|
|
2804
|
-
return bases.every((base) => base.type ===
|
|
3025
|
+
return bases.every((base) => base.type === import_utils26.AST_NODE_TYPES.Identifier) ? bases : null;
|
|
2805
3026
|
}
|
|
2806
3027
|
function moduleTypeDeclaration(node) {
|
|
2807
3028
|
const parent = node.parent;
|
|
2808
|
-
if (parent?.type ===
|
|
2809
|
-
if (parent?.type !==
|
|
2810
|
-
return parent.parent.type ===
|
|
3029
|
+
if (parent?.type === import_utils26.AST_NODE_TYPES.Program) return true;
|
|
3030
|
+
if (parent?.type !== import_utils26.AST_NODE_TYPES.ExportNamedDeclaration && parent?.type !== import_utils26.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
3031
|
+
return parent.parent.type === import_utils26.AST_NODE_TYPES.Program;
|
|
2811
3032
|
}
|
|
2812
3033
|
function coveringAlternative(leftNode, rightNode, checker, fieldsOf, reads) {
|
|
2813
3034
|
const left = checker.getTypeFromTypeNode(leftNode);
|
|
@@ -2842,7 +3063,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2842
3063
|
let dynamic = false;
|
|
2843
3064
|
const remember = (node) => {
|
|
2844
3065
|
const annotation = consumerAnnotation(node);
|
|
2845
|
-
if (annotation?.type ===
|
|
3066
|
+
if (annotation?.type === import_utils26.AST_NODE_TYPES.TSUnionType && annotation.types.length === 2) candidates.push(node);
|
|
2846
3067
|
};
|
|
2847
3068
|
return {
|
|
2848
3069
|
FunctionDeclaration: remember,
|
|
@@ -2852,7 +3073,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2852
3073
|
},
|
|
2853
3074
|
"Program:exit"() {
|
|
2854
3075
|
if (dynamic || !candidates.length) return;
|
|
2855
|
-
const services =
|
|
3076
|
+
const services = import_utils26.ESLintUtils.getParserServices(context);
|
|
2856
3077
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2857
3078
|
if (!source) return;
|
|
2858
3079
|
const checker = services.program.getTypeChecker();
|
|
@@ -2876,7 +3097,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2876
3097
|
const coverage = coveringAlternative(leftNode, rightNode, checker, fieldsOf, consumer.reads);
|
|
2877
3098
|
if (!coverage) continue;
|
|
2878
3099
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
2879
|
-
if (coverage.mutual && (reportNode.type !==
|
|
3100
|
+
if (coverage.mutual && (reportNode.type !== import_utils26.AST_NODE_TYPES.TSUnionType || !localContractBindings(reportNode.types, context.sourceCode, services))) continue;
|
|
2880
3101
|
const { covered: coveredNode, covering: coveringNode } = coverage;
|
|
2881
3102
|
const fix = privateUnionFix(context.sourceCode, services, {
|
|
2882
3103
|
candidate: candidate2,
|
|
@@ -2894,7 +3115,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2894
3115
|
});
|
|
2895
3116
|
|
|
2896
3117
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
2897
|
-
var
|
|
3118
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
2898
3119
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
2899
3120
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
2900
3121
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
@@ -2945,7 +3166,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2945
3166
|
const candidates = [];
|
|
2946
3167
|
let dynamic = false;
|
|
2947
3168
|
const remember = (node) => {
|
|
2948
|
-
if (consumerAnnotation(node)?.type ===
|
|
3169
|
+
if (consumerAnnotation(node)?.type === import_utils27.AST_NODE_TYPES.TSTypeLiteral) candidates.push(node);
|
|
2949
3170
|
};
|
|
2950
3171
|
return {
|
|
2951
3172
|
FunctionDeclaration: remember,
|
|
@@ -2955,7 +3176,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2955
3176
|
},
|
|
2956
3177
|
"Program:exit"() {
|
|
2957
3178
|
if (dynamic || !candidates.length) return;
|
|
2958
|
-
const services =
|
|
3179
|
+
const services = import_utils27.ESLintUtils.getParserServices(context);
|
|
2959
3180
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2960
3181
|
if (!source) return;
|
|
2961
3182
|
const checker = services.program.getTypeChecker();
|
|
@@ -2979,7 +3200,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2979
3200
|
});
|
|
2980
3201
|
|
|
2981
3202
|
// src/rules/no-excess-jsx-props.ts
|
|
2982
|
-
var
|
|
3203
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
2983
3204
|
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
2984
3205
|
|
|
2985
3206
|
// src/rules/_ordinary-object-effects.ts
|
|
@@ -3321,11 +3542,11 @@ var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3321
3542
|
function plainLiteralFields(node) {
|
|
3322
3543
|
const fields2 = /* @__PURE__ */ new Map();
|
|
3323
3544
|
for (const property of node.properties) {
|
|
3324
|
-
if (property.type !==
|
|
3545
|
+
if (property.type !== import_utils28.AST_NODE_TYPES.Property || property.kind !== "init") return null;
|
|
3325
3546
|
const key = property.key;
|
|
3326
3547
|
let name;
|
|
3327
|
-
if (!property.computed && key.type ===
|
|
3328
|
-
else if (key.type ===
|
|
3548
|
+
if (!property.computed && key.type === import_utils28.AST_NODE_TYPES.Identifier) name = key.name;
|
|
3549
|
+
else if (key.type === import_utils28.AST_NODE_TYPES.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
3329
3550
|
else return null;
|
|
3330
3551
|
if (name === "__proto__") return null;
|
|
3331
3552
|
fields2.set(name, property);
|
|
@@ -3437,35 +3658,35 @@ function localObjectFields(symbol, source, proof) {
|
|
|
3437
3658
|
if (!native || native.getSourceFile() !== source || !initializer || !import_typescript10.default.isObjectLiteralExpression(initializer)) return null;
|
|
3438
3659
|
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
3439
3660
|
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
3440
|
-
if (declaration.type !==
|
|
3661
|
+
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;
|
|
3441
3662
|
const fields2 = plainLiteralFields(literal2);
|
|
3442
3663
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3443
3664
|
if (!fields2 || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
3444
3665
|
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
3445
3666
|
const member3 = reference.identifier.parent;
|
|
3446
|
-
return member3.type ===
|
|
3667
|
+
return member3.type === import_utils28.AST_NODE_TYPES.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields2);
|
|
3447
3668
|
})) return null;
|
|
3448
3669
|
return fields2;
|
|
3449
3670
|
}
|
|
3450
3671
|
function staticMemberKey(member3) {
|
|
3451
3672
|
const property = member3.property;
|
|
3452
|
-
return !member3.computed && property.type ===
|
|
3673
|
+
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;
|
|
3453
3674
|
}
|
|
3454
3675
|
function readonlyFieldValue(member3, fields2) {
|
|
3455
3676
|
const key = staticMemberKey(member3);
|
|
3456
3677
|
if (key === void 0 || !fields2.has(key)) return false;
|
|
3457
3678
|
const parent = member3.parent;
|
|
3458
|
-
if (parent.type ===
|
|
3679
|
+
if (parent.type === import_utils28.AST_NODE_TYPES.Property && parent.value === member3 && parent.parent.type === import_utils28.AST_NODE_TYPES.ObjectExpression) {
|
|
3459
3680
|
const object = parent.parent;
|
|
3460
3681
|
const owner = object.parent;
|
|
3461
|
-
return owner.type ===
|
|
3682
|
+
return owner.type === import_utils28.AST_NODE_TYPES.JSXSpreadAttribute && owner.argument === object || owner.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && owner.init === object;
|
|
3462
3683
|
}
|
|
3463
|
-
return parent.type ===
|
|
3684
|
+
return parent.type === import_utils28.AST_NODE_TYPES.JSXExpressionContainer && parent.expression === member3 || parent.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && parent.init === member3;
|
|
3464
3685
|
}
|
|
3465
3686
|
function privateElementDeclaration(opening) {
|
|
3466
3687
|
const value = outerExpression(opening.parent);
|
|
3467
3688
|
const declaration = value.parent;
|
|
3468
|
-
return declaration.type ===
|
|
3689
|
+
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;
|
|
3469
3690
|
}
|
|
3470
3691
|
function closedElementValue(opening, declaration, fields2, reads, proof) {
|
|
3471
3692
|
if (!proof.staticScope || !closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
@@ -3491,10 +3712,10 @@ function closedInvocation(node, proof) {
|
|
|
3491
3712
|
}
|
|
3492
3713
|
function independentInvocation(scope, proof) {
|
|
3493
3714
|
const block = scope.block;
|
|
3494
|
-
if (block.type !==
|
|
3715
|
+
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;
|
|
3495
3716
|
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3496
3717
|
for (const parameter of block.params) {
|
|
3497
|
-
if (parameter.type !==
|
|
3718
|
+
if (parameter.type !== import_utils28.AST_NODE_TYPES.Identifier || parameter.name === "this") return false;
|
|
3498
3719
|
const binding3 = scope.set.get(parameter.name);
|
|
3499
3720
|
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3500
3721
|
}
|
|
@@ -3502,16 +3723,16 @@ function independentInvocation(scope, proof) {
|
|
|
3502
3723
|
if (typeOnlyReference(reference)) return true;
|
|
3503
3724
|
const value = outerExpression(reference.identifier);
|
|
3504
3725
|
const parent = value.parent;
|
|
3505
|
-
const read = parent?.type ===
|
|
3726
|
+
const read = parent?.type === import_utils28.AST_NODE_TYPES.MemberExpression && parent.object === value ? parent : value;
|
|
3506
3727
|
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
3507
3728
|
});
|
|
3508
3729
|
}
|
|
3509
3730
|
function consumedElementRead(node, fields2, reads) {
|
|
3510
3731
|
const identifier = outerExpression(node);
|
|
3511
3732
|
const props = identifier.parent;
|
|
3512
|
-
if (!props || props.type !==
|
|
3733
|
+
if (!props || props.type !== import_utils28.AST_NODE_TYPES.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
3513
3734
|
const member3 = props.parent;
|
|
3514
|
-
if (member3.type !==
|
|
3735
|
+
if (member3.type !== import_utils28.AST_NODE_TYPES.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
3515
3736
|
const key = staticMemberKey(member3);
|
|
3516
3737
|
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields2);
|
|
3517
3738
|
}
|
|
@@ -3539,7 +3760,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3539
3760
|
const evaluate = (node, declaration, fields2) => {
|
|
3540
3761
|
const keys = [...fields2.keys()];
|
|
3541
3762
|
const opening = node.parent;
|
|
3542
|
-
services ??=
|
|
3763
|
+
services ??= import_utils28.ESLintUtils.getParserServices(context);
|
|
3543
3764
|
standardJSX ??= supportedJSX(services.program.getCompilerOptions(), context.sourceCode.getAllComments());
|
|
3544
3765
|
if (!standardJSX) return;
|
|
3545
3766
|
const checker = services.program.getTypeChecker();
|
|
@@ -3572,9 +3793,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3572
3793
|
};
|
|
3573
3794
|
return {
|
|
3574
3795
|
JSXSpreadAttribute(node) {
|
|
3575
|
-
if (node.argument.type !==
|
|
3796
|
+
if (node.argument.type !== import_utils28.AST_NODE_TYPES.ObjectExpression) return;
|
|
3576
3797
|
const opening = node.parent;
|
|
3577
|
-
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !==
|
|
3798
|
+
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== import_utils28.AST_NODE_TYPES.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
3578
3799
|
const declaration = privateElementDeclaration(opening);
|
|
3579
3800
|
if (!declaration) return;
|
|
3580
3801
|
const fields2 = literalFields(node.argument);
|
|
@@ -3586,7 +3807,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3586
3807
|
},
|
|
3587
3808
|
"Program:exit"() {
|
|
3588
3809
|
if (!candidates.length) return;
|
|
3589
|
-
services =
|
|
3810
|
+
services = import_utils28.ESLintUtils.getParserServices(context);
|
|
3590
3811
|
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
3591
3812
|
for (const { node, declaration, fields: fields2 } of candidates) evaluate(node, declaration, fields2);
|
|
3592
3813
|
}
|
|
@@ -3595,7 +3816,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3595
3816
|
});
|
|
3596
3817
|
|
|
3597
3818
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3598
|
-
var
|
|
3819
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
3599
3820
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3600
3821
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3601
3822
|
defaultLevel: "warning",
|
|
@@ -3659,19 +3880,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3659
3880
|
});
|
|
3660
3881
|
function hasUseServerDirective(program) {
|
|
3661
3882
|
for (const statement of program.body) {
|
|
3662
|
-
if (statement.type !==
|
|
3883
|
+
if (statement.type !== import_utils29.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0) return false;
|
|
3663
3884
|
if (statement.directive === "use server") return true;
|
|
3664
3885
|
}
|
|
3665
3886
|
return false;
|
|
3666
3887
|
}
|
|
3667
3888
|
function isTypeOnly(node) {
|
|
3668
3889
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3669
|
-
(specifier) => specifier.type ===
|
|
3890
|
+
(specifier) => specifier.type === import_utils29.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3670
3891
|
);
|
|
3671
3892
|
}
|
|
3672
3893
|
|
|
3673
3894
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3674
|
-
var
|
|
3895
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3675
3896
|
|
|
3676
3897
|
// src/rules/_secret-names.ts
|
|
3677
3898
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -3815,54 +4036,10 @@ function isAuthSecretName(identifier) {
|
|
|
3815
4036
|
return hasApiKey(tokens);
|
|
3816
4037
|
}
|
|
3817
4038
|
|
|
3818
|
-
// src/rules/_static-string.ts
|
|
3819
|
-
var import_utils28 = require("@typescript-eslint/utils");
|
|
3820
|
-
function staticString(node) {
|
|
3821
|
-
if (node === void 0) return null;
|
|
3822
|
-
const value = unwrapExpression(node);
|
|
3823
|
-
if (value.type === import_utils28.AST_NODE_TYPES.Literal && typeof value.value === "string") return value.value;
|
|
3824
|
-
return value.type === import_utils28.AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
3825
|
-
}
|
|
3826
|
-
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
3827
|
-
function scopedStaticString(node, sourceCode) {
|
|
3828
|
-
let value = unwrapExpression(node);
|
|
3829
|
-
if (value.type !== import_utils28.AST_NODE_TYPES.Identifier) return staticString(value);
|
|
3830
|
-
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
3831
|
-
if (values === void 0) {
|
|
3832
|
-
values = /* @__PURE__ */ new WeakMap();
|
|
3833
|
-
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
3834
|
-
}
|
|
3835
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3836
|
-
const pending = [];
|
|
3837
|
-
let result = null;
|
|
3838
|
-
while (value.type === import_utils28.AST_NODE_TYPES.Identifier) {
|
|
3839
|
-
const binding3 = import_utils28.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
3840
|
-
if (binding3 === null || seen.has(binding3)) break;
|
|
3841
|
-
if (values.has(binding3)) {
|
|
3842
|
-
result = values.get(binding3) ?? null;
|
|
3843
|
-
break;
|
|
3844
|
-
}
|
|
3845
|
-
seen.add(binding3);
|
|
3846
|
-
pending.push(binding3);
|
|
3847
|
-
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
3848
|
-
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;
|
|
3849
|
-
value = unwrapExpression(definition.node.init);
|
|
3850
|
-
if (value.type !== import_utils28.AST_NODE_TYPES.Identifier) result = staticString(value);
|
|
3851
|
-
}
|
|
3852
|
-
for (const binding3 of pending) values.set(binding3, result);
|
|
3853
|
-
return result;
|
|
3854
|
-
}
|
|
3855
|
-
function staticPropertyName(node, sourceCode) {
|
|
3856
|
-
const direct = import_utils28.ASTUtils.getPropertyName(node);
|
|
3857
|
-
if (direct !== null || !node.computed) return direct;
|
|
3858
|
-
const key = node.type === import_utils28.AST_NODE_TYPES.MemberExpression ? node.property : node.key;
|
|
3859
|
-
return scopedStaticString(key, sourceCode);
|
|
3860
|
-
}
|
|
3861
|
-
|
|
3862
4039
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3863
4040
|
var STORAGE_NAMES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
3864
4041
|
var METADATA_WORDS = /* @__PURE__ */ new Set(["page", "cursor", "next", "hint", "expires", "expiry", "expiration"]);
|
|
3865
|
-
var
|
|
4042
|
+
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
3866
4043
|
var NO_CREDENTIAL_IN_BROWSER_STORAGE_DOCUMENTATION = {
|
|
3867
4044
|
defaultLevel: "warning",
|
|
3868
4045
|
summary: "Do not write credential-named values to browser storage or script-readable cookies.",
|
|
@@ -3920,7 +4097,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3920
4097
|
return {
|
|
3921
4098
|
CallExpression(node) {
|
|
3922
4099
|
const callee = unwrapExpression(node.callee);
|
|
3923
|
-
if (callee.type !==
|
|
4100
|
+
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)) {
|
|
3924
4101
|
return;
|
|
3925
4102
|
}
|
|
3926
4103
|
const [key] = node.arguments;
|
|
@@ -3928,12 +4105,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3928
4105
|
},
|
|
3929
4106
|
AssignmentExpression(node) {
|
|
3930
4107
|
const target = node.left;
|
|
3931
|
-
if (target.type !==
|
|
4108
|
+
if (target.type !== import_utils30.AST_NODE_TYPES.MemberExpression) return;
|
|
3932
4109
|
if (isStorage(sourceCode, target.object)) {
|
|
3933
4110
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
3934
4111
|
return;
|
|
3935
4112
|
}
|
|
3936
|
-
if (!target.computed && target.property.type ===
|
|
4113
|
+
if (!target.computed && target.property.type === import_utils30.AST_NODE_TYPES.Identifier && target.property.name === "cookie" && globalMemberName(sourceCode, target.object) === "document") {
|
|
3937
4114
|
report2(node, cookieName(node.right));
|
|
3938
4115
|
}
|
|
3939
4116
|
}
|
|
@@ -3946,34 +4123,34 @@ function isStorage(sourceCode, node) {
|
|
|
3946
4123
|
}
|
|
3947
4124
|
function globalMemberName(sourceCode, node) {
|
|
3948
4125
|
const value = unwrapExpression(node);
|
|
3949
|
-
if (value.type ===
|
|
3950
|
-
if (value.type ===
|
|
4126
|
+
if (value.type === import_utils30.AST_NODE_TYPES.Identifier) return isUnshadowed(sourceCode, value) ? value.name : null;
|
|
4127
|
+
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)) {
|
|
3951
4128
|
return value.property.name;
|
|
3952
4129
|
}
|
|
3953
4130
|
return null;
|
|
3954
4131
|
}
|
|
3955
4132
|
function isUnshadowed(sourceCode, node) {
|
|
3956
|
-
const variable =
|
|
4133
|
+
const variable = import_utils30.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3957
4134
|
return variable === null || variable.defs.length === 0;
|
|
3958
4135
|
}
|
|
3959
4136
|
function storedPropertyKey(sourceCode, target) {
|
|
3960
|
-
if (!target.computed) return target.property.type ===
|
|
4137
|
+
if (!target.computed) return target.property.type === import_utils30.AST_NODE_TYPES.Identifier ? target.property.name : null;
|
|
3961
4138
|
return scopedStaticString(target.property, sourceCode);
|
|
3962
4139
|
}
|
|
3963
4140
|
function cookieName(value) {
|
|
3964
4141
|
let expression = unwrapExpression(value);
|
|
3965
|
-
while (expression.type ===
|
|
4142
|
+
while (expression.type === import_utils30.AST_NODE_TYPES.BinaryExpression && expression.operator === "+") {
|
|
3966
4143
|
expression = unwrapExpression(expression.left);
|
|
3967
4144
|
}
|
|
3968
4145
|
let text = null;
|
|
3969
|
-
if (expression.type ===
|
|
3970
|
-
if (expression.type ===
|
|
4146
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.Literal && typeof expression.value === "string") text = expression.value;
|
|
4147
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.TemplateLiteral) text = expression.quasis[0]?.value.cooked ?? null;
|
|
3971
4148
|
if (text === null || !text.includes("=")) return null;
|
|
3972
4149
|
return text.slice(0, text.indexOf("=")).trim();
|
|
3973
4150
|
}
|
|
3974
4151
|
|
|
3975
4152
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
3976
|
-
var
|
|
4153
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3977
4154
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
3978
4155
|
var NUMBER_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat"]);
|
|
3979
4156
|
var SEARCH_PARAM_TYPES = /* @__PURE__ */ new Set(["URLSearchParams", "ReadonlyURLSearchParams"]);
|
|
@@ -4030,7 +4207,7 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4030
4207
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context)) return {};
|
|
4031
4208
|
let services;
|
|
4032
4209
|
try {
|
|
4033
|
-
services =
|
|
4210
|
+
services = import_utils31.ESLintUtils.getParserServices(context);
|
|
4034
4211
|
} catch {
|
|
4035
4212
|
services = null;
|
|
4036
4213
|
}
|
|
@@ -4052,27 +4229,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4052
4229
|
}
|
|
4053
4230
|
});
|
|
4054
4231
|
function isNumericParser(sourceCode, callee) {
|
|
4055
|
-
if (callee.type ===
|
|
4232
|
+
if (callee.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4056
4233
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
4057
4234
|
}
|
|
4058
|
-
return callee.type ===
|
|
4235
|
+
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);
|
|
4059
4236
|
}
|
|
4060
4237
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4061
|
-
const variable =
|
|
4238
|
+
const variable = import_utils31.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4062
4239
|
return variable === null || variable.defs.length === 0;
|
|
4063
4240
|
}
|
|
4064
4241
|
function searchParamGetCall(argument) {
|
|
4065
4242
|
let value = unwrapExpression(argument);
|
|
4066
|
-
if (value.type ===
|
|
4067
|
-
if (value.type ===
|
|
4068
|
-
if (value.type ===
|
|
4069
|
-
if (value.type !==
|
|
4243
|
+
if (value.type === import_utils31.AST_NODE_TYPES.AwaitExpression) value = unwrapExpression(value.argument);
|
|
4244
|
+
if (value.type === import_utils31.AST_NODE_TYPES.LogicalExpression && value.operator === "??") value = unwrapExpression(value.left);
|
|
4245
|
+
if (value.type === import_utils31.AST_NODE_TYPES.ChainExpression) value = value.expression;
|
|
4246
|
+
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") {
|
|
4070
4247
|
return null;
|
|
4071
4248
|
}
|
|
4072
4249
|
return value;
|
|
4073
4250
|
}
|
|
4074
4251
|
function isSearchParamReceiver(call, services) {
|
|
4075
|
-
if (call.callee.type !==
|
|
4252
|
+
if (call.callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression) return false;
|
|
4076
4253
|
const checker = services.program.getTypeChecker();
|
|
4077
4254
|
const type = checker.getNonNullableType(
|
|
4078
4255
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4084,7 +4261,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4084
4261
|
// package.json
|
|
4085
4262
|
var package_default = {
|
|
4086
4263
|
name: "@sarj/eslint-plugin",
|
|
4087
|
-
version: "16.
|
|
4264
|
+
version: "16.38.52",
|
|
4088
4265
|
packageManager: "npm@12.2.1",
|
|
4089
4266
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4090
4267
|
type: "module",
|
|
@@ -4206,11 +4383,11 @@ var package_default = {
|
|
|
4206
4383
|
};
|
|
4207
4384
|
|
|
4208
4385
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4209
|
-
var
|
|
4386
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4210
4387
|
var ts12 = __toESM(require("typescript"), 1);
|
|
4211
4388
|
|
|
4212
4389
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4213
|
-
var
|
|
4390
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4214
4391
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
4215
4392
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
4216
4393
|
const source = call.getSourceFile();
|
|
@@ -4284,7 +4461,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4284
4461
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4285
4462
|
rejected.expression.expression.getStart()
|
|
4286
4463
|
);
|
|
4287
|
-
return identifier?.type ===
|
|
4464
|
+
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;
|
|
4288
4465
|
}
|
|
4289
4466
|
function exactConstruction(node, consumer, implementation) {
|
|
4290
4467
|
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4650,7 +4827,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4650
4827
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
4651
4828
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
4652
4829
|
return {};
|
|
4653
|
-
const services =
|
|
4830
|
+
const services = import_utils33.ESLintUtils.getParserServices(context);
|
|
4654
4831
|
const checker = services.program.getTypeChecker();
|
|
4655
4832
|
function inspect(node) {
|
|
4656
4833
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -4665,7 +4842,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4665
4842
|
return;
|
|
4666
4843
|
const parameters = signature.getParameters();
|
|
4667
4844
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4668
|
-
if (argument.type !==
|
|
4845
|
+
if (argument.type !== import_utils33.AST_NODE_TYPES.NewExpression) continue;
|
|
4669
4846
|
const parameter = parameters[index];
|
|
4670
4847
|
if (parameter === void 0) continue;
|
|
4671
4848
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4712,18 +4889,18 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4712
4889
|
});
|
|
4713
4890
|
|
|
4714
4891
|
// src/rules/require-explicit-service-contract.ts
|
|
4715
|
-
var
|
|
4892
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
4716
4893
|
|
|
4717
4894
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4718
|
-
var
|
|
4895
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4719
4896
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4720
4897
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4721
4898
|
return null;
|
|
4722
4899
|
const [contractStatement, worker, classStatement, factoryStatement] = sourceCode.ast.body;
|
|
4723
|
-
const contract = contractStatement?.type ===
|
|
4724
|
-
const implementation = classStatement?.type ===
|
|
4725
|
-
const factory = factoryStatement?.type ===
|
|
4726
|
-
if (contract?.type !==
|
|
4900
|
+
const contract = contractStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? contractStatement.declaration : null;
|
|
4901
|
+
const implementation = classStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? classStatement.declaration : classStatement;
|
|
4902
|
+
const factory = factoryStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? factoryStatement.declaration : null;
|
|
4903
|
+
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))
|
|
4727
4904
|
return null;
|
|
4728
4905
|
const operation2 = contractOperation(contract);
|
|
4729
4906
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4742,17 +4919,17 @@ function ordinaryClass(node) {
|
|
|
4742
4919
|
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;
|
|
4743
4920
|
}
|
|
4744
4921
|
function ordinaryFactory(node) {
|
|
4745
|
-
return node?.type ===
|
|
4922
|
+
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;
|
|
4746
4923
|
}
|
|
4747
4924
|
function interfaceOperation(node) {
|
|
4748
4925
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4749
4926
|
}
|
|
4750
4927
|
function contractOperation(node) {
|
|
4751
|
-
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type ===
|
|
4928
|
+
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type === import_utils34.AST_NODE_TYPES.TSTypeLiteral ? singletonOperation(node.typeAnnotation.members) : null;
|
|
4752
4929
|
}
|
|
4753
4930
|
function singletonOperation(members) {
|
|
4754
4931
|
const member3 = members[0];
|
|
4755
|
-
return members.length === 1 && member3?.type ===
|
|
4932
|
+
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;
|
|
4756
4933
|
}
|
|
4757
4934
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4758
4935
|
const names = declarations.flatMap(
|
|
@@ -4763,7 +4940,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4763
4940
|
);
|
|
4764
4941
|
}
|
|
4765
4942
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4766
|
-
const binding3 =
|
|
4943
|
+
const binding3 = import_utils34.ASTUtils.findVariable(
|
|
4767
4944
|
sourceCode.getScope(reference),
|
|
4768
4945
|
reference.name
|
|
4769
4946
|
);
|
|
@@ -4771,45 +4948,45 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
4771
4948
|
}
|
|
4772
4949
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
4773
4950
|
const constructor = implementation.body.body[0];
|
|
4774
|
-
if (constructor?.type !==
|
|
4951
|
+
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)
|
|
4775
4952
|
return null;
|
|
4776
4953
|
const property = constructor.value.params[0];
|
|
4777
|
-
if (property?.type !==
|
|
4954
|
+
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))
|
|
4778
4955
|
return null;
|
|
4779
4956
|
return property.parameter.name;
|
|
4780
4957
|
}
|
|
4781
4958
|
function typeReference(sourceCode, annotation, declaration) {
|
|
4782
4959
|
const type = annotation?.typeAnnotation;
|
|
4783
|
-
return type?.type ===
|
|
4960
|
+
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);
|
|
4784
4961
|
}
|
|
4785
4962
|
function forwardsOperation(implementation, field, operation2) {
|
|
4786
4963
|
const method = implementation.body.body[1];
|
|
4787
|
-
if (method?.type !==
|
|
4964
|
+
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)
|
|
4788
4965
|
return false;
|
|
4789
4966
|
const statement = method.value.body.body[0];
|
|
4790
|
-
const call = statement?.type ===
|
|
4791
|
-
return call?.type ===
|
|
4967
|
+
const call = statement?.type === import_utils34.AST_NODE_TYPES.ExpressionStatement ? statement.expression : null;
|
|
4968
|
+
return call?.type === import_utils34.AST_NODE_TYPES.CallExpression && !call.optional && call.typeArguments === void 0 && call.arguments.length === 0 && forwardedMember(call.callee, field, operation2);
|
|
4792
4969
|
}
|
|
4793
4970
|
function forwardedMember(node, field, operation2) {
|
|
4794
|
-
if (node.type !==
|
|
4971
|
+
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)
|
|
4795
4972
|
return false;
|
|
4796
4973
|
const receiver = node.object;
|
|
4797
|
-
return receiver.type ===
|
|
4974
|
+
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;
|
|
4798
4975
|
}
|
|
4799
4976
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
4800
4977
|
const parameter = factory.params[0];
|
|
4801
|
-
if (parameter?.type !==
|
|
4978
|
+
if (parameter?.type !== import_utils34.AST_NODE_TYPES.Identifier || parameter.optional || !typeReference(sourceCode, parameter.typeAnnotation, worker) || !typeReference(sourceCode, factory.returnType, contract))
|
|
4802
4979
|
return false;
|
|
4803
4980
|
const statement = factory.body.body[0];
|
|
4804
|
-
const constructed = statement?.type ===
|
|
4805
|
-
if (constructed?.type !==
|
|
4981
|
+
const constructed = statement?.type === import_utils34.AST_NODE_TYPES.ReturnStatement ? statement.argument : null;
|
|
4982
|
+
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)
|
|
4806
4983
|
return false;
|
|
4807
4984
|
const argument = constructed.arguments[0];
|
|
4808
|
-
return argument?.type ===
|
|
4985
|
+
return argument?.type === import_utils34.AST_NODE_TYPES.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
4809
4986
|
}
|
|
4810
4987
|
|
|
4811
4988
|
// src/rules/require-port-for-service.ts
|
|
4812
|
-
var
|
|
4989
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4813
4990
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
4814
4991
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
4815
4992
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -4893,50 +5070,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
4893
5070
|
"||="
|
|
4894
5071
|
]);
|
|
4895
5072
|
var staticMemberName = (member3) => {
|
|
4896
|
-
if (member3.property.type ===
|
|
5073
|
+
if (member3.property.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier)
|
|
4897
5074
|
return `#${member3.property.name}`;
|
|
4898
|
-
return
|
|
5075
|
+
return import_utils35.ASTUtils.getPropertyName(member3);
|
|
4899
5076
|
};
|
|
4900
5077
|
var detachedValueExports = (program) => {
|
|
4901
5078
|
const names = /* @__PURE__ */ new Set();
|
|
4902
5079
|
for (const statement of program.body) {
|
|
4903
|
-
if (statement.type ===
|
|
5080
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
4904
5081
|
for (const specifier of statement.specifiers) {
|
|
4905
5082
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
4906
5083
|
}
|
|
4907
|
-
} else if (statement.type ===
|
|
5084
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4908
5085
|
names.add(statement.declaration.name);
|
|
4909
|
-
} else if (statement.type ===
|
|
5086
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4910
5087
|
names.add(statement.expression.name);
|
|
4911
5088
|
}
|
|
4912
5089
|
}
|
|
4913
5090
|
return names;
|
|
4914
5091
|
};
|
|
4915
|
-
var isExportedClass = (node, detached) => node.parent.type ===
|
|
5092
|
+
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);
|
|
4916
5093
|
var createExportedServiceClassResolver = (program) => {
|
|
4917
5094
|
const detached = detachedValueExports(program);
|
|
4918
5095
|
return (node) => isExportedClass(node, detached);
|
|
4919
5096
|
};
|
|
4920
5097
|
var readTypeReference = (annotation) => {
|
|
4921
|
-
if (annotation?.type ===
|
|
5098
|
+
if (annotation?.type === import_utils35.AST_NODE_TYPES.TSUnionType) {
|
|
4922
5099
|
const members = annotation.types.filter(
|
|
4923
|
-
(member3) => member3.type !==
|
|
5100
|
+
(member3) => member3.type !== import_utils35.AST_NODE_TYPES.TSUndefinedKeyword && member3.type !== import_utils35.AST_NODE_TYPES.TSNullKeyword
|
|
4924
5101
|
);
|
|
4925
5102
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
4926
5103
|
}
|
|
4927
|
-
if (annotation === void 0 || annotation.type !==
|
|
5104
|
+
if (annotation === void 0 || annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference)
|
|
4928
5105
|
return null;
|
|
4929
5106
|
const { typeName } = annotation;
|
|
4930
|
-
const rightmost = typeName.type ===
|
|
5107
|
+
const rightmost = typeName.type === import_utils35.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils35.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
4931
5108
|
if (rightmost === null) return null;
|
|
4932
5109
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
4933
5110
|
};
|
|
4934
|
-
var qualifiedName = (name) => name.type ===
|
|
5111
|
+
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}` : "";
|
|
4935
5112
|
var propertySignatureTypes = (members) => {
|
|
4936
5113
|
const types = /* @__PURE__ */ new Map();
|
|
4937
5114
|
for (const member3 of members) {
|
|
4938
|
-
if (member3.type !==
|
|
4939
|
-
if (member3.computed || member3.key.type !==
|
|
5115
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5116
|
+
if (member3.computed || member3.key.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
4940
5117
|
continue;
|
|
4941
5118
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
4942
5119
|
if (reference === null) continue;
|
|
@@ -4948,18 +5125,18 @@ var fileTypeIndex = (program) => {
|
|
|
4948
5125
|
const objects = /* @__PURE__ */ new Map();
|
|
4949
5126
|
const functionAliases = localFunctionAliases(program);
|
|
4950
5127
|
function collectDeclaredType(statement) {
|
|
4951
|
-
const declaration = statement.type ===
|
|
4952
|
-
if (declaration?.type ===
|
|
5128
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5129
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
4953
5130
|
objects.set(
|
|
4954
5131
|
declaration.id.name,
|
|
4955
5132
|
propertySignatureTypes(declaration.body.body)
|
|
4956
5133
|
);
|
|
4957
5134
|
return;
|
|
4958
5135
|
}
|
|
4959
|
-
if (declaration?.type !==
|
|
5136
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) return;
|
|
4960
5137
|
const aliased = declaration.typeAnnotation;
|
|
4961
|
-
const literals = aliased.type ===
|
|
4962
|
-
(part) => part.type ===
|
|
5138
|
+
const literals = aliased.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter(
|
|
5139
|
+
(part) => part.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral
|
|
4963
5140
|
) : [];
|
|
4964
5141
|
if (literals.length === 0) return;
|
|
4965
5142
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -4979,12 +5156,12 @@ function localFunctionAliases(program) {
|
|
|
4979
5156
|
const names = /* @__PURE__ */ new Set();
|
|
4980
5157
|
const parents = /* @__PURE__ */ new Map();
|
|
4981
5158
|
for (const statement of program.body) {
|
|
4982
|
-
const declaration = statement.type ===
|
|
4983
|
-
if (declaration?.type !==
|
|
5159
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5160
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
4984
5161
|
const annotation = declaration.typeAnnotation;
|
|
4985
|
-
if (annotation.type ===
|
|
5162
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSFunctionType || annotation.type === import_utils35.AST_NODE_TYPES.TSConstructorType)
|
|
4986
5163
|
names.add(declaration.id.name);
|
|
4987
|
-
if (annotation.type ===
|
|
5164
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
4988
5165
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
4989
5166
|
}
|
|
4990
5167
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -5020,32 +5197,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5020
5197
|
function scanStoredFields(body4) {
|
|
5021
5198
|
const pending = [...body4.body];
|
|
5022
5199
|
function recordStoredField(current) {
|
|
5023
|
-
if (current.type ===
|
|
5200
|
+
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)
|
|
5024
5201
|
return;
|
|
5025
|
-
if (current.type ===
|
|
5202
|
+
if (current.type === import_utils35.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5026
5203
|
localBindings2.add(current.id.name);
|
|
5027
|
-
const expression = current.type ===
|
|
5204
|
+
const expression = current.type === import_utils35.AST_NODE_TYPES.AssignmentExpression ? current : null;
|
|
5028
5205
|
const storedField = writtenInstanceField(current);
|
|
5029
5206
|
if (storedField !== null) {
|
|
5030
5207
|
if (writtenFieldNames.has(storedField))
|
|
5031
5208
|
unstableFieldNames.add(storedField);
|
|
5032
5209
|
writtenFieldNames.add(storedField);
|
|
5033
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5210
|
+
if (expression?.operator !== "=" || expression.parent.type !== import_utils35.AST_NODE_TYPES.ExpressionStatement || expression.parent.parent !== body4)
|
|
5034
5211
|
unstableFieldNames.add(storedField);
|
|
5035
5212
|
}
|
|
5036
|
-
if (expression?.type !==
|
|
5213
|
+
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) {
|
|
5037
5214
|
enqueueChildren(current);
|
|
5038
5215
|
return;
|
|
5039
5216
|
}
|
|
5040
5217
|
const source = unwrapExpression(expression.right);
|
|
5041
|
-
if (source.type ===
|
|
5218
|
+
if (source.type === import_utils35.AST_NODE_TYPES.NewExpression) {
|
|
5042
5219
|
constructedFields += 1;
|
|
5043
5220
|
constructedFieldNames.add(storedField);
|
|
5044
|
-
} else if (source.type ===
|
|
5221
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5045
5222
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
5046
5223
|
fields2.add(storedField);
|
|
5047
5224
|
storedFieldsFrom.set(source.name, fields2);
|
|
5048
|
-
} else if (source.type ===
|
|
5225
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5049
5226
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
5050
5227
|
fields2.add(storedField);
|
|
5051
5228
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5080,7 +5257,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5080
5257
|
)) {
|
|
5081
5258
|
if (localBindings2.has(reference.name)) continue;
|
|
5082
5259
|
let fields2 = reference.fields;
|
|
5083
|
-
if (parameter.type ===
|
|
5260
|
+
if (parameter.type === import_utils35.AST_NODE_TYPES.TSParameterProperty) {
|
|
5084
5261
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5085
5262
|
fields2 = [reference.name];
|
|
5086
5263
|
} else if (fields2.length === 0)
|
|
@@ -5103,8 +5280,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5103
5280
|
};
|
|
5104
5281
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5105
5282
|
let target = parameter;
|
|
5106
|
-
if (target.type ===
|
|
5107
|
-
if (target.type ===
|
|
5283
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5284
|
+
if (target.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5108
5285
|
return objectPatternCollaborators(target, declared);
|
|
5109
5286
|
}
|
|
5110
5287
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5114,10 +5291,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5114
5291
|
};
|
|
5115
5292
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5116
5293
|
let target = annotated;
|
|
5117
|
-
if (target.type ===
|
|
5294
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5118
5295
|
target = target.parameter;
|
|
5119
|
-
if (target.type ===
|
|
5120
|
-
if (target.type !==
|
|
5296
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5297
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return [];
|
|
5121
5298
|
const members = bagMemberTypes(
|
|
5122
5299
|
target.typeAnnotation?.typeAnnotation,
|
|
5123
5300
|
declared
|
|
@@ -5136,10 +5313,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5136
5313
|
};
|
|
5137
5314
|
var namedParameterCollaborator = (annotated) => {
|
|
5138
5315
|
let target = annotated;
|
|
5139
|
-
if (target.type ===
|
|
5316
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5140
5317
|
target = target.parameter;
|
|
5141
|
-
if (target.type ===
|
|
5142
|
-
if (target.type !==
|
|
5318
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5319
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5143
5320
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5144
5321
|
if (reference === null) return null;
|
|
5145
5322
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5151,12 +5328,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5151
5328
|
if (members === null) return [];
|
|
5152
5329
|
const collaborators = [];
|
|
5153
5330
|
for (const property of pattern.properties) {
|
|
5154
|
-
if (property.type !==
|
|
5331
|
+
if (property.type !== import_utils35.AST_NODE_TYPES.Property || property.computed)
|
|
5155
5332
|
continue;
|
|
5156
|
-
if (property.key.type !==
|
|
5333
|
+
if (property.key.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5157
5334
|
const key = property.key.name;
|
|
5158
|
-
const bound = property.value.type ===
|
|
5159
|
-
if (bound.type !==
|
|
5335
|
+
const bound = property.value.type === import_utils35.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
5336
|
+
if (bound.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5160
5337
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5161
5338
|
const reference = members.get(key);
|
|
5162
5339
|
if (reference === void 0) continue;
|
|
@@ -5166,22 +5343,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5166
5343
|
};
|
|
5167
5344
|
var bagMemberTypes = (annotation, declared) => {
|
|
5168
5345
|
if (annotation === void 0) return null;
|
|
5169
|
-
if (annotation.type ===
|
|
5346
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5170
5347
|
return propertySignatureTypes(annotation.members);
|
|
5171
5348
|
}
|
|
5172
|
-
if (annotation.type !==
|
|
5349
|
+
if (annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5173
5350
|
return null;
|
|
5174
5351
|
}
|
|
5175
5352
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5176
5353
|
};
|
|
5177
5354
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5178
|
-
if (node.type ===
|
|
5355
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5179
5356
|
const { callee } = node;
|
|
5180
|
-
if (callee.type ===
|
|
5357
|
+
if (callee.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5181
5358
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5182
|
-
return callee.type ===
|
|
5359
|
+
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;
|
|
5183
5360
|
}
|
|
5184
|
-
return node.type ===
|
|
5361
|
+
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);
|
|
5185
5362
|
});
|
|
5186
5363
|
var subtreeHas = (root, found) => {
|
|
5187
5364
|
let hit = false;
|
|
@@ -5201,26 +5378,26 @@ var subtreeHas = (root, found) => {
|
|
|
5201
5378
|
};
|
|
5202
5379
|
var invokedInstanceField = (call) => {
|
|
5203
5380
|
let callee = unwrapExpression(call.callee);
|
|
5204
|
-
while (callee.type ===
|
|
5381
|
+
while (callee.type === import_utils35.AST_NODE_TYPES.ChainExpression)
|
|
5205
5382
|
callee = unwrapExpression(callee.expression);
|
|
5206
5383
|
const direct = instanceField(callee);
|
|
5207
5384
|
if (direct !== null) return direct;
|
|
5208
|
-
return callee.type ===
|
|
5385
|
+
return callee.type === import_utils35.AST_NODE_TYPES.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5209
5386
|
};
|
|
5210
5387
|
var instanceField = (candidate2) => {
|
|
5211
5388
|
let node = candidate2;
|
|
5212
|
-
while (node.type ===
|
|
5389
|
+
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)
|
|
5213
5390
|
node = node.expression;
|
|
5214
|
-
return node.type ===
|
|
5391
|
+
return node.type === import_utils35.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils35.AST_NODE_TYPES.ThisExpression ? staticMemberName(node) : null;
|
|
5215
5392
|
};
|
|
5216
5393
|
function writtenInstanceField(node) {
|
|
5217
|
-
if (node.type ===
|
|
5394
|
+
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)
|
|
5218
5395
|
return instanceField(node.left);
|
|
5219
|
-
if (node.type ===
|
|
5396
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UpdateExpression)
|
|
5220
5397
|
return instanceField(node.argument);
|
|
5221
|
-
if (node.type ===
|
|
5398
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UnaryExpression && node.operator === "delete")
|
|
5222
5399
|
return instanceField(node.argument);
|
|
5223
|
-
if (node.type ===
|
|
5400
|
+
if (node.type === import_utils35.AST_NODE_TYPES.MemberExpression && isDestructuredWriteTarget(node))
|
|
5224
5401
|
return instanceField(node);
|
|
5225
5402
|
return null;
|
|
5226
5403
|
}
|
|
@@ -5229,39 +5406,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5229
5406
|
let target = access;
|
|
5230
5407
|
for (; ; ) {
|
|
5231
5408
|
const parent = target.parent;
|
|
5232
|
-
if (parent.type ===
|
|
5409
|
+
if (parent.type === import_utils35.AST_NODE_TYPES.Property && parent.value === target && parent.parent.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5233
5410
|
target = parent.parent;
|
|
5234
5411
|
continue;
|
|
5235
5412
|
}
|
|
5236
|
-
if (parent.type ===
|
|
5413
|
+
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) {
|
|
5237
5414
|
target = parent;
|
|
5238
5415
|
continue;
|
|
5239
5416
|
}
|
|
5240
|
-
return target !== access && (parent.type ===
|
|
5417
|
+
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;
|
|
5241
5418
|
}
|
|
5242
5419
|
}
|
|
5243
5420
|
var behaviorallyInvokedFields = (body3) => {
|
|
5244
5421
|
const invoked = /* @__PURE__ */ new Set();
|
|
5245
5422
|
const visit = (current) => {
|
|
5246
|
-
if (current.type ===
|
|
5423
|
+
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)
|
|
5247
5424
|
return;
|
|
5248
|
-
if (current.type ===
|
|
5425
|
+
if (current.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5249
5426
|
const field = invokedInstanceField(current);
|
|
5250
5427
|
if (field !== null) invoked.add(field);
|
|
5251
5428
|
}
|
|
5252
5429
|
forEachOwnAstChild(current, visit);
|
|
5253
5430
|
};
|
|
5254
5431
|
for (const member3 of body3.body) {
|
|
5255
|
-
if (member3.type ===
|
|
5256
|
-
if (member3.type ===
|
|
5432
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.StaticBlock || member3.static) continue;
|
|
5433
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition) {
|
|
5257
5434
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5258
5435
|
visit(member3.value.body);
|
|
5259
5436
|
continue;
|
|
5260
5437
|
}
|
|
5261
|
-
if (member3.type !==
|
|
5438
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition || member3.value === null)
|
|
5262
5439
|
continue;
|
|
5263
5440
|
visit(
|
|
5264
|
-
member3.value.type ===
|
|
5441
|
+
member3.value.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5265
5442
|
);
|
|
5266
5443
|
}
|
|
5267
5444
|
return invoked;
|
|
@@ -5281,8 +5458,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5281
5458
|
var fileInterfaceNames = (program) => {
|
|
5282
5459
|
const names = [];
|
|
5283
5460
|
for (const statement of program.body) {
|
|
5284
|
-
const declaration = statement.type ===
|
|
5285
|
-
if (declaration?.type ===
|
|
5461
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5462
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration)
|
|
5286
5463
|
names.push(declaration.id.name);
|
|
5287
5464
|
}
|
|
5288
5465
|
return names;
|
|
@@ -5290,22 +5467,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5290
5467
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5291
5468
|
const names = [];
|
|
5292
5469
|
function collectPublicCallable(member3) {
|
|
5293
|
-
if (member3.type ===
|
|
5470
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.PropertyDefinition) {
|
|
5294
5471
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5295
5472
|
return;
|
|
5296
|
-
if (member3.key.type ===
|
|
5297
|
-
if (member3.value?.type !==
|
|
5473
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5474
|
+
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(
|
|
5298
5475
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5299
5476
|
)))
|
|
5300
5477
|
return;
|
|
5301
5478
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5302
5479
|
return;
|
|
5303
5480
|
}
|
|
5304
|
-
if (member3.type !==
|
|
5481
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition) return;
|
|
5305
5482
|
if (member3.kind !== "method" || member3.static) return;
|
|
5306
5483
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5307
5484
|
return;
|
|
5308
|
-
if (member3.key.type ===
|
|
5485
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5309
5486
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5310
5487
|
}
|
|
5311
5488
|
for (const member3 of body3.body) {
|
|
@@ -5316,13 +5493,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5316
5493
|
var isFluentConstructionObject = (node, getText) => {
|
|
5317
5494
|
if (node.id === null) return false;
|
|
5318
5495
|
const methods = node.body.body.filter(
|
|
5319
|
-
(member3) => member3.type ===
|
|
5496
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "method" && !member3.static && member3.accessibility !== "private" && member3.accessibility !== "protected" && member3.value.body !== null
|
|
5320
5497
|
);
|
|
5321
5498
|
if (methods.length === 0) return false;
|
|
5322
5499
|
return methods.every((member3) => {
|
|
5323
5500
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5324
5501
|
if (result === void 0) return false;
|
|
5325
|
-
const returnsOwnType = result.type ===
|
|
5502
|
+
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;
|
|
5326
5503
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5327
5504
|
});
|
|
5328
5505
|
};
|
|
@@ -5330,10 +5507,10 @@ function localClassAbstractness(program) {
|
|
|
5330
5507
|
const classes = /* @__PURE__ */ new Map();
|
|
5331
5508
|
const parents = /* @__PURE__ */ new Map();
|
|
5332
5509
|
for (const statement of program.body) {
|
|
5333
|
-
const declaration = statement.type ===
|
|
5334
|
-
if (declaration?.type ===
|
|
5510
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5511
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
5335
5512
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5336
|
-
if (declaration.superClass?.type ===
|
|
5513
|
+
if (declaration.superClass?.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5337
5514
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5338
5515
|
}
|
|
5339
5516
|
}
|
|
@@ -5351,9 +5528,9 @@ function localClassAbstractness(program) {
|
|
|
5351
5528
|
return classes;
|
|
5352
5529
|
}
|
|
5353
5530
|
function declaredMemberName(member3) {
|
|
5354
|
-
if (!member3.computed && member3.key.type ===
|
|
5531
|
+
if (!member3.computed && member3.key.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5355
5532
|
return member3.key.name;
|
|
5356
|
-
if (member3.key.type ===
|
|
5533
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.Literal && typeof member3.key.value === "string")
|
|
5357
5534
|
return member3.key.value;
|
|
5358
5535
|
return null;
|
|
5359
5536
|
}
|
|
@@ -5362,35 +5539,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5362
5539
|
const parents = /* @__PURE__ */ new Map();
|
|
5363
5540
|
const functionAliases = localFunctionAliases(program);
|
|
5364
5541
|
function collectInterfaceSurface(statement) {
|
|
5365
|
-
const declaration = statement.type ===
|
|
5366
|
-
if (declaration?.type ===
|
|
5542
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5543
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
5367
5544
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5368
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5545
|
+
const parts = declaration.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5369
5546
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5370
5547
|
for (const part of parts) {
|
|
5371
|
-
if (part.type ===
|
|
5548
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5372
5549
|
inherited.push(part.typeName.name);
|
|
5373
5550
|
continue;
|
|
5374
5551
|
}
|
|
5375
|
-
if (part.type ===
|
|
5552
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference) {
|
|
5376
5553
|
inherited.push("*");
|
|
5377
5554
|
continue;
|
|
5378
5555
|
}
|
|
5379
|
-
if (part.type !==
|
|
5556
|
+
if (part.type !== import_utils35.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
5380
5557
|
addCallableMembers(part.members, callables2);
|
|
5381
5558
|
}
|
|
5382
5559
|
interfaces.set(declaration.id.name, callables2);
|
|
5383
5560
|
parents.set(declaration.id.name, inherited);
|
|
5384
5561
|
return;
|
|
5385
5562
|
}
|
|
5386
|
-
if (declaration?.type !==
|
|
5563
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) return;
|
|
5387
5564
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5388
5565
|
addCallableMembers(declaration.body.body, callables);
|
|
5389
5566
|
interfaces.set(declaration.id.name, callables);
|
|
5390
5567
|
parents.set(declaration.id.name, [
|
|
5391
5568
|
...parents.get(declaration.id.name) ?? [],
|
|
5392
5569
|
...declaration.extends.flatMap(
|
|
5393
|
-
(heritage) => heritage.expression.type ===
|
|
5570
|
+
(heritage) => heritage.expression.type === import_utils35.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
5394
5571
|
)
|
|
5395
5572
|
]);
|
|
5396
5573
|
}
|
|
@@ -5399,17 +5576,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5399
5576
|
}
|
|
5400
5577
|
function addCallableMembers(members, callables) {
|
|
5401
5578
|
for (const member3 of members) {
|
|
5402
|
-
if (member3.type !==
|
|
5579
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature)
|
|
5403
5580
|
continue;
|
|
5404
5581
|
const name = declaredMemberName(member3);
|
|
5405
5582
|
if (name === null) continue;
|
|
5406
|
-
if (member3.type ===
|
|
5583
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSMethodSignature) {
|
|
5407
5584
|
callables.add(name);
|
|
5408
5585
|
continue;
|
|
5409
5586
|
}
|
|
5410
|
-
if (member3.type !==
|
|
5587
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5411
5588
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5412
|
-
if (annotation?.type ===
|
|
5589
|
+
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))
|
|
5413
5590
|
callables.add(name);
|
|
5414
5591
|
}
|
|
5415
5592
|
}
|
|
@@ -5439,7 +5616,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5439
5616
|
}
|
|
5440
5617
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5441
5618
|
if (node.superClass !== null) {
|
|
5442
|
-
if (node.superClass.type !==
|
|
5619
|
+
if (node.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return true;
|
|
5443
5620
|
const localAbstract = classes.get(node.superClass.name);
|
|
5444
5621
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5445
5622
|
}
|
|
@@ -5478,7 +5655,7 @@ var require_port_for_service_default = createRule({
|
|
|
5478
5655
|
if (node.abstract === true) return;
|
|
5479
5656
|
if (node.decorators.length > 0) return;
|
|
5480
5657
|
const ctor = node.body.body.find(
|
|
5481
|
-
(member3) => member3.type ===
|
|
5658
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null && member3.value.body !== void 0
|
|
5482
5659
|
);
|
|
5483
5660
|
if (ctor === void 0) return;
|
|
5484
5661
|
const constructorFacts = readConstructor(
|
|
@@ -5528,7 +5705,7 @@ var require_port_for_service_default = createRule({
|
|
|
5528
5705
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5529
5706
|
const combined = /* @__PURE__ */ new Set();
|
|
5530
5707
|
for (const implementation of node.implements) {
|
|
5531
|
-
if (implementation.expression.type !==
|
|
5708
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5532
5709
|
return true;
|
|
5533
5710
|
const name = implementation.expression.name;
|
|
5534
5711
|
const localAbstract = classes.get(name);
|
|
@@ -5545,7 +5722,7 @@ function createServiceOperationResolver(program) {
|
|
|
5545
5722
|
let declaredTypes = null;
|
|
5546
5723
|
return (node) => {
|
|
5547
5724
|
const ctor = node.body.body.find(
|
|
5548
|
-
(member3) => member3.type ===
|
|
5725
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5549
5726
|
);
|
|
5550
5727
|
if (ctor === void 0) return [];
|
|
5551
5728
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5563,7 +5740,7 @@ function createServiceOperationResolver(program) {
|
|
|
5563
5740
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5564
5741
|
forEachServiceCall(body3, (call) => {
|
|
5565
5742
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5566
|
-
if (call.callee.type ===
|
|
5743
|
+
if (call.callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && call.callee.object.type === import_utils35.AST_NODE_TYPES.ThisExpression) {
|
|
5567
5744
|
const callee = staticMemberName(call.callee);
|
|
5568
5745
|
if (callee !== null) {
|
|
5569
5746
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5602,11 +5779,11 @@ function serviceOperationBodies(node) {
|
|
|
5602
5779
|
});
|
|
5603
5780
|
}
|
|
5604
5781
|
for (const member3 of node.body.body) {
|
|
5605
|
-
if (member3.type !==
|
|
5782
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition)
|
|
5606
5783
|
continue;
|
|
5607
|
-
if (member3.static || member3.decorators.length > 0 || member3.type ===
|
|
5784
|
+
if (member3.static || member3.decorators.length > 0 || member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind !== "method")
|
|
5608
5785
|
continue;
|
|
5609
|
-
if (member3.value?.type !==
|
|
5786
|
+
if (member3.value?.type !== import_utils35.AST_NODE_TYPES.FunctionExpression && member3.value?.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
5610
5787
|
continue;
|
|
5611
5788
|
const name = declaredMemberName(member3);
|
|
5612
5789
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5615,9 +5792,9 @@ function serviceOperationBodies(node) {
|
|
|
5615
5792
|
return bodies;
|
|
5616
5793
|
}
|
|
5617
5794
|
function forEachServiceCall(node, onCall) {
|
|
5618
|
-
if (node.type ===
|
|
5795
|
+
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)
|
|
5619
5796
|
return;
|
|
5620
|
-
if (node.type ===
|
|
5797
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement) {
|
|
5621
5798
|
for (const statement of node.body) {
|
|
5622
5799
|
forEachServiceCall(statement, onCall);
|
|
5623
5800
|
if (terminatesOperation(statement)) break;
|
|
@@ -5629,29 +5806,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5629
5806
|
forEachServiceCall(branch, onCall);
|
|
5630
5807
|
return;
|
|
5631
5808
|
}
|
|
5632
|
-
if (node.type ===
|
|
5809
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) onCall(node);
|
|
5633
5810
|
forEachOwnAstChild(node, (child) => {
|
|
5634
5811
|
forEachServiceCall(child, onCall);
|
|
5635
5812
|
});
|
|
5636
5813
|
}
|
|
5637
5814
|
function literalExecutionBranch(node) {
|
|
5638
|
-
if (node.type ===
|
|
5815
|
+
if (node.type === import_utils35.AST_NODE_TYPES.WhileStatement && node.test.type === import_utils35.AST_NODE_TYPES.Literal && node.test.value === false)
|
|
5639
5816
|
return node.test;
|
|
5640
|
-
if ((node.type ===
|
|
5817
|
+
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") {
|
|
5641
5818
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5642
5819
|
}
|
|
5643
|
-
if (node.type !==
|
|
5820
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.LogicalExpression || node.left.type !== import_utils35.AST_NODE_TYPES.Literal || typeof node.left.value !== "boolean")
|
|
5644
5821
|
return null;
|
|
5645
5822
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5646
5823
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5647
5824
|
return node.left;
|
|
5648
5825
|
}
|
|
5649
5826
|
function terminatesOperation(node) {
|
|
5650
|
-
if (node.type ===
|
|
5827
|
+
if (node.type === import_utils35.AST_NODE_TYPES.ReturnStatement || node.type === import_utils35.AST_NODE_TYPES.ThrowStatement)
|
|
5651
5828
|
return true;
|
|
5652
|
-
if (node.type ===
|
|
5829
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement)
|
|
5653
5830
|
return node.body.some(terminatesOperation);
|
|
5654
|
-
if (node.type !==
|
|
5831
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.IfStatement) return false;
|
|
5655
5832
|
const branch = literalExecutionBranch(node);
|
|
5656
5833
|
if (branch !== null) return terminatesOperation(branch);
|
|
5657
5834
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5665,7 +5842,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5665
5842
|
const seen = /* @__PURE__ */ new Set();
|
|
5666
5843
|
function addImplementedContracts(current) {
|
|
5667
5844
|
for (const implementation of current.implements) {
|
|
5668
|
-
if (implementation.expression.type !==
|
|
5845
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5669
5846
|
return false;
|
|
5670
5847
|
const name = implementation.expression.name;
|
|
5671
5848
|
const surface = interfaces.get(name);
|
|
@@ -5688,7 +5865,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5688
5865
|
}
|
|
5689
5866
|
if (!addImplementedContracts(current)) return null;
|
|
5690
5867
|
if (current.superClass === null) continue;
|
|
5691
|
-
if (current.superClass.type !==
|
|
5868
|
+
if (current.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5692
5869
|
const base = classes.get(current.superClass.name);
|
|
5693
5870
|
if (base === void 0) return null;
|
|
5694
5871
|
pending.push(base);
|
|
@@ -5698,8 +5875,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5698
5875
|
function localClassDeclarations(program) {
|
|
5699
5876
|
const classes = /* @__PURE__ */ new Map();
|
|
5700
5877
|
for (const statement of program.body) {
|
|
5701
|
-
const declaration = statement.type ===
|
|
5702
|
-
if (declaration?.type ===
|
|
5878
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5879
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null)
|
|
5703
5880
|
classes.set(declaration.id.name, declaration);
|
|
5704
5881
|
}
|
|
5705
5882
|
return classes;
|
|
@@ -5707,13 +5884,13 @@ function localClassDeclarations(program) {
|
|
|
5707
5884
|
function abstractContractOperations(node, functionAliases) {
|
|
5708
5885
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5709
5886
|
for (const member3 of node.body.body) {
|
|
5710
|
-
if (member3.type !==
|
|
5887
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractMethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition)
|
|
5711
5888
|
continue;
|
|
5712
5889
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5713
5890
|
continue;
|
|
5714
|
-
if (member3.type ===
|
|
5891
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition) {
|
|
5715
5892
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5716
|
-
if (annotation?.type !==
|
|
5893
|
+
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)))
|
|
5717
5894
|
continue;
|
|
5718
5895
|
}
|
|
5719
5896
|
const name = declaredMemberName(member3);
|
|
@@ -5849,7 +6026,7 @@ function isServiceRole(name, filename) {
|
|
|
5849
6026
|
}
|
|
5850
6027
|
|
|
5851
6028
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
5852
|
-
var
|
|
6029
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5853
6030
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
5854
6031
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
5855
6032
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -5901,7 +6078,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
5901
6078
|
]
|
|
5902
6079
|
};
|
|
5903
6080
|
function isEmptyObject(node) {
|
|
5904
|
-
return node.type ===
|
|
6081
|
+
return node.type === import_utils37.AST_NODE_TYPES.ObjectExpression && node.properties.length === 0;
|
|
5905
6082
|
}
|
|
5906
6083
|
var no_conditional_empty_object_spread_default = createRule({
|
|
5907
6084
|
name: "no-conditional-empty-object-spread",
|
|
@@ -5922,13 +6099,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5922
6099
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
5923
6100
|
return {
|
|
5924
6101
|
SpreadElement(node) {
|
|
5925
|
-
if (node.parent.type !==
|
|
6102
|
+
if (node.parent.type !== import_utils37.AST_NODE_TYPES.ObjectExpression || node.argument.type !== import_utils37.AST_NODE_TYPES.ConditionalExpression)
|
|
5926
6103
|
return;
|
|
5927
6104
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
5928
6105
|
const conditional = node.argument;
|
|
5929
6106
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
5930
6107
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
5931
|
-
const canFix = populated.type ===
|
|
6108
|
+
const canFix = populated.type === import_utils37.AST_NODE_TYPES.ObjectExpression && populated.properties.length > 0 && context.sourceCode.getCommentsInside(conditional).length === 0;
|
|
5932
6109
|
context.report({
|
|
5933
6110
|
node,
|
|
5934
6111
|
messageId: "avoid",
|
|
@@ -5944,7 +6121,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5944
6121
|
});
|
|
5945
6122
|
|
|
5946
6123
|
// src/rules/prefer-typed-reflection.ts
|
|
5947
|
-
var
|
|
6124
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5948
6125
|
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
5949
6126
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
5950
6127
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
@@ -6017,20 +6194,20 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6017
6194
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6018
6195
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6019
6196
|
return {};
|
|
6020
|
-
const services =
|
|
6197
|
+
const services = import_utils38.ESLintUtils.getParserServices(context);
|
|
6021
6198
|
if (!services.program) return {};
|
|
6022
6199
|
const checker = services.program.getTypeChecker();
|
|
6023
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
6024
|
-
const globalName = (node, name) => node.type ===
|
|
6200
|
+
const isReflect = (node) => globalName(node, "Reflect") || node.type === import_utils38.AST_NODE_TYPES.MemberExpression && import_utils38.ASTUtils.getPropertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
6201
|
+
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;
|
|
6025
6202
|
const closedObject = (type) => {
|
|
6026
6203
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
6027
6204
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
6028
6205
|
};
|
|
6029
6206
|
const inspectGet = (node, type) => {
|
|
6030
6207
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
6031
|
-
return node.arguments.length === 2 && (staticString(key) !== null || key?.type ===
|
|
6208
|
+
return node.arguments.length === 2 && (staticString(key) !== null || key?.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number") && closedObject(type);
|
|
6032
6209
|
};
|
|
6033
|
-
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type ===
|
|
6210
|
+
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type === import_utils38.AST_NODE_TYPES.ArrayExpression && knownType(type) && type.getCallSignatures().some(
|
|
6034
6211
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
6035
6212
|
(parameter) => knownType(
|
|
6036
6213
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -6041,25 +6218,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6041
6218
|
)
|
|
6042
6219
|
);
|
|
6043
6220
|
const getReplacement = (node, type, target) => {
|
|
6044
|
-
if (node.optional || node.callee.type !==
|
|
6221
|
+
if (node.optional || node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || node.callee.optional || context.sourceCode.getCommentsInside(node).length > 0) return null;
|
|
6045
6222
|
let outer = node;
|
|
6046
|
-
while (outer.parent.type ===
|
|
6047
|
-
if (outer.parent.type ===
|
|
6223
|
+
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;
|
|
6224
|
+
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;
|
|
6048
6225
|
const writtenKey = node.arguments[1];
|
|
6049
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6226
|
+
if (writtenKey === void 0 || writtenKey.type === import_utils38.AST_NODE_TYPES.SpreadElement) return null;
|
|
6050
6227
|
const key = unwrapExpression(writtenKey);
|
|
6051
|
-
const name = staticString(key) ?? (key.type ===
|
|
6228
|
+
const name = staticString(key) ?? (key.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
6052
6229
|
const members = type.isUnion() ? type.types : [type];
|
|
6053
6230
|
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
6054
6231
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
6055
6232
|
};
|
|
6056
6233
|
return {
|
|
6057
6234
|
CallExpression(node) {
|
|
6058
|
-
if (node.callee.type !==
|
|
6235
|
+
if (node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || !isReflect(node.callee.object))
|
|
6059
6236
|
return;
|
|
6060
|
-
const method =
|
|
6237
|
+
const method = import_utils38.ASTUtils.getPropertyName(node.callee);
|
|
6061
6238
|
const target = node.arguments[0];
|
|
6062
|
-
if (!target || target.type ===
|
|
6239
|
+
if (!target || target.type === import_utils38.AST_NODE_TYPES.SpreadElement || method !== "get" && method !== "apply")
|
|
6063
6240
|
return;
|
|
6064
6241
|
const type = checker.getTypeAtLocation(
|
|
6065
6242
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6074,28 +6251,28 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6074
6251
|
});
|
|
6075
6252
|
|
|
6076
6253
|
// src/rules/no-broad-return-type.ts
|
|
6077
|
-
var
|
|
6254
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
6078
6255
|
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
6079
6256
|
|
|
6080
6257
|
// src/rules/_unused-private-binding.ts
|
|
6081
|
-
var
|
|
6258
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6082
6259
|
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6083
6260
|
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6084
6261
|
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6085
6262
|
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;
|
|
6086
6263
|
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
6087
|
-
const statement = declaration.type ===
|
|
6088
|
-
if (statement.parent.type ===
|
|
6089
|
-
if (statement.parent.type !==
|
|
6090
|
-
return sourceCode.ast.body.some((node) => node.type ===
|
|
6264
|
+
const statement = declaration.type === import_utils39.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
6265
|
+
if (statement.parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
6266
|
+
if (statement.parent.type !== import_utils39.AST_NODE_TYPES.Program) return statement.parent.type === import_utils39.AST_NODE_TYPES.BlockStatement;
|
|
6267
|
+
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);
|
|
6091
6268
|
}
|
|
6092
6269
|
function hasOnlyDirectFactoryUses(variable) {
|
|
6093
6270
|
return variable.references.every((reference) => {
|
|
6094
6271
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6095
6272
|
const identifier = reference.identifier;
|
|
6096
6273
|
const parent = identifier.parent;
|
|
6097
|
-
if (parent.type ===
|
|
6098
|
-
return parent.type ===
|
|
6274
|
+
if (parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
6275
|
+
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;
|
|
6099
6276
|
});
|
|
6100
6277
|
}
|
|
6101
6278
|
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
@@ -6109,7 +6286,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6109
6286
|
const current = pending.pop();
|
|
6110
6287
|
if (current === void 0 || seen.has(current)) continue;
|
|
6111
6288
|
seen.add(current);
|
|
6112
|
-
if (current.type ===
|
|
6289
|
+
if (current.type === import_utils39.AST_NODE_TYPES.Identifier || current.type === import_utils39.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
6113
6290
|
forEachOwnAstChild(current, (child) => {
|
|
6114
6291
|
pending.push(child);
|
|
6115
6292
|
}, (key) => key !== "tokens" && key !== "comments");
|
|
@@ -6120,7 +6297,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6120
6297
|
return names.has(name);
|
|
6121
6298
|
}
|
|
6122
6299
|
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6123
|
-
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !==
|
|
6300
|
+
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;
|
|
6124
6301
|
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6125
6302
|
}
|
|
6126
6303
|
|
|
@@ -6209,7 +6386,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6209
6386
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6210
6387
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6211
6388
|
return {};
|
|
6212
|
-
const services =
|
|
6389
|
+
const services = import_utils40.ESLintUtils.getParserServices(context);
|
|
6213
6390
|
if (!services.program) return {};
|
|
6214
6391
|
const checker = services.program.getTypeChecker();
|
|
6215
6392
|
const frames = [];
|
|
@@ -6234,7 +6411,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6234
6411
|
known: false,
|
|
6235
6412
|
opaque: false
|
|
6236
6413
|
});
|
|
6237
|
-
if (node.body && node.body.type !==
|
|
6414
|
+
if (node.body && node.body.type !== import_utils40.AST_NODE_TYPES.BlockStatement)
|
|
6238
6415
|
inspectReturn(node.body);
|
|
6239
6416
|
};
|
|
6240
6417
|
const leave = () => {
|
|
@@ -6242,7 +6419,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6242
6419
|
if (frame?.annotation && frame.known && !frame.opaque) {
|
|
6243
6420
|
const annotation = frame.annotation;
|
|
6244
6421
|
const node = frame.node;
|
|
6245
|
-
const canFix = node.type ===
|
|
6422
|
+
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);
|
|
6246
6423
|
context.report({ node: annotation, messageId: "avoid", fix: canFix ? (fixer) => fixer.replaceText(annotation, context.sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")) : null });
|
|
6247
6424
|
}
|
|
6248
6425
|
};
|
|
@@ -6261,43 +6438,43 @@ var no_broad_return_type_default = createRule({
|
|
|
6261
6438
|
});
|
|
6262
6439
|
|
|
6263
6440
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
6264
|
-
var
|
|
6441
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6265
6442
|
var import_typescript14 = __toESM(require("typescript"), 1);
|
|
6266
6443
|
|
|
6267
6444
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
6268
|
-
var
|
|
6445
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6269
6446
|
function literalIdentityReduceFix(sourceCode, node) {
|
|
6270
|
-
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !==
|
|
6447
|
+
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")
|
|
6271
6448
|
return null;
|
|
6272
6449
|
const values = node.callee.object;
|
|
6273
|
-
if (values.type !==
|
|
6274
|
-
(element) => element?.type ===
|
|
6450
|
+
if (values.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || values.elements.length === 0 || !values.elements.every(
|
|
6451
|
+
(element) => element?.type === import_utils41.AST_NODE_TYPES.Literal && typeof element.value === "string"
|
|
6275
6452
|
))
|
|
6276
6453
|
return null;
|
|
6277
6454
|
const statement = sourceCode.ast.body[0];
|
|
6278
|
-
if (statement?.type !==
|
|
6455
|
+
if (statement?.type !== import_utils41.AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration?.type !== import_utils41.AST_NODE_TYPES.FunctionDeclaration)
|
|
6279
6456
|
return null;
|
|
6280
6457
|
const owner = statement.declaration;
|
|
6281
6458
|
if (owner.async || owner.declare || owner.generator || owner.typeParameters !== void 0 || owner.params.length !== 0 || owner.body.body.length !== 1 || !stringArray(owner.returnType?.typeAnnotation))
|
|
6282
6459
|
return null;
|
|
6283
6460
|
const returned2 = owner.body.body[0];
|
|
6284
|
-
if (returned2?.type !==
|
|
6461
|
+
if (returned2?.type !== import_utils41.AST_NODE_TYPES.ReturnStatement || returned2.argument !== node || node.typeArguments?.params.length !== 1 || !stringArray(node.typeArguments.params[0]))
|
|
6285
6462
|
return null;
|
|
6286
6463
|
const [callback, seed] = node.arguments;
|
|
6287
|
-
if (seed?.type !==
|
|
6464
|
+
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)
|
|
6288
6465
|
return null;
|
|
6289
6466
|
if (!identitySpread(sourceCode, callback)) return null;
|
|
6290
6467
|
return (fixer) => fixer.replaceText(node, sourceCode.getText(values));
|
|
6291
6468
|
}
|
|
6292
6469
|
function stringArray(node) {
|
|
6293
|
-
return node?.type ===
|
|
6470
|
+
return node?.type === import_utils41.AST_NODE_TYPES.TSArrayType && node.elementType.type === import_utils41.AST_NODE_TYPES.TSStringKeyword;
|
|
6294
6471
|
}
|
|
6295
6472
|
function identitySpread(sourceCode, callback) {
|
|
6296
6473
|
const [accumulator, item] = callback.params;
|
|
6297
|
-
if (accumulator?.type !==
|
|
6474
|
+
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)
|
|
6298
6475
|
return false;
|
|
6299
6476
|
const [spread, appended] = callback.body.elements;
|
|
6300
|
-
if (spread?.type !==
|
|
6477
|
+
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)
|
|
6301
6478
|
return false;
|
|
6302
6479
|
const bindings = sourceCode.getDeclaredVariables(callback);
|
|
6303
6480
|
const left = bindings.find(
|
|
@@ -6306,10 +6483,10 @@ function identitySpread(sourceCode, callback) {
|
|
|
6306
6483
|
const right = bindings.find(
|
|
6307
6484
|
(variable) => variable.identifiers.includes(item)
|
|
6308
6485
|
);
|
|
6309
|
-
return left !== void 0 && right !== void 0 &&
|
|
6486
|
+
return left !== void 0 && right !== void 0 && import_utils41.ASTUtils.findVariable(
|
|
6310
6487
|
sourceCode.getScope(spread.argument),
|
|
6311
6488
|
spread.argument.name
|
|
6312
|
-
) === left &&
|
|
6489
|
+
) === left && import_utils41.ASTUtils.findVariable(sourceCode.getScope(appended), appended.name) === right;
|
|
6313
6490
|
}
|
|
6314
6491
|
|
|
6315
6492
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
@@ -6399,25 +6576,25 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6399
6576
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6400
6577
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6401
6578
|
return {};
|
|
6402
|
-
const services =
|
|
6579
|
+
const services = import_utils42.ESLintUtils.getParserServices(context);
|
|
6403
6580
|
const program = services.program;
|
|
6404
6581
|
if (program === null) return {};
|
|
6405
6582
|
const checker = program.getTypeChecker();
|
|
6406
6583
|
return {
|
|
6407
6584
|
CallExpression(node) {
|
|
6408
|
-
if (node.callee.type !==
|
|
6409
|
-
|
|
6585
|
+
if (node.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression || !["reduce", "reduceRight"].includes(
|
|
6586
|
+
import_utils42.ASTUtils.getPropertyName(node.callee) ?? ""
|
|
6410
6587
|
) || node.arguments.length !== 2)
|
|
6411
6588
|
return;
|
|
6412
6589
|
const seed = node.arguments[1];
|
|
6413
|
-
const arraySeed = seed?.type ===
|
|
6414
|
-
const objectSeed = seed?.type ===
|
|
6590
|
+
const arraySeed = seed?.type === import_utils42.AST_NODE_TYPES.ArrayExpression && seed.elements.length === 0;
|
|
6591
|
+
const objectSeed = seed?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && seed.properties.length === 0;
|
|
6415
6592
|
if (!arraySeed && !objectSeed) return;
|
|
6416
6593
|
const callback = node.arguments[0];
|
|
6417
|
-
if (!callback || callback.type !==
|
|
6594
|
+
if (!callback || callback.type !== import_utils42.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils42.AST_NODE_TYPES.FunctionExpression)
|
|
6418
6595
|
return;
|
|
6419
6596
|
const parameter = callback.params[0];
|
|
6420
|
-
if (parameter?.type !==
|
|
6597
|
+
if (parameter?.type !== import_utils42.AST_NODE_TYPES.Identifier) return;
|
|
6421
6598
|
const signature = checker.getResolvedSignature(
|
|
6422
6599
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
6423
6600
|
);
|
|
@@ -6428,51 +6605,51 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6428
6605
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
6429
6606
|
return;
|
|
6430
6607
|
const fix = literalIdentityReduceFix(context.sourceCode, node);
|
|
6431
|
-
const referencesAccumulator = (value) => value.type ===
|
|
6608
|
+
const referencesAccumulator = (value) => value.type === import_utils42.AST_NODE_TYPES.Identifier && import_utils42.ASTUtils.findVariable(
|
|
6432
6609
|
context.sourceCode.getScope(value),
|
|
6433
6610
|
value.name
|
|
6434
6611
|
) === accumulator;
|
|
6435
6612
|
const inspect = (current) => {
|
|
6436
6613
|
if (current !== callback.body && [
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6614
|
+
import_utils42.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6615
|
+
import_utils42.AST_NODE_TYPES.FunctionExpression,
|
|
6616
|
+
import_utils42.AST_NODE_TYPES.FunctionDeclaration,
|
|
6617
|
+
import_utils42.AST_NODE_TYPES.ClassDeclaration,
|
|
6618
|
+
import_utils42.AST_NODE_TYPES.ClassExpression,
|
|
6619
|
+
import_utils42.AST_NODE_TYPES.ForStatement,
|
|
6620
|
+
import_utils42.AST_NODE_TYPES.ForInStatement,
|
|
6621
|
+
import_utils42.AST_NODE_TYPES.ForOfStatement,
|
|
6622
|
+
import_utils42.AST_NODE_TYPES.WhileStatement,
|
|
6623
|
+
import_utils42.AST_NODE_TYPES.DoWhileStatement
|
|
6447
6624
|
].some((kind) => kind === current.type))
|
|
6448
6625
|
return;
|
|
6449
|
-
if (current.type ===
|
|
6626
|
+
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)) {
|
|
6450
6627
|
context.report({
|
|
6451
6628
|
node: current,
|
|
6452
6629
|
messageId: "copy",
|
|
6453
6630
|
fix
|
|
6454
6631
|
});
|
|
6455
6632
|
}
|
|
6456
|
-
if (current.type ===
|
|
6633
|
+
if (current.type === import_utils42.AST_NODE_TYPES.CallExpression)
|
|
6457
6634
|
inspectCall(current);
|
|
6458
6635
|
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
6459
6636
|
};
|
|
6460
6637
|
const inspectCall = (current) => {
|
|
6461
|
-
if (current.callee.type !==
|
|
6638
|
+
if (current.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression) return;
|
|
6462
6639
|
const member3 = current.callee;
|
|
6463
|
-
const name =
|
|
6640
|
+
const name = import_utils42.ASTUtils.getPropertyName(member3);
|
|
6464
6641
|
const directCopy = arraySeed && name !== null && COPY_METHODS.has(name) && referencesAccumulator(member3.object);
|
|
6465
|
-
const globalArray = member3.object.type ===
|
|
6642
|
+
const globalArray = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Array" && !import_utils42.ASTUtils.findVariable(
|
|
6466
6643
|
context.sourceCode.getScope(member3.object),
|
|
6467
6644
|
"Array"
|
|
6468
6645
|
)?.defs.length;
|
|
6469
6646
|
const fromCopy = arraySeed && name === "from" && globalArray && current.arguments[0] !== void 0 && referencesAccumulator(current.arguments[0]);
|
|
6470
|
-
const globalObject = member3.object.type ===
|
|
6647
|
+
const globalObject = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Object" && !import_utils42.ASTUtils.findVariable(
|
|
6471
6648
|
context.sourceCode.getScope(member3.object),
|
|
6472
6649
|
"Object"
|
|
6473
6650
|
)?.defs.length;
|
|
6474
6651
|
const target = current.arguments[0];
|
|
6475
|
-
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type ===
|
|
6652
|
+
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && current.arguments.slice(1).some(referencesAccumulator);
|
|
6476
6653
|
if (directCopy || fromCopy || assignCopy)
|
|
6477
6654
|
context.report({ node: current, messageId: "copy" });
|
|
6478
6655
|
};
|
|
@@ -6483,7 +6660,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6483
6660
|
});
|
|
6484
6661
|
|
|
6485
6662
|
// src/rules/no-known-value-widening.ts
|
|
6486
|
-
var
|
|
6663
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6487
6664
|
var import_typescript15 = __toESM(require("typescript"), 1);
|
|
6488
6665
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
6489
6666
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
@@ -6533,12 +6710,12 @@ var no_known_value_widening_default = createRule({
|
|
|
6533
6710
|
create(context) {
|
|
6534
6711
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6535
6712
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap) return {};
|
|
6536
|
-
const services =
|
|
6713
|
+
const services = import_utils43.ESLintUtils.getParserServices(context);
|
|
6537
6714
|
if (services.program === null) return {};
|
|
6538
6715
|
const checker = services.program.getTypeChecker();
|
|
6539
6716
|
return {
|
|
6540
6717
|
VariableDeclarator(node) {
|
|
6541
|
-
if (node.id.type !==
|
|
6718
|
+
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;
|
|
6542
6719
|
const source = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.init));
|
|
6543
6720
|
if (hasUnknownContract(source, checker)) return;
|
|
6544
6721
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.id.typeAnnotation.typeAnnotation));
|
|
@@ -6557,7 +6734,7 @@ var no_known_value_widening_default = createRule({
|
|
|
6557
6734
|
});
|
|
6558
6735
|
|
|
6559
6736
|
// src/rules/no-invalid-typed-mutation.ts
|
|
6560
|
-
var
|
|
6737
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6561
6738
|
var import_ts_api_utils = require("ts-api-utils");
|
|
6562
6739
|
var import_typescript16 = __toESM(require("typescript"), 1);
|
|
6563
6740
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
@@ -6594,7 +6771,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6594
6771
|
defaultOptions: [],
|
|
6595
6772
|
create(context) {
|
|
6596
6773
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
6597
|
-
const services =
|
|
6774
|
+
const services = import_utils44.ESLintUtils.getParserServices(context);
|
|
6598
6775
|
const checker = services.program.getTypeChecker();
|
|
6599
6776
|
const candidates = [];
|
|
6600
6777
|
const replaced = /* @__PURE__ */ new Set();
|
|
@@ -6665,7 +6842,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6665
6842
|
const target = node.arguments[0];
|
|
6666
6843
|
if (target === void 0) return;
|
|
6667
6844
|
invalidateNamespace(target);
|
|
6668
|
-
if (target.type !==
|
|
6845
|
+
if (target.type !== import_utils44.AST_NODE_TYPES.Identifier) return;
|
|
6669
6846
|
const writes = mutationWrites(node, method.namespace, method.method);
|
|
6670
6847
|
if (writes !== void 0) candidates.push({ call: node, ...method, target, writes });
|
|
6671
6848
|
},
|
|
@@ -6676,9 +6853,9 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6676
6853
|
}
|
|
6677
6854
|
});
|
|
6678
6855
|
function localDataTarget(target, sourceCode) {
|
|
6679
|
-
const binding3 =
|
|
6856
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(target), target.name);
|
|
6680
6857
|
const definition = binding3?.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
6681
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !==
|
|
6858
|
+
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;
|
|
6682
6859
|
const properties = plainProperties(definition.node.init);
|
|
6683
6860
|
if (properties === void 0) return void 0;
|
|
6684
6861
|
const scope = sourceCode.getScope(definition.node).variableScope;
|
|
@@ -6689,29 +6866,29 @@ function localDataTarget(target, sourceCode) {
|
|
|
6689
6866
|
return new Set(properties.map((property) => property.key));
|
|
6690
6867
|
}
|
|
6691
6868
|
function safeTargetUse(identifier, sourceCode) {
|
|
6692
|
-
if (identifier.type !==
|
|
6869
|
+
if (identifier.type !== import_utils44.AST_NODE_TYPES.Identifier) return false;
|
|
6693
6870
|
const parent = identifier.parent;
|
|
6694
|
-
if (parent.type ===
|
|
6695
|
-
const key =
|
|
6871
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.MemberExpression && parent.object === identifier) {
|
|
6872
|
+
const key = import_utils44.ASTUtils.getPropertyName(parent);
|
|
6696
6873
|
const use = outerExpression(parent);
|
|
6697
|
-
if (parent.optional || use.parent.type ===
|
|
6698
|
-
return key !== null && key !== "__proto__" && !(use.parent.type ===
|
|
6874
|
+
if (parent.optional || use.parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && use.parent.operator === "delete") return false;
|
|
6875
|
+
return key !== null && key !== "__proto__" && !(use.parent.type === import_utils44.AST_NODE_TYPES.CallExpression && use.parent.callee === use);
|
|
6699
6876
|
}
|
|
6700
|
-
if (parent.type !==
|
|
6877
|
+
if (parent.type !== import_utils44.AST_NODE_TYPES.CallExpression || parent.arguments[0] !== identifier) return false;
|
|
6701
6878
|
const method = nativeMember(parent.callee, sourceCode);
|
|
6702
6879
|
if (method === void 0) return false;
|
|
6703
6880
|
const writes = mutationWrites(parent, method.namespace, method.method);
|
|
6704
|
-
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type ===
|
|
6881
|
+
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);
|
|
6705
6882
|
}
|
|
6706
6883
|
function keepsMutableDescriptor(call, method) {
|
|
6707
6884
|
if (method !== "defineProperty") return true;
|
|
6708
6885
|
const descriptor = call.arguments[2];
|
|
6709
|
-
if (descriptor?.type !==
|
|
6886
|
+
if (descriptor?.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return false;
|
|
6710
6887
|
const properties = plainProperties(descriptor);
|
|
6711
6888
|
return properties !== void 0 && properties.every((property) => {
|
|
6712
6889
|
if (property.key !== "writable" && property.key !== "configurable") return true;
|
|
6713
6890
|
const value = unwrapExpression(property.value);
|
|
6714
|
-
return value.type ===
|
|
6891
|
+
return value.type === import_utils44.AST_NODE_TYPES.Literal && value.value === true;
|
|
6715
6892
|
});
|
|
6716
6893
|
}
|
|
6717
6894
|
function declaredTargetType(node, checker) {
|
|
@@ -6761,9 +6938,9 @@ function definiteSignatures(type, checker, seen) {
|
|
|
6761
6938
|
}
|
|
6762
6939
|
function nativeMember(node, sourceCode) {
|
|
6763
6940
|
const member3 = unwrapExpression(node);
|
|
6764
|
-
if (member3.type !==
|
|
6941
|
+
if (member3.type !== import_utils44.AST_NODE_TYPES.MemberExpression || member3.optional) return void 0;
|
|
6765
6942
|
const namespace = nativeNamespace(member3.object, sourceCode);
|
|
6766
|
-
const method =
|
|
6943
|
+
const method = import_utils44.ASTUtils.getPropertyName(member3);
|
|
6767
6944
|
if (namespace === void 0 || method === null) return void 0;
|
|
6768
6945
|
const supported2 = namespace === "Object" ? ["assign", "defineProperty", "defineProperties", "setPrototypeOf"] : ["set", "defineProperty", "setPrototypeOf"];
|
|
6769
6946
|
return supported2.includes(method) ? { namespace, method } : void 0;
|
|
@@ -6772,43 +6949,43 @@ function ordinaryNamespaceUse(node) {
|
|
|
6772
6949
|
const value = outerExpression(node);
|
|
6773
6950
|
const parent = value.parent;
|
|
6774
6951
|
if (parent === void 0) return false;
|
|
6775
|
-
return parent.type ===
|
|
6952
|
+
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;
|
|
6776
6953
|
}
|
|
6777
6954
|
function replacementNamespace(node, sourceCode) {
|
|
6778
6955
|
const value = unwrapExpression(node);
|
|
6779
6956
|
if (nativeObjectPrototype(value, sourceCode)) return "ObjectPrototype";
|
|
6780
|
-
return nativeNamespace(value, sourceCode) ?? (value.type ===
|
|
6957
|
+
return nativeNamespace(value, sourceCode) ?? (value.type === import_utils44.AST_NODE_TYPES.MemberExpression ? replacementNamespace(value.object, sourceCode) : void 0);
|
|
6781
6958
|
}
|
|
6782
6959
|
function nativeObjectPrototype(node, sourceCode) {
|
|
6783
6960
|
const value = unwrapExpression(node);
|
|
6784
|
-
return value.type ===
|
|
6961
|
+
return value.type === import_utils44.AST_NODE_TYPES.MemberExpression && import_utils44.ASTUtils.getPropertyName(value) === "prototype" && nativeNamespace(value.object, sourceCode) === "Object";
|
|
6785
6962
|
}
|
|
6786
6963
|
function nativeNamespace(node, sourceCode) {
|
|
6787
6964
|
const value = unwrapExpression(node);
|
|
6788
|
-
if (value.type ===
|
|
6789
|
-
const key =
|
|
6965
|
+
if (value.type === import_utils44.AST_NODE_TYPES.MemberExpression && !value.optional && nativeGlobalReceiver(value.object, sourceCode)) {
|
|
6966
|
+
const key = import_utils44.ASTUtils.getPropertyName(value);
|
|
6790
6967
|
if (key === "Object" || key === "Reflect") return key;
|
|
6791
6968
|
}
|
|
6792
|
-
if (value.type !==
|
|
6793
|
-
const binding3 =
|
|
6969
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.Identifier || value.name !== "Object" && value.name !== "Reflect") return void 0;
|
|
6970
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
6794
6971
|
return binding3 === null || binding3.defs.length === 0 ? value.name : void 0;
|
|
6795
6972
|
}
|
|
6796
6973
|
function nativeGlobalReceiver(node, sourceCode) {
|
|
6797
|
-
if (node.type !==
|
|
6798
|
-
const binding3 =
|
|
6974
|
+
if (node.type !== import_utils44.AST_NODE_TYPES.Identifier || !["globalThis", "window", "self"].includes(node.name)) return false;
|
|
6975
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
6799
6976
|
return binding3 === null || binding3.defs.length === 0;
|
|
6800
6977
|
}
|
|
6801
6978
|
function mutationWrites(node, namespace, method) {
|
|
6802
6979
|
if (namespace === "Object" && method === "assign") {
|
|
6803
6980
|
const source = node.arguments[1];
|
|
6804
|
-
return node.arguments.length === 2 && source?.type ===
|
|
6981
|
+
return node.arguments.length === 2 && source?.type === import_utils44.AST_NODE_TYPES.ObjectExpression ? plainProperties(source) : void 0;
|
|
6805
6982
|
}
|
|
6806
6983
|
if (node.arguments.length !== 3 || method !== "set" && method !== "defineProperty") return void 0;
|
|
6807
6984
|
const key = staticString(node.arguments[1]);
|
|
6808
6985
|
const value = node.arguments[2];
|
|
6809
|
-
if (key === null || value === void 0 || value.type ===
|
|
6986
|
+
if (key === null || value === void 0 || value.type === import_utils44.AST_NODE_TYPES.SpreadElement) return void 0;
|
|
6810
6987
|
if (method === "set") return [{ key, value }];
|
|
6811
|
-
if (value.type !==
|
|
6988
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return void 0;
|
|
6812
6989
|
const properties = plainProperties(value);
|
|
6813
6990
|
if (properties === void 0 || properties.some((property) => !["value", "configurable", "enumerable", "writable"].includes(property.key))) return void 0;
|
|
6814
6991
|
const payload = properties.find((property) => property.key === "value");
|
|
@@ -6818,8 +6995,8 @@ function plainProperties(node) {
|
|
|
6818
6995
|
const writes = [];
|
|
6819
6996
|
const names = /* @__PURE__ */ new Set();
|
|
6820
6997
|
for (const property of node.properties) {
|
|
6821
|
-
if (property.type !==
|
|
6822
|
-
const key =
|
|
6998
|
+
if (property.type !== import_utils44.AST_NODE_TYPES.Property || property.kind !== "init" || property.method) return void 0;
|
|
6999
|
+
const key = import_utils44.ASTUtils.getPropertyName(property);
|
|
6823
7000
|
if (key === null || key === "__proto__" || names.has(key)) return void 0;
|
|
6824
7001
|
names.add(key);
|
|
6825
7002
|
writes.push({ key, value: property.value });
|
|
@@ -6828,7 +7005,7 @@ function plainProperties(node) {
|
|
|
6828
7005
|
}
|
|
6829
7006
|
|
|
6830
7007
|
// src/rules/no-contradictory-type-predicate.ts
|
|
6831
|
-
var
|
|
7008
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6832
7009
|
var import_typescript19 = __toESM(require("typescript"), 1);
|
|
6833
7010
|
|
|
6834
7011
|
// src/rules/_has-separate-predicate-contract.ts
|
|
@@ -6844,7 +7021,7 @@ function hasSeparatePredicateContract(node, checker) {
|
|
|
6844
7021
|
}
|
|
6845
7022
|
|
|
6846
7023
|
// src/rules/_contradictory-array-predicate.ts
|
|
6847
|
-
var
|
|
7024
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6848
7025
|
var import_typescript18 = __toESM(require("typescript"), 1);
|
|
6849
7026
|
var import_ts_api_utils2 = require("ts-api-utils");
|
|
6850
7027
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
@@ -6857,12 +7034,12 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6857
7034
|
function matches(expression, parameter, input, target) {
|
|
6858
7035
|
if ((input.flags & import_typescript18.default.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
6859
7036
|
const call = unwrapExpression(expression);
|
|
6860
|
-
if (call.type !==
|
|
7037
|
+
if (call.type !== import_utils45.AST_NODE_TYPES.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
6861
7038
|
const argument = call.arguments[0];
|
|
6862
7039
|
const callee = unwrapExpression(call.callee);
|
|
6863
|
-
if (argument?.type !==
|
|
6864
|
-
const declared =
|
|
6865
|
-
if (declared === null || declared !==
|
|
7040
|
+
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;
|
|
7041
|
+
const declared = import_utils45.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name);
|
|
7042
|
+
if (declared === null || declared !== import_utils45.ASTUtils.findVariable(sourceCode.getScope(argument), argument.name)) return false;
|
|
6866
7043
|
const binding3 = nativeBinding(callee.object, sourceCode);
|
|
6867
7044
|
if (binding3 === void 0 || !stableArray(binding3, sourceCode, stable2)) return false;
|
|
6868
7045
|
const signature = checker.getResolvedSignature(services.esTreeNodeToTSNodeMap.get(call));
|
|
@@ -6872,7 +7049,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6872
7049
|
return {
|
|
6873
7050
|
matches,
|
|
6874
7051
|
observeConstructor(member3) {
|
|
6875
|
-
const name =
|
|
7052
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3, sourceCode.getScope(member3));
|
|
6876
7053
|
if (name === "constructor" || name === null && member3.computed) constructorCapability = true;
|
|
6877
7054
|
},
|
|
6878
7055
|
stable() {
|
|
@@ -6886,7 +7063,7 @@ function plainPrimitiveArray(target, checker) {
|
|
|
6886
7063
|
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;
|
|
6887
7064
|
}
|
|
6888
7065
|
function nativeBinding(identifier, sourceCode) {
|
|
6889
|
-
const binding3 =
|
|
7066
|
+
const binding3 = import_utils45.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6890
7067
|
return binding3 !== null && binding3.defs.length === 0 ? binding3 : void 0;
|
|
6891
7068
|
}
|
|
6892
7069
|
function stableArray(binding3, sourceCode, cache) {
|
|
@@ -6913,8 +7090,8 @@ function typeOnlyReference2(reference) {
|
|
|
6913
7090
|
}
|
|
6914
7091
|
function ordinaryObjectUse(node) {
|
|
6915
7092
|
const member3 = node.parent;
|
|
6916
|
-
if (member3?.type !==
|
|
6917
|
-
const name =
|
|
7093
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node) return false;
|
|
7094
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6918
7095
|
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
6919
7096
|
}
|
|
6920
7097
|
function ordinaryArrayReference(reference) {
|
|
@@ -6924,17 +7101,17 @@ function ordinaryArrayReference(reference) {
|
|
|
6924
7101
|
}
|
|
6925
7102
|
function ordinaryArrayUse(node) {
|
|
6926
7103
|
const member3 = node.parent;
|
|
6927
|
-
if (member3?.type ===
|
|
6928
|
-
if (member3?.type !==
|
|
6929
|
-
return member3.parent.type ===
|
|
7104
|
+
if (member3?.type === import_utils45.AST_NODE_TYPES.TSTypeQuery) return true;
|
|
7105
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node || member3.optional || import_utils45.ASTUtils.getPropertyName(member3) !== "isArray") return false;
|
|
7106
|
+
return member3.parent.type === import_utils45.AST_NODE_TYPES.CallExpression && member3.parent.callee === member3 && !member3.parent.optional;
|
|
6930
7107
|
}
|
|
6931
7108
|
function ordinaryHostReference(reference) {
|
|
6932
7109
|
if (reference.isWrite()) return false;
|
|
6933
7110
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6934
7111
|
let node = reference.identifier;
|
|
6935
|
-
while (node.parent?.type ===
|
|
7112
|
+
while (node.parent?.type === import_utils45.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
6936
7113
|
const member3 = node.parent;
|
|
6937
|
-
const name =
|
|
7114
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6938
7115
|
if (name === null) return false;
|
|
6939
7116
|
if (name === "Array") return ordinaryArrayUse(member3);
|
|
6940
7117
|
if (name === "Reflect") return false;
|
|
@@ -7014,16 +7191,16 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
7014
7191
|
defaultOptions: [],
|
|
7015
7192
|
create(context) {
|
|
7016
7193
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
7017
|
-
const services =
|
|
7194
|
+
const services = import_utils46.ESLintUtils.getParserServices(context);
|
|
7018
7195
|
const checker = services.program.getTypeChecker();
|
|
7019
7196
|
const uncheckedArray = contradictoryArrayPredicate(context.sourceCode, services);
|
|
7020
7197
|
const pendingArrays = [];
|
|
7021
7198
|
function inspect(node) {
|
|
7022
7199
|
const annotation = node.returnType?.typeAnnotation;
|
|
7023
|
-
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !==
|
|
7200
|
+
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;
|
|
7024
7201
|
const name = annotation.parameterName.name;
|
|
7025
7202
|
if (hasSeparatePredicateContract(services.esTreeNodeToTSNodeMap.get(node), checker)) return;
|
|
7026
|
-
const parameter = node.params.find((candidate2) => candidate2.type ===
|
|
7203
|
+
const parameter = node.params.find((candidate2) => candidate2.type === import_utils46.AST_NODE_TYPES.Identifier && candidate2.name === name);
|
|
7027
7204
|
const expression = singleReturn(node);
|
|
7028
7205
|
if (parameter?.typeAnnotation === void 0 || expression === void 0) return;
|
|
7029
7206
|
const check = typeofCheck(expression);
|
|
@@ -7068,13 +7245,13 @@ function shallowRecordCheck(expression, parameter, input, target, sourceCode, ch
|
|
|
7068
7245
|
const value = unwrapExpression(expression);
|
|
7069
7246
|
const direct = typeofCheck(value);
|
|
7070
7247
|
if (direct !== void 0) return direct.kind === "object" && sameParameter(parameter, direct.parameter, sourceCode);
|
|
7071
|
-
if (value.type !==
|
|
7248
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.LogicalExpression || value.operator !== "&&") return false;
|
|
7072
7249
|
for (const [left, right] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7073
7250
|
const check = typeofCheck(left);
|
|
7074
7251
|
const excluded = unwrapExpression(right);
|
|
7075
|
-
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !==
|
|
7252
|
+
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || excluded.operator !== "!==" && excluded.operator !== "!=") continue;
|
|
7076
7253
|
for (const [tested, sentinel] of [[excluded.left, excluded.right], [excluded.right, excluded.left]]) {
|
|
7077
|
-
if (tested.type ===
|
|
7254
|
+
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;
|
|
7078
7255
|
}
|
|
7079
7256
|
}
|
|
7080
7257
|
return false;
|
|
@@ -7107,17 +7284,17 @@ function literalKind(type, checker) {
|
|
|
7107
7284
|
}
|
|
7108
7285
|
function singleReturn(node) {
|
|
7109
7286
|
if (node.body === void 0) return void 0;
|
|
7110
|
-
if (node.body.type !==
|
|
7287
|
+
if (node.body.type !== import_utils46.AST_NODE_TYPES.BlockStatement) return node.body;
|
|
7111
7288
|
const statement = node.body.body[0];
|
|
7112
|
-
return node.body.body.length === 1 && statement?.type ===
|
|
7289
|
+
return node.body.body.length === 1 && statement?.type === import_utils46.AST_NODE_TYPES.ReturnStatement && statement.argument !== null ? statement.argument : void 0;
|
|
7113
7290
|
}
|
|
7114
7291
|
function typeofCheck(expression) {
|
|
7115
7292
|
const value = unwrapExpression(expression);
|
|
7116
|
-
if (value.type !==
|
|
7293
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || value.operator !== "===" && value.operator !== "==") return void 0;
|
|
7117
7294
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7118
7295
|
const operand = unwrapExpression(tested);
|
|
7119
7296
|
const kind = staticString(expected);
|
|
7120
|
-
if (operand.type !==
|
|
7297
|
+
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;
|
|
7121
7298
|
return { parameter: operand.argument, kind };
|
|
7122
7299
|
}
|
|
7123
7300
|
return void 0;
|
|
@@ -7126,8 +7303,8 @@ function isRuntimeKind(value) {
|
|
|
7126
7303
|
return RUNTIME_KINDS.has(value);
|
|
7127
7304
|
}
|
|
7128
7305
|
function sameParameter(declared, tested, sourceCode) {
|
|
7129
|
-
const parameter =
|
|
7130
|
-
return parameter !== null && parameter ===
|
|
7306
|
+
const parameter = import_utils46.ASTUtils.findVariable(sourceCode.getScope(declared), declared.name);
|
|
7307
|
+
return parameter !== null && parameter === import_utils46.ASTUtils.findVariable(sourceCode.getScope(tested), tested.name);
|
|
7131
7308
|
}
|
|
7132
7309
|
function inputKinds(type, checker) {
|
|
7133
7310
|
if ((type.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
@@ -7171,62 +7348,6 @@ var import_typescript21 = __toESM(require("typescript"), 1);
|
|
|
7171
7348
|
// src/rules/_uuid-predicate-witness.ts
|
|
7172
7349
|
var import_utils47 = require("@typescript-eslint/utils");
|
|
7173
7350
|
var import_typescript20 = __toESM(require("typescript"), 1);
|
|
7174
|
-
|
|
7175
|
-
// src/rules/_native-runtime-unchanged.ts
|
|
7176
|
-
var import_utils46 = require("@typescript-eslint/utils");
|
|
7177
|
-
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
7178
|
-
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
7179
|
-
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
7180
|
-
const index = runtimeIndex(sourceCode);
|
|
7181
|
-
const cached = index.results.get(name);
|
|
7182
|
-
if (cached !== void 0) return cached;
|
|
7183
|
-
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));
|
|
7184
|
-
index.results.set(name, !changed);
|
|
7185
|
-
return !changed;
|
|
7186
|
-
}
|
|
7187
|
-
function runtimeIndex(sourceCode) {
|
|
7188
|
-
const cached = INDEXES.get(sourceCode);
|
|
7189
|
-
if (cached !== void 0) return cached;
|
|
7190
|
-
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false).map((reference) => reference.identifier)) ?? [];
|
|
7191
|
-
const nodes = [];
|
|
7192
|
-
const pending = [sourceCode.ast];
|
|
7193
|
-
while (pending.length > 0) {
|
|
7194
|
-
const node = pending.pop();
|
|
7195
|
-
if (node === void 0) continue;
|
|
7196
|
-
nodes.push(node);
|
|
7197
|
-
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
7198
|
-
pending.push(child);
|
|
7199
|
-
});
|
|
7200
|
-
}
|
|
7201
|
-
const index = { references, nodes, results: /* @__PURE__ */ new Map() };
|
|
7202
|
-
INDEXES.set(sourceCode, index);
|
|
7203
|
-
return index;
|
|
7204
|
-
}
|
|
7205
|
-
function unsafeReference(node, sourceCode, name) {
|
|
7206
|
-
if (!ambient(node, sourceCode)) return false;
|
|
7207
|
-
if (node.name === "eval" || node.name === "Function") return true;
|
|
7208
|
-
if (node.name === name) return !nativeRead(node, name);
|
|
7209
|
-
if (!GLOBAL_OBJECTS2.has(node.name)) return false;
|
|
7210
|
-
const value = outerExpression(node);
|
|
7211
|
-
const property = value.parent;
|
|
7212
|
-
if (property?.type !== import_utils46.AST_NODE_TYPES.MemberExpression || property.object !== value) return true;
|
|
7213
|
-
const key = staticPropertyName(property, sourceCode);
|
|
7214
|
-
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
7215
|
-
return key === name && !nativeRead(property, name);
|
|
7216
|
-
}
|
|
7217
|
-
function ambient(node, sourceCode) {
|
|
7218
|
-
const variable = import_utils46.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
7219
|
-
return variable === null || variable.defs.length === 0;
|
|
7220
|
-
}
|
|
7221
|
-
function nativeRead(node, name) {
|
|
7222
|
-
const value = outerExpression(node);
|
|
7223
|
-
const parent = value.parent;
|
|
7224
|
-
if (parent?.type === import_utils46.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
7225
|
-
if (name !== "Error") return false;
|
|
7226
|
-
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;
|
|
7227
|
-
}
|
|
7228
|
-
|
|
7229
|
-
// src/rules/_uuid-predicate-witness.ts
|
|
7230
7351
|
function uuidPredicateWitness(expression, parameter, sourceCode, services) {
|
|
7231
7352
|
const success = unwrapExpression(expression);
|
|
7232
7353
|
if (!member(success, "success")) return void 0;
|
|
@@ -11451,14 +11572,21 @@ function canAutofixNextConfigLiteral(sourceCode) {
|
|
|
11451
11572
|
// src/rules/no-dangerously-allow-svg.ts
|
|
11452
11573
|
var NEXT_CONFIG_RE = /(?:^|\/)next\.config\.[cm]?[jt]s$/;
|
|
11453
11574
|
var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
11454
|
-
summary: "
|
|
11455
|
-
rationale: "SVG
|
|
11456
|
-
remediation: "
|
|
11575
|
+
summary: "Require an explicit hardening policy for Next Image SVG delivery",
|
|
11576
|
+
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.",
|
|
11577
|
+
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.",
|
|
11457
11578
|
category: "security",
|
|
11458
11579
|
autofix: "safe",
|
|
11580
|
+
references: [
|
|
11581
|
+
"https://www.w3.org/TR/2026/WD-CSP3-20261027/#parse-serialized-policy",
|
|
11582
|
+
"https://github.com/vercel/next.js/blob/v16.4.3/packages/next/src/shared/lib/image-config.ts#L255"
|
|
11583
|
+
],
|
|
11459
11584
|
limitations: [
|
|
11460
11585
|
"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.",
|
|
11461
|
-
"
|
|
11586
|
+
"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.",
|
|
11587
|
+
"Omitted contentDispositionType is treated as attachment. Older or customized runtime defaults are not established by this source-only check.",
|
|
11588
|
+
"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.",
|
|
11589
|
+
"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."
|
|
11462
11590
|
],
|
|
11463
11591
|
examples: [
|
|
11464
11592
|
{
|
|
@@ -11472,7 +11600,7 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11472
11600
|
},
|
|
11473
11601
|
{
|
|
11474
11602
|
id: "svg-enabled",
|
|
11475
|
-
title: "
|
|
11603
|
+
title: "SVG opt-in requires explicit hardening under this policy",
|
|
11476
11604
|
outcome: "match",
|
|
11477
11605
|
files: [{ path: "next.config.mjs", source: "export default { images: { dangerouslyAllowSVG: true } };\n" }],
|
|
11478
11606
|
focusPath: "next.config.mjs",
|
|
@@ -11481,12 +11609,34 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11481
11609
|
},
|
|
11482
11610
|
{
|
|
11483
11611
|
id: "safe-autofix",
|
|
11484
|
-
title: "
|
|
11612
|
+
title: "Disable SVG delivery to satisfy this policy",
|
|
11485
11613
|
outcome: "match",
|
|
11486
11614
|
files: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: true } };" }],
|
|
11487
11615
|
fixedFiles: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: false } };" }],
|
|
11488
11616
|
focusPath: "next.config.ts",
|
|
11489
11617
|
expectedCount: 1
|
|
11618
|
+
},
|
|
11619
|
+
{
|
|
11620
|
+
id: "svg-explicit-hardening",
|
|
11621
|
+
scenarioId: "explicit-hardening",
|
|
11622
|
+
title: "Allow SVG delivery with explicit hardening",
|
|
11623
|
+
outcome: "no-match",
|
|
11624
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'none'; sandbox;" } };
|
|
11625
|
+
` }],
|
|
11626
|
+
focusPath: "next.config.mjs",
|
|
11627
|
+
expectedCount: 0,
|
|
11628
|
+
public: true
|
|
11629
|
+
},
|
|
11630
|
+
{
|
|
11631
|
+
id: "svg-unsafe-first-directive",
|
|
11632
|
+
scenarioId: "explicit-hardening",
|
|
11633
|
+
title: "A later duplicate cannot replace the effective policy",
|
|
11634
|
+
outcome: "match",
|
|
11635
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'unsafe-inline'; script-src 'none'; sandbox;" } };
|
|
11636
|
+
` }],
|
|
11637
|
+
focusPath: "next.config.mjs",
|
|
11638
|
+
expectedCount: 1,
|
|
11639
|
+
public: true
|
|
11490
11640
|
}
|
|
11491
11641
|
]
|
|
11492
11642
|
};
|
|
@@ -11496,12 +11646,16 @@ function literalString2(node) {
|
|
|
11496
11646
|
return null;
|
|
11497
11647
|
}
|
|
11498
11648
|
function hasHardenedSvgPolicy(policy) {
|
|
11499
|
-
const directives =
|
|
11500
|
-
const
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11649
|
+
const directives = /* @__PURE__ */ new Map();
|
|
11650
|
+
for (const part of policy.split(";")) {
|
|
11651
|
+
const [name, ...values] = part.split(/[\t\n\f\r ]+/u).filter(Boolean);
|
|
11652
|
+
if (name === void 0 || !/^[A-Za-z0-9-]+$/u.test(name)) continue;
|
|
11653
|
+
const key = name.toLowerCase();
|
|
11654
|
+
if (!directives.has(key)) directives.set(key, values);
|
|
11655
|
+
}
|
|
11656
|
+
const scriptSource = directives.get("script-src");
|
|
11657
|
+
const sandbox = directives.get("sandbox");
|
|
11658
|
+
return scriptSource?.length === 1 && scriptSource[0]?.toLowerCase() === "'none'" && sandbox?.length === 0;
|
|
11505
11659
|
}
|
|
11506
11660
|
var no_dangerously_allow_svg_default = createRule({
|
|
11507
11661
|
name: "no-dangerously-allow-svg",
|
|
@@ -11512,7 +11666,7 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
11512
11666
|
docs: { description: NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION.summary },
|
|
11513
11667
|
schema: [],
|
|
11514
11668
|
messages: {
|
|
11515
|
-
noDangerouslyAllowSvg: "
|
|
11669
|
+
noDangerouslyAllowSvg: "SVG opt-in requires a recognized explicit script-blocking sandbox CSP and attachment disposition under this policy."
|
|
11516
11670
|
}
|
|
11517
11671
|
},
|
|
11518
11672
|
defaultOptions: [],
|
|
@@ -17808,7 +17962,7 @@ var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
|
17808
17962
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
17809
17963
|
remediation: "Move the request into a client module and call that abstraction from application code.",
|
|
17810
17964
|
category: "architecture",
|
|
17811
|
-
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."],
|
|
17965
|
+
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."],
|
|
17812
17966
|
examples: [
|
|
17813
17967
|
{ 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 },
|
|
17814
17968
|
{ 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 }
|
|
@@ -17829,11 +17983,6 @@ var DEFAULT_ALLOW = [
|
|
|
17829
17983
|
"[\\\\/][^\\\\/]*(?:Client|client)\\.[cm]?[jt]sx?$"
|
|
17830
17984
|
];
|
|
17831
17985
|
var NON_PRODUCTION_TREE_RE = /[\\/](playwright|cypress|__testfixtures__)[\\/]/;
|
|
17832
|
-
var GLOBAL_RECEIVERS3 = /* @__PURE__ */ new Set([
|
|
17833
|
-
"globalThis",
|
|
17834
|
-
"window",
|
|
17835
|
-
"self"
|
|
17836
|
-
]);
|
|
17837
17986
|
var PRESIGNED_URL_NAME_RE = /(?:pre-?signed|signed|upload|download)Url$/i;
|
|
17838
17987
|
var INTERNAL_MUTATION_METHODS = /* @__PURE__ */ new Set([
|
|
17839
17988
|
"POST",
|
|
@@ -17857,23 +18006,13 @@ var BASE_PATH_RE = /^\/(?!$)(?!.*[?#])(?:[^/]+\/)*[^/]+$/u;
|
|
|
17857
18006
|
function isValidBasePath(basePath) {
|
|
17858
18007
|
return BASE_PATH_RE.test(basePath) && !basePath.split("/").some((segment) => segment === "." || segment === "..");
|
|
17859
18008
|
}
|
|
17860
|
-
function isGlobalFetchCall(node, resolvesToGlobal) {
|
|
17861
|
-
const callee = unwrapExpression(node.callee);
|
|
17862
|
-
if (callee.type === "Identifier") {
|
|
17863
|
-
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
17864
|
-
}
|
|
17865
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "fetch" && callee.object.type === "Identifier") {
|
|
17866
|
-
return GLOBAL_RECEIVERS3.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
17867
|
-
}
|
|
17868
|
-
return false;
|
|
17869
|
-
}
|
|
17870
18009
|
function isConstructedArgumentHandoff(node, resolvesToGlobal) {
|
|
17871
18010
|
const [first] = node.arguments;
|
|
17872
18011
|
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);
|
|
17873
18012
|
}
|
|
17874
18013
|
function effectOwns(node) {
|
|
17875
18014
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17876
|
-
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier) return false;
|
|
18015
|
+
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || unwrappedNodeCallee.name !== "fetch") return false;
|
|
17877
18016
|
const method = readDirectMethod(node);
|
|
17878
18017
|
if (method !== null && method !== "GET") return false;
|
|
17879
18018
|
const first = node.arguments[0];
|
|
@@ -18010,7 +18149,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18010
18149
|
}
|
|
18011
18150
|
function serverActionOwns(node) {
|
|
18012
18151
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
18013
|
-
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
18152
|
+
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) {
|
|
18014
18153
|
return false;
|
|
18015
18154
|
}
|
|
18016
18155
|
const url = node.arguments[0];
|
|
@@ -18067,7 +18206,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18067
18206
|
}
|
|
18068
18207
|
return {
|
|
18069
18208
|
CallExpression(node) {
|
|
18070
|
-
if (!
|
|
18209
|
+
if (!nativeFetchReference(unwrapExpression(node.callee), context.sourceCode)) {
|
|
18071
18210
|
return;
|
|
18072
18211
|
}
|
|
18073
18212
|
if (isPresignedUrlTransfer(node) || isConstructedArgumentHandoff(node, resolvesToGlobal) || effectOwns(node) || serverActionOwns(node)) {
|
|
@@ -32689,6 +32828,7 @@ var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
|
32689
32828
|
limitations: [
|
|
32690
32829
|
"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.",
|
|
32691
32830
|
"Unshadowed native fetch members and bounded stable const aliases or destructuring are recognized. Reassigned, defaulted and unknown aliases and arbitrary forwarding functions are excluded.",
|
|
32831
|
+
"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.",
|
|
32692
32832
|
"Accessors and unproved prototypes are excluded because native option conversion can attach or replace a signal before it is read."
|
|
32693
32833
|
],
|
|
32694
32834
|
examples: [
|
|
@@ -32735,7 +32875,7 @@ function emptySignal(expression, resolvesToGlobal) {
|
|
|
32735
32875
|
}
|
|
32736
32876
|
return null;
|
|
32737
32877
|
}
|
|
32738
|
-
function initSignalState(init, resolvesToGlobal) {
|
|
32878
|
+
function initSignalState(init, resolvesToGlobal, sourceCode) {
|
|
32739
32879
|
init = unwrapExpression(init);
|
|
32740
32880
|
if (init.type !== import_utils176.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
32741
32881
|
let state = "absent";
|
|
@@ -32745,12 +32885,12 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
32745
32885
|
continue;
|
|
32746
32886
|
}
|
|
32747
32887
|
if (prop.kind !== "init" || hasUnprovedPrototype(prop)) return "unknown";
|
|
32748
|
-
const
|
|
32749
|
-
if (
|
|
32888
|
+
const name = staticPropertyName(prop, sourceCode);
|
|
32889
|
+
if (name === "signal") {
|
|
32750
32890
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
32751
|
-
} else if (!prop.computed &&
|
|
32891
|
+
} else if (!prop.computed && name === "__proto__" && state === "absent") {
|
|
32752
32892
|
state = "unknown";
|
|
32753
|
-
} else if (prop.computed &&
|
|
32893
|
+
} else if (prop.computed && name === null) {
|
|
32754
32894
|
state = "unknown";
|
|
32755
32895
|
}
|
|
32756
32896
|
}
|
|
@@ -32828,7 +32968,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32828
32968
|
return "unknown";
|
|
32829
32969
|
}
|
|
32830
32970
|
}
|
|
32831
|
-
return initSignalState(definition.node.init, resolvesToGlobal);
|
|
32971
|
+
return initSignalState(definition.node.init, resolvesToGlobal, context.sourceCode);
|
|
32832
32972
|
}
|
|
32833
32973
|
function isForwardedRequest(argument) {
|
|
32834
32974
|
let value = unwrapExpression(argument);
|
|
@@ -32856,7 +32996,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32856
32996
|
}
|
|
32857
32997
|
const [first, rawInit] = node.arguments;
|
|
32858
32998
|
const init = rawInit === void 0 ? void 0 : unwrapExpression(rawInit);
|
|
32859
|
-
const state = init === void 0 ? "unknown" : init.type === import_utils176.AST_NODE_TYPES.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal);
|
|
32999
|
+
const state = init === void 0 ? "unknown" : init.type === import_utils176.AST_NODE_TYPES.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal, context.sourceCode);
|
|
32860
33000
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first) && state !== "null")) {
|
|
32861
33001
|
return;
|
|
32862
33002
|
}
|