@sarj/eslint-plugin 16.36.7 → 16.38.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +850 -762
- package/dist/index.js +844 -756
- package/dist/rule-examples.cjs +168 -44
- package/dist/rule-examples.js +168 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -678,41 +678,230 @@ var no_mutating_input_with_result_default = createRule({
|
|
|
678
678
|
});
|
|
679
679
|
|
|
680
680
|
// src/rules/no-negative-only-http-status-assertion.ts
|
|
681
|
-
var
|
|
681
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
682
682
|
|
|
683
683
|
// src/rules/_native-fetch-reference.ts
|
|
684
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
685
|
+
|
|
686
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
687
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
688
|
+
|
|
689
|
+
// src/rules/_stable-value-binding.ts
|
|
684
690
|
var import_utils5 = require("@typescript-eslint/utils");
|
|
691
|
+
function typeOnlyReference(reference) {
|
|
692
|
+
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
693
|
+
let current = outerExpression(reference.identifier);
|
|
694
|
+
while (current.parent?.type === import_utils5.AST_NODE_TYPES.TSQualifiedName && current.parent.left === current) {
|
|
695
|
+
current = current.parent;
|
|
696
|
+
}
|
|
697
|
+
return current.parent?.type === import_utils5.AST_NODE_TYPES.TSTypeQuery && current.parent.exprName === current;
|
|
698
|
+
}
|
|
699
|
+
function stableValueBinding(variable, acceptRead) {
|
|
700
|
+
let initializer;
|
|
701
|
+
return variable.references.every((reference) => {
|
|
702
|
+
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
703
|
+
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
704
|
+
initializer = reference.identifier;
|
|
705
|
+
return true;
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/rules/_static-string.ts
|
|
710
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
711
|
+
function staticString(node) {
|
|
712
|
+
if (node === void 0) return null;
|
|
713
|
+
const value = unwrapExpression(node);
|
|
714
|
+
if (value.type === import_utils6.AST_NODE_TYPES.Literal && typeof value.value === "string") return value.value;
|
|
715
|
+
return value.type === import_utils6.AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
716
|
+
}
|
|
717
|
+
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
718
|
+
function scopedStaticString(node, sourceCode) {
|
|
719
|
+
let value = unwrapExpression(node);
|
|
720
|
+
if (value.type !== import_utils6.AST_NODE_TYPES.Identifier) return staticString(value);
|
|
721
|
+
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
722
|
+
if (values === void 0) {
|
|
723
|
+
values = /* @__PURE__ */ new WeakMap();
|
|
724
|
+
SCOPED_STRING_VALUES.set(sourceCode, values);
|
|
725
|
+
}
|
|
726
|
+
const seen = /* @__PURE__ */ new Set();
|
|
727
|
+
const pending = [];
|
|
728
|
+
let result = null;
|
|
729
|
+
while (value.type === import_utils6.AST_NODE_TYPES.Identifier) {
|
|
730
|
+
const binding3 = import_utils6.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
731
|
+
if (binding3 === null || seen.has(binding3)) break;
|
|
732
|
+
if (values.has(binding3)) {
|
|
733
|
+
result = values.get(binding3) ?? null;
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
seen.add(binding3);
|
|
737
|
+
pending.push(binding3);
|
|
738
|
+
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
739
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== import_utils6.AST_NODE_TYPES.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
740
|
+
value = unwrapExpression(definition.node.init);
|
|
741
|
+
if (value.type !== import_utils6.AST_NODE_TYPES.Identifier) result = staticString(value);
|
|
742
|
+
}
|
|
743
|
+
for (const binding3 of pending) values.set(binding3, result);
|
|
744
|
+
return result;
|
|
745
|
+
}
|
|
746
|
+
function staticPropertyName(node, sourceCode) {
|
|
747
|
+
const direct = import_utils6.ASTUtils.getPropertyName(node);
|
|
748
|
+
if (direct !== null || !node.computed) return direct;
|
|
749
|
+
const key = node.type === import_utils6.AST_NODE_TYPES.MemberExpression ? node.property : node.key;
|
|
750
|
+
return scopedStaticString(key, sourceCode);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/rules/_native-runtime-unchanged.ts
|
|
754
|
+
var INDEXES = /* @__PURE__ */ new WeakMap();
|
|
755
|
+
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "global", "window", "self"]);
|
|
756
|
+
function nativeRuntimeUnchanged(sourceCode, name) {
|
|
757
|
+
const index = runtimeIndex(sourceCode);
|
|
758
|
+
const cached = index.results.get(name);
|
|
759
|
+
if (cached !== void 0) return cached;
|
|
760
|
+
const changed = index.nodes.some((node) => node.type === import_utils7.AST_NODE_TYPES.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "fetch" && node.type === import_utils7.AST_NODE_TYPES.Property && node.parent.type === import_utils7.AST_NODE_TYPES.ObjectPattern && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === import_utils7.AST_NODE_TYPES.Literal && "regex" in node) || index.references.some((reference) => (name !== "fetch" || !typeOnlyReference(reference)) && unsafeReference(reference.identifier, sourceCode, name, index));
|
|
761
|
+
index.results.set(name, !changed);
|
|
762
|
+
return !changed;
|
|
763
|
+
}
|
|
764
|
+
function runtimeIndex(sourceCode) {
|
|
765
|
+
const cached = INDEXES.get(sourceCode);
|
|
766
|
+
if (cached !== void 0) return cached;
|
|
767
|
+
const references = sourceCode.scopeManager?.scopes.flatMap((scope) => scope.references.filter((reference) => reference.isValueReference !== false)) ?? [];
|
|
768
|
+
const nodes = [];
|
|
769
|
+
const pending = [sourceCode.ast];
|
|
770
|
+
while (pending.length > 0) {
|
|
771
|
+
const node = pending.pop();
|
|
772
|
+
if (node === void 0) continue;
|
|
773
|
+
nodes.push(node);
|
|
774
|
+
forEachAstChild(node, sourceCode.visitorKeys, (child) => {
|
|
775
|
+
pending.push(child);
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
const index = { references, nodes, results: /* @__PURE__ */ new Map(), fetchAliases: /* @__PURE__ */ new Map() };
|
|
779
|
+
INDEXES.set(sourceCode, index);
|
|
780
|
+
return index;
|
|
781
|
+
}
|
|
782
|
+
function unsafeReference(node, sourceCode, name, index) {
|
|
783
|
+
if (!ambient(node, sourceCode)) return false;
|
|
784
|
+
if (node.name === "eval" || node.name === "Function") return true;
|
|
785
|
+
if (node.name === name) return name === "fetch" ? !fetchRead(node, sourceCode, index) : !nativeRead(node, name);
|
|
786
|
+
if (!GLOBAL_OBJECTS.has(node.name)) return false;
|
|
787
|
+
const value = outerExpression(node);
|
|
788
|
+
const property = value.parent;
|
|
789
|
+
if (name === "fetch" && property?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && property.operator === "typeof") return false;
|
|
790
|
+
if (property?.type !== import_utils7.AST_NODE_TYPES.MemberExpression || property.object !== value) {
|
|
791
|
+
return name !== "fetch" || !fetchProjection(value, sourceCode, index);
|
|
792
|
+
}
|
|
793
|
+
const key = staticPropertyName(property, sourceCode);
|
|
794
|
+
if (key === null || key === "eval" || key === "Function" || key === "constructor") return true;
|
|
795
|
+
if (name === "fetch" && GLOBAL_OBJECTS.has(key)) return true;
|
|
796
|
+
return key === name && !(name === "fetch" ? fetchRead(property, sourceCode, index) : nativeRead(property, name));
|
|
797
|
+
}
|
|
798
|
+
function ambient(node, sourceCode) {
|
|
799
|
+
const variable = import_utils7.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
800
|
+
return variable === null || variable.defs.length === 0;
|
|
801
|
+
}
|
|
802
|
+
function fetchUse(node, sourceCode) {
|
|
803
|
+
const value = outerExpression(node);
|
|
804
|
+
const parent = value.parent;
|
|
805
|
+
if (parent?.type === import_utils7.AST_NODE_TYPES.CallExpression && parent.callee === value || parent?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
806
|
+
if (parent?.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator || parent.init !== value || parent.id.type !== import_utils7.AST_NODE_TYPES.Identifier) return false;
|
|
807
|
+
return stableConstBinding(parent.id, sourceCode) ?? false;
|
|
808
|
+
}
|
|
809
|
+
function stableConstBinding(node, sourceCode) {
|
|
810
|
+
const binding3 = import_utils7.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
811
|
+
if (binding3 === null || binding3.defs.length !== 1) return null;
|
|
812
|
+
const [definition] = binding3.defs;
|
|
813
|
+
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && definition.parent.parent.type !== import_utils7.AST_NODE_TYPES.ExportNamedDeclaration && !binding3.references.some((reference) => reference.isWrite() && reference.init !== true) ? binding3 : null;
|
|
814
|
+
}
|
|
815
|
+
function fetchRead(node, sourceCode, index) {
|
|
816
|
+
const use = fetchUse(node, sourceCode);
|
|
817
|
+
return use === true || use !== false && fetchAliasRead(use, sourceCode, index);
|
|
818
|
+
}
|
|
819
|
+
function fetchAliasRead(binding3, sourceCode, index) {
|
|
820
|
+
const pending = [binding3];
|
|
821
|
+
const visited = [];
|
|
822
|
+
let safe = true;
|
|
823
|
+
while (pending.length > 0 && safe) {
|
|
824
|
+
const current = pending.pop();
|
|
825
|
+
if (current === void 0) continue;
|
|
826
|
+
const cached = index.fetchAliases.get(current);
|
|
827
|
+
if (cached === "safe") continue;
|
|
828
|
+
if (cached !== void 0) {
|
|
829
|
+
safe = false;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
index.fetchAliases.set(current, "visiting");
|
|
833
|
+
visited.push(current);
|
|
834
|
+
const captures = fetchAliasCaptures(current, sourceCode);
|
|
835
|
+
if (captures === false) {
|
|
836
|
+
safe = false;
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
for (const captured of captures) pending.push(captured);
|
|
840
|
+
}
|
|
841
|
+
for (const current of visited) index.fetchAliases.set(current, safe ? "safe" : "unsafe");
|
|
842
|
+
return safe;
|
|
843
|
+
}
|
|
844
|
+
function fetchAliasCaptures(binding3, sourceCode) {
|
|
845
|
+
const captures = [];
|
|
846
|
+
for (const reference of binding3.references) {
|
|
847
|
+
if (reference.isValueReference === false || reference.init === true || typeOnlyReference(reference)) continue;
|
|
848
|
+
const use = fetchUse(reference.identifier, sourceCode);
|
|
849
|
+
if (use === false) return false;
|
|
850
|
+
if (use !== true) captures.push(use);
|
|
851
|
+
}
|
|
852
|
+
return captures;
|
|
853
|
+
}
|
|
854
|
+
function fetchProjection(node, sourceCode, index) {
|
|
855
|
+
const declaration = node.parent;
|
|
856
|
+
if (declaration?.type !== import_utils7.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils7.AST_NODE_TYPES.ObjectPattern || declaration.id.properties.length !== 1) return false;
|
|
857
|
+
const [property] = declaration.id.properties;
|
|
858
|
+
if (property?.type !== import_utils7.AST_NODE_TYPES.Property || staticPropertyName(property, sourceCode) !== "fetch" || property.value.type !== import_utils7.AST_NODE_TYPES.Identifier) return false;
|
|
859
|
+
const binding3 = stableConstBinding(property.value, sourceCode);
|
|
860
|
+
return binding3 !== null && fetchAliasRead(binding3, sourceCode, index);
|
|
861
|
+
}
|
|
862
|
+
function nativeRead(node, name) {
|
|
863
|
+
const value = outerExpression(node);
|
|
864
|
+
const parent = value.parent;
|
|
865
|
+
if (parent?.type === import_utils7.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
866
|
+
if (name !== "Error") return false;
|
|
867
|
+
return parent?.type === import_utils7.AST_NODE_TYPES.NewExpression && parent.callee === value || parent?.type === import_utils7.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/rules/_native-fetch-reference.ts
|
|
685
871
|
var GLOBAL_RECEIVERS = /* @__PURE__ */ new Set(["globalThis", "self", "window"]);
|
|
686
|
-
function nativeFetchReference(node, sourceCode
|
|
872
|
+
function nativeFetchReference(node, sourceCode) {
|
|
873
|
+
return lexicalFetchReference(node, sourceCode) && nativeRuntimeUnchanged(sourceCode, "fetch");
|
|
874
|
+
}
|
|
875
|
+
function lexicalFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
687
876
|
const expression = unwrapExpression(node);
|
|
688
|
-
if (expression.type ===
|
|
689
|
-
return
|
|
877
|
+
if (expression.type === import_utils8.AST_NODE_TYPES.MemberExpression) {
|
|
878
|
+
return staticPropertyName(expression, sourceCode) === "fetch" && globalReceiver(expression.object, sourceCode);
|
|
690
879
|
}
|
|
691
|
-
if (expression.type !==
|
|
692
|
-
const binding3 =
|
|
880
|
+
if (expression.type !== import_utils8.AST_NODE_TYPES.Identifier) return false;
|
|
881
|
+
const binding3 = import_utils8.ASTUtils.findVariable(sourceCode.getScope(expression), expression.name);
|
|
693
882
|
if (binding3 === null || binding3.defs.length === 0) return expression.name === "fetch";
|
|
694
883
|
if (seen.has(binding3) || seen.size >= 8 || binding3.defs.length !== 1 || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
695
884
|
seen.add(binding3);
|
|
696
885
|
const [definition] = binding3.defs;
|
|
697
886
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null) return false;
|
|
698
|
-
if (definition.node.id.type ===
|
|
699
|
-
return
|
|
887
|
+
if (definition.node.id.type === import_utils8.AST_NODE_TYPES.Identifier) {
|
|
888
|
+
return lexicalFetchReference(definition.node.init, sourceCode, seen);
|
|
700
889
|
}
|
|
701
|
-
return definition.node.id.type ===
|
|
890
|
+
return definition.node.id.type === import_utils8.AST_NODE_TYPES.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === import_utils8.AST_NODE_TYPES.Property && staticPropertyName(property, sourceCode) === "fetch" && property.value.type === import_utils8.AST_NODE_TYPES.Identifier && import_utils8.ASTUtils.findVariable(sourceCode.getScope(property.value), property.value.name) === binding3);
|
|
702
891
|
}
|
|
703
892
|
function globalReceiver(node, sourceCode) {
|
|
704
893
|
const receiver = unwrapExpression(node);
|
|
705
|
-
return receiver.type ===
|
|
894
|
+
return receiver.type === import_utils8.AST_NODE_TYPES.Identifier && GLOBAL_RECEIVERS.has(receiver.name) && !import_utils8.ASTUtils.findVariable(sourceCode.getScope(receiver), receiver.name)?.defs.length;
|
|
706
895
|
}
|
|
707
896
|
|
|
708
897
|
// src/rules/_test-mock-provenance.ts
|
|
709
|
-
var
|
|
898
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
710
899
|
function importedTestMockNamespace(source, identifier) {
|
|
711
|
-
const binding3 =
|
|
900
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
712
901
|
const importedBinding = runtimeImportBinding(binding3);
|
|
713
|
-
if (importedBinding === null || importedBinding.specifier.type !==
|
|
902
|
+
if (importedBinding === null || importedBinding.specifier.type !== import_utils9.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
714
903
|
const specifier = importedBinding.specifier;
|
|
715
|
-
const imported = specifier.imported.type ===
|
|
904
|
+
const imported = specifier.imported.type === import_utils9.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
716
905
|
const module2 = importedBinding.module;
|
|
717
906
|
if (module2 === "vitest" && (imported === "vi" || imported === "vitest")) return "vitest";
|
|
718
907
|
if (module2 === "@jest/globals" && imported === "jest") return "jest";
|
|
@@ -720,12 +909,12 @@ function importedTestMockNamespace(source, identifier) {
|
|
|
720
909
|
}
|
|
721
910
|
function isUnshadowedTestMockGlobal(source, identifier) {
|
|
722
911
|
if (identifier.name !== "vi" && identifier.name !== "jest") return false;
|
|
723
|
-
const binding3 =
|
|
912
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
724
913
|
return binding3 === null || binding3.defs.length === 0 && !binding3.references.some((reference) => reference.isWrite());
|
|
725
914
|
}
|
|
726
915
|
var TEST_FRAMEWORK_MODULES = /* @__PURE__ */ new Set(["@jest/globals", "@playwright/test", "bun:test", "node:test", "vitest"]);
|
|
727
916
|
function runtimeTestFrameworkName(source, identifier, kind) {
|
|
728
|
-
const binding3 =
|
|
917
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
729
918
|
if (binding3 === null || binding3.defs.length === 0) {
|
|
730
919
|
return binding3?.references.some((reference) => reference.isWrite()) ? null : identifier.name;
|
|
731
920
|
}
|
|
@@ -733,22 +922,22 @@ function runtimeTestFrameworkName(source, identifier, kind) {
|
|
|
733
922
|
if (importedBinding === null) return null;
|
|
734
923
|
const { specifier, module: module2 } = importedBinding;
|
|
735
924
|
const isNodeAssertion = kind === "assertion" && (module2 === "node:assert" || module2 === "node:assert/strict");
|
|
736
|
-
if (specifier.type ===
|
|
925
|
+
if (specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier) {
|
|
737
926
|
if (isNodeAssertion) return "assert";
|
|
738
927
|
if (!TEST_FRAMEWORK_MODULES.has(module2)) return null;
|
|
739
|
-
const imported = specifier.imported.type ===
|
|
928
|
+
const imported = specifier.imported.type === import_utils9.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
740
929
|
return imported;
|
|
741
930
|
}
|
|
742
931
|
if (isNodeAssertion) return "assert";
|
|
743
|
-
return kind === "test" && module2 === "node:test" && specifier.type ===
|
|
932
|
+
return kind === "test" && module2 === "node:test" && specifier.type === import_utils9.AST_NODE_TYPES.ImportDefaultSpecifier ? "test" : null;
|
|
744
933
|
}
|
|
745
934
|
function runtimeImportBinding(binding3) {
|
|
746
935
|
if (binding3?.defs.length !== 1) return null;
|
|
747
936
|
const definition = binding3.defs[0];
|
|
748
|
-
if (definition?.type !== "ImportBinding" || definition.parent.type !==
|
|
937
|
+
if (definition?.type !== "ImportBinding" || definition.parent.type !== import_utils9.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type") return null;
|
|
749
938
|
const specifier = definition.node;
|
|
750
|
-
if (specifier.type !==
|
|
751
|
-
if (specifier.type ===
|
|
939
|
+
if (specifier.type !== import_utils9.AST_NODE_TYPES.ImportSpecifier && specifier.type !== import_utils9.AST_NODE_TYPES.ImportDefaultSpecifier && specifier.type !== import_utils9.AST_NODE_TYPES.ImportNamespaceSpecifier) return null;
|
|
940
|
+
if (specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") return null;
|
|
752
941
|
return { module: definition.parent.source.value, specifier };
|
|
753
942
|
}
|
|
754
943
|
function vitestFixtureTestName(source, identifier) {
|
|
@@ -756,24 +945,24 @@ function vitestFixtureTestName(source, identifier) {
|
|
|
756
945
|
}
|
|
757
946
|
function fixtureTestName(node, source, seen) {
|
|
758
947
|
node = unwrapExpression(node);
|
|
759
|
-
if (node.type ===
|
|
948
|
+
if (node.type === import_utils9.AST_NODE_TYPES.CallExpression) {
|
|
760
949
|
const callee = unwrapExpression(node.callee);
|
|
761
|
-
return !node.optional && callee.type ===
|
|
950
|
+
return !node.optional && callee.type === import_utils9.AST_NODE_TYPES.MemberExpression && !callee.optional && import_utils9.ASTUtils.getPropertyName(callee) === "extend" && node.arguments.length > 0 && !node.arguments.some((argument) => argument.type === import_utils9.AST_NODE_TYPES.SpreadElement) ? fixtureTestName(callee.object, source, seen) : null;
|
|
762
951
|
}
|
|
763
|
-
if (node.type !==
|
|
764
|
-
const binding3 =
|
|
952
|
+
if (node.type !== import_utils9.AST_NODE_TYPES.Identifier) return null;
|
|
953
|
+
const binding3 = import_utils9.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
765
954
|
if (binding3 === null || seen.has(binding3) || !unchangedFixtureApi(binding3)) return null;
|
|
766
955
|
seen.add(binding3);
|
|
767
956
|
const imported = runtimeImportBinding(binding3);
|
|
768
|
-
if (imported?.module === "vitest" && imported.specifier.type ===
|
|
957
|
+
if (imported?.module === "vitest" && imported.specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier) {
|
|
769
958
|
const name = imported.specifier.imported;
|
|
770
|
-
const value = name.type ===
|
|
959
|
+
const value = name.type === import_utils9.AST_NODE_TYPES.Identifier ? name.name : name.value;
|
|
771
960
|
return value === "test" || value === "it" ? value : null;
|
|
772
961
|
}
|
|
773
962
|
const definition = binding3.defs[0];
|
|
774
|
-
if (binding3.defs.length !== 1 || definition?.node.type !==
|
|
963
|
+
if (binding3.defs.length !== 1 || definition?.node.type !== import_utils9.AST_NODE_TYPES.VariableDeclarator || definition.node.id.type !== import_utils9.AST_NODE_TYPES.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0]) return null;
|
|
775
964
|
const initializer = unwrapExpression(definition.node.init);
|
|
776
|
-
return initializer.type ===
|
|
965
|
+
return initializer.type === import_utils9.AST_NODE_TYPES.CallExpression ? fixtureTestName(initializer, source, seen) : null;
|
|
777
966
|
}
|
|
778
967
|
var FIXTURE_API_STABILITY = /* @__PURE__ */ new WeakMap();
|
|
779
968
|
function unchangedFixtureApi(binding3) {
|
|
@@ -783,9 +972,9 @@ function unchangedFixtureApi(binding3) {
|
|
|
783
972
|
if (reference.isWrite()) return reference.init === true;
|
|
784
973
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
785
974
|
let use = outerExpression(reference.identifier);
|
|
786
|
-
while (use.parent?.type ===
|
|
975
|
+
while (use.parent?.type === import_utils9.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = outerExpression(use.parent);
|
|
787
976
|
const parent = use.parent;
|
|
788
|
-
return parent?.type ===
|
|
977
|
+
return parent?.type === import_utils9.AST_NODE_TYPES.CallExpression && parent.callee === use || parent?.type === import_utils9.AST_NODE_TYPES.ExportSpecifier || parent?.type === import_utils9.AST_NODE_TYPES.ExportDefaultDeclaration || parent?.type === import_utils9.AST_NODE_TYPES.TSTypeQuery || parent?.type === import_utils9.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof";
|
|
789
978
|
});
|
|
790
979
|
FIXTURE_API_STABILITY.set(binding3, unchanged);
|
|
791
980
|
return unchanged;
|
|
@@ -815,72 +1004,72 @@ var NO_NEGATIVE_ONLY_HTTP_STATUS_ASSERTION_DOCUMENTATION = {
|
|
|
815
1004
|
]
|
|
816
1005
|
};
|
|
817
1006
|
function statusAssertion(source, call) {
|
|
818
|
-
if (call.arguments.length !== 1 || call.arguments[0]?.type !==
|
|
819
|
-
const matcher =
|
|
1007
|
+
if (call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils10.AST_NODE_TYPES.Literal || typeof call.arguments[0].value !== "number" || call.callee.type !== import_utils10.AST_NODE_TYPES.MemberExpression) return null;
|
|
1008
|
+
const matcher = import_utils10.ASTUtils.getPropertyName(call.callee);
|
|
820
1009
|
if (matcher === null) return null;
|
|
821
1010
|
let object = unwrapExpression(call.callee.object);
|
|
822
|
-
const negative = object.type ===
|
|
823
|
-
if (negative && object.type ===
|
|
824
|
-
if (object.type !==
|
|
1011
|
+
const negative = object.type === import_utils10.AST_NODE_TYPES.MemberExpression && import_utils10.ASTUtils.getPropertyName(object) === "not";
|
|
1012
|
+
if (negative && object.type === import_utils10.AST_NODE_TYPES.MemberExpression) object = unwrapExpression(object.object);
|
|
1013
|
+
if (object.type !== import_utils10.AST_NODE_TYPES.CallExpression || object.arguments.length !== 1 || object.callee.type !== import_utils10.AST_NODE_TYPES.Identifier || runtimeTestFrameworkName(source, object.callee, "assertion") !== "expect") return null;
|
|
825
1014
|
const argument = object.arguments[0];
|
|
826
|
-
const response = argument === void 0 || argument.type ===
|
|
1015
|
+
const response = argument === void 0 || argument.type === import_utils10.AST_NODE_TYPES.SpreadElement ? null : fetchResponse(source, argument);
|
|
827
1016
|
return response === null ? null : { response, expected: call.arguments[0].value, matcher, negative };
|
|
828
1017
|
}
|
|
829
1018
|
function fetchResponse(source, value) {
|
|
830
1019
|
const node = unwrapExpression(value);
|
|
831
|
-
if (node.type !==
|
|
1020
|
+
if (node.type !== import_utils10.AST_NODE_TYPES.MemberExpression || import_utils10.ASTUtils.getPropertyName(node) !== "status" || node.object.type !== import_utils10.AST_NODE_TYPES.Identifier) return null;
|
|
832
1021
|
return responseBinding(source, node.object);
|
|
833
1022
|
}
|
|
834
1023
|
function responseBinding(source, node, seen = /* @__PURE__ */ new Set()) {
|
|
835
|
-
const variable =
|
|
1024
|
+
const variable = import_utils10.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
836
1025
|
const definition = variable?.defs[0]?.node;
|
|
837
1026
|
if (variable?.defs.length !== 1 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
838
1027
|
seen.add(variable);
|
|
839
1028
|
const parameter = variable.defs[0];
|
|
840
|
-
if (parameter?.type === "Parameter" && parameter.name.type ===
|
|
1029
|
+
if (parameter?.type === "Parameter" && parameter.name.type === import_utils10.AST_NODE_TYPES.Identifier) {
|
|
841
1030
|
const annotation = parameter.name.typeAnnotation?.typeAnnotation;
|
|
842
|
-
return annotation?.type ===
|
|
1031
|
+
return annotation?.type === import_utils10.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils10.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Response" && (import_utils10.ASTUtils.findVariable(source.getScope(annotation.typeName), "Response")?.defs.length ?? 0) === 0 ? variable : null;
|
|
843
1032
|
}
|
|
844
|
-
if (definition?.type !==
|
|
1033
|
+
if (definition?.type !== import_utils10.AST_NODE_TYPES.VariableDeclarator || definition.parent.kind !== "const" || definition.init === null) return null;
|
|
845
1034
|
let initial = unwrapExpression(definition.init);
|
|
846
|
-
if (initial.type ===
|
|
847
|
-
if (initial.type ===
|
|
1035
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.AwaitExpression) initial = unwrapExpression(initial.argument);
|
|
1036
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.Identifier) return responseBinding(source, initial, seen);
|
|
848
1037
|
return nativeResponse(initial, source) ? variable : null;
|
|
849
1038
|
}
|
|
850
1039
|
function nativeResponse(initial, source) {
|
|
851
|
-
if (initial.type ===
|
|
852
|
-
if (initial.type ===
|
|
853
|
-
if (initial.type !==
|
|
1040
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.NewExpression && initial.callee.type === import_utils10.AST_NODE_TYPES.Identifier && initial.callee.name === "Response" && (import_utils10.ASTUtils.findVariable(source.getScope(initial.callee), "Response")?.defs.length ?? 0) === 0) return true;
|
|
1041
|
+
if (initial.type === import_utils10.AST_NODE_TYPES.CallExpression && nativeFetchReference(initial.callee, source)) return true;
|
|
1042
|
+
if (initial.type !== import_utils10.AST_NODE_TYPES.CallExpression || initial.callee.type !== import_utils10.AST_NODE_TYPES.Identifier) return false;
|
|
854
1043
|
const callee = initial.callee;
|
|
855
|
-
const binding3 =
|
|
1044
|
+
const binding3 = import_utils10.ASTUtils.findVariable(source.getScope(callee), callee.name);
|
|
856
1045
|
if ((binding3?.defs.length ?? 0) === 0) return callee.name === "fetch";
|
|
857
1046
|
const imported = binding3?.defs[0];
|
|
858
|
-
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !==
|
|
1047
|
+
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !== import_utils10.AST_NODE_TYPES.ImportDeclaration || imported.parent.importKind === "type" || !FETCH_MODULES.has(imported.parent.source.value)) return false;
|
|
859
1048
|
const specifier = imported.node;
|
|
860
|
-
if (specifier.type ===
|
|
861
|
-
if (specifier.type !==
|
|
862
|
-
const importedName7 = specifier.imported.type ===
|
|
1049
|
+
if (specifier.type === import_utils10.AST_NODE_TYPES.ImportDefaultSpecifier) return imported.parent.source.value === "node-fetch";
|
|
1050
|
+
if (specifier.type !== import_utils10.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type") return false;
|
|
1051
|
+
const importedName7 = specifier.imported.type === import_utils10.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
863
1052
|
return importedName7 === "fetch";
|
|
864
1053
|
}
|
|
865
1054
|
function enclosingTest(source, node) {
|
|
866
1055
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
867
|
-
if (current.type ===
|
|
868
|
-
if (current.type !==
|
|
1056
|
+
if (current.type === import_utils10.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
1057
|
+
if (current.type !== import_utils10.AST_NODE_TYPES.ArrowFunctionExpression && current.type !== import_utils10.AST_NODE_TYPES.FunctionExpression) continue;
|
|
869
1058
|
const registration2 = directArgumentCall(current);
|
|
870
1059
|
const callee = registration2?.callee;
|
|
871
|
-
if (callee?.type !==
|
|
1060
|
+
if (callee?.type !== import_utils10.AST_NODE_TYPES.Identifier) return null;
|
|
872
1061
|
const name = runtimeTestFrameworkName(source, callee, "test") ?? vitestFixtureTestName(source, callee);
|
|
873
1062
|
return name === "test" || name === "it" ? current : null;
|
|
874
1063
|
}
|
|
875
1064
|
return null;
|
|
876
1065
|
}
|
|
877
1066
|
function hasExactStatus(source, test, response) {
|
|
878
|
-
if (test.body.type !==
|
|
1067
|
+
if (test.body.type !== import_utils10.AST_NODE_TYPES.BlockStatement) return false;
|
|
879
1068
|
return test.body.body.some((statement) => {
|
|
880
|
-
if (statement.type !==
|
|
1069
|
+
if (statement.type !== import_utils10.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
881
1070
|
let expression = unwrapExpression(statement.expression);
|
|
882
|
-
if (expression.type ===
|
|
883
|
-
if (expression.type !==
|
|
1071
|
+
if (expression.type === import_utils10.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1072
|
+
if (expression.type !== import_utils10.AST_NODE_TYPES.CallExpression) return false;
|
|
884
1073
|
const assertion = statusAssertion(source, expression);
|
|
885
1074
|
return assertion !== null && assertion.response === response && !assertion.negative && EXACT_MATCHERS.has(assertion.matcher) && Number.isInteger(assertion.expected) && assertion.expected >= HTTP_STATUS_MIN && assertion.expected <= SERVER_ERROR_MAX;
|
|
886
1075
|
});
|
|
@@ -911,7 +1100,7 @@ var no_negative_only_http_status_assertion_default = createRule({
|
|
|
911
1100
|
});
|
|
912
1101
|
|
|
913
1102
|
// src/rules/prefer-test-fixture-reuse.ts
|
|
914
|
-
var
|
|
1103
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
915
1104
|
var MAX_DEPTH = 8;
|
|
916
1105
|
var FRAMEWORKS = /* @__PURE__ */ new Set(["vitest", "@playwright/test"]);
|
|
917
1106
|
var TEST_MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "sequential"]);
|
|
@@ -933,24 +1122,24 @@ var PREFER_TEST_FIXTURE_REUSE_DOCUMENTATION = {
|
|
|
933
1122
|
]
|
|
934
1123
|
};
|
|
935
1124
|
function stableBinding(source, identifier) {
|
|
936
|
-
const variable =
|
|
1125
|
+
const variable = import_utils11.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
937
1126
|
if (variable?.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
938
1127
|
return variable;
|
|
939
1128
|
}
|
|
940
1129
|
function constructorBinding(source, node, depth = 0) {
|
|
941
1130
|
node = unwrapExpression(node);
|
|
942
|
-
if (node.type !==
|
|
1131
|
+
if (node.type !== import_utils11.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
943
1132
|
const variable = stableBinding(source, node);
|
|
944
1133
|
const definition = variable?.defs[0];
|
|
945
1134
|
if (variable === null || definition === void 0) return null;
|
|
946
1135
|
if (definition.type === "ClassName") return variable;
|
|
947
|
-
if (definition.type === "ImportBinding" && definition.parent.type ===
|
|
948
|
-
if (definition.node.type ===
|
|
1136
|
+
if (definition.type === "ImportBinding" && definition.parent.type === import_utils11.AST_NODE_TYPES.ImportDeclaration && definition.parent.importKind !== "type" && (definition.node.type !== import_utils11.AST_NODE_TYPES.ImportSpecifier || definition.node.importKind !== "type")) return variable;
|
|
1137
|
+
if (definition.node.type === import_utils11.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < node.range[0]) return constructorBinding(source, definition.node.init, depth + 1);
|
|
949
1138
|
return null;
|
|
950
1139
|
}
|
|
951
1140
|
function fixtureApi(source, expression, depth = 0) {
|
|
952
1141
|
const node = unwrapExpression(expression);
|
|
953
|
-
if (node.type !==
|
|
1142
|
+
if (node.type !== import_utils11.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
954
1143
|
const variable = stableBinding(source, node);
|
|
955
1144
|
const definition = variable?.defs[0];
|
|
956
1145
|
if (variable === null || definition === void 0) return null;
|
|
@@ -962,35 +1151,35 @@ function fixtureApi(source, expression, depth = 0) {
|
|
|
962
1151
|
}
|
|
963
1152
|
function importedFixtureApi(variable) {
|
|
964
1153
|
const definition = variable.defs[0];
|
|
965
|
-
if (definition?.type === "ImportBinding" && definition.parent.type ===
|
|
1154
|
+
if (definition?.type === "ImportBinding" && definition.parent.type === import_utils11.AST_NODE_TYPES.ImportDeclaration && FRAMEWORKS.has(definition.parent.source.value) && definition.parent.importKind !== "type" && definition.node.type === import_utils11.AST_NODE_TYPES.ImportSpecifier && definition.node.importKind !== "type") {
|
|
966
1155
|
const imported = definition.node.imported;
|
|
967
|
-
const name = imported.type ===
|
|
1156
|
+
const name = imported.type === import_utils11.AST_NODE_TYPES.Identifier ? imported.name : imported.value;
|
|
968
1157
|
return name === "test" || name === "it";
|
|
969
1158
|
}
|
|
970
1159
|
return false;
|
|
971
1160
|
}
|
|
972
1161
|
function fixtureExtension(declaration, before) {
|
|
973
|
-
if (declaration.type !==
|
|
1162
|
+
if (declaration.type !== import_utils11.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= before) return null;
|
|
974
1163
|
const initial = unwrapExpression(declaration.init);
|
|
975
|
-
if (initial.type !==
|
|
1164
|
+
if (initial.type !== import_utils11.AST_NODE_TYPES.CallExpression || initial.optional || initial.arguments.length !== 1 || initial.callee.type !== import_utils11.AST_NODE_TYPES.MemberExpression || initial.callee.optional || import_utils11.ASTUtils.getPropertyName(initial.callee) !== "extend") return null;
|
|
976
1165
|
const declarations = initial.arguments[0];
|
|
977
|
-
if (declarations?.type !==
|
|
1166
|
+
if (declarations?.type !== import_utils11.AST_NODE_TYPES.ObjectExpression || declarations.properties.some((property) => property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed || property.kind !== "init")) return null;
|
|
978
1167
|
return { receiver: initial.callee.object, declarations };
|
|
979
1168
|
}
|
|
980
1169
|
function fixtureApiStable(variable) {
|
|
981
1170
|
return !variable.references.some((reference) => {
|
|
982
1171
|
if (reference.isWrite() || reference.isTypeReference && !reference.isValueReference) return false;
|
|
983
1172
|
let use = reference.identifier;
|
|
984
|
-
while (use.parent?.type ===
|
|
985
|
-
return use.parent?.type !==
|
|
1173
|
+
while (use.parent?.type === import_utils11.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = use.parent;
|
|
1174
|
+
return use.parent?.type !== import_utils11.AST_NODE_TYPES.CallExpression || use.parent.callee !== use;
|
|
986
1175
|
});
|
|
987
1176
|
}
|
|
988
1177
|
function fixtureConstructors(source, declarations, inherited) {
|
|
989
1178
|
const result = new Map(inherited);
|
|
990
1179
|
for (const property of declarations.properties) {
|
|
991
|
-
if (property.type !==
|
|
992
|
-
const name =
|
|
993
|
-
if (name === null || property.value.type ===
|
|
1180
|
+
if (property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed || property.value.type === import_utils11.AST_NODE_TYPES.AssignmentPattern) continue;
|
|
1181
|
+
const name = import_utils11.ASTUtils.getPropertyName(property);
|
|
1182
|
+
if (name === null || property.value.type === import_utils11.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) continue;
|
|
994
1183
|
const constructor = fixtureConstructor(source, property.value);
|
|
995
1184
|
if (constructor === null) result.delete(name);
|
|
996
1185
|
else result.set(name, constructor);
|
|
@@ -999,24 +1188,24 @@ function fixtureConstructors(source, declarations, inherited) {
|
|
|
999
1188
|
}
|
|
1000
1189
|
function fixtureConstructor(source, value) {
|
|
1001
1190
|
value = unwrapExpression(value);
|
|
1002
|
-
if (value.type !==
|
|
1191
|
+
if (value.type !== import_utils11.AST_NODE_TYPES.ArrowFunctionExpression && value.type !== import_utils11.AST_NODE_TYPES.FunctionExpression) return newConstructor(source, value);
|
|
1003
1192
|
const use = value.params[1];
|
|
1004
|
-
if (use?.type !==
|
|
1193
|
+
if (use?.type !== import_utils11.AST_NODE_TYPES.Identifier) return null;
|
|
1005
1194
|
const binding3 = stableBinding(source, use);
|
|
1006
|
-
const calls = scopeNodes(value.body, source).filter((node) => node.type ===
|
|
1195
|
+
const calls = scopeNodes(value.body, source).filter((node) => node.type === import_utils11.AST_NODE_TYPES.CallExpression && !node.optional && node.arguments.length === 1 && node.callee.type === import_utils11.AST_NODE_TYPES.Identifier && stableBinding(source, node.callee) === binding3);
|
|
1007
1196
|
if (calls.length !== 1 || binding3 === null) return null;
|
|
1008
1197
|
const argument = calls[0]?.arguments[0];
|
|
1009
|
-
return argument === void 0 || argument.type ===
|
|
1198
|
+
return argument === void 0 || argument.type === import_utils11.AST_NODE_TYPES.SpreadElement ? null : newConstructor(source, argument);
|
|
1010
1199
|
}
|
|
1011
1200
|
function newConstructor(source, expression) {
|
|
1012
1201
|
const value = unwrapExpression(expression);
|
|
1013
|
-
if (value.type ===
|
|
1014
|
-
if (value.type !==
|
|
1202
|
+
if (value.type === import_utils11.AST_NODE_TYPES.NewExpression) return constructorBinding(source, value.callee);
|
|
1203
|
+
if (value.type !== import_utils11.AST_NODE_TYPES.Identifier) return null;
|
|
1015
1204
|
const variable = stableBinding(source, value);
|
|
1016
1205
|
const declaration = variable?.defs[0]?.node;
|
|
1017
|
-
if (declaration?.type !==
|
|
1206
|
+
if (declaration?.type !== import_utils11.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= value.range[0]) return null;
|
|
1018
1207
|
const initial = unwrapExpression(declaration.init);
|
|
1019
|
-
return initial.type ===
|
|
1208
|
+
return initial.type === import_utils11.AST_NODE_TYPES.NewExpression ? constructorBinding(source, initial.callee) : null;
|
|
1020
1209
|
}
|
|
1021
1210
|
function scopeNodes(root, source) {
|
|
1022
1211
|
const result = [];
|
|
@@ -1025,7 +1214,7 @@ function scopeNodes(root, source) {
|
|
|
1025
1214
|
const node = pending.pop();
|
|
1026
1215
|
if (node === void 0) continue;
|
|
1027
1216
|
result.push(node);
|
|
1028
|
-
if (node !== root && (node.type ===
|
|
1217
|
+
if (node !== root && (node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils11.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils11.AST_NODE_TYPES.ClassExpression)) continue;
|
|
1029
1218
|
for (const key of source.visitorKeys[node.type] ?? []) {
|
|
1030
1219
|
const value = Reflect.get(node, key);
|
|
1031
1220
|
if (Array.isArray(value)) pending.push(...value.filter(isNode2));
|
|
@@ -1039,13 +1228,13 @@ function isNode2(value) {
|
|
|
1039
1228
|
}
|
|
1040
1229
|
function testApiCallee(expression) {
|
|
1041
1230
|
let node = unwrapExpression(expression);
|
|
1042
|
-
while (node.type ===
|
|
1231
|
+
while (node.type === import_utils11.AST_NODE_TYPES.MemberExpression && !node.optional && TEST_MODIFIERS.has(import_utils11.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
1043
1232
|
return node;
|
|
1044
1233
|
}
|
|
1045
1234
|
function requestingFunction(node) {
|
|
1046
1235
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
1047
|
-
if (current.type ===
|
|
1048
|
-
if (current.type ===
|
|
1236
|
+
if (current.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils11.AST_NODE_TYPES.FunctionExpression) return current;
|
|
1237
|
+
if (current.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
1049
1238
|
}
|
|
1050
1239
|
return null;
|
|
1051
1240
|
}
|
|
@@ -1067,13 +1256,13 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1067
1256
|
const call = functionNode === null ? null : directArgumentCall(functionNode);
|
|
1068
1257
|
if (functionNode === null || call === null) return;
|
|
1069
1258
|
const parameter = functionNode.params[0];
|
|
1070
|
-
if (parameter?.type !==
|
|
1259
|
+
if (parameter?.type !== import_utils11.AST_NODE_TYPES.ObjectPattern) return;
|
|
1071
1260
|
const entries = fixtureApi(context.sourceCode, testApiCallee(call.callee));
|
|
1072
1261
|
const constructor = constructorBinding(context.sourceCode, node.callee);
|
|
1073
1262
|
if (entries === null || constructor === null) return;
|
|
1074
1263
|
for (const property of parameter.properties) {
|
|
1075
|
-
if (property.type !==
|
|
1076
|
-
const name =
|
|
1264
|
+
if (property.type !== import_utils11.AST_NODE_TYPES.Property || property.computed) continue;
|
|
1265
|
+
const name = import_utils11.ASTUtils.getPropertyName(property);
|
|
1077
1266
|
if (name !== null && entries.get(name) === constructor) {
|
|
1078
1267
|
context.report({ node, messageId: "reuseFixture", data: { fixture: name } });
|
|
1079
1268
|
return;
|
|
@@ -1085,7 +1274,7 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
1085
1274
|
});
|
|
1086
1275
|
|
|
1087
1276
|
// src/rules/no-return-disposed-resource.ts
|
|
1088
|
-
var
|
|
1277
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
1089
1278
|
var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
1090
1279
|
defaultLevel: "warning",
|
|
1091
1280
|
summary: "Do not return a resource whose using declaration disposes it before the caller receives it.",
|
|
@@ -1105,16 +1294,16 @@ var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
|
1105
1294
|
};
|
|
1106
1295
|
function owningFunction(node) {
|
|
1107
1296
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
1108
|
-
if (current.type ===
|
|
1297
|
+
if (current.type === import_utils12.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils12.AST_NODE_TYPES.FunctionExpression || current.type === import_utils12.AST_NODE_TYPES.ArrowFunctionExpression) return current;
|
|
1109
1298
|
}
|
|
1110
1299
|
return null;
|
|
1111
1300
|
}
|
|
1112
1301
|
function resourceOwner(source, value, seen = /* @__PURE__ */ new Set()) {
|
|
1113
1302
|
const node = unwrapExpression(value);
|
|
1114
|
-
if (node.type !==
|
|
1115
|
-
const variable =
|
|
1303
|
+
if (node.type !== import_utils12.AST_NODE_TYPES.Identifier) return null;
|
|
1304
|
+
const variable = import_utils12.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
1116
1305
|
const definition = variable?.defs[0];
|
|
1117
|
-
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !==
|
|
1306
|
+
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !== import_utils12.AST_NODE_TYPES.VariableDeclarator) return null;
|
|
1118
1307
|
const declaration = definition.node;
|
|
1119
1308
|
if (declaration.parent.kind === "using" || declaration.parent.kind === "await using") return declaration;
|
|
1120
1309
|
if (declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= node.range[0]) return null;
|
|
@@ -1143,7 +1332,7 @@ var no_return_disposed_resource_default = createRule({
|
|
|
1143
1332
|
});
|
|
1144
1333
|
|
|
1145
1334
|
// src/rules/require-jwt-lifetime.ts
|
|
1146
|
-
var
|
|
1335
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
1147
1336
|
var REQUIRE_JWT_LIFETIME_DOCUMENTATION = {
|
|
1148
1337
|
defaultLevel: "warning",
|
|
1149
1338
|
summary: "Require an expiration claim or a maximum token age when returning a verified JWT.",
|
|
@@ -1171,36 +1360,36 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1171
1360
|
function inspect(input) {
|
|
1172
1361
|
if (input === null) return;
|
|
1173
1362
|
let node = unwrapExpression(input);
|
|
1174
|
-
if (node.type ===
|
|
1175
|
-
if (node.type !==
|
|
1363
|
+
if (node.type === import_utils13.AST_NODE_TYPES.AwaitExpression) node = unwrapExpression(node.argument);
|
|
1364
|
+
if (node.type !== import_utils13.AST_NODE_TYPES.CallExpression || !isVerifier(node.callee)) return;
|
|
1176
1365
|
if (!missingLifetime(node.arguments[2])) return;
|
|
1177
1366
|
context.report({ node, messageId: "lifetime" });
|
|
1178
1367
|
}
|
|
1179
1368
|
function isVerifier(node) {
|
|
1180
1369
|
node = unwrapExpression(node);
|
|
1181
|
-
if (node.type ===
|
|
1182
|
-
const variable =
|
|
1370
|
+
if (node.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
1371
|
+
const variable = import_utils13.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1183
1372
|
const declaration = variable?.defs[0]?.node;
|
|
1184
|
-
return variable?.defs.length === 1 && declaration?.type ===
|
|
1373
|
+
return variable?.defs.length === 1 && declaration?.type === import_utils13.AST_NODE_TYPES.ImportSpecifier && declaration.parent.type === import_utils13.AST_NODE_TYPES.ImportDeclaration && declaration.importKind !== "type" && declaration.parent.importKind !== "type" && declaration.parent.source.value === "jose" && declaration.imported.type === import_utils13.AST_NODE_TYPES.Identifier && declaration.imported.name === "jwtVerify";
|
|
1185
1374
|
}
|
|
1186
|
-
if (node.type !==
|
|
1187
|
-
const definition =
|
|
1188
|
-
return definition?.type ===
|
|
1375
|
+
if (node.type !== import_utils13.AST_NODE_TYPES.MemberExpression || import_utils13.ASTUtils.getPropertyName(node) !== "jwtVerify" || node.object.type !== import_utils13.AST_NODE_TYPES.Identifier) return false;
|
|
1376
|
+
const definition = import_utils13.ASTUtils.findVariable(sourceCode.getScope(node.object), node.object.name)?.defs[0]?.node;
|
|
1377
|
+
return definition?.type === import_utils13.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && definition.parent.source.value === "jose";
|
|
1189
1378
|
}
|
|
1190
1379
|
function missingLifetime(options) {
|
|
1191
1380
|
if (options === void 0) return true;
|
|
1192
|
-
if (options.type !==
|
|
1193
|
-
return !options.properties.some((property) => property.type ===
|
|
1381
|
+
if (options.type !== import_utils13.AST_NODE_TYPES.ObjectExpression || options.properties.some((property) => property.type !== import_utils13.AST_NODE_TYPES.Property || property.computed)) return false;
|
|
1382
|
+
return !options.properties.some((property) => property.type === import_utils13.AST_NODE_TYPES.Property && lifetimeProperty(property));
|
|
1194
1383
|
}
|
|
1195
1384
|
function lifetimeProperty(property) {
|
|
1196
|
-
const name = property.key.type ===
|
|
1385
|
+
const name = property.key.type === import_utils13.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils13.AST_NODE_TYPES.Literal ? property.key.value : null;
|
|
1197
1386
|
if (name === "maxTokenAge") {
|
|
1198
|
-
if (property.value.type !==
|
|
1387
|
+
if (property.value.type !== import_utils13.AST_NODE_TYPES.Literal) return true;
|
|
1199
1388
|
return typeof property.value.value === "number" && Number.isFinite(property.value.value) || typeof property.value.value === "string" && property.value.value.trim() !== "";
|
|
1200
1389
|
}
|
|
1201
1390
|
if (name !== "requiredClaims") return false;
|
|
1202
|
-
if (property.value.type !==
|
|
1203
|
-
return property.value.elements.some((element) => element?.type ===
|
|
1391
|
+
if (property.value.type !== import_utils13.AST_NODE_TYPES.ArrayExpression || property.value.elements.some((element) => element?.type !== import_utils13.AST_NODE_TYPES.Literal)) return true;
|
|
1392
|
+
return property.value.elements.some((element) => element?.type === import_utils13.AST_NODE_TYPES.Literal && element.value === "exp");
|
|
1204
1393
|
}
|
|
1205
1394
|
return {
|
|
1206
1395
|
ReturnStatement(node) {
|
|
@@ -1214,7 +1403,7 @@ var require_jwt_lifetime_default = createRule({
|
|
|
1214
1403
|
});
|
|
1215
1404
|
|
|
1216
1405
|
// src/rules/no-discarded-validation-result.ts
|
|
1217
|
-
var
|
|
1406
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
1218
1407
|
|
|
1219
1408
|
// src/rules/_zod.ts
|
|
1220
1409
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
@@ -1250,52 +1439,52 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1250
1439
|
function schema(node, depth = 0) {
|
|
1251
1440
|
if (depth > 24) return null;
|
|
1252
1441
|
node = unwrapExpression(node);
|
|
1253
|
-
if (node.type ===
|
|
1254
|
-
const variable =
|
|
1442
|
+
if (node.type === import_utils14.AST_NODE_TYPES.Identifier) {
|
|
1443
|
+
const variable = import_utils14.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1255
1444
|
const definition = variable?.defs[0]?.node;
|
|
1256
1445
|
if (variable?.defs.length !== 1) return null;
|
|
1257
|
-
if (definition?.type ===
|
|
1258
|
-
if (definition?.type ===
|
|
1259
|
-
if (definition?.type ===
|
|
1446
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.ImportSpecifier && definition.parent.type === import_utils14.AST_NODE_TYPES.ImportDeclaration && definition.importKind !== "type" && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1447
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
1448
|
+
if (definition?.type === import_utils14.AST_NODE_TYPES.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && !variable.references.some((reference) => reference.isWrite() && !reference.init)) return schema(definition.init, depth + 1);
|
|
1260
1449
|
return null;
|
|
1261
1450
|
}
|
|
1262
|
-
if (node.type ===
|
|
1451
|
+
if (node.type === import_utils14.AST_NODE_TYPES.MemberExpression) {
|
|
1263
1452
|
const owner2 = schema(node.object, depth + 1);
|
|
1264
1453
|
return owner2;
|
|
1265
1454
|
}
|
|
1266
|
-
if (node.type !==
|
|
1455
|
+
if (node.type !== import_utils14.AST_NODE_TYPES.CallExpression) return null;
|
|
1267
1456
|
const owner = schema(node.callee, depth + 1);
|
|
1268
1457
|
if (owner === null) return null;
|
|
1269
|
-
const invokedChange = node.callee.type ===
|
|
1270
|
-
const coerced = node.callee.type ===
|
|
1458
|
+
const invokedChange = node.callee.type === import_utils14.AST_NODE_TYPES.MemberExpression && CHANGING.has(import_utils14.ASTUtils.getPropertyName(node.callee) ?? "");
|
|
1459
|
+
const coerced = node.callee.type === import_utils14.AST_NODE_TYPES.MemberExpression && coercionNamespace(node.callee.object);
|
|
1271
1460
|
const changedArgument = node.arguments.some((argument) => {
|
|
1272
|
-
if (argument.type ===
|
|
1273
|
-
if (argument.type ===
|
|
1461
|
+
if (argument.type === import_utils14.AST_NODE_TYPES.ArrayExpression) return argument.elements.some((element) => element !== null && schema(element, depth + 1)?.changed === true);
|
|
1462
|
+
if (argument.type === import_utils14.AST_NODE_TYPES.ObjectExpression) return argument.properties.some((property) => property.type === import_utils14.AST_NODE_TYPES.Property && schema(property.value, depth + 1)?.changed === true);
|
|
1274
1463
|
return schema(argument, depth + 1)?.changed === true;
|
|
1275
1464
|
});
|
|
1276
1465
|
return { changed: owner.changed || invokedChange || coerced || changedArgument };
|
|
1277
1466
|
}
|
|
1278
1467
|
function coercionNamespace(node) {
|
|
1279
1468
|
let namespace = false;
|
|
1280
|
-
if (node.type ===
|
|
1469
|
+
if (node.type === import_utils14.AST_NODE_TYPES.MemberExpression && import_utils14.ASTUtils.getPropertyName(node) === "coerce") {
|
|
1281
1470
|
namespace = true;
|
|
1282
1471
|
node = node.object;
|
|
1283
1472
|
}
|
|
1284
|
-
if (node.type !==
|
|
1285
|
-
const variable =
|
|
1473
|
+
if (node.type !== import_utils14.AST_NODE_TYPES.Identifier) return false;
|
|
1474
|
+
const variable = import_utils14.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1286
1475
|
const definition = variable?.defs[0]?.node;
|
|
1287
|
-
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !==
|
|
1288
|
-
if (definition.type ===
|
|
1289
|
-
if (definition.type !==
|
|
1290
|
-
const name = definition.imported.type ===
|
|
1476
|
+
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !== import_utils14.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return false;
|
|
1477
|
+
if (definition.type === import_utils14.AST_NODE_TYPES.ImportNamespaceSpecifier) return namespace;
|
|
1478
|
+
if (definition.type !== import_utils14.AST_NODE_TYPES.ImportSpecifier || definition.importKind === "type") return false;
|
|
1479
|
+
const name = definition.imported.type === import_utils14.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value;
|
|
1291
1480
|
return namespace ? name === "z" : name === "coerce";
|
|
1292
1481
|
}
|
|
1293
1482
|
return {
|
|
1294
1483
|
ExpressionStatement(statement) {
|
|
1295
1484
|
let expression = unwrapExpression(statement.expression);
|
|
1296
|
-
if (expression.type ===
|
|
1297
|
-
if (expression.type !==
|
|
1298
|
-
const method =
|
|
1485
|
+
if (expression.type === import_utils14.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
1486
|
+
if (expression.type !== import_utils14.AST_NODE_TYPES.CallExpression || expression.callee.type !== import_utils14.AST_NODE_TYPES.MemberExpression) return;
|
|
1487
|
+
const method = import_utils14.ASTUtils.getPropertyName(expression.callee);
|
|
1299
1488
|
if (!(/* @__PURE__ */ new Set(["parse", "parseAsync", "safeParse", "safeParseAsync"])).has(method ?? "")) return;
|
|
1300
1489
|
const owner = schema(expression.callee.object);
|
|
1301
1490
|
if (owner !== null && (owner.changed || method?.startsWith("safe") === true)) context.report({ node: expression, messageId: "discarded" });
|
|
@@ -1305,7 +1494,7 @@ var no_discarded_validation_result_default = createRule({
|
|
|
1305
1494
|
});
|
|
1306
1495
|
|
|
1307
1496
|
// src/rules/production-derived-test-cases.ts
|
|
1308
|
-
var
|
|
1497
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
1309
1498
|
var MEMBERSHIP = /(?:^|_)(?:ALLOWED|ELIGIBLE|REQUIRED|SUPPORTED)(?:_|$)/u;
|
|
1310
1499
|
var SUPPORT_PATH = /(?:^|[/_.-])(?:tests?|fixtures?|fakes?|mocks?|stubs?|__tests__)(?:[/_.-]|$)/u;
|
|
1311
1500
|
var PRODUCTION_DERIVED_TEST_CASES_DOCUMENTATION = {
|
|
@@ -1340,52 +1529,52 @@ var production_derived_test_cases_default = createRule({
|
|
|
1340
1529
|
const tables = [];
|
|
1341
1530
|
const asserted = /* @__PURE__ */ new Set();
|
|
1342
1531
|
function binding3(node) {
|
|
1343
|
-
return
|
|
1532
|
+
return import_utils15.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1344
1533
|
}
|
|
1345
1534
|
function importedName7(node, module2) {
|
|
1346
1535
|
const variable = binding3(node);
|
|
1347
1536
|
const specifier = variable?.defs[0]?.node;
|
|
1348
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1349
|
-
return specifier.imported.type ===
|
|
1537
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils15.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils15.AST_NODE_TYPES.ImportDeclaration || specifier.parent.importKind === "type" || specifier.parent.source.value !== module2 || variable.references.some((reference) => reference.isWrite())) return null;
|
|
1538
|
+
return specifier.imported.type === import_utils15.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1350
1539
|
}
|
|
1351
1540
|
function production(node) {
|
|
1352
1541
|
node = unwrapExpression(node);
|
|
1353
|
-
if (node.type !==
|
|
1542
|
+
if (node.type !== import_utils15.AST_NODE_TYPES.Identifier) return null;
|
|
1354
1543
|
const variable = binding3(node);
|
|
1355
1544
|
const specifier = variable?.defs[0]?.node;
|
|
1356
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
1357
|
-
const name = specifier.imported.type ===
|
|
1545
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils15.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils15.AST_NODE_TYPES.ImportDeclaration || specifier.parent.importKind === "type" || !specifier.parent.source.value.startsWith(".") || SUPPORT_PATH.test(specifier.parent.source.value) || variable.references.some((reference) => reference.isWrite())) return null;
|
|
1546
|
+
const name = specifier.imported.type === import_utils15.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1358
1547
|
return MEMBERSHIP.test(name) && !name.endsWith("REGISTRY") ? variable : null;
|
|
1359
1548
|
}
|
|
1360
1549
|
function runner(node) {
|
|
1361
1550
|
node = unwrapExpression(node);
|
|
1362
|
-
while (node.type ===
|
|
1363
|
-
if (node.type !==
|
|
1551
|
+
while (node.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["only", "skip", "concurrent", "sequential"].includes(import_utils15.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
1552
|
+
if (node.type !== import_utils15.AST_NODE_TYPES.Identifier) return false;
|
|
1364
1553
|
const name = importedName7(node, "vitest");
|
|
1365
1554
|
return name === "test" || name === "it" || vitestFixtureTestName(sourceCode, node) !== null;
|
|
1366
1555
|
}
|
|
1367
1556
|
function caseTable(node) {
|
|
1368
|
-
return node.type ===
|
|
1557
|
+
return node.type === import_utils15.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["each", "for"].includes(import_utils15.ASTUtils.getPropertyName(node.callee) ?? "") && runner(node.callee.object);
|
|
1369
1558
|
}
|
|
1370
1559
|
function literalTable(node, seen = /* @__PURE__ */ new Set()) {
|
|
1371
1560
|
node = unwrapExpression(node);
|
|
1372
1561
|
if (seen.has(node)) return false;
|
|
1373
1562
|
seen.add(node);
|
|
1374
|
-
if (node.type ===
|
|
1563
|
+
if (node.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
1375
1564
|
const variable = binding3(node);
|
|
1376
1565
|
const definition = variable?.defs[0]?.node;
|
|
1377
|
-
return variable?.defs.length === 1 && definition?.type ===
|
|
1566
|
+
return variable?.defs.length === 1 && definition?.type === import_utils15.AST_NODE_TYPES.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && variable.references.every((reference) => reference.init || !reference.isWrite() && reference.identifier.parent.type === import_utils15.AST_NODE_TYPES.CallExpression && (caseTable(reference.identifier.parent) || reference.identifier.parent.callee.type === import_utils15.AST_NODE_TYPES.Identifier && importedName7(reference.identifier.parent.callee, "vitest") === "expect" || reference.identifier.parent.callee.type === import_utils15.AST_NODE_TYPES.MemberExpression && ["toEqual", "toStrictEqual"].includes(import_utils15.ASTUtils.getPropertyName(reference.identifier.parent.callee) ?? ""))) && literalTable(definition.init, seen);
|
|
1378
1567
|
}
|
|
1379
|
-
return node.type ===
|
|
1568
|
+
return node.type === import_utils15.AST_NODE_TYPES.ArrayExpression && node.elements.every((element) => element?.type === import_utils15.AST_NODE_TYPES.Literal && !("regex" in element));
|
|
1380
1569
|
}
|
|
1381
1570
|
function unconditional(node) {
|
|
1382
1571
|
const statement = node.parent;
|
|
1383
|
-
if (statement.type !==
|
|
1384
|
-
if (statement.parent.type ===
|
|
1572
|
+
if (statement.type !== import_utils15.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
1573
|
+
if (statement.parent.type === import_utils15.AST_NODE_TYPES.Program) return true;
|
|
1385
1574
|
const block = statement.parent;
|
|
1386
|
-
if (block.type !==
|
|
1575
|
+
if (block.type !== import_utils15.AST_NODE_TYPES.BlockStatement || block.parent.type !== import_utils15.AST_NODE_TYPES.ArrowFunctionExpression && block.parent.type !== import_utils15.AST_NODE_TYPES.FunctionExpression) return false;
|
|
1387
1576
|
const call = block.parent.parent;
|
|
1388
|
-
return call.type ===
|
|
1577
|
+
return call.type === import_utils15.AST_NODE_TYPES.CallExpression && runner(call.callee);
|
|
1389
1578
|
}
|
|
1390
1579
|
return {
|
|
1391
1580
|
CallExpression(node) {
|
|
@@ -1393,9 +1582,9 @@ var production_derived_test_cases_default = createRule({
|
|
|
1393
1582
|
const variable2 = production(node.arguments[0]);
|
|
1394
1583
|
if (variable2 !== null) tables.push({ node, variable: variable2 });
|
|
1395
1584
|
}
|
|
1396
|
-
if (node.callee.type !==
|
|
1585
|
+
if (node.callee.type !== import_utils15.AST_NODE_TYPES.MemberExpression || !["toEqual", "toStrictEqual"].includes(import_utils15.ASTUtils.getPropertyName(node.callee) ?? "") || node.arguments.length !== 1 || node.arguments[0] === void 0 || !literalTable(node.arguments[0]) || !unconditional(node)) return;
|
|
1397
1586
|
const expect = node.callee.object;
|
|
1398
|
-
if (expect.type !==
|
|
1587
|
+
if (expect.type !== import_utils15.AST_NODE_TYPES.CallExpression || expect.callee.type !== import_utils15.AST_NODE_TYPES.Identifier || importedName7(expect.callee, "vitest") !== "expect" || expect.arguments.length !== 1 || expect.arguments[0] === void 0) return;
|
|
1399
1588
|
const variable = production(expect.arguments[0]);
|
|
1400
1589
|
if (variable !== null) asserted.add(variable);
|
|
1401
1590
|
},
|
|
@@ -1407,14 +1596,14 @@ var production_derived_test_cases_default = createRule({
|
|
|
1407
1596
|
});
|
|
1408
1597
|
|
|
1409
1598
|
// src/rules/require-constrained-schema-integer.ts
|
|
1410
|
-
var
|
|
1599
|
+
var import_utils16 = require("@typescript-eslint/utils");
|
|
1411
1600
|
var FIELD_MINIMUMS = /* @__PURE__ */ new Map([["limit", 1], ["version", 0]]);
|
|
1412
1601
|
var NUMBER_FACTORIES = /* @__PURE__ */ new Set(["number", "int", "int32", "uint32"]);
|
|
1413
1602
|
var PRESERVING = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta", "max", "lte", "lt", "finite", "safe", "multipleOf"]);
|
|
1414
1603
|
function numericLiteral(node) {
|
|
1415
1604
|
node = unwrapExpression(node);
|
|
1416
|
-
if (node.type ===
|
|
1417
|
-
if (node.type ===
|
|
1605
|
+
if (node.type === import_utils16.AST_NODE_TYPES.Literal && typeof node.value === "number") return node.value;
|
|
1606
|
+
if (node.type === import_utils16.AST_NODE_TYPES.UnaryExpression && (node.operator === "-" || node.operator === "+")) {
|
|
1418
1607
|
const value = numericLiteral(node.argument);
|
|
1419
1608
|
return value === null ? null : node.operator === "-" ? -value : value;
|
|
1420
1609
|
}
|
|
@@ -1451,35 +1640,35 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1451
1640
|
const sourceCode = context.sourceCode;
|
|
1452
1641
|
function factory(node) {
|
|
1453
1642
|
node = unwrapExpression(node);
|
|
1454
|
-
if (node.type ===
|
|
1643
|
+
if (node.type === import_utils16.AST_NODE_TYPES.Identifier) {
|
|
1455
1644
|
const definition2 = imported(node);
|
|
1456
|
-
return definition2?.type ===
|
|
1645
|
+
return definition2?.type === import_utils16.AST_NODE_TYPES.ImportSpecifier ? definition2.imported.type === import_utils16.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value : null;
|
|
1457
1646
|
}
|
|
1458
|
-
if (node.type !==
|
|
1647
|
+
if (node.type !== import_utils16.AST_NODE_TYPES.MemberExpression) return null;
|
|
1459
1648
|
let receiver = unwrapExpression(node.object);
|
|
1460
|
-
if (receiver.type ===
|
|
1461
|
-
if (receiver.type !==
|
|
1649
|
+
if (receiver.type === import_utils16.AST_NODE_TYPES.MemberExpression && import_utils16.ASTUtils.getPropertyName(receiver) === "coerce") receiver = unwrapExpression(receiver.object);
|
|
1650
|
+
if (receiver.type !== import_utils16.AST_NODE_TYPES.Identifier) return null;
|
|
1462
1651
|
const definition = imported(receiver);
|
|
1463
|
-
if (definition === null || definition.type ===
|
|
1464
|
-
return
|
|
1652
|
+
if (definition === null || definition.type === import_utils16.AST_NODE_TYPES.ImportSpecifier && (definition.imported.type === import_utils16.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z") return null;
|
|
1653
|
+
return import_utils16.ASTUtils.getPropertyName(node);
|
|
1465
1654
|
}
|
|
1466
1655
|
function imported(identifier) {
|
|
1467
|
-
const variable =
|
|
1656
|
+
const variable = import_utils16.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
1468
1657
|
const definition = variable?.defs[0]?.node;
|
|
1469
|
-
if (variable?.defs.length !== 1 || definition?.type !==
|
|
1470
|
-
return definition.type ===
|
|
1658
|
+
if (variable?.defs.length !== 1 || definition?.type !== import_utils16.AST_NODE_TYPES.ImportSpecifier && definition?.type !== import_utils16.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils16.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1659
|
+
return definition.type === import_utils16.AST_NODE_TYPES.ImportSpecifier && definition.importKind === "type" ? null : definition;
|
|
1471
1660
|
}
|
|
1472
1661
|
function constrained(value, minimum) {
|
|
1473
1662
|
const calls = [];
|
|
1474
1663
|
value = unwrapExpression(value);
|
|
1475
|
-
while (value.type ===
|
|
1664
|
+
while (value.type === import_utils16.AST_NODE_TYPES.CallExpression) {
|
|
1476
1665
|
const name = factory(value.callee);
|
|
1477
1666
|
if (name !== null) {
|
|
1478
1667
|
return chainContract(name, calls, minimum);
|
|
1479
1668
|
}
|
|
1480
1669
|
const callee = unwrapExpression(value.callee);
|
|
1481
|
-
if (callee.type !==
|
|
1482
|
-
const method =
|
|
1670
|
+
if (callee.type !== import_utils16.AST_NODE_TYPES.MemberExpression) return null;
|
|
1671
|
+
const method = import_utils16.ASTUtils.getPropertyName(callee);
|
|
1483
1672
|
if (method === null) return null;
|
|
1484
1673
|
calls.push({ method, call: value });
|
|
1485
1674
|
value = unwrapExpression(callee.object);
|
|
@@ -1504,7 +1693,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1504
1693
|
}
|
|
1505
1694
|
function lowerBound(call, minimum, exclusive) {
|
|
1506
1695
|
const argument = call.arguments[0];
|
|
1507
|
-
if (argument === void 0 || argument.type ===
|
|
1696
|
+
if (argument === void 0 || argument.type === import_utils16.AST_NODE_TYPES.SpreadElement) return null;
|
|
1508
1697
|
const bound = numericLiteral(argument);
|
|
1509
1698
|
return bound === null || bound >= minimum - (exclusive ? 1 : 0);
|
|
1510
1699
|
}
|
|
@@ -1513,10 +1702,10 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1513
1702
|
const name = factory(node.callee);
|
|
1514
1703
|
if (name === null || !["object", "strictObject", "looseObject"].includes(name) || node.arguments.length !== 1) return;
|
|
1515
1704
|
const shape = node.arguments[0];
|
|
1516
|
-
if (shape?.type !==
|
|
1705
|
+
if (shape?.type !== import_utils16.AST_NODE_TYPES.ObjectExpression) return;
|
|
1517
1706
|
for (const property of shape.properties) {
|
|
1518
|
-
if (property.type !==
|
|
1519
|
-
const field =
|
|
1707
|
+
if (property.type !== import_utils16.AST_NODE_TYPES.Property || property.computed || property.kind !== "init" || property.method) continue;
|
|
1708
|
+
const field = import_utils16.ASTUtils.getPropertyName(property);
|
|
1520
1709
|
const minimum = field === null ? void 0 : FIELD_MINIMUMS.get(field);
|
|
1521
1710
|
if (minimum === void 0 || field === null || constrained(property.value, minimum) !== false) continue;
|
|
1522
1711
|
context.report({ node: property, messageId: "constrainInteger", data: { field, minimum } });
|
|
@@ -1527,7 +1716,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
1527
1716
|
});
|
|
1528
1717
|
|
|
1529
1718
|
// src/rules/no-generic-json-parser.ts
|
|
1530
|
-
var
|
|
1719
|
+
var import_utils17 = require("@typescript-eslint/utils");
|
|
1531
1720
|
var OPEN_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "json", "record", "partialRecord"]);
|
|
1532
1721
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta"]);
|
|
1533
1722
|
var NO_GENERIC_JSON_PARSER_DOCUMENTATION = {
|
|
@@ -1560,60 +1749,60 @@ var no_generic_json_parser_default = createRule({
|
|
|
1560
1749
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1561
1750
|
const sourceCode = context.sourceCode;
|
|
1562
1751
|
function binding3(node) {
|
|
1563
|
-
return
|
|
1752
|
+
return import_utils17.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
1564
1753
|
}
|
|
1565
1754
|
function initializer(node) {
|
|
1566
1755
|
const variable = binding3(node);
|
|
1567
1756
|
const definition = variable?.defs[0];
|
|
1568
|
-
if (variable?.defs.length !== 1 || definition?.node.type !==
|
|
1757
|
+
if (variable?.defs.length !== 1 || definition?.node.type !== import_utils17.AST_NODE_TYPES.VariableDeclarator || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.range[1] >= node.range[0] || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
1569
1758
|
return definition.node.init;
|
|
1570
1759
|
}
|
|
1571
1760
|
function parser(node, seen = /* @__PURE__ */ new Set(), awaited = false) {
|
|
1572
1761
|
node = unwrapExpression(node);
|
|
1573
1762
|
if (seen.has(node)) return null;
|
|
1574
1763
|
seen.add(node);
|
|
1575
|
-
if (node.type ===
|
|
1576
|
-
if (node.type ===
|
|
1764
|
+
if (node.type === import_utils17.AST_NODE_TYPES.AwaitExpression) return parser(node.argument, seen, true);
|
|
1765
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1577
1766
|
const value = initializer(node);
|
|
1578
1767
|
return value === null ? null : parser(value, seen, awaited);
|
|
1579
1768
|
}
|
|
1580
|
-
if (node.type !==
|
|
1581
|
-
if (
|
|
1769
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.CallExpression || node.callee.type !== import_utils17.AST_NODE_TYPES.MemberExpression || !["parse", "parseAsync"].includes(import_utils17.ASTUtils.getPropertyName(node.callee) ?? "")) return null;
|
|
1770
|
+
if (import_utils17.ASTUtils.getPropertyName(node.callee) === "parseAsync" && !awaited) return null;
|
|
1582
1771
|
return openSchema(node.callee.object) ? node : null;
|
|
1583
1772
|
}
|
|
1584
1773
|
function openSchema(node, seen = /* @__PURE__ */ new Set()) {
|
|
1585
1774
|
node = unwrapExpression(node);
|
|
1586
1775
|
if (seen.has(node)) return false;
|
|
1587
1776
|
seen.add(node);
|
|
1588
|
-
if (node.type ===
|
|
1777
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1589
1778
|
const value = initializer(node);
|
|
1590
1779
|
return value !== null && openSchema(value, seen);
|
|
1591
1780
|
}
|
|
1592
|
-
if (node.type !==
|
|
1781
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.CallExpression) return false;
|
|
1593
1782
|
const name = factory(node.callee);
|
|
1594
1783
|
if (name !== null) return OPEN_FACTORIES.has(name);
|
|
1595
1784
|
const callee = unwrapExpression(node.callee);
|
|
1596
|
-
return callee.type ===
|
|
1785
|
+
return callee.type === import_utils17.AST_NODE_TYPES.MemberExpression && WRAPPERS.has(import_utils17.ASTUtils.getPropertyName(callee) ?? "") && openSchema(callee.object, seen);
|
|
1597
1786
|
}
|
|
1598
1787
|
function factory(node) {
|
|
1599
1788
|
node = unwrapExpression(node);
|
|
1600
|
-
if (node.type ===
|
|
1789
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Identifier) {
|
|
1601
1790
|
const definition2 = binding3(node)?.defs[0]?.node;
|
|
1602
|
-
if (definition2?.type !==
|
|
1603
|
-
return definition2.imported.type ===
|
|
1791
|
+
if (definition2?.type !== import_utils17.AST_NODE_TYPES.ImportSpecifier || definition2.parent.type !== import_utils17.AST_NODE_TYPES.ImportDeclaration || definition2.importKind === "type" || definition2.parent.importKind === "type" || !isZodModule(definition2.parent.source.value)) return null;
|
|
1792
|
+
return definition2.imported.type === import_utils17.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value;
|
|
1604
1793
|
}
|
|
1605
|
-
if (node.type !==
|
|
1794
|
+
if (node.type !== import_utils17.AST_NODE_TYPES.MemberExpression) return null;
|
|
1606
1795
|
const receiver = unwrapExpression(node.object);
|
|
1607
|
-
if (receiver.type !==
|
|
1796
|
+
if (receiver.type !== import_utils17.AST_NODE_TYPES.Identifier) return null;
|
|
1608
1797
|
const definition = binding3(receiver)?.defs[0]?.node;
|
|
1609
|
-
if (definition === void 0 || definition.type !==
|
|
1610
|
-
if (definition.type ===
|
|
1611
|
-
return
|
|
1798
|
+
if (definition === void 0 || definition.type !== import_utils17.AST_NODE_TYPES.ImportSpecifier && definition.type !== import_utils17.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils17.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
1799
|
+
if (definition.type === import_utils17.AST_NODE_TYPES.ImportSpecifier && (definition.importKind === "type" || (definition.imported.type === import_utils17.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z")) return null;
|
|
1800
|
+
return import_utils17.ASTUtils.getPropertyName(node);
|
|
1612
1801
|
}
|
|
1613
1802
|
const reported = /* @__PURE__ */ new Set();
|
|
1614
1803
|
return {
|
|
1615
1804
|
MemberExpression(node) {
|
|
1616
|
-
const field =
|
|
1805
|
+
const field = import_utils17.ASTUtils.getPropertyName(node);
|
|
1617
1806
|
if (field === null) return;
|
|
1618
1807
|
const call = parser(node.object);
|
|
1619
1808
|
if (call === null || reported.has(call)) return;
|
|
@@ -1625,7 +1814,7 @@ var no_generic_json_parser_default = createRule({
|
|
|
1625
1814
|
});
|
|
1626
1815
|
|
|
1627
1816
|
// src/rules/no-redundant-local-alias.ts
|
|
1628
|
-
var
|
|
1817
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
1629
1818
|
var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
1630
1819
|
defaultLevel: "warning",
|
|
1631
1820
|
summary: "Pass the original local into an object field instead of creating a single-use rename.",
|
|
@@ -1644,7 +1833,7 @@ var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
|
1644
1833
|
function stableSource(variable, alias) {
|
|
1645
1834
|
const definition = variable.defs[0];
|
|
1646
1835
|
if (variable.defs.length !== 1 || definition === void 0 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
1647
|
-
return definition.type === "Parameter" || definition.node.type ===
|
|
1836
|
+
return definition.type === "Parameter" || definition.node.type === import_utils18.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < alias.range[0];
|
|
1648
1837
|
}
|
|
1649
1838
|
var no_redundant_local_alias_default = createRule({
|
|
1650
1839
|
name: "no-redundant-local-alias",
|
|
@@ -1660,18 +1849,18 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1660
1849
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
1661
1850
|
return {
|
|
1662
1851
|
VariableDeclarator(node) {
|
|
1663
|
-
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !==
|
|
1852
|
+
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !== import_utils18.AST_NODE_TYPES.Identifier || node.id.typeAnnotation !== void 0 || node.init?.type !== import_utils18.AST_NODE_TYPES.Identifier) return;
|
|
1664
1853
|
const scope = context.sourceCode.getScope(node);
|
|
1665
1854
|
if (scope.variableScope.type !== "function") return;
|
|
1666
|
-
const target =
|
|
1667
|
-
const source =
|
|
1855
|
+
const target = import_utils18.ASTUtils.findVariable(scope, node.id.name);
|
|
1856
|
+
const source = import_utils18.ASTUtils.findVariable(scope, node.init.name);
|
|
1668
1857
|
if (target === null || source === null || !stableSource(source, node)) return;
|
|
1669
1858
|
const reads = target.references.filter((reference) => reference.isRead());
|
|
1670
1859
|
if (reads.length !== 1 || target.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
1671
1860
|
const read = reads[0];
|
|
1672
1861
|
if (read === void 0 || read.from.variableScope !== scope.variableScope) return;
|
|
1673
1862
|
const property = read.identifier.parent;
|
|
1674
|
-
if (property.type !==
|
|
1863
|
+
if (property.type !== import_utils18.AST_NODE_TYPES.Property || !property.shorthand || property.value !== read.identifier || property.parent.type !== import_utils18.AST_NODE_TYPES.ObjectExpression || property.computed || property.method || property.kind !== "init") return;
|
|
1675
1864
|
context.report({ node, messageId: "redundantAlias", data: { source: node.init.name, target: node.id.name } });
|
|
1676
1865
|
}
|
|
1677
1866
|
};
|
|
@@ -1679,10 +1868,10 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1679
1868
|
});
|
|
1680
1869
|
|
|
1681
1870
|
// src/rules/no-test-comments.ts
|
|
1682
|
-
var
|
|
1871
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
1683
1872
|
|
|
1684
1873
|
// src/rules/_comments.ts
|
|
1685
|
-
var
|
|
1874
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
1686
1875
|
var REF_RE = /https?:\/\/|\bRFC[- ]?\d+|\bPEP[- ]?\d+|\bCVE-\d{4}|\b(?!UTF-|SHA-|ISO-|AES-|CRC-|MD-|PCM-|EOF-|API-|BASE-)[A-Z][A-Z0-9]{1,9}-\d[A-Z0-9]{0,5}\b|(?<![&\w])#\d{2,6}\b|@[a-z][\w.-]*\.(?:us|com|ai|io|net|org|dev)\b/;
|
|
1687
1876
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
1688
1877
|
var UNITS_RE = /[~<>]?\d+(?:\.\d+)?\s?(?:ms|s\b|sec\b|seconds?\b|min\b|minutes?\b|hours?\b|days?\b|KB|MB|MiB|GiB|kHz|Hz|bytes?\b|bit\b|-bit\b|%|px\b|rps\b|qps\b)|\b[1-5]xx\b|\b(?:301|302|304|307|308|400|401|403|404|405|409|410|412|422|425|429|500|501|502|503|504)\b/;
|
|
@@ -1768,10 +1957,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
1768
1957
|
var NARRATION_MIN_CONTENT = 1;
|
|
1769
1958
|
var TOKEN_PLURAL_MIN = 4;
|
|
1770
1959
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1960
|
+
import_utils19.AST_NODE_TYPES.ExpressionStatement,
|
|
1961
|
+
import_utils19.AST_NODE_TYPES.ReturnStatement,
|
|
1962
|
+
import_utils19.AST_NODE_TYPES.ThrowStatement,
|
|
1963
|
+
import_utils19.AST_NODE_TYPES.VariableDeclaration
|
|
1775
1964
|
]);
|
|
1776
1965
|
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
1777
1966
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -1830,12 +2019,12 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
1830
2019
|
function restatableStatementNodeBelow(comment, sourceCode) {
|
|
1831
2020
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
1832
2021
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
1833
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
2022
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils19.AST_NODE_TYPES.Program; node = node.parent) {
|
|
1834
2023
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
1835
2024
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
1836
2025
|
return null;
|
|
1837
2026
|
}
|
|
1838
|
-
if (node.type ===
|
|
2027
|
+
if (node.type === import_utils19.AST_NODE_TYPES.VariableDeclaration && isTrivialInitializer(node)) {
|
|
1839
2028
|
return null;
|
|
1840
2029
|
}
|
|
1841
2030
|
return node;
|
|
@@ -1845,8 +2034,8 @@ function restatableStatementNodeBelow(comment, sourceCode) {
|
|
|
1845
2034
|
function isTrivialInitializer(node) {
|
|
1846
2035
|
return node.declarations.every((declarator) => {
|
|
1847
2036
|
const init = declarator.init;
|
|
1848
|
-
if (init == null || init.type ===
|
|
1849
|
-
return init.type ===
|
|
2037
|
+
if (init == null || init.type === import_utils19.AST_NODE_TYPES.Literal) return true;
|
|
2038
|
+
return init.type === import_utils19.AST_NODE_TYPES.ArrayExpression && init.elements.length === 0 || init.type === import_utils19.AST_NODE_TYPES.ObjectExpression && init.properties.length === 0;
|
|
1850
2039
|
});
|
|
1851
2040
|
}
|
|
1852
2041
|
function restatesStatementHead(body3, statement) {
|
|
@@ -1873,7 +2062,7 @@ function headTokens(source) {
|
|
|
1873
2062
|
}
|
|
1874
2063
|
|
|
1875
2064
|
// src/rules/_comment-edits.ts
|
|
1876
|
-
var
|
|
2065
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
1877
2066
|
function physicalLineEnd(text, offset) {
|
|
1878
2067
|
const newline = text.indexOf("\n", offset);
|
|
1879
2068
|
return newline < 0 ? text.length : newline;
|
|
@@ -2000,7 +2189,7 @@ var no_test_comments_default = createRule({
|
|
|
2000
2189
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2001
2190
|
const filename = scopedFilename(context);
|
|
2002
2191
|
const unambiguous = /(?:^|\/)(?:tests?|__tests__|fixtures|__fixtures__|__mocks__)\//u.test(filename) || /\.(?:test|spec|e2e|integration)\.[cm]?[jt]sx?$/u.test(filename);
|
|
2003
|
-
const framework = context.sourceCode.ast.body.some((statement) => statement.type ===
|
|
2192
|
+
const framework = context.sourceCode.ast.body.some((statement) => statement.type === import_utils21.AST_NODE_TYPES.ImportDeclaration && statement.importKind !== "type" && (statement.specifiers.length === 0 || statement.specifiers.some((specifier) => specifier.type !== import_utils21.AST_NODE_TYPES.ImportSpecifier || specifier.importKind !== "type")) && ["vitest", "@jest/globals", "@playwright/test", "bun:test", "node:test"].includes(statement.source.value));
|
|
2004
2193
|
if (!unambiguous && !framework) return {};
|
|
2005
2194
|
return {
|
|
2006
2195
|
Program() {
|
|
@@ -2050,14 +2239,14 @@ var no_test_comments_default = createRule({
|
|
|
2050
2239
|
});
|
|
2051
2240
|
|
|
2052
2241
|
// src/rules/no-mutating-container-transform.ts
|
|
2053
|
-
var
|
|
2242
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
2054
2243
|
var MUTATORS = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
2055
2244
|
var PRIMITIVES = /* @__PURE__ */ new Set([
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2245
|
+
import_utils22.AST_NODE_TYPES.TSStringKeyword,
|
|
2246
|
+
import_utils22.AST_NODE_TYPES.TSNumberKeyword,
|
|
2247
|
+
import_utils22.AST_NODE_TYPES.TSBooleanKeyword,
|
|
2248
|
+
import_utils22.AST_NODE_TYPES.TSBigIntKeyword,
|
|
2249
|
+
import_utils22.AST_NODE_TYPES.TSSymbolKeyword
|
|
2061
2250
|
]);
|
|
2062
2251
|
var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
2063
2252
|
defaultLevel: "warning",
|
|
@@ -2076,27 +2265,27 @@ var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
|
2076
2265
|
]
|
|
2077
2266
|
};
|
|
2078
2267
|
function arrayElement(node, sourceCode) {
|
|
2079
|
-
if (node.type ===
|
|
2080
|
-
if (node.type ===
|
|
2268
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSArrayType) return node.elementType;
|
|
2269
|
+
if (node.type === import_utils22.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && (node.typeName.name === "Array" || node.typeName.name === "ReadonlyArray") && (import_utils22.ASTUtils.findVariable(sourceCode.getScope(node.typeName), node.typeName.name)?.defs.length ?? 0) === 0 && node.typeArguments?.params.length === 1) return node.typeArguments.params[0] ?? null;
|
|
2081
2270
|
return null;
|
|
2082
2271
|
}
|
|
2083
2272
|
function returnsArray(node, sourceCode) {
|
|
2084
2273
|
let annotation = node.returnType?.typeAnnotation;
|
|
2085
|
-
if (annotation?.type ===
|
|
2274
|
+
if (annotation?.type === import_utils22.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils22.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Promise" && (import_utils22.ASTUtils.findVariable(sourceCode.getScope(annotation.typeName), "Promise")?.defs.length ?? 0) === 0 && annotation.typeArguments?.params.length === 1) annotation = annotation.typeArguments.params[0];
|
|
2086
2275
|
return annotation !== void 0 && arrayElement(annotation, sourceCode) !== null;
|
|
2087
2276
|
}
|
|
2088
2277
|
function supported(statements) {
|
|
2089
2278
|
return statements.every((statement) => {
|
|
2090
2279
|
switch (statement.type) {
|
|
2091
|
-
case
|
|
2092
|
-
case
|
|
2093
|
-
case
|
|
2094
|
-
case
|
|
2095
|
-
case
|
|
2280
|
+
case import_utils22.AST_NODE_TYPES.ExpressionStatement:
|
|
2281
|
+
case import_utils22.AST_NODE_TYPES.VariableDeclaration:
|
|
2282
|
+
case import_utils22.AST_NODE_TYPES.ReturnStatement:
|
|
2283
|
+
case import_utils22.AST_NODE_TYPES.ThrowStatement:
|
|
2284
|
+
case import_utils22.AST_NODE_TYPES.EmptyStatement:
|
|
2096
2285
|
return true;
|
|
2097
|
-
case
|
|
2286
|
+
case import_utils22.AST_NODE_TYPES.BlockStatement:
|
|
2098
2287
|
return supported(statement.body);
|
|
2099
|
-
case
|
|
2288
|
+
case import_utils22.AST_NODE_TYPES.IfStatement:
|
|
2100
2289
|
return supported([statement.consequent]) && (statement.alternate === null || supported([statement.alternate]));
|
|
2101
2290
|
default:
|
|
2102
2291
|
return false;
|
|
@@ -2117,13 +2306,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2117
2306
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2118
2307
|
const sourceCode = context.sourceCode;
|
|
2119
2308
|
function binding3(node) {
|
|
2120
|
-
return node.type ===
|
|
2309
|
+
return node.type === import_utils22.AST_NODE_TYPES.Identifier ? import_utils22.ASTUtils.findVariable(sourceCode.getScope(node), node.name) : null;
|
|
2121
2310
|
}
|
|
2122
2311
|
function inspect(node) {
|
|
2123
|
-
if (node.body?.type !==
|
|
2312
|
+
if (node.body?.type !== import_utils22.AST_NODE_TYPES.BlockStatement || !returnsArray(node, sourceCode) || !supported(node.body.body)) return;
|
|
2124
2313
|
const initial = /* @__PURE__ */ new Map();
|
|
2125
2314
|
for (const parameter of node.params) {
|
|
2126
|
-
if (parameter.type !==
|
|
2315
|
+
if (parameter.type !== import_utils22.AST_NODE_TYPES.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
2127
2316
|
const element = arrayElement(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
2128
2317
|
const variable = binding3(parameter);
|
|
2129
2318
|
if (element !== null && PRIMITIVES.has(element.type) && variable !== null) initial.set(variable, parameter.name);
|
|
@@ -2136,26 +2325,26 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2136
2325
|
}
|
|
2137
2326
|
function expression(current, state) {
|
|
2138
2327
|
switch (current.type) {
|
|
2139
|
-
case
|
|
2140
|
-
case
|
|
2141
|
-
case
|
|
2328
|
+
case import_utils22.AST_NODE_TYPES.FunctionExpression:
|
|
2329
|
+
case import_utils22.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
2330
|
+
case import_utils22.AST_NODE_TYPES.ClassExpression:
|
|
2142
2331
|
return;
|
|
2143
|
-
case
|
|
2332
|
+
case import_utils22.AST_NODE_TYPES.AssignmentExpression:
|
|
2144
2333
|
assignment(current, state);
|
|
2145
2334
|
return;
|
|
2146
|
-
case
|
|
2335
|
+
case import_utils22.AST_NODE_TYPES.LogicalExpression:
|
|
2147
2336
|
logical(current, state);
|
|
2148
2337
|
return;
|
|
2149
|
-
case
|
|
2338
|
+
case import_utils22.AST_NODE_TYPES.ConditionalExpression:
|
|
2150
2339
|
conditional(current, state);
|
|
2151
2340
|
return;
|
|
2152
|
-
case
|
|
2341
|
+
case import_utils22.AST_NODE_TYPES.UpdateExpression:
|
|
2153
2342
|
write(current.argument, state);
|
|
2154
2343
|
break;
|
|
2155
|
-
case
|
|
2344
|
+
case import_utils22.AST_NODE_TYPES.UnaryExpression:
|
|
2156
2345
|
if (current.operator === "delete") write(current.argument, state);
|
|
2157
2346
|
break;
|
|
2158
|
-
case
|
|
2347
|
+
case import_utils22.AST_NODE_TYPES.CallExpression:
|
|
2159
2348
|
mutationCall(current, state);
|
|
2160
2349
|
break;
|
|
2161
2350
|
default:
|
|
@@ -2175,13 +2364,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2175
2364
|
function logical(current, state) {
|
|
2176
2365
|
expression(current.left, state);
|
|
2177
2366
|
const left = unwrapExpression(current.left);
|
|
2178
|
-
if (left.type ===
|
|
2367
|
+
if (left.type === import_utils22.AST_NODE_TYPES.Literal && (current.operator === "&&" && !left.value || current.operator === "||" && !!left.value || current.operator === "??" && left.value !== null)) return;
|
|
2179
2368
|
expression(current.right, state);
|
|
2180
2369
|
}
|
|
2181
2370
|
function conditional(current, state) {
|
|
2182
2371
|
expression(current.test, state);
|
|
2183
2372
|
const test = unwrapExpression(current.test);
|
|
2184
|
-
if (test.type ===
|
|
2373
|
+
if (test.type === import_utils22.AST_NODE_TYPES.Literal) {
|
|
2185
2374
|
expression(test.value ? current.consequent : current.alternate, state);
|
|
2186
2375
|
return;
|
|
2187
2376
|
}
|
|
@@ -2189,13 +2378,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2189
2378
|
expression(current.alternate, state);
|
|
2190
2379
|
}
|
|
2191
2380
|
function mutationCall(current, state) {
|
|
2192
|
-
if (current.callee.type !==
|
|
2381
|
+
if (current.callee.type !== import_utils22.AST_NODE_TYPES.MemberExpression || !MUTATORS.has(import_utils22.ASTUtils.getPropertyName(current.callee) ?? "")) return;
|
|
2193
2382
|
const parameter = origin(current.callee.object, state);
|
|
2194
2383
|
if (parameter !== void 0 && first === null) first = { node: current, parameter };
|
|
2195
2384
|
}
|
|
2196
2385
|
function write(target, state) {
|
|
2197
2386
|
target = unwrapExpression(target);
|
|
2198
|
-
if (target.type !==
|
|
2387
|
+
if (target.type !== import_utils22.AST_NODE_TYPES.MemberExpression || !target.computed && import_utils22.ASTUtils.getPropertyName(target) !== "length") return;
|
|
2199
2388
|
const parameter = origin(target.object, state);
|
|
2200
2389
|
if (parameter !== void 0 && first === null) first = { node: target, parameter };
|
|
2201
2390
|
}
|
|
@@ -2205,18 +2394,18 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2205
2394
|
}
|
|
2206
2395
|
function statement(current, state) {
|
|
2207
2396
|
switch (current.type) {
|
|
2208
|
-
case
|
|
2397
|
+
case import_utils22.AST_NODE_TYPES.BlockStatement:
|
|
2209
2398
|
return statements(current.body, state);
|
|
2210
|
-
case
|
|
2399
|
+
case import_utils22.AST_NODE_TYPES.IfStatement:
|
|
2211
2400
|
return branch(current, state);
|
|
2212
|
-
case
|
|
2401
|
+
case import_utils22.AST_NODE_TYPES.VariableDeclaration:
|
|
2213
2402
|
declarations(current, state);
|
|
2214
2403
|
return false;
|
|
2215
|
-
case
|
|
2216
|
-
case
|
|
2404
|
+
case import_utils22.AST_NODE_TYPES.ReturnStatement:
|
|
2405
|
+
case import_utils22.AST_NODE_TYPES.ThrowStatement:
|
|
2217
2406
|
if (current.argument !== null) expression(current.argument, state);
|
|
2218
2407
|
return true;
|
|
2219
|
-
case
|
|
2408
|
+
case import_utils22.AST_NODE_TYPES.ExpressionStatement:
|
|
2220
2409
|
expression(current.expression, state);
|
|
2221
2410
|
return false;
|
|
2222
2411
|
default:
|
|
@@ -2225,7 +2414,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2225
2414
|
}
|
|
2226
2415
|
function branch(current, state) {
|
|
2227
2416
|
expression(current.test, state);
|
|
2228
|
-
if (current.test.type ===
|
|
2417
|
+
if (current.test.type === import_utils22.AST_NODE_TYPES.Literal) return current.test.value ? statements([current.consequent], state) : current.alternate !== null && statements([current.alternate], state);
|
|
2229
2418
|
const left = new Map(state);
|
|
2230
2419
|
const right = new Map(state);
|
|
2231
2420
|
const leftEnds = statements([current.consequent], left);
|
|
@@ -2257,7 +2446,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2257
2446
|
});
|
|
2258
2447
|
|
|
2259
2448
|
// src/rules/no-redundant-consumer-union.ts
|
|
2260
|
-
var
|
|
2449
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
2261
2450
|
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
2262
2451
|
|
|
2263
2452
|
// src/rules/_checked-native-source.ts
|
|
@@ -2368,11 +2557,11 @@ function finiteMember(member3, checker) {
|
|
|
2368
2557
|
}
|
|
2369
2558
|
|
|
2370
2559
|
// src/rules/_private-consumer-fix.ts
|
|
2371
|
-
var
|
|
2560
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
2372
2561
|
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
2373
2562
|
|
|
2374
2563
|
// src/rules/_type-binding.ts
|
|
2375
|
-
var
|
|
2564
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
2376
2565
|
function typeBinding(source, identifier) {
|
|
2377
2566
|
let scope = source.getScope(identifier);
|
|
2378
2567
|
while (scope !== null) {
|
|
@@ -2398,12 +2587,12 @@ function retainsNamedTypeUses(source, removed) {
|
|
|
2398
2587
|
function publicTypeUse(identifier) {
|
|
2399
2588
|
let node = identifier;
|
|
2400
2589
|
while (node.parent) {
|
|
2401
|
-
if (node.type ===
|
|
2402
|
-
if (node.type ===
|
|
2403
|
-
return node.parent.type ===
|
|
2590
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils23.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils23.AST_NODE_TYPES.TSAsExpression || node.type === import_utils23.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
2591
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
2592
|
+
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2404
2593
|
}
|
|
2405
|
-
if (node.type ===
|
|
2406
|
-
return node.parent.type ===
|
|
2594
|
+
if (node.type === import_utils23.AST_NODE_TYPES.ExportSpecifier) {
|
|
2595
|
+
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2407
2596
|
}
|
|
2408
2597
|
node = node.parent;
|
|
2409
2598
|
}
|
|
@@ -2417,8 +2606,8 @@ function insideTypeRange(node, range) {
|
|
|
2417
2606
|
var UNSAFE = import_typescript3.default.TypeFlags.Any | import_typescript3.default.TypeFlags.Unknown | import_typescript3.default.TypeFlags.Never | import_typescript3.default.TypeFlags.TypeParameter | import_typescript3.default.TypeFlags.Conditional | import_typescript3.default.TypeFlags.IndexedAccess | import_typescript3.default.TypeFlags.Substitution;
|
|
2418
2607
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
2419
2608
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
2420
|
-
const owner = node.type ===
|
|
2421
|
-
if (owner.type !==
|
|
2609
|
+
const owner = node.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
2610
|
+
if (owner.type !== import_utils24.AST_NODE_TYPES.FunctionDeclaration && owner.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator) return false;
|
|
2422
2611
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
2423
2612
|
if (!binding3) return false;
|
|
2424
2613
|
const checker = services.program.getTypeChecker();
|
|
@@ -2436,7 +2625,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
2436
2625
|
continue;
|
|
2437
2626
|
}
|
|
2438
2627
|
const call = reference.identifier.parent;
|
|
2439
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2628
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils24.AST_NODE_TYPES.CallExpression || call.callee !== reference.identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils24.AST_NODE_TYPES.Identifier) return false;
|
|
2440
2629
|
const argument = services.esTreeNodeToTSNodeMap.get(call.arguments[0]);
|
|
2441
2630
|
const type = checker.getTypeAtLocation(argument);
|
|
2442
2631
|
if (!knownArgument(type, argument, fields2, checker) || !checker.isTypeAssignableTo(type, original)) return false;
|
|
@@ -2491,7 +2680,7 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
2491
2680
|
}
|
|
2492
2681
|
|
|
2493
2682
|
// src/rules/_private-scalar-consumer.ts
|
|
2494
|
-
var
|
|
2683
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2495
2684
|
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
2496
2685
|
|
|
2497
2686
|
// src/rules/_scalar-parameter-view.ts
|
|
@@ -2637,31 +2826,11 @@ function intrinsicAttribute(attribute, view) {
|
|
|
2637
2826
|
return import_typescript5.default.isJsxAttribute(attribute) && import_typescript5.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
2638
2827
|
}
|
|
2639
2828
|
|
|
2640
|
-
// src/rules/_stable-value-binding.ts
|
|
2641
|
-
var import_utils22 = require("@typescript-eslint/utils");
|
|
2642
|
-
function typeOnlyReference(reference) {
|
|
2643
|
-
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
2644
|
-
let current = outerExpression(reference.identifier);
|
|
2645
|
-
while (current.parent?.type === import_utils22.AST_NODE_TYPES.TSQualifiedName && current.parent.left === current) {
|
|
2646
|
-
current = current.parent;
|
|
2647
|
-
}
|
|
2648
|
-
return current.parent?.type === import_utils22.AST_NODE_TYPES.TSTypeQuery && current.parent.exprName === current;
|
|
2649
|
-
}
|
|
2650
|
-
function stableValueBinding(variable, acceptRead) {
|
|
2651
|
-
let initializer;
|
|
2652
|
-
return variable.references.every((reference) => {
|
|
2653
|
-
if (!reference.isWrite()) return acceptRead?.(reference) ?? true;
|
|
2654
|
-
if (reference.init !== true || initializer !== void 0 && initializer !== reference.identifier) return false;
|
|
2655
|
-
initializer = reference.identifier;
|
|
2656
|
-
return true;
|
|
2657
|
-
});
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
2829
|
// src/rules/_private-scalar-consumer.ts
|
|
2661
2830
|
function directEval(node) {
|
|
2662
2831
|
let callee = unwrapExpression(node.callee);
|
|
2663
|
-
while (callee.type ===
|
|
2664
|
-
return callee.type ===
|
|
2832
|
+
while (callee.type === import_utils25.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
2833
|
+
return callee.type === import_utils25.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
2665
2834
|
}
|
|
2666
2835
|
function primitiveKeyword(node) {
|
|
2667
2836
|
return node !== void 0 && (node.kind === import_typescript6.default.SyntaxKind.StringKeyword || node.kind === import_typescript6.default.SyntaxKind.NumberKeyword || node.kind === import_typescript6.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript6.default.SyntaxKind.BigIntKeyword);
|
|
@@ -2672,7 +2841,7 @@ function nullishPrimitiveUnion(node) {
|
|
|
2672
2841
|
function consumerAnnotation(node) {
|
|
2673
2842
|
if (node.params.length !== 1) return void 0;
|
|
2674
2843
|
const parameter = node.params[0];
|
|
2675
|
-
return parameter?.type ===
|
|
2844
|
+
return parameter?.type === import_utils25.AST_NODE_TYPES.Identifier || parameter?.type === import_utils25.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
2676
2845
|
}
|
|
2677
2846
|
function exportedSymbols(source, checker) {
|
|
2678
2847
|
const symbol = checker.getSymbolAtLocation(source);
|
|
@@ -2703,12 +2872,12 @@ function independentSignature(native) {
|
|
|
2703
2872
|
return parameter !== void 0 && parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!import_typescript6.default.isIdentifier(parameter.name) || parameter.name.text !== "this");
|
|
2704
2873
|
}
|
|
2705
2874
|
function callableBinding(node, sourceCode) {
|
|
2706
|
-
if (node.type ===
|
|
2707
|
-
if (node.parent.type !==
|
|
2875
|
+
if (node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration) {
|
|
2876
|
+
if (node.parent.type !== import_utils25.AST_NODE_TYPES.Program) return void 0;
|
|
2708
2877
|
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
2709
2878
|
}
|
|
2710
2879
|
const declaration = node.parent;
|
|
2711
|
-
if (declaration.type !==
|
|
2880
|
+
if (declaration.type !== import_utils25.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils25.AST_NODE_TYPES.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== import_utils25.AST_NODE_TYPES.Program) return void 0;
|
|
2712
2881
|
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
2713
2882
|
}
|
|
2714
2883
|
function directCalls(binding3) {
|
|
@@ -2716,7 +2885,7 @@ function directCalls(binding3) {
|
|
|
2716
2885
|
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
2717
2886
|
const identifier = reference.identifier;
|
|
2718
2887
|
const call = identifier.parent;
|
|
2719
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2888
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils25.AST_NODE_TYPES.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils25.AST_NODE_TYPES.Identifier) return false;
|
|
2720
2889
|
calls += 1;
|
|
2721
2890
|
return true;
|
|
2722
2891
|
});
|
|
@@ -2776,13 +2945,13 @@ function localContractBindings(roots, source, services) {
|
|
|
2776
2945
|
}
|
|
2777
2946
|
function localContractReferences(node, source, services) {
|
|
2778
2947
|
switch (node.type) {
|
|
2779
|
-
case
|
|
2948
|
+
case import_utils26.AST_NODE_TYPES.TSTypeLiteral:
|
|
2780
2949
|
return [];
|
|
2781
|
-
case
|
|
2950
|
+
case import_utils26.AST_NODE_TYPES.TSIntersectionType:
|
|
2782
2951
|
return node.types;
|
|
2783
|
-
case
|
|
2784
|
-
return !node.typeArguments && node.typeName.type ===
|
|
2785
|
-
case
|
|
2952
|
+
case import_utils26.AST_NODE_TYPES.TSTypeReference:
|
|
2953
|
+
return !node.typeArguments && node.typeName.type === import_utils26.AST_NODE_TYPES.Identifier ? [node.typeName] : null;
|
|
2954
|
+
case import_utils26.AST_NODE_TYPES.Identifier:
|
|
2786
2955
|
return localBindingReferences(node, source, services);
|
|
2787
2956
|
default:
|
|
2788
2957
|
return null;
|
|
@@ -2792,8 +2961,8 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2792
2961
|
const definitions2 = typeBinding(source, identifier)?.defs.filter((definition) => definition.isTypeDefinition).map((definition) => definition.node);
|
|
2793
2962
|
if (!definitions2?.length || !definitions2.every(moduleTypeDeclaration)) return null;
|
|
2794
2963
|
const first = definitions2[0];
|
|
2795
|
-
if (definitions2.length === 1 && first?.type ===
|
|
2796
|
-
const interfaces = definitions2.filter((definition) => definition.type ===
|
|
2964
|
+
if (definitions2.length === 1 && first?.type === import_utils26.AST_NODE_TYPES.TSTypeAliasDeclaration && !first.typeParameters) return [first.typeAnnotation];
|
|
2965
|
+
const interfaces = definitions2.filter((definition) => definition.type === import_utils26.AST_NODE_TYPES.TSInterfaceDeclaration);
|
|
2797
2966
|
if (interfaces.length !== definitions2.length || interfaces.some((declaration) => declaration.typeParameters)) return null;
|
|
2798
2967
|
if (interfaces.length > 1) {
|
|
2799
2968
|
const checker = services.program.getTypeChecker();
|
|
@@ -2801,13 +2970,13 @@ function localBindingReferences(identifier, source, services) {
|
|
|
2801
2970
|
if (!symbol || interfaces.some((declaration) => checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(declaration.id)) !== symbol)) return null;
|
|
2802
2971
|
}
|
|
2803
2972
|
const bases = interfaces.flatMap((declaration) => declaration.extends.map((base) => base.expression));
|
|
2804
|
-
return bases.every((base) => base.type ===
|
|
2973
|
+
return bases.every((base) => base.type === import_utils26.AST_NODE_TYPES.Identifier) ? bases : null;
|
|
2805
2974
|
}
|
|
2806
2975
|
function moduleTypeDeclaration(node) {
|
|
2807
2976
|
const parent = node.parent;
|
|
2808
|
-
if (parent?.type ===
|
|
2809
|
-
if (parent?.type !==
|
|
2810
|
-
return parent.parent.type ===
|
|
2977
|
+
if (parent?.type === import_utils26.AST_NODE_TYPES.Program) return true;
|
|
2978
|
+
if (parent?.type !== import_utils26.AST_NODE_TYPES.ExportNamedDeclaration && parent?.type !== import_utils26.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
2979
|
+
return parent.parent.type === import_utils26.AST_NODE_TYPES.Program;
|
|
2811
2980
|
}
|
|
2812
2981
|
function coveringAlternative(leftNode, rightNode, checker, fieldsOf, reads) {
|
|
2813
2982
|
const left = checker.getTypeFromTypeNode(leftNode);
|
|
@@ -2842,7 +3011,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2842
3011
|
let dynamic = false;
|
|
2843
3012
|
const remember = (node) => {
|
|
2844
3013
|
const annotation = consumerAnnotation(node);
|
|
2845
|
-
if (annotation?.type ===
|
|
3014
|
+
if (annotation?.type === import_utils26.AST_NODE_TYPES.TSUnionType && annotation.types.length === 2) candidates.push(node);
|
|
2846
3015
|
};
|
|
2847
3016
|
return {
|
|
2848
3017
|
FunctionDeclaration: remember,
|
|
@@ -2852,7 +3021,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2852
3021
|
},
|
|
2853
3022
|
"Program:exit"() {
|
|
2854
3023
|
if (dynamic || !candidates.length) return;
|
|
2855
|
-
const services =
|
|
3024
|
+
const services = import_utils26.ESLintUtils.getParserServices(context);
|
|
2856
3025
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2857
3026
|
if (!source) return;
|
|
2858
3027
|
const checker = services.program.getTypeChecker();
|
|
@@ -2876,7 +3045,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2876
3045
|
const coverage = coveringAlternative(leftNode, rightNode, checker, fieldsOf, consumer.reads);
|
|
2877
3046
|
if (!coverage) continue;
|
|
2878
3047
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
2879
|
-
if (coverage.mutual && (reportNode.type !==
|
|
3048
|
+
if (coverage.mutual && (reportNode.type !== import_utils26.AST_NODE_TYPES.TSUnionType || !localContractBindings(reportNode.types, context.sourceCode, services))) continue;
|
|
2880
3049
|
const { covered: coveredNode, covering: coveringNode } = coverage;
|
|
2881
3050
|
const fix = privateUnionFix(context.sourceCode, services, {
|
|
2882
3051
|
candidate: candidate2,
|
|
@@ -2894,7 +3063,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
2894
3063
|
});
|
|
2895
3064
|
|
|
2896
3065
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
2897
|
-
var
|
|
3066
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
2898
3067
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
2899
3068
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
2900
3069
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
@@ -2945,7 +3114,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2945
3114
|
const candidates = [];
|
|
2946
3115
|
let dynamic = false;
|
|
2947
3116
|
const remember = (node) => {
|
|
2948
|
-
if (consumerAnnotation(node)?.type ===
|
|
3117
|
+
if (consumerAnnotation(node)?.type === import_utils27.AST_NODE_TYPES.TSTypeLiteral) candidates.push(node);
|
|
2949
3118
|
};
|
|
2950
3119
|
return {
|
|
2951
3120
|
FunctionDeclaration: remember,
|
|
@@ -2955,7 +3124,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2955
3124
|
},
|
|
2956
3125
|
"Program:exit"() {
|
|
2957
3126
|
if (dynamic || !candidates.length) return;
|
|
2958
|
-
const services =
|
|
3127
|
+
const services = import_utils27.ESLintUtils.getParserServices(context);
|
|
2959
3128
|
const source = currentNativeSource(context.sourceCode, services);
|
|
2960
3129
|
if (!source) return;
|
|
2961
3130
|
const checker = services.program.getTypeChecker();
|
|
@@ -2979,7 +3148,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
2979
3148
|
});
|
|
2980
3149
|
|
|
2981
3150
|
// src/rules/no-excess-jsx-props.ts
|
|
2982
|
-
var
|
|
3151
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
2983
3152
|
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
2984
3153
|
|
|
2985
3154
|
// src/rules/_ordinary-object-effects.ts
|
|
@@ -3321,11 +3490,11 @@ var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3321
3490
|
function plainLiteralFields(node) {
|
|
3322
3491
|
const fields2 = /* @__PURE__ */ new Map();
|
|
3323
3492
|
for (const property of node.properties) {
|
|
3324
|
-
if (property.type !==
|
|
3493
|
+
if (property.type !== import_utils28.AST_NODE_TYPES.Property || property.kind !== "init") return null;
|
|
3325
3494
|
const key = property.key;
|
|
3326
3495
|
let name;
|
|
3327
|
-
if (!property.computed && key.type ===
|
|
3328
|
-
else if (key.type ===
|
|
3496
|
+
if (!property.computed && key.type === import_utils28.AST_NODE_TYPES.Identifier) name = key.name;
|
|
3497
|
+
else if (key.type === import_utils28.AST_NODE_TYPES.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
3329
3498
|
else return null;
|
|
3330
3499
|
if (name === "__proto__") return null;
|
|
3331
3500
|
fields2.set(name, property);
|
|
@@ -3437,35 +3606,35 @@ function localObjectFields(symbol, source, proof) {
|
|
|
3437
3606
|
if (!native || native.getSourceFile() !== source || !initializer || !import_typescript10.default.isObjectLiteralExpression(initializer)) return null;
|
|
3438
3607
|
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
3439
3608
|
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
3440
|
-
if (declaration.type !==
|
|
3609
|
+
if (declaration.type !== import_utils28.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.id.type !== import_utils28.AST_NODE_TYPES.Identifier || literal2.type !== import_utils28.AST_NODE_TYPES.ObjectExpression || declaration.parent.parent.type === import_utils28.AST_NODE_TYPES.ExportNamedDeclaration) return null;
|
|
3441
3610
|
const fields2 = plainLiteralFields(literal2);
|
|
3442
3611
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3443
3612
|
if (!fields2 || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
3444
3613
|
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
3445
3614
|
const member3 = reference.identifier.parent;
|
|
3446
|
-
return member3.type ===
|
|
3615
|
+
return member3.type === import_utils28.AST_NODE_TYPES.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields2);
|
|
3447
3616
|
})) return null;
|
|
3448
3617
|
return fields2;
|
|
3449
3618
|
}
|
|
3450
3619
|
function staticMemberKey(member3) {
|
|
3451
3620
|
const property = member3.property;
|
|
3452
|
-
return !member3.computed && property.type ===
|
|
3621
|
+
return !member3.computed && property.type === import_utils28.AST_NODE_TYPES.Identifier ? property.name : property.type === import_utils28.AST_NODE_TYPES.Literal && (typeof property.value === "string" || typeof property.value === "number") ? String(property.value) : void 0;
|
|
3453
3622
|
}
|
|
3454
3623
|
function readonlyFieldValue(member3, fields2) {
|
|
3455
3624
|
const key = staticMemberKey(member3);
|
|
3456
3625
|
if (key === void 0 || !fields2.has(key)) return false;
|
|
3457
3626
|
const parent = member3.parent;
|
|
3458
|
-
if (parent.type ===
|
|
3627
|
+
if (parent.type === import_utils28.AST_NODE_TYPES.Property && parent.value === member3 && parent.parent.type === import_utils28.AST_NODE_TYPES.ObjectExpression) {
|
|
3459
3628
|
const object = parent.parent;
|
|
3460
3629
|
const owner = object.parent;
|
|
3461
|
-
return owner.type ===
|
|
3630
|
+
return owner.type === import_utils28.AST_NODE_TYPES.JSXSpreadAttribute && owner.argument === object || owner.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && owner.init === object;
|
|
3462
3631
|
}
|
|
3463
|
-
return parent.type ===
|
|
3632
|
+
return parent.type === import_utils28.AST_NODE_TYPES.JSXExpressionContainer && parent.expression === member3 || parent.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && parent.init === member3;
|
|
3464
3633
|
}
|
|
3465
3634
|
function privateElementDeclaration(opening) {
|
|
3466
3635
|
const value = outerExpression(opening.parent);
|
|
3467
3636
|
const declaration = value.parent;
|
|
3468
|
-
return declaration.type ===
|
|
3637
|
+
return declaration.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && declaration.init === value && declaration.id.type === import_utils28.AST_NODE_TYPES.Identifier && declaration.parent.kind === "const" && declaration.parent.parent.type !== import_utils28.AST_NODE_TYPES.ExportNamedDeclaration ? declaration : null;
|
|
3469
3638
|
}
|
|
3470
3639
|
function closedElementValue(opening, declaration, fields2, reads, proof) {
|
|
3471
3640
|
if (!proof.staticScope || !closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
@@ -3491,10 +3660,10 @@ function closedInvocation(node, proof) {
|
|
|
3491
3660
|
}
|
|
3492
3661
|
function independentInvocation(scope, proof) {
|
|
3493
3662
|
const block = scope.block;
|
|
3494
|
-
if (block.type !==
|
|
3663
|
+
if (block.type !== import_utils28.AST_NODE_TYPES.ArrowFunctionExpression && block.type !== import_utils28.AST_NODE_TYPES.FunctionDeclaration && block.type !== import_utils28.AST_NODE_TYPES.FunctionExpression) return false;
|
|
3495
3664
|
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3496
3665
|
for (const parameter of block.params) {
|
|
3497
|
-
if (parameter.type !==
|
|
3666
|
+
if (parameter.type !== import_utils28.AST_NODE_TYPES.Identifier || parameter.name === "this") return false;
|
|
3498
3667
|
const binding3 = scope.set.get(parameter.name);
|
|
3499
3668
|
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3500
3669
|
}
|
|
@@ -3502,16 +3671,16 @@ function independentInvocation(scope, proof) {
|
|
|
3502
3671
|
if (typeOnlyReference(reference)) return true;
|
|
3503
3672
|
const value = outerExpression(reference.identifier);
|
|
3504
3673
|
const parent = value.parent;
|
|
3505
|
-
const read = parent?.type ===
|
|
3674
|
+
const read = parent?.type === import_utils28.AST_NODE_TYPES.MemberExpression && parent.object === value ? parent : value;
|
|
3506
3675
|
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
3507
3676
|
});
|
|
3508
3677
|
}
|
|
3509
3678
|
function consumedElementRead(node, fields2, reads) {
|
|
3510
3679
|
const identifier = outerExpression(node);
|
|
3511
3680
|
const props = identifier.parent;
|
|
3512
|
-
if (!props || props.type !==
|
|
3681
|
+
if (!props || props.type !== import_utils28.AST_NODE_TYPES.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
3513
3682
|
const member3 = props.parent;
|
|
3514
|
-
if (member3.type !==
|
|
3683
|
+
if (member3.type !== import_utils28.AST_NODE_TYPES.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
3515
3684
|
const key = staticMemberKey(member3);
|
|
3516
3685
|
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields2);
|
|
3517
3686
|
}
|
|
@@ -3539,7 +3708,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3539
3708
|
const evaluate = (node, declaration, fields2) => {
|
|
3540
3709
|
const keys = [...fields2.keys()];
|
|
3541
3710
|
const opening = node.parent;
|
|
3542
|
-
services ??=
|
|
3711
|
+
services ??= import_utils28.ESLintUtils.getParserServices(context);
|
|
3543
3712
|
standardJSX ??= supportedJSX(services.program.getCompilerOptions(), context.sourceCode.getAllComments());
|
|
3544
3713
|
if (!standardJSX) return;
|
|
3545
3714
|
const checker = services.program.getTypeChecker();
|
|
@@ -3572,9 +3741,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3572
3741
|
};
|
|
3573
3742
|
return {
|
|
3574
3743
|
JSXSpreadAttribute(node) {
|
|
3575
|
-
if (node.argument.type !==
|
|
3744
|
+
if (node.argument.type !== import_utils28.AST_NODE_TYPES.ObjectExpression) return;
|
|
3576
3745
|
const opening = node.parent;
|
|
3577
|
-
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !==
|
|
3746
|
+
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== import_utils28.AST_NODE_TYPES.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
3578
3747
|
const declaration = privateElementDeclaration(opening);
|
|
3579
3748
|
if (!declaration) return;
|
|
3580
3749
|
const fields2 = literalFields(node.argument);
|
|
@@ -3586,7 +3755,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3586
3755
|
},
|
|
3587
3756
|
"Program:exit"() {
|
|
3588
3757
|
if (!candidates.length) return;
|
|
3589
|
-
services =
|
|
3758
|
+
services = import_utils28.ESLintUtils.getParserServices(context);
|
|
3590
3759
|
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
3591
3760
|
for (const { node, declaration, fields: fields2 } of candidates) evaluate(node, declaration, fields2);
|
|
3592
3761
|
}
|
|
@@ -3595,7 +3764,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3595
3764
|
});
|
|
3596
3765
|
|
|
3597
3766
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3598
|
-
var
|
|
3767
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
3599
3768
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3600
3769
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3601
3770
|
defaultLevel: "warning",
|
|
@@ -3659,19 +3828,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3659
3828
|
});
|
|
3660
3829
|
function hasUseServerDirective(program) {
|
|
3661
3830
|
for (const statement of program.body) {
|
|
3662
|
-
if (statement.type !==
|
|
3831
|
+
if (statement.type !== import_utils29.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0) return false;
|
|
3663
3832
|
if (statement.directive === "use server") return true;
|
|
3664
3833
|
}
|
|
3665
3834
|
return false;
|
|
3666
3835
|
}
|
|
3667
3836
|
function isTypeOnly(node) {
|
|
3668
3837
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3669
|
-
(specifier) => specifier.type ===
|
|
3838
|
+
(specifier) => specifier.type === import_utils29.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3670
3839
|
);
|
|
3671
3840
|
}
|
|
3672
3841
|
|
|
3673
3842
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3674
|
-
var
|
|
3843
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3675
3844
|
|
|
3676
3845
|
// src/rules/_secret-names.ts
|
|
3677
3846
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -3815,54 +3984,10 @@ function isAuthSecretName(identifier) {
|
|
|
3815
3984
|
return hasApiKey(tokens);
|
|
3816
3985
|
}
|
|
3817
3986
|
|
|
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
3987
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3863
3988
|
var STORAGE_NAMES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
3864
3989
|
var METADATA_WORDS = /* @__PURE__ */ new Set(["page", "cursor", "next", "hint", "expires", "expiry", "expiration"]);
|
|
3865
|
-
var
|
|
3990
|
+
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
3866
3991
|
var NO_CREDENTIAL_IN_BROWSER_STORAGE_DOCUMENTATION = {
|
|
3867
3992
|
defaultLevel: "warning",
|
|
3868
3993
|
summary: "Do not write credential-named values to browser storage or script-readable cookies.",
|
|
@@ -3920,7 +4045,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3920
4045
|
return {
|
|
3921
4046
|
CallExpression(node) {
|
|
3922
4047
|
const callee = unwrapExpression(node.callee);
|
|
3923
|
-
if (callee.type !==
|
|
4048
|
+
if (callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils30.AST_NODE_TYPES.Identifier || callee.property.name !== "setItem" || !isStorage(sourceCode, callee.object)) {
|
|
3924
4049
|
return;
|
|
3925
4050
|
}
|
|
3926
4051
|
const [key] = node.arguments;
|
|
@@ -3928,12 +4053,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
3928
4053
|
},
|
|
3929
4054
|
AssignmentExpression(node) {
|
|
3930
4055
|
const target = node.left;
|
|
3931
|
-
if (target.type !==
|
|
4056
|
+
if (target.type !== import_utils30.AST_NODE_TYPES.MemberExpression) return;
|
|
3932
4057
|
if (isStorage(sourceCode, target.object)) {
|
|
3933
4058
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
3934
4059
|
return;
|
|
3935
4060
|
}
|
|
3936
|
-
if (!target.computed && target.property.type ===
|
|
4061
|
+
if (!target.computed && target.property.type === import_utils30.AST_NODE_TYPES.Identifier && target.property.name === "cookie" && globalMemberName(sourceCode, target.object) === "document") {
|
|
3937
4062
|
report2(node, cookieName(node.right));
|
|
3938
4063
|
}
|
|
3939
4064
|
}
|
|
@@ -3946,34 +4071,34 @@ function isStorage(sourceCode, node) {
|
|
|
3946
4071
|
}
|
|
3947
4072
|
function globalMemberName(sourceCode, node) {
|
|
3948
4073
|
const value = unwrapExpression(node);
|
|
3949
|
-
if (value.type ===
|
|
3950
|
-
if (value.type ===
|
|
4074
|
+
if (value.type === import_utils30.AST_NODE_TYPES.Identifier) return isUnshadowed(sourceCode, value) ? value.name : null;
|
|
4075
|
+
if (value.type === import_utils30.AST_NODE_TYPES.MemberExpression && !value.computed && value.object.type === import_utils30.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(value.object.name) && value.property.type === import_utils30.AST_NODE_TYPES.Identifier && isUnshadowed(sourceCode, value.object)) {
|
|
3951
4076
|
return value.property.name;
|
|
3952
4077
|
}
|
|
3953
4078
|
return null;
|
|
3954
4079
|
}
|
|
3955
4080
|
function isUnshadowed(sourceCode, node) {
|
|
3956
|
-
const variable =
|
|
4081
|
+
const variable = import_utils30.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3957
4082
|
return variable === null || variable.defs.length === 0;
|
|
3958
4083
|
}
|
|
3959
4084
|
function storedPropertyKey(sourceCode, target) {
|
|
3960
|
-
if (!target.computed) return target.property.type ===
|
|
4085
|
+
if (!target.computed) return target.property.type === import_utils30.AST_NODE_TYPES.Identifier ? target.property.name : null;
|
|
3961
4086
|
return scopedStaticString(target.property, sourceCode);
|
|
3962
4087
|
}
|
|
3963
4088
|
function cookieName(value) {
|
|
3964
4089
|
let expression = unwrapExpression(value);
|
|
3965
|
-
while (expression.type ===
|
|
4090
|
+
while (expression.type === import_utils30.AST_NODE_TYPES.BinaryExpression && expression.operator === "+") {
|
|
3966
4091
|
expression = unwrapExpression(expression.left);
|
|
3967
4092
|
}
|
|
3968
4093
|
let text = null;
|
|
3969
|
-
if (expression.type ===
|
|
3970
|
-
if (expression.type ===
|
|
4094
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.Literal && typeof expression.value === "string") text = expression.value;
|
|
4095
|
+
if (expression.type === import_utils30.AST_NODE_TYPES.TemplateLiteral) text = expression.quasis[0]?.value.cooked ?? null;
|
|
3971
4096
|
if (text === null || !text.includes("=")) return null;
|
|
3972
4097
|
return text.slice(0, text.indexOf("=")).trim();
|
|
3973
4098
|
}
|
|
3974
4099
|
|
|
3975
4100
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
3976
|
-
var
|
|
4101
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3977
4102
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
3978
4103
|
var NUMBER_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat"]);
|
|
3979
4104
|
var SEARCH_PARAM_TYPES = /* @__PURE__ */ new Set(["URLSearchParams", "ReadonlyURLSearchParams"]);
|
|
@@ -4030,7 +4155,7 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4030
4155
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context)) return {};
|
|
4031
4156
|
let services;
|
|
4032
4157
|
try {
|
|
4033
|
-
services =
|
|
4158
|
+
services = import_utils31.ESLintUtils.getParserServices(context);
|
|
4034
4159
|
} catch {
|
|
4035
4160
|
services = null;
|
|
4036
4161
|
}
|
|
@@ -4052,27 +4177,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4052
4177
|
}
|
|
4053
4178
|
});
|
|
4054
4179
|
function isNumericParser(sourceCode, callee) {
|
|
4055
|
-
if (callee.type ===
|
|
4180
|
+
if (callee.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4056
4181
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
4057
4182
|
}
|
|
4058
|
-
return callee.type ===
|
|
4183
|
+
return callee.type === import_utils31.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils31.AST_NODE_TYPES.Identifier && callee.object.name === "Number" && callee.property.type === import_utils31.AST_NODE_TYPES.Identifier && NUMBER_PARSERS.has(callee.property.name) && isUnshadowedGlobal(sourceCode, callee.object);
|
|
4059
4184
|
}
|
|
4060
4185
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4061
|
-
const variable =
|
|
4186
|
+
const variable = import_utils31.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4062
4187
|
return variable === null || variable.defs.length === 0;
|
|
4063
4188
|
}
|
|
4064
4189
|
function searchParamGetCall(argument) {
|
|
4065
4190
|
let value = unwrapExpression(argument);
|
|
4066
|
-
if (value.type ===
|
|
4067
|
-
if (value.type ===
|
|
4068
|
-
if (value.type ===
|
|
4069
|
-
if (value.type !==
|
|
4191
|
+
if (value.type === import_utils31.AST_NODE_TYPES.AwaitExpression) value = unwrapExpression(value.argument);
|
|
4192
|
+
if (value.type === import_utils31.AST_NODE_TYPES.LogicalExpression && value.operator === "??") value = unwrapExpression(value.left);
|
|
4193
|
+
if (value.type === import_utils31.AST_NODE_TYPES.ChainExpression) value = value.expression;
|
|
4194
|
+
if (value.type !== import_utils31.AST_NODE_TYPES.CallExpression || value.callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression || value.callee.computed || value.callee.property.type !== import_utils31.AST_NODE_TYPES.Identifier || value.callee.property.name !== "get") {
|
|
4070
4195
|
return null;
|
|
4071
4196
|
}
|
|
4072
4197
|
return value;
|
|
4073
4198
|
}
|
|
4074
4199
|
function isSearchParamReceiver(call, services) {
|
|
4075
|
-
if (call.callee.type !==
|
|
4200
|
+
if (call.callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression) return false;
|
|
4076
4201
|
const checker = services.program.getTypeChecker();
|
|
4077
4202
|
const type = checker.getNonNullableType(
|
|
4078
4203
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4084,7 +4209,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4084
4209
|
// package.json
|
|
4085
4210
|
var package_default = {
|
|
4086
4211
|
name: "@sarj/eslint-plugin",
|
|
4087
|
-
version: "16.
|
|
4212
|
+
version: "16.38.50",
|
|
4088
4213
|
packageManager: "npm@12.2.1",
|
|
4089
4214
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4090
4215
|
type: "module",
|
|
@@ -4206,11 +4331,11 @@ var package_default = {
|
|
|
4206
4331
|
};
|
|
4207
4332
|
|
|
4208
4333
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4209
|
-
var
|
|
4334
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4210
4335
|
var ts12 = __toESM(require("typescript"), 1);
|
|
4211
4336
|
|
|
4212
4337
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4213
|
-
var
|
|
4338
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4214
4339
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
4215
4340
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
4216
4341
|
const source = call.getSourceFile();
|
|
@@ -4284,7 +4409,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4284
4409
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4285
4410
|
rejected.expression.expression.getStart()
|
|
4286
4411
|
);
|
|
4287
|
-
return identifier?.type ===
|
|
4412
|
+
return identifier?.type === import_utils32.AST_NODE_TYPES.Identifier && identifier.name === "TypeError" && (import_utils32.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
4288
4413
|
}
|
|
4289
4414
|
function exactConstruction(node, consumer, implementation) {
|
|
4290
4415
|
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4650,7 +4775,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4650
4775
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
4651
4776
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
4652
4777
|
return {};
|
|
4653
|
-
const services =
|
|
4778
|
+
const services = import_utils33.ESLintUtils.getParserServices(context);
|
|
4654
4779
|
const checker = services.program.getTypeChecker();
|
|
4655
4780
|
function inspect(node) {
|
|
4656
4781
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -4665,7 +4790,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4665
4790
|
return;
|
|
4666
4791
|
const parameters = signature.getParameters();
|
|
4667
4792
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4668
|
-
if (argument.type !==
|
|
4793
|
+
if (argument.type !== import_utils33.AST_NODE_TYPES.NewExpression) continue;
|
|
4669
4794
|
const parameter = parameters[index];
|
|
4670
4795
|
if (parameter === void 0) continue;
|
|
4671
4796
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4712,18 +4837,18 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4712
4837
|
});
|
|
4713
4838
|
|
|
4714
4839
|
// src/rules/require-explicit-service-contract.ts
|
|
4715
|
-
var
|
|
4840
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
4716
4841
|
|
|
4717
4842
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4718
|
-
var
|
|
4843
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4719
4844
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4720
4845
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4721
4846
|
return null;
|
|
4722
4847
|
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 !==
|
|
4848
|
+
const contract = contractStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? contractStatement.declaration : null;
|
|
4849
|
+
const implementation = classStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? classStatement.declaration : classStatement;
|
|
4850
|
+
const factory = factoryStatement?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration ? factoryStatement.declaration : null;
|
|
4851
|
+
if (contract?.type !== import_utils34.AST_NODE_TYPES.TSTypeAliasDeclaration || worker?.type !== import_utils34.AST_NODE_TYPES.TSInterfaceDeclaration || implementation?.type !== import_utils34.AST_NODE_TYPES.ClassDeclaration || implementation !== candidate2 || !ordinaryClass(implementation) || !ordinaryFactory(factory))
|
|
4727
4852
|
return null;
|
|
4728
4853
|
const operation2 = contractOperation(contract);
|
|
4729
4854
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4742,17 +4867,17 @@ function ordinaryClass(node) {
|
|
|
4742
4867
|
return node.id !== null && !node.declare && !node.abstract && node.decorators.length === 0 && node.superClass === null && node.implements.length === 0 && node.typeParameters === void 0 && node.body.body.length === 2;
|
|
4743
4868
|
}
|
|
4744
4869
|
function ordinaryFactory(node) {
|
|
4745
|
-
return node?.type ===
|
|
4870
|
+
return node?.type === import_utils34.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && !node.declare && !node.async && !node.generator && node.typeParameters === void 0 && node.params.length === 1 && node.body.body.length === 1;
|
|
4746
4871
|
}
|
|
4747
4872
|
function interfaceOperation(node) {
|
|
4748
4873
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4749
4874
|
}
|
|
4750
4875
|
function contractOperation(node) {
|
|
4751
|
-
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type ===
|
|
4876
|
+
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type === import_utils34.AST_NODE_TYPES.TSTypeLiteral ? singletonOperation(node.typeAnnotation.members) : null;
|
|
4752
4877
|
}
|
|
4753
4878
|
function singletonOperation(members) {
|
|
4754
4879
|
const member3 = members[0];
|
|
4755
|
-
return members.length === 1 && member3?.type ===
|
|
4880
|
+
return members.length === 1 && member3?.type === import_utils34.AST_NODE_TYPES.TSMethodSignature && member3.kind === "method" && !member3.computed && !member3.optional && member3.key.type === import_utils34.AST_NODE_TYPES.Identifier && member3.params.length === 0 && member3.typeParameters === void 0 && member3.returnType?.typeAnnotation.type === import_utils34.AST_NODE_TYPES.TSVoidKeyword ? member3.key.name : null;
|
|
4756
4881
|
}
|
|
4757
4882
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4758
4883
|
const names = declarations.flatMap(
|
|
@@ -4763,7 +4888,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4763
4888
|
);
|
|
4764
4889
|
}
|
|
4765
4890
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4766
|
-
const binding3 =
|
|
4891
|
+
const binding3 = import_utils34.ASTUtils.findVariable(
|
|
4767
4892
|
sourceCode.getScope(reference),
|
|
4768
4893
|
reference.name
|
|
4769
4894
|
);
|
|
@@ -4771,45 +4896,45 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
4771
4896
|
}
|
|
4772
4897
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
4773
4898
|
const constructor = implementation.body.body[0];
|
|
4774
|
-
if (constructor?.type !==
|
|
4899
|
+
if (constructor?.type !== import_utils34.AST_NODE_TYPES.MethodDefinition || constructor.value.type !== import_utils34.AST_NODE_TYPES.FunctionExpression || constructor.kind !== "constructor" || constructor.computed || constructor.static || constructor.decorators.length !== 0 || constructor.optional || constructor.accessibility !== void 0 && constructor.accessibility !== "public" || constructor.value.async || constructor.value.generator || constructor.value.typeParameters !== void 0 || constructor.value.returnType !== void 0 || constructor.value.body.body.length !== 0 || constructor.value.params.length !== 1)
|
|
4775
4900
|
return null;
|
|
4776
4901
|
const property = constructor.value.params[0];
|
|
4777
|
-
if (property?.type !==
|
|
4902
|
+
if (property?.type !== import_utils34.AST_NODE_TYPES.TSParameterProperty || property.accessibility !== "private" || !property.readonly || property.override || property.decorators.length !== 0 || property.parameter.type !== import_utils34.AST_NODE_TYPES.Identifier || property.parameter.optional || !typeReference(sourceCode, property.parameter.typeAnnotation, worker))
|
|
4778
4903
|
return null;
|
|
4779
4904
|
return property.parameter.name;
|
|
4780
4905
|
}
|
|
4781
4906
|
function typeReference(sourceCode, annotation, declaration) {
|
|
4782
4907
|
const type = annotation?.typeAnnotation;
|
|
4783
|
-
return type?.type ===
|
|
4908
|
+
return type?.type === import_utils34.AST_NODE_TYPES.TSTypeReference && type.typeArguments === void 0 && type.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && sameBinding(sourceCode, type.typeName, declaration);
|
|
4784
4909
|
}
|
|
4785
4910
|
function forwardsOperation(implementation, field, operation2) {
|
|
4786
4911
|
const method = implementation.body.body[1];
|
|
4787
|
-
if (method?.type !==
|
|
4912
|
+
if (method?.type !== import_utils34.AST_NODE_TYPES.MethodDefinition || method.kind !== "method" || method.value.type !== import_utils34.AST_NODE_TYPES.FunctionExpression || method.computed || method.static || method.optional || method.override || method.decorators.length !== 0 || method.accessibility !== void 0 && method.accessibility !== "public" || method.key.type !== import_utils34.AST_NODE_TYPES.Identifier || method.key.name !== operation2 || method.value.async || method.value.generator || method.value.typeParameters !== void 0 || method.value.params.length !== 0 || method.value.body.body.length !== 1 || method.value.returnType?.typeAnnotation.type !== import_utils34.AST_NODE_TYPES.TSVoidKeyword)
|
|
4788
4913
|
return false;
|
|
4789
4914
|
const statement = method.value.body.body[0];
|
|
4790
|
-
const call = statement?.type ===
|
|
4791
|
-
return call?.type ===
|
|
4915
|
+
const call = statement?.type === import_utils34.AST_NODE_TYPES.ExpressionStatement ? statement.expression : null;
|
|
4916
|
+
return call?.type === import_utils34.AST_NODE_TYPES.CallExpression && !call.optional && call.typeArguments === void 0 && call.arguments.length === 0 && forwardedMember(call.callee, field, operation2);
|
|
4792
4917
|
}
|
|
4793
4918
|
function forwardedMember(node, field, operation2) {
|
|
4794
|
-
if (node.type !==
|
|
4919
|
+
if (node.type !== import_utils34.AST_NODE_TYPES.MemberExpression || node.computed || node.optional || node.property.type !== import_utils34.AST_NODE_TYPES.Identifier || node.property.name !== operation2)
|
|
4795
4920
|
return false;
|
|
4796
4921
|
const receiver = node.object;
|
|
4797
|
-
return receiver.type ===
|
|
4922
|
+
return receiver.type === import_utils34.AST_NODE_TYPES.MemberExpression && !receiver.computed && !receiver.optional && receiver.object.type === import_utils34.AST_NODE_TYPES.ThisExpression && receiver.property.type === import_utils34.AST_NODE_TYPES.Identifier && receiver.property.name === field;
|
|
4798
4923
|
}
|
|
4799
4924
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
4800
4925
|
const parameter = factory.params[0];
|
|
4801
|
-
if (parameter?.type !==
|
|
4926
|
+
if (parameter?.type !== import_utils34.AST_NODE_TYPES.Identifier || parameter.optional || !typeReference(sourceCode, parameter.typeAnnotation, worker) || !typeReference(sourceCode, factory.returnType, contract))
|
|
4802
4927
|
return false;
|
|
4803
4928
|
const statement = factory.body.body[0];
|
|
4804
|
-
const constructed = statement?.type ===
|
|
4805
|
-
if (constructed?.type !==
|
|
4929
|
+
const constructed = statement?.type === import_utils34.AST_NODE_TYPES.ReturnStatement ? statement.argument : null;
|
|
4930
|
+
if (constructed?.type !== import_utils34.AST_NODE_TYPES.NewExpression || constructed.typeArguments !== void 0 || constructed.callee.type !== import_utils34.AST_NODE_TYPES.Identifier || !sameBinding(sourceCode, constructed.callee, implementation) || constructed.arguments.length !== 1)
|
|
4806
4931
|
return false;
|
|
4807
4932
|
const argument = constructed.arguments[0];
|
|
4808
|
-
return argument?.type ===
|
|
4933
|
+
return argument?.type === import_utils34.AST_NODE_TYPES.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
4809
4934
|
}
|
|
4810
4935
|
|
|
4811
4936
|
// src/rules/require-port-for-service.ts
|
|
4812
|
-
var
|
|
4937
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4813
4938
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
4814
4939
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
4815
4940
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -4893,50 +5018,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
4893
5018
|
"||="
|
|
4894
5019
|
]);
|
|
4895
5020
|
var staticMemberName = (member3) => {
|
|
4896
|
-
if (member3.property.type ===
|
|
5021
|
+
if (member3.property.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier)
|
|
4897
5022
|
return `#${member3.property.name}`;
|
|
4898
|
-
return
|
|
5023
|
+
return import_utils35.ASTUtils.getPropertyName(member3);
|
|
4899
5024
|
};
|
|
4900
5025
|
var detachedValueExports = (program) => {
|
|
4901
5026
|
const names = /* @__PURE__ */ new Set();
|
|
4902
5027
|
for (const statement of program.body) {
|
|
4903
|
-
if (statement.type ===
|
|
5028
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
4904
5029
|
for (const specifier of statement.specifiers) {
|
|
4905
5030
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
4906
5031
|
}
|
|
4907
|
-
} else if (statement.type ===
|
|
5032
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4908
5033
|
names.add(statement.declaration.name);
|
|
4909
|
-
} else if (statement.type ===
|
|
5034
|
+
} else if (statement.type === import_utils35.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4910
5035
|
names.add(statement.expression.name);
|
|
4911
5036
|
}
|
|
4912
5037
|
}
|
|
4913
5038
|
return names;
|
|
4914
5039
|
};
|
|
4915
|
-
var isExportedClass = (node, detached) => node.parent.type ===
|
|
5040
|
+
var isExportedClass = (node, detached) => node.parent.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
4916
5041
|
var createExportedServiceClassResolver = (program) => {
|
|
4917
5042
|
const detached = detachedValueExports(program);
|
|
4918
5043
|
return (node) => isExportedClass(node, detached);
|
|
4919
5044
|
};
|
|
4920
5045
|
var readTypeReference = (annotation) => {
|
|
4921
|
-
if (annotation?.type ===
|
|
5046
|
+
if (annotation?.type === import_utils35.AST_NODE_TYPES.TSUnionType) {
|
|
4922
5047
|
const members = annotation.types.filter(
|
|
4923
|
-
(member3) => member3.type !==
|
|
5048
|
+
(member3) => member3.type !== import_utils35.AST_NODE_TYPES.TSUndefinedKeyword && member3.type !== import_utils35.AST_NODE_TYPES.TSNullKeyword
|
|
4924
5049
|
);
|
|
4925
5050
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
4926
5051
|
}
|
|
4927
|
-
if (annotation === void 0 || annotation.type !==
|
|
5052
|
+
if (annotation === void 0 || annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference)
|
|
4928
5053
|
return null;
|
|
4929
5054
|
const { typeName } = annotation;
|
|
4930
|
-
const rightmost = typeName.type ===
|
|
5055
|
+
const rightmost = typeName.type === import_utils35.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils35.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
4931
5056
|
if (rightmost === null) return null;
|
|
4932
5057
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
4933
5058
|
};
|
|
4934
|
-
var qualifiedName = (name) => name.type ===
|
|
5059
|
+
var qualifiedName = (name) => name.type === import_utils35.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils35.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
4935
5060
|
var propertySignatureTypes = (members) => {
|
|
4936
5061
|
const types = /* @__PURE__ */ new Map();
|
|
4937
5062
|
for (const member3 of members) {
|
|
4938
|
-
if (member3.type !==
|
|
4939
|
-
if (member3.computed || member3.key.type !==
|
|
5063
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5064
|
+
if (member3.computed || member3.key.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
4940
5065
|
continue;
|
|
4941
5066
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
4942
5067
|
if (reference === null) continue;
|
|
@@ -4948,18 +5073,18 @@ var fileTypeIndex = (program) => {
|
|
|
4948
5073
|
const objects = /* @__PURE__ */ new Map();
|
|
4949
5074
|
const functionAliases = localFunctionAliases(program);
|
|
4950
5075
|
function collectDeclaredType(statement) {
|
|
4951
|
-
const declaration = statement.type ===
|
|
4952
|
-
if (declaration?.type ===
|
|
5076
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5077
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
4953
5078
|
objects.set(
|
|
4954
5079
|
declaration.id.name,
|
|
4955
5080
|
propertySignatureTypes(declaration.body.body)
|
|
4956
5081
|
);
|
|
4957
5082
|
return;
|
|
4958
5083
|
}
|
|
4959
|
-
if (declaration?.type !==
|
|
5084
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) return;
|
|
4960
5085
|
const aliased = declaration.typeAnnotation;
|
|
4961
|
-
const literals = aliased.type ===
|
|
4962
|
-
(part) => part.type ===
|
|
5086
|
+
const literals = aliased.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter(
|
|
5087
|
+
(part) => part.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral
|
|
4963
5088
|
) : [];
|
|
4964
5089
|
if (literals.length === 0) return;
|
|
4965
5090
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -4979,12 +5104,12 @@ function localFunctionAliases(program) {
|
|
|
4979
5104
|
const names = /* @__PURE__ */ new Set();
|
|
4980
5105
|
const parents = /* @__PURE__ */ new Map();
|
|
4981
5106
|
for (const statement of program.body) {
|
|
4982
|
-
const declaration = statement.type ===
|
|
4983
|
-
if (declaration?.type !==
|
|
5107
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5108
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
4984
5109
|
const annotation = declaration.typeAnnotation;
|
|
4985
|
-
if (annotation.type ===
|
|
5110
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSFunctionType || annotation.type === import_utils35.AST_NODE_TYPES.TSConstructorType)
|
|
4986
5111
|
names.add(declaration.id.name);
|
|
4987
|
-
if (annotation.type ===
|
|
5112
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
4988
5113
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
4989
5114
|
}
|
|
4990
5115
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -5020,32 +5145,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5020
5145
|
function scanStoredFields(body4) {
|
|
5021
5146
|
const pending = [...body4.body];
|
|
5022
5147
|
function recordStoredField(current) {
|
|
5023
|
-
if (current.type ===
|
|
5148
|
+
if (current.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils35.AST_NODE_TYPES.ClassExpression || current.type === import_utils35.AST_NODE_TYPES.ClassDeclaration)
|
|
5024
5149
|
return;
|
|
5025
|
-
if (current.type ===
|
|
5150
|
+
if (current.type === import_utils35.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5026
5151
|
localBindings2.add(current.id.name);
|
|
5027
|
-
const expression = current.type ===
|
|
5152
|
+
const expression = current.type === import_utils35.AST_NODE_TYPES.AssignmentExpression ? current : null;
|
|
5028
5153
|
const storedField = writtenInstanceField(current);
|
|
5029
5154
|
if (storedField !== null) {
|
|
5030
5155
|
if (writtenFieldNames.has(storedField))
|
|
5031
5156
|
unstableFieldNames.add(storedField);
|
|
5032
5157
|
writtenFieldNames.add(storedField);
|
|
5033
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5158
|
+
if (expression?.operator !== "=" || expression.parent.type !== import_utils35.AST_NODE_TYPES.ExpressionStatement || expression.parent.parent !== body4)
|
|
5034
5159
|
unstableFieldNames.add(storedField);
|
|
5035
5160
|
}
|
|
5036
|
-
if (expression?.type !==
|
|
5161
|
+
if (expression?.type !== import_utils35.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils35.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils35.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
5037
5162
|
enqueueChildren(current);
|
|
5038
5163
|
return;
|
|
5039
5164
|
}
|
|
5040
5165
|
const source = unwrapExpression(expression.right);
|
|
5041
|
-
if (source.type ===
|
|
5166
|
+
if (source.type === import_utils35.AST_NODE_TYPES.NewExpression) {
|
|
5042
5167
|
constructedFields += 1;
|
|
5043
5168
|
constructedFieldNames.add(storedField);
|
|
5044
|
-
} else if (source.type ===
|
|
5169
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5045
5170
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
5046
5171
|
fields2.add(storedField);
|
|
5047
5172
|
storedFieldsFrom.set(source.name, fields2);
|
|
5048
|
-
} else if (source.type ===
|
|
5173
|
+
} else if (source.type === import_utils35.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5049
5174
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
5050
5175
|
fields2.add(storedField);
|
|
5051
5176
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5080,7 +5205,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5080
5205
|
)) {
|
|
5081
5206
|
if (localBindings2.has(reference.name)) continue;
|
|
5082
5207
|
let fields2 = reference.fields;
|
|
5083
|
-
if (parameter.type ===
|
|
5208
|
+
if (parameter.type === import_utils35.AST_NODE_TYPES.TSParameterProperty) {
|
|
5084
5209
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5085
5210
|
fields2 = [reference.name];
|
|
5086
5211
|
} else if (fields2.length === 0)
|
|
@@ -5103,8 +5228,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5103
5228
|
};
|
|
5104
5229
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5105
5230
|
let target = parameter;
|
|
5106
|
-
if (target.type ===
|
|
5107
|
-
if (target.type ===
|
|
5231
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5232
|
+
if (target.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5108
5233
|
return objectPatternCollaborators(target, declared);
|
|
5109
5234
|
}
|
|
5110
5235
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5114,10 +5239,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5114
5239
|
};
|
|
5115
5240
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5116
5241
|
let target = annotated;
|
|
5117
|
-
if (target.type ===
|
|
5242
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5118
5243
|
target = target.parameter;
|
|
5119
|
-
if (target.type ===
|
|
5120
|
-
if (target.type !==
|
|
5244
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5245
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return [];
|
|
5121
5246
|
const members = bagMemberTypes(
|
|
5122
5247
|
target.typeAnnotation?.typeAnnotation,
|
|
5123
5248
|
declared
|
|
@@ -5136,10 +5261,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5136
5261
|
};
|
|
5137
5262
|
var namedParameterCollaborator = (annotated) => {
|
|
5138
5263
|
let target = annotated;
|
|
5139
|
-
if (target.type ===
|
|
5264
|
+
if (target.type === import_utils35.AST_NODE_TYPES.TSParameterProperty)
|
|
5140
5265
|
target = target.parameter;
|
|
5141
|
-
if (target.type ===
|
|
5142
|
-
if (target.type !==
|
|
5266
|
+
if (target.type === import_utils35.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5267
|
+
if (target.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5143
5268
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5144
5269
|
if (reference === null) return null;
|
|
5145
5270
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5151,12 +5276,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5151
5276
|
if (members === null) return [];
|
|
5152
5277
|
const collaborators = [];
|
|
5153
5278
|
for (const property of pattern.properties) {
|
|
5154
|
-
if (property.type !==
|
|
5279
|
+
if (property.type !== import_utils35.AST_NODE_TYPES.Property || property.computed)
|
|
5155
5280
|
continue;
|
|
5156
|
-
if (property.key.type !==
|
|
5281
|
+
if (property.key.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5157
5282
|
const key = property.key.name;
|
|
5158
|
-
const bound = property.value.type ===
|
|
5159
|
-
if (bound.type !==
|
|
5283
|
+
const bound = property.value.type === import_utils35.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
5284
|
+
if (bound.type !== import_utils35.AST_NODE_TYPES.Identifier) continue;
|
|
5160
5285
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5161
5286
|
const reference = members.get(key);
|
|
5162
5287
|
if (reference === void 0) continue;
|
|
@@ -5166,22 +5291,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5166
5291
|
};
|
|
5167
5292
|
var bagMemberTypes = (annotation, declared) => {
|
|
5168
5293
|
if (annotation === void 0) return null;
|
|
5169
|
-
if (annotation.type ===
|
|
5294
|
+
if (annotation.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5170
5295
|
return propertySignatureTypes(annotation.members);
|
|
5171
5296
|
}
|
|
5172
|
-
if (annotation.type !==
|
|
5297
|
+
if (annotation.type !== import_utils35.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5173
5298
|
return null;
|
|
5174
5299
|
}
|
|
5175
5300
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5176
5301
|
};
|
|
5177
5302
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5178
|
-
if (node.type ===
|
|
5303
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5179
5304
|
const { callee } = node;
|
|
5180
|
-
if (callee.type ===
|
|
5305
|
+
if (callee.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5181
5306
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5182
|
-
return callee.type ===
|
|
5307
|
+
return callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils35.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
5183
5308
|
}
|
|
5184
|
-
return node.type ===
|
|
5309
|
+
return node.type === import_utils35.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils35.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
5185
5310
|
});
|
|
5186
5311
|
var subtreeHas = (root, found) => {
|
|
5187
5312
|
let hit = false;
|
|
@@ -5201,26 +5326,26 @@ var subtreeHas = (root, found) => {
|
|
|
5201
5326
|
};
|
|
5202
5327
|
var invokedInstanceField = (call) => {
|
|
5203
5328
|
let callee = unwrapExpression(call.callee);
|
|
5204
|
-
while (callee.type ===
|
|
5329
|
+
while (callee.type === import_utils35.AST_NODE_TYPES.ChainExpression)
|
|
5205
5330
|
callee = unwrapExpression(callee.expression);
|
|
5206
5331
|
const direct = instanceField(callee);
|
|
5207
5332
|
if (direct !== null) return direct;
|
|
5208
|
-
return callee.type ===
|
|
5333
|
+
return callee.type === import_utils35.AST_NODE_TYPES.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5209
5334
|
};
|
|
5210
5335
|
var instanceField = (candidate2) => {
|
|
5211
5336
|
let node = candidate2;
|
|
5212
|
-
while (node.type ===
|
|
5337
|
+
while (node.type === import_utils35.AST_NODE_TYPES.ChainExpression || node.type === import_utils35.AST_NODE_TYPES.TSAsExpression || node.type === import_utils35.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils35.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils35.AST_NODE_TYPES.TSTypeAssertion)
|
|
5213
5338
|
node = node.expression;
|
|
5214
|
-
return node.type ===
|
|
5339
|
+
return node.type === import_utils35.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils35.AST_NODE_TYPES.ThisExpression ? staticMemberName(node) : null;
|
|
5215
5340
|
};
|
|
5216
5341
|
function writtenInstanceField(node) {
|
|
5217
|
-
if (node.type ===
|
|
5342
|
+
if (node.type === import_utils35.AST_NODE_TYPES.AssignmentExpression || node.type === import_utils35.AST_NODE_TYPES.ForOfStatement || node.type === import_utils35.AST_NODE_TYPES.ForInStatement)
|
|
5218
5343
|
return instanceField(node.left);
|
|
5219
|
-
if (node.type ===
|
|
5344
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UpdateExpression)
|
|
5220
5345
|
return instanceField(node.argument);
|
|
5221
|
-
if (node.type ===
|
|
5346
|
+
if (node.type === import_utils35.AST_NODE_TYPES.UnaryExpression && node.operator === "delete")
|
|
5222
5347
|
return instanceField(node.argument);
|
|
5223
|
-
if (node.type ===
|
|
5348
|
+
if (node.type === import_utils35.AST_NODE_TYPES.MemberExpression && isDestructuredWriteTarget(node))
|
|
5224
5349
|
return instanceField(node);
|
|
5225
5350
|
return null;
|
|
5226
5351
|
}
|
|
@@ -5229,39 +5354,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5229
5354
|
let target = access;
|
|
5230
5355
|
for (; ; ) {
|
|
5231
5356
|
const parent = target.parent;
|
|
5232
|
-
if (parent.type ===
|
|
5357
|
+
if (parent.type === import_utils35.AST_NODE_TYPES.Property && parent.value === target && parent.parent.type === import_utils35.AST_NODE_TYPES.ObjectPattern) {
|
|
5233
5358
|
target = parent.parent;
|
|
5234
5359
|
continue;
|
|
5235
5360
|
}
|
|
5236
|
-
if (parent.type ===
|
|
5361
|
+
if (parent.type === import_utils35.AST_NODE_TYPES.ArrayPattern || parent.type === import_utils35.AST_NODE_TYPES.ObjectPattern || parent.type === import_utils35.AST_NODE_TYPES.RestElement && parent.argument === target || parent.type === import_utils35.AST_NODE_TYPES.AssignmentPattern && parent.left === target) {
|
|
5237
5362
|
target = parent;
|
|
5238
5363
|
continue;
|
|
5239
5364
|
}
|
|
5240
|
-
return target !== access && (parent.type ===
|
|
5365
|
+
return target !== access && (parent.type === import_utils35.AST_NODE_TYPES.AssignmentExpression || parent.type === import_utils35.AST_NODE_TYPES.ForOfStatement || parent.type === import_utils35.AST_NODE_TYPES.ForInStatement) && parent.left === target;
|
|
5241
5366
|
}
|
|
5242
5367
|
}
|
|
5243
5368
|
var behaviorallyInvokedFields = (body3) => {
|
|
5244
5369
|
const invoked = /* @__PURE__ */ new Set();
|
|
5245
5370
|
const visit = (current) => {
|
|
5246
|
-
if (current.type ===
|
|
5371
|
+
if (current.type === import_utils35.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils35.AST_NODE_TYPES.ClassExpression || current.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils35.AST_NODE_TYPES.FunctionExpression)
|
|
5247
5372
|
return;
|
|
5248
|
-
if (current.type ===
|
|
5373
|
+
if (current.type === import_utils35.AST_NODE_TYPES.CallExpression) {
|
|
5249
5374
|
const field = invokedInstanceField(current);
|
|
5250
5375
|
if (field !== null) invoked.add(field);
|
|
5251
5376
|
}
|
|
5252
5377
|
forEachOwnAstChild(current, visit);
|
|
5253
5378
|
};
|
|
5254
5379
|
for (const member3 of body3.body) {
|
|
5255
|
-
if (member3.type ===
|
|
5256
|
-
if (member3.type ===
|
|
5380
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.StaticBlock || member3.static) continue;
|
|
5381
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition) {
|
|
5257
5382
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5258
5383
|
visit(member3.value.body);
|
|
5259
5384
|
continue;
|
|
5260
5385
|
}
|
|
5261
|
-
if (member3.type !==
|
|
5386
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition || member3.value === null)
|
|
5262
5387
|
continue;
|
|
5263
5388
|
visit(
|
|
5264
|
-
member3.value.type ===
|
|
5389
|
+
member3.value.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5265
5390
|
);
|
|
5266
5391
|
}
|
|
5267
5392
|
return invoked;
|
|
@@ -5281,8 +5406,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5281
5406
|
var fileInterfaceNames = (program) => {
|
|
5282
5407
|
const names = [];
|
|
5283
5408
|
for (const statement of program.body) {
|
|
5284
|
-
const declaration = statement.type ===
|
|
5285
|
-
if (declaration?.type ===
|
|
5409
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5410
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration)
|
|
5286
5411
|
names.push(declaration.id.name);
|
|
5287
5412
|
}
|
|
5288
5413
|
return names;
|
|
@@ -5290,22 +5415,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5290
5415
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5291
5416
|
const names = [];
|
|
5292
5417
|
function collectPublicCallable(member3) {
|
|
5293
|
-
if (member3.type ===
|
|
5418
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.PropertyDefinition) {
|
|
5294
5419
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5295
5420
|
return;
|
|
5296
|
-
if (member3.key.type ===
|
|
5297
|
-
if (member3.value?.type !==
|
|
5421
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5422
|
+
if (member3.value?.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression && member3.value?.type !== import_utils35.AST_NODE_TYPES.FunctionExpression && member3.typeAnnotation?.typeAnnotation.type !== import_utils35.AST_NODE_TYPES.TSFunctionType && !(member3.typeAnnotation?.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSTypeReference && member3.typeAnnotation.typeAnnotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(
|
|
5298
5423
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5299
5424
|
)))
|
|
5300
5425
|
return;
|
|
5301
5426
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5302
5427
|
return;
|
|
5303
5428
|
}
|
|
5304
|
-
if (member3.type !==
|
|
5429
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition) return;
|
|
5305
5430
|
if (member3.kind !== "method" || member3.static) return;
|
|
5306
5431
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5307
5432
|
return;
|
|
5308
|
-
if (member3.key.type ===
|
|
5433
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5309
5434
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5310
5435
|
}
|
|
5311
5436
|
for (const member3 of body3.body) {
|
|
@@ -5316,13 +5441,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5316
5441
|
var isFluentConstructionObject = (node, getText) => {
|
|
5317
5442
|
if (node.id === null) return false;
|
|
5318
5443
|
const methods = node.body.body.filter(
|
|
5319
|
-
(member3) => member3.type ===
|
|
5444
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "method" && !member3.static && member3.accessibility !== "private" && member3.accessibility !== "protected" && member3.value.body !== null
|
|
5320
5445
|
);
|
|
5321
5446
|
if (methods.length === 0) return false;
|
|
5322
5447
|
return methods.every((member3) => {
|
|
5323
5448
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5324
5449
|
if (result === void 0) return false;
|
|
5325
|
-
const returnsOwnType = result.type ===
|
|
5450
|
+
const returnsOwnType = result.type === import_utils35.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
5326
5451
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5327
5452
|
});
|
|
5328
5453
|
};
|
|
@@ -5330,10 +5455,10 @@ function localClassAbstractness(program) {
|
|
|
5330
5455
|
const classes = /* @__PURE__ */ new Map();
|
|
5331
5456
|
const parents = /* @__PURE__ */ new Map();
|
|
5332
5457
|
for (const statement of program.body) {
|
|
5333
|
-
const declaration = statement.type ===
|
|
5334
|
-
if (declaration?.type ===
|
|
5458
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5459
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
5335
5460
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5336
|
-
if (declaration.superClass?.type ===
|
|
5461
|
+
if (declaration.superClass?.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5337
5462
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5338
5463
|
}
|
|
5339
5464
|
}
|
|
@@ -5351,9 +5476,9 @@ function localClassAbstractness(program) {
|
|
|
5351
5476
|
return classes;
|
|
5352
5477
|
}
|
|
5353
5478
|
function declaredMemberName(member3) {
|
|
5354
|
-
if (!member3.computed && member3.key.type ===
|
|
5479
|
+
if (!member3.computed && member3.key.type === import_utils35.AST_NODE_TYPES.Identifier)
|
|
5355
5480
|
return member3.key.name;
|
|
5356
|
-
if (member3.key.type ===
|
|
5481
|
+
if (member3.key.type === import_utils35.AST_NODE_TYPES.Literal && typeof member3.key.value === "string")
|
|
5357
5482
|
return member3.key.value;
|
|
5358
5483
|
return null;
|
|
5359
5484
|
}
|
|
@@ -5362,35 +5487,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5362
5487
|
const parents = /* @__PURE__ */ new Map();
|
|
5363
5488
|
const functionAliases = localFunctionAliases(program);
|
|
5364
5489
|
function collectInterfaceSurface(statement) {
|
|
5365
|
-
const declaration = statement.type ===
|
|
5366
|
-
if (declaration?.type ===
|
|
5490
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5491
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
5367
5492
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5368
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5493
|
+
const parts = declaration.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5369
5494
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5370
5495
|
for (const part of parts) {
|
|
5371
|
-
if (part.type ===
|
|
5496
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5372
5497
|
inherited.push(part.typeName.name);
|
|
5373
5498
|
continue;
|
|
5374
5499
|
}
|
|
5375
|
-
if (part.type ===
|
|
5500
|
+
if (part.type === import_utils35.AST_NODE_TYPES.TSTypeReference) {
|
|
5376
5501
|
inherited.push("*");
|
|
5377
5502
|
continue;
|
|
5378
5503
|
}
|
|
5379
|
-
if (part.type !==
|
|
5504
|
+
if (part.type !== import_utils35.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
5380
5505
|
addCallableMembers(part.members, callables2);
|
|
5381
5506
|
}
|
|
5382
5507
|
interfaces.set(declaration.id.name, callables2);
|
|
5383
5508
|
parents.set(declaration.id.name, inherited);
|
|
5384
5509
|
return;
|
|
5385
5510
|
}
|
|
5386
|
-
if (declaration?.type !==
|
|
5511
|
+
if (declaration?.type !== import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration) return;
|
|
5387
5512
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5388
5513
|
addCallableMembers(declaration.body.body, callables);
|
|
5389
5514
|
interfaces.set(declaration.id.name, callables);
|
|
5390
5515
|
parents.set(declaration.id.name, [
|
|
5391
5516
|
...parents.get(declaration.id.name) ?? [],
|
|
5392
5517
|
...declaration.extends.flatMap(
|
|
5393
|
-
(heritage) => heritage.expression.type ===
|
|
5518
|
+
(heritage) => heritage.expression.type === import_utils35.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
5394
5519
|
)
|
|
5395
5520
|
]);
|
|
5396
5521
|
}
|
|
@@ -5399,17 +5524,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5399
5524
|
}
|
|
5400
5525
|
function addCallableMembers(members, callables) {
|
|
5401
5526
|
for (const member3 of members) {
|
|
5402
|
-
if (member3.type !==
|
|
5527
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature)
|
|
5403
5528
|
continue;
|
|
5404
5529
|
const name = declaredMemberName(member3);
|
|
5405
5530
|
if (name === null) continue;
|
|
5406
|
-
if (member3.type ===
|
|
5531
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSMethodSignature) {
|
|
5407
5532
|
callables.add(name);
|
|
5408
5533
|
continue;
|
|
5409
5534
|
}
|
|
5410
|
-
if (member3.type !==
|
|
5535
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5411
5536
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5412
|
-
if (annotation?.type ===
|
|
5537
|
+
if (annotation?.type === import_utils35.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name))
|
|
5413
5538
|
callables.add(name);
|
|
5414
5539
|
}
|
|
5415
5540
|
}
|
|
@@ -5439,7 +5564,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5439
5564
|
}
|
|
5440
5565
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5441
5566
|
if (node.superClass !== null) {
|
|
5442
|
-
if (node.superClass.type !==
|
|
5567
|
+
if (node.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return true;
|
|
5443
5568
|
const localAbstract = classes.get(node.superClass.name);
|
|
5444
5569
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5445
5570
|
}
|
|
@@ -5478,7 +5603,7 @@ var require_port_for_service_default = createRule({
|
|
|
5478
5603
|
if (node.abstract === true) return;
|
|
5479
5604
|
if (node.decorators.length > 0) return;
|
|
5480
5605
|
const ctor = node.body.body.find(
|
|
5481
|
-
(member3) => member3.type ===
|
|
5606
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null && member3.value.body !== void 0
|
|
5482
5607
|
);
|
|
5483
5608
|
if (ctor === void 0) return;
|
|
5484
5609
|
const constructorFacts = readConstructor(
|
|
@@ -5528,7 +5653,7 @@ var require_port_for_service_default = createRule({
|
|
|
5528
5653
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5529
5654
|
const combined = /* @__PURE__ */ new Set();
|
|
5530
5655
|
for (const implementation of node.implements) {
|
|
5531
|
-
if (implementation.expression.type !==
|
|
5656
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5532
5657
|
return true;
|
|
5533
5658
|
const name = implementation.expression.name;
|
|
5534
5659
|
const localAbstract = classes.get(name);
|
|
@@ -5545,7 +5670,7 @@ function createServiceOperationResolver(program) {
|
|
|
5545
5670
|
let declaredTypes = null;
|
|
5546
5671
|
return (node) => {
|
|
5547
5672
|
const ctor = node.body.body.find(
|
|
5548
|
-
(member3) => member3.type ===
|
|
5673
|
+
(member3) => member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5549
5674
|
);
|
|
5550
5675
|
if (ctor === void 0) return [];
|
|
5551
5676
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5563,7 +5688,7 @@ function createServiceOperationResolver(program) {
|
|
|
5563
5688
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5564
5689
|
forEachServiceCall(body3, (call) => {
|
|
5565
5690
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5566
|
-
if (call.callee.type ===
|
|
5691
|
+
if (call.callee.type === import_utils35.AST_NODE_TYPES.MemberExpression && call.callee.object.type === import_utils35.AST_NODE_TYPES.ThisExpression) {
|
|
5567
5692
|
const callee = staticMemberName(call.callee);
|
|
5568
5693
|
if (callee !== null) {
|
|
5569
5694
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5602,11 +5727,11 @@ function serviceOperationBodies(node) {
|
|
|
5602
5727
|
});
|
|
5603
5728
|
}
|
|
5604
5729
|
for (const member3 of node.body.body) {
|
|
5605
|
-
if (member3.type !==
|
|
5730
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.MethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.PropertyDefinition)
|
|
5606
5731
|
continue;
|
|
5607
|
-
if (member3.static || member3.decorators.length > 0 || member3.type ===
|
|
5732
|
+
if (member3.static || member3.decorators.length > 0 || member3.type === import_utils35.AST_NODE_TYPES.MethodDefinition && member3.kind !== "method")
|
|
5608
5733
|
continue;
|
|
5609
|
-
if (member3.value?.type !==
|
|
5734
|
+
if (member3.value?.type !== import_utils35.AST_NODE_TYPES.FunctionExpression && member3.value?.type !== import_utils35.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
5610
5735
|
continue;
|
|
5611
5736
|
const name = declaredMemberName(member3);
|
|
5612
5737
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5615,9 +5740,9 @@ function serviceOperationBodies(node) {
|
|
|
5615
5740
|
return bodies;
|
|
5616
5741
|
}
|
|
5617
5742
|
function forEachServiceCall(node, onCall) {
|
|
5618
|
-
if (node.type ===
|
|
5743
|
+
if (node.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils35.AST_NODE_TYPES.FunctionExpression || node.type === import_utils35.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils35.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils35.AST_NODE_TYPES.ClassExpression)
|
|
5619
5744
|
return;
|
|
5620
|
-
if (node.type ===
|
|
5745
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement) {
|
|
5621
5746
|
for (const statement of node.body) {
|
|
5622
5747
|
forEachServiceCall(statement, onCall);
|
|
5623
5748
|
if (terminatesOperation(statement)) break;
|
|
@@ -5629,29 +5754,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5629
5754
|
forEachServiceCall(branch, onCall);
|
|
5630
5755
|
return;
|
|
5631
5756
|
}
|
|
5632
|
-
if (node.type ===
|
|
5757
|
+
if (node.type === import_utils35.AST_NODE_TYPES.CallExpression) onCall(node);
|
|
5633
5758
|
forEachOwnAstChild(node, (child) => {
|
|
5634
5759
|
forEachServiceCall(child, onCall);
|
|
5635
5760
|
});
|
|
5636
5761
|
}
|
|
5637
5762
|
function literalExecutionBranch(node) {
|
|
5638
|
-
if (node.type ===
|
|
5763
|
+
if (node.type === import_utils35.AST_NODE_TYPES.WhileStatement && node.test.type === import_utils35.AST_NODE_TYPES.Literal && node.test.value === false)
|
|
5639
5764
|
return node.test;
|
|
5640
|
-
if ((node.type ===
|
|
5765
|
+
if ((node.type === import_utils35.AST_NODE_TYPES.IfStatement || node.type === import_utils35.AST_NODE_TYPES.ConditionalExpression) && node.test.type === import_utils35.AST_NODE_TYPES.Literal && typeof node.test.value === "boolean") {
|
|
5641
5766
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5642
5767
|
}
|
|
5643
|
-
if (node.type !==
|
|
5768
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.LogicalExpression || node.left.type !== import_utils35.AST_NODE_TYPES.Literal || typeof node.left.value !== "boolean")
|
|
5644
5769
|
return null;
|
|
5645
5770
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5646
5771
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5647
5772
|
return node.left;
|
|
5648
5773
|
}
|
|
5649
5774
|
function terminatesOperation(node) {
|
|
5650
|
-
if (node.type ===
|
|
5775
|
+
if (node.type === import_utils35.AST_NODE_TYPES.ReturnStatement || node.type === import_utils35.AST_NODE_TYPES.ThrowStatement)
|
|
5651
5776
|
return true;
|
|
5652
|
-
if (node.type ===
|
|
5777
|
+
if (node.type === import_utils35.AST_NODE_TYPES.BlockStatement)
|
|
5653
5778
|
return node.body.some(terminatesOperation);
|
|
5654
|
-
if (node.type !==
|
|
5779
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.IfStatement) return false;
|
|
5655
5780
|
const branch = literalExecutionBranch(node);
|
|
5656
5781
|
if (branch !== null) return terminatesOperation(branch);
|
|
5657
5782
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5665,7 +5790,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5665
5790
|
const seen = /* @__PURE__ */ new Set();
|
|
5666
5791
|
function addImplementedContracts(current) {
|
|
5667
5792
|
for (const implementation of current.implements) {
|
|
5668
|
-
if (implementation.expression.type !==
|
|
5793
|
+
if (implementation.expression.type !== import_utils35.AST_NODE_TYPES.Identifier)
|
|
5669
5794
|
return false;
|
|
5670
5795
|
const name = implementation.expression.name;
|
|
5671
5796
|
const surface = interfaces.get(name);
|
|
@@ -5688,7 +5813,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5688
5813
|
}
|
|
5689
5814
|
if (!addImplementedContracts(current)) return null;
|
|
5690
5815
|
if (current.superClass === null) continue;
|
|
5691
|
-
if (current.superClass.type !==
|
|
5816
|
+
if (current.superClass.type !== import_utils35.AST_NODE_TYPES.Identifier) return null;
|
|
5692
5817
|
const base = classes.get(current.superClass.name);
|
|
5693
5818
|
if (base === void 0) return null;
|
|
5694
5819
|
pending.push(base);
|
|
@@ -5698,8 +5823,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5698
5823
|
function localClassDeclarations(program) {
|
|
5699
5824
|
const classes = /* @__PURE__ */ new Map();
|
|
5700
5825
|
for (const statement of program.body) {
|
|
5701
|
-
const declaration = statement.type ===
|
|
5702
|
-
if (declaration?.type ===
|
|
5826
|
+
const declaration = statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5827
|
+
if (declaration?.type === import_utils35.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null)
|
|
5703
5828
|
classes.set(declaration.id.name, declaration);
|
|
5704
5829
|
}
|
|
5705
5830
|
return classes;
|
|
@@ -5707,13 +5832,13 @@ function localClassDeclarations(program) {
|
|
|
5707
5832
|
function abstractContractOperations(node, functionAliases) {
|
|
5708
5833
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5709
5834
|
for (const member3 of node.body.body) {
|
|
5710
|
-
if (member3.type !==
|
|
5835
|
+
if (member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractMethodDefinition && member3.type !== import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition)
|
|
5711
5836
|
continue;
|
|
5712
5837
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5713
5838
|
continue;
|
|
5714
|
-
if (member3.type ===
|
|
5839
|
+
if (member3.type === import_utils35.AST_NODE_TYPES.TSAbstractPropertyDefinition) {
|
|
5715
5840
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5716
|
-
if (annotation?.type !==
|
|
5841
|
+
if (annotation?.type !== import_utils35.AST_NODE_TYPES.TSFunctionType && !(annotation?.type === import_utils35.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)))
|
|
5717
5842
|
continue;
|
|
5718
5843
|
}
|
|
5719
5844
|
const name = declaredMemberName(member3);
|
|
@@ -5849,7 +5974,7 @@ function isServiceRole(name, filename) {
|
|
|
5849
5974
|
}
|
|
5850
5975
|
|
|
5851
5976
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
5852
|
-
var
|
|
5977
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5853
5978
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
5854
5979
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
5855
5980
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -5901,7 +6026,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
5901
6026
|
]
|
|
5902
6027
|
};
|
|
5903
6028
|
function isEmptyObject(node) {
|
|
5904
|
-
return node.type ===
|
|
6029
|
+
return node.type === import_utils37.AST_NODE_TYPES.ObjectExpression && node.properties.length === 0;
|
|
5905
6030
|
}
|
|
5906
6031
|
var no_conditional_empty_object_spread_default = createRule({
|
|
5907
6032
|
name: "no-conditional-empty-object-spread",
|
|
@@ -5922,13 +6047,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5922
6047
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
5923
6048
|
return {
|
|
5924
6049
|
SpreadElement(node) {
|
|
5925
|
-
if (node.parent.type !==
|
|
6050
|
+
if (node.parent.type !== import_utils37.AST_NODE_TYPES.ObjectExpression || node.argument.type !== import_utils37.AST_NODE_TYPES.ConditionalExpression)
|
|
5926
6051
|
return;
|
|
5927
6052
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
5928
6053
|
const conditional = node.argument;
|
|
5929
6054
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
5930
6055
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
5931
|
-
const canFix = populated.type ===
|
|
6056
|
+
const canFix = populated.type === import_utils37.AST_NODE_TYPES.ObjectExpression && populated.properties.length > 0 && context.sourceCode.getCommentsInside(conditional).length === 0;
|
|
5932
6057
|
context.report({
|
|
5933
6058
|
node,
|
|
5934
6059
|
messageId: "avoid",
|
|
@@ -5944,7 +6069,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
5944
6069
|
});
|
|
5945
6070
|
|
|
5946
6071
|
// src/rules/prefer-typed-reflection.ts
|
|
5947
|
-
var
|
|
6072
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5948
6073
|
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
5949
6074
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
5950
6075
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
@@ -6017,20 +6142,20 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6017
6142
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6018
6143
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6019
6144
|
return {};
|
|
6020
|
-
const services =
|
|
6145
|
+
const services = import_utils38.ESLintUtils.getParserServices(context);
|
|
6021
6146
|
if (!services.program) return {};
|
|
6022
6147
|
const checker = services.program.getTypeChecker();
|
|
6023
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
6024
|
-
const globalName = (node, name) => node.type ===
|
|
6148
|
+
const isReflect = (node) => globalName(node, "Reflect") || node.type === import_utils38.AST_NODE_TYPES.MemberExpression && import_utils38.ASTUtils.getPropertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
6149
|
+
const globalName = (node, name) => node.type === import_utils38.AST_NODE_TYPES.Identifier && node.name === name && !import_utils38.ASTUtils.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
6025
6150
|
const closedObject = (type) => {
|
|
6026
6151
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
6027
6152
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
6028
6153
|
};
|
|
6029
6154
|
const inspectGet = (node, type) => {
|
|
6030
6155
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
6031
|
-
return node.arguments.length === 2 && (staticString(key) !== null || key?.type ===
|
|
6156
|
+
return node.arguments.length === 2 && (staticString(key) !== null || key?.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number") && closedObject(type);
|
|
6032
6157
|
};
|
|
6033
|
-
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type ===
|
|
6158
|
+
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type === import_utils38.AST_NODE_TYPES.ArrayExpression && knownType(type) && type.getCallSignatures().some(
|
|
6034
6159
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
6035
6160
|
(parameter) => knownType(
|
|
6036
6161
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -6041,25 +6166,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6041
6166
|
)
|
|
6042
6167
|
);
|
|
6043
6168
|
const getReplacement = (node, type, target) => {
|
|
6044
|
-
if (node.optional || node.callee.type !==
|
|
6169
|
+
if (node.optional || node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || node.callee.optional || context.sourceCode.getCommentsInside(node).length > 0) return null;
|
|
6045
6170
|
let outer = node;
|
|
6046
|
-
while (outer.parent.type ===
|
|
6047
|
-
if (outer.parent.type ===
|
|
6171
|
+
while (outer.parent.type === import_utils38.AST_NODE_TYPES.TSAsExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.TSTypeAssertion || outer.parent.type === import_utils38.AST_NODE_TYPES.TSSatisfiesExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.TSNonNullExpression || outer.parent.type === import_utils38.AST_NODE_TYPES.ChainExpression) outer = outer.parent;
|
|
6172
|
+
if (outer.parent.type === import_utils38.AST_NODE_TYPES.UnaryExpression && outer.parent.operator === "delete" || outer.parent.type === import_utils38.AST_NODE_TYPES.CallExpression && outer.parent.callee === outer || outer.parent.type === import_utils38.AST_NODE_TYPES.TaggedTemplateExpression && outer.parent.tag === outer) return null;
|
|
6048
6173
|
const writtenKey = node.arguments[1];
|
|
6049
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6174
|
+
if (writtenKey === void 0 || writtenKey.type === import_utils38.AST_NODE_TYPES.SpreadElement) return null;
|
|
6050
6175
|
const key = unwrapExpression(writtenKey);
|
|
6051
|
-
const name = staticString(key) ?? (key.type ===
|
|
6176
|
+
const name = staticString(key) ?? (key.type === import_utils38.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
6052
6177
|
const members = type.isUnion() ? type.types : [type];
|
|
6053
6178
|
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
6054
6179
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
6055
6180
|
};
|
|
6056
6181
|
return {
|
|
6057
6182
|
CallExpression(node) {
|
|
6058
|
-
if (node.callee.type !==
|
|
6183
|
+
if (node.callee.type !== import_utils38.AST_NODE_TYPES.MemberExpression || !isReflect(node.callee.object))
|
|
6059
6184
|
return;
|
|
6060
|
-
const method =
|
|
6185
|
+
const method = import_utils38.ASTUtils.getPropertyName(node.callee);
|
|
6061
6186
|
const target = node.arguments[0];
|
|
6062
|
-
if (!target || target.type ===
|
|
6187
|
+
if (!target || target.type === import_utils38.AST_NODE_TYPES.SpreadElement || method !== "get" && method !== "apply")
|
|
6063
6188
|
return;
|
|
6064
6189
|
const type = checker.getTypeAtLocation(
|
|
6065
6190
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6074,28 +6199,28 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6074
6199
|
});
|
|
6075
6200
|
|
|
6076
6201
|
// src/rules/no-broad-return-type.ts
|
|
6077
|
-
var
|
|
6202
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
6078
6203
|
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
6079
6204
|
|
|
6080
6205
|
// src/rules/_unused-private-binding.ts
|
|
6081
|
-
var
|
|
6206
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6082
6207
|
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6083
6208
|
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6084
6209
|
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6085
6210
|
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
6086
6211
|
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 ===
|
|
6212
|
+
const statement = declaration.type === import_utils39.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
6213
|
+
if (statement.parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
6214
|
+
if (statement.parent.type !== import_utils39.AST_NODE_TYPES.Program) return statement.parent.type === import_utils39.AST_NODE_TYPES.BlockStatement;
|
|
6215
|
+
return sourceCode.ast.body.some((node) => node.type === import_utils39.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportAllDeclaration);
|
|
6091
6216
|
}
|
|
6092
6217
|
function hasOnlyDirectFactoryUses(variable) {
|
|
6093
6218
|
return variable.references.every((reference) => {
|
|
6094
6219
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6095
6220
|
const identifier = reference.identifier;
|
|
6096
6221
|
const parent = identifier.parent;
|
|
6097
|
-
if (parent.type ===
|
|
6098
|
-
return parent.type ===
|
|
6222
|
+
if (parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
6223
|
+
return parent.type === import_utils39.AST_NODE_TYPES.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent;
|
|
6099
6224
|
});
|
|
6100
6225
|
}
|
|
6101
6226
|
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
@@ -6109,7 +6234,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6109
6234
|
const current = pending.pop();
|
|
6110
6235
|
if (current === void 0 || seen.has(current)) continue;
|
|
6111
6236
|
seen.add(current);
|
|
6112
|
-
if (current.type ===
|
|
6237
|
+
if (current.type === import_utils39.AST_NODE_TYPES.Identifier || current.type === import_utils39.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
6113
6238
|
forEachOwnAstChild(current, (child) => {
|
|
6114
6239
|
pending.push(child);
|
|
6115
6240
|
}, (key) => key !== "tokens" && key !== "comments");
|
|
@@ -6120,7 +6245,7 @@ function hasIdentifierNamed(node, name) {
|
|
|
6120
6245
|
return names.has(name);
|
|
6121
6246
|
}
|
|
6122
6247
|
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6123
|
-
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !==
|
|
6248
|
+
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== import_utils39.AST_NODE_TYPES.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
6124
6249
|
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6125
6250
|
}
|
|
6126
6251
|
|
|
@@ -6209,7 +6334,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6209
6334
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6210
6335
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6211
6336
|
return {};
|
|
6212
|
-
const services =
|
|
6337
|
+
const services = import_utils40.ESLintUtils.getParserServices(context);
|
|
6213
6338
|
if (!services.program) return {};
|
|
6214
6339
|
const checker = services.program.getTypeChecker();
|
|
6215
6340
|
const frames = [];
|
|
@@ -6234,7 +6359,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6234
6359
|
known: false,
|
|
6235
6360
|
opaque: false
|
|
6236
6361
|
});
|
|
6237
|
-
if (node.body && node.body.type !==
|
|
6362
|
+
if (node.body && node.body.type !== import_utils40.AST_NODE_TYPES.BlockStatement)
|
|
6238
6363
|
inspectReturn(node.body);
|
|
6239
6364
|
};
|
|
6240
6365
|
const leave = () => {
|
|
@@ -6242,7 +6367,7 @@ var no_broad_return_type_default = createRule({
|
|
|
6242
6367
|
if (frame?.annotation && frame.known && !frame.opaque) {
|
|
6243
6368
|
const annotation = frame.annotation;
|
|
6244
6369
|
const node = frame.node;
|
|
6245
|
-
const canFix = node.type ===
|
|
6370
|
+
const canFix = node.type === import_utils40.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && isUnusedPrivateBinding(context.sourceCode, node, node.id, context.filename) && context.sourceCode.getCommentsInside(annotation).length === 0 && retainsNamedTypeUses(context.sourceCode, annotation);
|
|
6246
6371
|
context.report({ node: annotation, messageId: "avoid", fix: canFix ? (fixer) => fixer.replaceText(annotation, context.sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")) : null });
|
|
6247
6372
|
}
|
|
6248
6373
|
};
|
|
@@ -6261,43 +6386,43 @@ var no_broad_return_type_default = createRule({
|
|
|
6261
6386
|
});
|
|
6262
6387
|
|
|
6263
6388
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
6264
|
-
var
|
|
6389
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6265
6390
|
var import_typescript14 = __toESM(require("typescript"), 1);
|
|
6266
6391
|
|
|
6267
6392
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
6268
|
-
var
|
|
6393
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6269
6394
|
function literalIdentityReduceFix(sourceCode, node) {
|
|
6270
|
-
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !==
|
|
6395
|
+
if (sourceCode.ast.body.length !== 1 || sourceCode.getAllComments().length > 0 || node.optional || node.arguments.length !== 2 || node.callee.type !== import_utils41.AST_NODE_TYPES.MemberExpression || node.callee.optional || import_utils41.ASTUtils.getPropertyName(node.callee) !== "reduce")
|
|
6271
6396
|
return null;
|
|
6272
6397
|
const values = node.callee.object;
|
|
6273
|
-
if (values.type !==
|
|
6274
|
-
(element) => element?.type ===
|
|
6398
|
+
if (values.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || values.elements.length === 0 || !values.elements.every(
|
|
6399
|
+
(element) => element?.type === import_utils41.AST_NODE_TYPES.Literal && typeof element.value === "string"
|
|
6275
6400
|
))
|
|
6276
6401
|
return null;
|
|
6277
6402
|
const statement = sourceCode.ast.body[0];
|
|
6278
|
-
if (statement?.type !==
|
|
6403
|
+
if (statement?.type !== import_utils41.AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration?.type !== import_utils41.AST_NODE_TYPES.FunctionDeclaration)
|
|
6279
6404
|
return null;
|
|
6280
6405
|
const owner = statement.declaration;
|
|
6281
6406
|
if (owner.async || owner.declare || owner.generator || owner.typeParameters !== void 0 || owner.params.length !== 0 || owner.body.body.length !== 1 || !stringArray(owner.returnType?.typeAnnotation))
|
|
6282
6407
|
return null;
|
|
6283
6408
|
const returned2 = owner.body.body[0];
|
|
6284
|
-
if (returned2?.type !==
|
|
6409
|
+
if (returned2?.type !== import_utils41.AST_NODE_TYPES.ReturnStatement || returned2.argument !== node || node.typeArguments?.params.length !== 1 || !stringArray(node.typeArguments.params[0]))
|
|
6285
6410
|
return null;
|
|
6286
6411
|
const [callback, seed] = node.arguments;
|
|
6287
|
-
if (seed?.type !==
|
|
6412
|
+
if (seed?.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || seed.elements.length !== 0 || callback?.type !== import_utils41.AST_NODE_TYPES.ArrowFunctionExpression || callback.async || callback.typeParameters !== void 0 || callback.returnType !== void 0 || callback.params.length !== 2 || callback.body.type !== import_utils41.AST_NODE_TYPES.ArrayExpression || callback.body.elements.length !== 2)
|
|
6288
6413
|
return null;
|
|
6289
6414
|
if (!identitySpread(sourceCode, callback)) return null;
|
|
6290
6415
|
return (fixer) => fixer.replaceText(node, sourceCode.getText(values));
|
|
6291
6416
|
}
|
|
6292
6417
|
function stringArray(node) {
|
|
6293
|
-
return node?.type ===
|
|
6418
|
+
return node?.type === import_utils41.AST_NODE_TYPES.TSArrayType && node.elementType.type === import_utils41.AST_NODE_TYPES.TSStringKeyword;
|
|
6294
6419
|
}
|
|
6295
6420
|
function identitySpread(sourceCode, callback) {
|
|
6296
6421
|
const [accumulator, item] = callback.params;
|
|
6297
|
-
if (accumulator?.type !==
|
|
6422
|
+
if (accumulator?.type !== import_utils41.AST_NODE_TYPES.Identifier || item?.type !== import_utils41.AST_NODE_TYPES.Identifier || accumulator.name === item.name || accumulator.optional || item.optional || accumulator.typeAnnotation !== void 0 || item.typeAnnotation !== void 0 || callback.body.type !== import_utils41.AST_NODE_TYPES.ArrayExpression)
|
|
6298
6423
|
return false;
|
|
6299
6424
|
const [spread, appended] = callback.body.elements;
|
|
6300
|
-
if (spread?.type !==
|
|
6425
|
+
if (spread?.type !== import_utils41.AST_NODE_TYPES.SpreadElement || spread.argument.type !== import_utils41.AST_NODE_TYPES.Identifier || appended?.type !== import_utils41.AST_NODE_TYPES.Identifier || spread.argument.name !== accumulator.name || appended.name !== item.name)
|
|
6301
6426
|
return false;
|
|
6302
6427
|
const bindings = sourceCode.getDeclaredVariables(callback);
|
|
6303
6428
|
const left = bindings.find(
|
|
@@ -6306,10 +6431,10 @@ function identitySpread(sourceCode, callback) {
|
|
|
6306
6431
|
const right = bindings.find(
|
|
6307
6432
|
(variable) => variable.identifiers.includes(item)
|
|
6308
6433
|
);
|
|
6309
|
-
return left !== void 0 && right !== void 0 &&
|
|
6434
|
+
return left !== void 0 && right !== void 0 && import_utils41.ASTUtils.findVariable(
|
|
6310
6435
|
sourceCode.getScope(spread.argument),
|
|
6311
6436
|
spread.argument.name
|
|
6312
|
-
) === left &&
|
|
6437
|
+
) === left && import_utils41.ASTUtils.findVariable(sourceCode.getScope(appended), appended.name) === right;
|
|
6313
6438
|
}
|
|
6314
6439
|
|
|
6315
6440
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
@@ -6399,25 +6524,25 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6399
6524
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6400
6525
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6401
6526
|
return {};
|
|
6402
|
-
const services =
|
|
6527
|
+
const services = import_utils42.ESLintUtils.getParserServices(context);
|
|
6403
6528
|
const program = services.program;
|
|
6404
6529
|
if (program === null) return {};
|
|
6405
6530
|
const checker = program.getTypeChecker();
|
|
6406
6531
|
return {
|
|
6407
6532
|
CallExpression(node) {
|
|
6408
|
-
if (node.callee.type !==
|
|
6409
|
-
|
|
6533
|
+
if (node.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression || !["reduce", "reduceRight"].includes(
|
|
6534
|
+
import_utils42.ASTUtils.getPropertyName(node.callee) ?? ""
|
|
6410
6535
|
) || node.arguments.length !== 2)
|
|
6411
6536
|
return;
|
|
6412
6537
|
const seed = node.arguments[1];
|
|
6413
|
-
const arraySeed = seed?.type ===
|
|
6414
|
-
const objectSeed = seed?.type ===
|
|
6538
|
+
const arraySeed = seed?.type === import_utils42.AST_NODE_TYPES.ArrayExpression && seed.elements.length === 0;
|
|
6539
|
+
const objectSeed = seed?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && seed.properties.length === 0;
|
|
6415
6540
|
if (!arraySeed && !objectSeed) return;
|
|
6416
6541
|
const callback = node.arguments[0];
|
|
6417
|
-
if (!callback || callback.type !==
|
|
6542
|
+
if (!callback || callback.type !== import_utils42.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils42.AST_NODE_TYPES.FunctionExpression)
|
|
6418
6543
|
return;
|
|
6419
6544
|
const parameter = callback.params[0];
|
|
6420
|
-
if (parameter?.type !==
|
|
6545
|
+
if (parameter?.type !== import_utils42.AST_NODE_TYPES.Identifier) return;
|
|
6421
6546
|
const signature = checker.getResolvedSignature(
|
|
6422
6547
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
6423
6548
|
);
|
|
@@ -6428,51 +6553,51 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6428
6553
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
6429
6554
|
return;
|
|
6430
6555
|
const fix = literalIdentityReduceFix(context.sourceCode, node);
|
|
6431
|
-
const referencesAccumulator = (value) => value.type ===
|
|
6556
|
+
const referencesAccumulator = (value) => value.type === import_utils42.AST_NODE_TYPES.Identifier && import_utils42.ASTUtils.findVariable(
|
|
6432
6557
|
context.sourceCode.getScope(value),
|
|
6433
6558
|
value.name
|
|
6434
6559
|
) === accumulator;
|
|
6435
6560
|
const inspect = (current) => {
|
|
6436
6561
|
if (current !== callback.body && [
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6562
|
+
import_utils42.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
6563
|
+
import_utils42.AST_NODE_TYPES.FunctionExpression,
|
|
6564
|
+
import_utils42.AST_NODE_TYPES.FunctionDeclaration,
|
|
6565
|
+
import_utils42.AST_NODE_TYPES.ClassDeclaration,
|
|
6566
|
+
import_utils42.AST_NODE_TYPES.ClassExpression,
|
|
6567
|
+
import_utils42.AST_NODE_TYPES.ForStatement,
|
|
6568
|
+
import_utils42.AST_NODE_TYPES.ForInStatement,
|
|
6569
|
+
import_utils42.AST_NODE_TYPES.ForOfStatement,
|
|
6570
|
+
import_utils42.AST_NODE_TYPES.WhileStatement,
|
|
6571
|
+
import_utils42.AST_NODE_TYPES.DoWhileStatement
|
|
6447
6572
|
].some((kind) => kind === current.type))
|
|
6448
6573
|
return;
|
|
6449
|
-
if (current.type ===
|
|
6574
|
+
if (current.type === import_utils42.AST_NODE_TYPES.SpreadElement && (arraySeed && current.parent.type === import_utils42.AST_NODE_TYPES.ArrayExpression || objectSeed && current.parent.type === import_utils42.AST_NODE_TYPES.ObjectExpression) && referencesAccumulator(current.argument)) {
|
|
6450
6575
|
context.report({
|
|
6451
6576
|
node: current,
|
|
6452
6577
|
messageId: "copy",
|
|
6453
6578
|
fix
|
|
6454
6579
|
});
|
|
6455
6580
|
}
|
|
6456
|
-
if (current.type ===
|
|
6581
|
+
if (current.type === import_utils42.AST_NODE_TYPES.CallExpression)
|
|
6457
6582
|
inspectCall(current);
|
|
6458
6583
|
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
6459
6584
|
};
|
|
6460
6585
|
const inspectCall = (current) => {
|
|
6461
|
-
if (current.callee.type !==
|
|
6586
|
+
if (current.callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression) return;
|
|
6462
6587
|
const member3 = current.callee;
|
|
6463
|
-
const name =
|
|
6588
|
+
const name = import_utils42.ASTUtils.getPropertyName(member3);
|
|
6464
6589
|
const directCopy = arraySeed && name !== null && COPY_METHODS.has(name) && referencesAccumulator(member3.object);
|
|
6465
|
-
const globalArray = member3.object.type ===
|
|
6590
|
+
const globalArray = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Array" && !import_utils42.ASTUtils.findVariable(
|
|
6466
6591
|
context.sourceCode.getScope(member3.object),
|
|
6467
6592
|
"Array"
|
|
6468
6593
|
)?.defs.length;
|
|
6469
6594
|
const fromCopy = arraySeed && name === "from" && globalArray && current.arguments[0] !== void 0 && referencesAccumulator(current.arguments[0]);
|
|
6470
|
-
const globalObject = member3.object.type ===
|
|
6595
|
+
const globalObject = member3.object.type === import_utils42.AST_NODE_TYPES.Identifier && member3.object.name === "Object" && !import_utils42.ASTUtils.findVariable(
|
|
6471
6596
|
context.sourceCode.getScope(member3.object),
|
|
6472
6597
|
"Object"
|
|
6473
6598
|
)?.defs.length;
|
|
6474
6599
|
const target = current.arguments[0];
|
|
6475
|
-
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type ===
|
|
6600
|
+
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type === import_utils42.AST_NODE_TYPES.ObjectExpression && current.arguments.slice(1).some(referencesAccumulator);
|
|
6476
6601
|
if (directCopy || fromCopy || assignCopy)
|
|
6477
6602
|
context.report({ node: current, messageId: "copy" });
|
|
6478
6603
|
};
|
|
@@ -6483,7 +6608,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
6483
6608
|
});
|
|
6484
6609
|
|
|
6485
6610
|
// src/rules/no-known-value-widening.ts
|
|
6486
|
-
var
|
|
6611
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6487
6612
|
var import_typescript15 = __toESM(require("typescript"), 1);
|
|
6488
6613
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
6489
6614
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
@@ -6533,12 +6658,12 @@ var no_known_value_widening_default = createRule({
|
|
|
6533
6658
|
create(context) {
|
|
6534
6659
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6535
6660
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap) return {};
|
|
6536
|
-
const services =
|
|
6661
|
+
const services = import_utils43.ESLintUtils.getParserServices(context);
|
|
6537
6662
|
if (services.program === null) return {};
|
|
6538
6663
|
const checker = services.program.getTypeChecker();
|
|
6539
6664
|
return {
|
|
6540
6665
|
VariableDeclarator(node) {
|
|
6541
|
-
if (node.id.type !==
|
|
6666
|
+
if (node.id.type !== import_utils43.AST_NODE_TYPES.Identifier || !node.id.typeAnnotation || node.init?.type !== import_utils43.AST_NODE_TYPES.Identifier || node.parent.kind !== "const" || node.parent.parent.type === import_utils43.AST_NODE_TYPES.ExportNamedDeclaration) return;
|
|
6542
6667
|
const source = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.init));
|
|
6543
6668
|
if (hasUnknownContract(source, checker)) return;
|
|
6544
6669
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.id.typeAnnotation.typeAnnotation));
|
|
@@ -6557,7 +6682,7 @@ var no_known_value_widening_default = createRule({
|
|
|
6557
6682
|
});
|
|
6558
6683
|
|
|
6559
6684
|
// src/rules/no-invalid-typed-mutation.ts
|
|
6560
|
-
var
|
|
6685
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6561
6686
|
var import_ts_api_utils = require("ts-api-utils");
|
|
6562
6687
|
var import_typescript16 = __toESM(require("typescript"), 1);
|
|
6563
6688
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
@@ -6594,7 +6719,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6594
6719
|
defaultOptions: [],
|
|
6595
6720
|
create(context) {
|
|
6596
6721
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
6597
|
-
const services =
|
|
6722
|
+
const services = import_utils44.ESLintUtils.getParserServices(context);
|
|
6598
6723
|
const checker = services.program.getTypeChecker();
|
|
6599
6724
|
const candidates = [];
|
|
6600
6725
|
const replaced = /* @__PURE__ */ new Set();
|
|
@@ -6665,7 +6790,7 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6665
6790
|
const target = node.arguments[0];
|
|
6666
6791
|
if (target === void 0) return;
|
|
6667
6792
|
invalidateNamespace(target);
|
|
6668
|
-
if (target.type !==
|
|
6793
|
+
if (target.type !== import_utils44.AST_NODE_TYPES.Identifier) return;
|
|
6669
6794
|
const writes = mutationWrites(node, method.namespace, method.method);
|
|
6670
6795
|
if (writes !== void 0) candidates.push({ call: node, ...method, target, writes });
|
|
6671
6796
|
},
|
|
@@ -6676,9 +6801,9 @@ var no_invalid_typed_mutation_default = createRule({
|
|
|
6676
6801
|
}
|
|
6677
6802
|
});
|
|
6678
6803
|
function localDataTarget(target, sourceCode) {
|
|
6679
|
-
const binding3 =
|
|
6804
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(target), target.name);
|
|
6680
6805
|
const definition = binding3?.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
6681
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !==
|
|
6806
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !== import_utils44.AST_NODE_TYPES.Identifier || definition.node.id.typeAnnotation === void 0 || definition.node.init?.type !== import_utils44.AST_NODE_TYPES.ObjectExpression || definition.parent.parent.type === import_utils44.AST_NODE_TYPES.ExportNamedDeclaration) return void 0;
|
|
6682
6807
|
const properties = plainProperties(definition.node.init);
|
|
6683
6808
|
if (properties === void 0) return void 0;
|
|
6684
6809
|
const scope = sourceCode.getScope(definition.node).variableScope;
|
|
@@ -6689,29 +6814,29 @@ function localDataTarget(target, sourceCode) {
|
|
|
6689
6814
|
return new Set(properties.map((property) => property.key));
|
|
6690
6815
|
}
|
|
6691
6816
|
function safeTargetUse(identifier, sourceCode) {
|
|
6692
|
-
if (identifier.type !==
|
|
6817
|
+
if (identifier.type !== import_utils44.AST_NODE_TYPES.Identifier) return false;
|
|
6693
6818
|
const parent = identifier.parent;
|
|
6694
|
-
if (parent.type ===
|
|
6695
|
-
const key =
|
|
6819
|
+
if (parent.type === import_utils44.AST_NODE_TYPES.MemberExpression && parent.object === identifier) {
|
|
6820
|
+
const key = import_utils44.ASTUtils.getPropertyName(parent);
|
|
6696
6821
|
const use = outerExpression(parent);
|
|
6697
|
-
if (parent.optional || use.parent.type ===
|
|
6698
|
-
return key !== null && key !== "__proto__" && !(use.parent.type ===
|
|
6822
|
+
if (parent.optional || use.parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && use.parent.operator === "delete") return false;
|
|
6823
|
+
return key !== null && key !== "__proto__" && !(use.parent.type === import_utils44.AST_NODE_TYPES.CallExpression && use.parent.callee === use);
|
|
6699
6824
|
}
|
|
6700
|
-
if (parent.type !==
|
|
6825
|
+
if (parent.type !== import_utils44.AST_NODE_TYPES.CallExpression || parent.arguments[0] !== identifier) return false;
|
|
6701
6826
|
const method = nativeMember(parent.callee, sourceCode);
|
|
6702
6827
|
if (method === void 0) return false;
|
|
6703
6828
|
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 ===
|
|
6829
|
+
return writes !== void 0 && writes.every((write) => write.key !== "__proto__") && keepsMutableDescriptor(parent, method.method) && (method.method === "set" || parent.parent.type === import_utils44.AST_NODE_TYPES.ExpressionStatement);
|
|
6705
6830
|
}
|
|
6706
6831
|
function keepsMutableDescriptor(call, method) {
|
|
6707
6832
|
if (method !== "defineProperty") return true;
|
|
6708
6833
|
const descriptor = call.arguments[2];
|
|
6709
|
-
if (descriptor?.type !==
|
|
6834
|
+
if (descriptor?.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return false;
|
|
6710
6835
|
const properties = plainProperties(descriptor);
|
|
6711
6836
|
return properties !== void 0 && properties.every((property) => {
|
|
6712
6837
|
if (property.key !== "writable" && property.key !== "configurable") return true;
|
|
6713
6838
|
const value = unwrapExpression(property.value);
|
|
6714
|
-
return value.type ===
|
|
6839
|
+
return value.type === import_utils44.AST_NODE_TYPES.Literal && value.value === true;
|
|
6715
6840
|
});
|
|
6716
6841
|
}
|
|
6717
6842
|
function declaredTargetType(node, checker) {
|
|
@@ -6761,9 +6886,9 @@ function definiteSignatures(type, checker, seen) {
|
|
|
6761
6886
|
}
|
|
6762
6887
|
function nativeMember(node, sourceCode) {
|
|
6763
6888
|
const member3 = unwrapExpression(node);
|
|
6764
|
-
if (member3.type !==
|
|
6889
|
+
if (member3.type !== import_utils44.AST_NODE_TYPES.MemberExpression || member3.optional) return void 0;
|
|
6765
6890
|
const namespace = nativeNamespace(member3.object, sourceCode);
|
|
6766
|
-
const method =
|
|
6891
|
+
const method = import_utils44.ASTUtils.getPropertyName(member3);
|
|
6767
6892
|
if (namespace === void 0 || method === null) return void 0;
|
|
6768
6893
|
const supported2 = namespace === "Object" ? ["assign", "defineProperty", "defineProperties", "setPrototypeOf"] : ["set", "defineProperty", "setPrototypeOf"];
|
|
6769
6894
|
return supported2.includes(method) ? { namespace, method } : void 0;
|
|
@@ -6772,43 +6897,43 @@ function ordinaryNamespaceUse(node) {
|
|
|
6772
6897
|
const value = outerExpression(node);
|
|
6773
6898
|
const parent = value.parent;
|
|
6774
6899
|
if (parent === void 0) return false;
|
|
6775
|
-
return parent.type ===
|
|
6900
|
+
return parent.type === import_utils44.AST_NODE_TYPES.MemberExpression && parent.object === value || parent.type === import_utils44.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" || parent.type === import_utils44.AST_NODE_TYPES.TSTypeQuery || parent.type === import_utils44.AST_NODE_TYPES.TSQualifiedName;
|
|
6776
6901
|
}
|
|
6777
6902
|
function replacementNamespace(node, sourceCode) {
|
|
6778
6903
|
const value = unwrapExpression(node);
|
|
6779
6904
|
if (nativeObjectPrototype(value, sourceCode)) return "ObjectPrototype";
|
|
6780
|
-
return nativeNamespace(value, sourceCode) ?? (value.type ===
|
|
6905
|
+
return nativeNamespace(value, sourceCode) ?? (value.type === import_utils44.AST_NODE_TYPES.MemberExpression ? replacementNamespace(value.object, sourceCode) : void 0);
|
|
6781
6906
|
}
|
|
6782
6907
|
function nativeObjectPrototype(node, sourceCode) {
|
|
6783
6908
|
const value = unwrapExpression(node);
|
|
6784
|
-
return value.type ===
|
|
6909
|
+
return value.type === import_utils44.AST_NODE_TYPES.MemberExpression && import_utils44.ASTUtils.getPropertyName(value) === "prototype" && nativeNamespace(value.object, sourceCode) === "Object";
|
|
6785
6910
|
}
|
|
6786
6911
|
function nativeNamespace(node, sourceCode) {
|
|
6787
6912
|
const value = unwrapExpression(node);
|
|
6788
|
-
if (value.type ===
|
|
6789
|
-
const key =
|
|
6913
|
+
if (value.type === import_utils44.AST_NODE_TYPES.MemberExpression && !value.optional && nativeGlobalReceiver(value.object, sourceCode)) {
|
|
6914
|
+
const key = import_utils44.ASTUtils.getPropertyName(value);
|
|
6790
6915
|
if (key === "Object" || key === "Reflect") return key;
|
|
6791
6916
|
}
|
|
6792
|
-
if (value.type !==
|
|
6793
|
-
const binding3 =
|
|
6917
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.Identifier || value.name !== "Object" && value.name !== "Reflect") return void 0;
|
|
6918
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
6794
6919
|
return binding3 === null || binding3.defs.length === 0 ? value.name : void 0;
|
|
6795
6920
|
}
|
|
6796
6921
|
function nativeGlobalReceiver(node, sourceCode) {
|
|
6797
|
-
if (node.type !==
|
|
6798
|
-
const binding3 =
|
|
6922
|
+
if (node.type !== import_utils44.AST_NODE_TYPES.Identifier || !["globalThis", "window", "self"].includes(node.name)) return false;
|
|
6923
|
+
const binding3 = import_utils44.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
6799
6924
|
return binding3 === null || binding3.defs.length === 0;
|
|
6800
6925
|
}
|
|
6801
6926
|
function mutationWrites(node, namespace, method) {
|
|
6802
6927
|
if (namespace === "Object" && method === "assign") {
|
|
6803
6928
|
const source = node.arguments[1];
|
|
6804
|
-
return node.arguments.length === 2 && source?.type ===
|
|
6929
|
+
return node.arguments.length === 2 && source?.type === import_utils44.AST_NODE_TYPES.ObjectExpression ? plainProperties(source) : void 0;
|
|
6805
6930
|
}
|
|
6806
6931
|
if (node.arguments.length !== 3 || method !== "set" && method !== "defineProperty") return void 0;
|
|
6807
6932
|
const key = staticString(node.arguments[1]);
|
|
6808
6933
|
const value = node.arguments[2];
|
|
6809
|
-
if (key === null || value === void 0 || value.type ===
|
|
6934
|
+
if (key === null || value === void 0 || value.type === import_utils44.AST_NODE_TYPES.SpreadElement) return void 0;
|
|
6810
6935
|
if (method === "set") return [{ key, value }];
|
|
6811
|
-
if (value.type !==
|
|
6936
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) return void 0;
|
|
6812
6937
|
const properties = plainProperties(value);
|
|
6813
6938
|
if (properties === void 0 || properties.some((property) => !["value", "configurable", "enumerable", "writable"].includes(property.key))) return void 0;
|
|
6814
6939
|
const payload = properties.find((property) => property.key === "value");
|
|
@@ -6818,8 +6943,8 @@ function plainProperties(node) {
|
|
|
6818
6943
|
const writes = [];
|
|
6819
6944
|
const names = /* @__PURE__ */ new Set();
|
|
6820
6945
|
for (const property of node.properties) {
|
|
6821
|
-
if (property.type !==
|
|
6822
|
-
const key =
|
|
6946
|
+
if (property.type !== import_utils44.AST_NODE_TYPES.Property || property.kind !== "init" || property.method) return void 0;
|
|
6947
|
+
const key = import_utils44.ASTUtils.getPropertyName(property);
|
|
6823
6948
|
if (key === null || key === "__proto__" || names.has(key)) return void 0;
|
|
6824
6949
|
names.add(key);
|
|
6825
6950
|
writes.push({ key, value: property.value });
|
|
@@ -6828,7 +6953,7 @@ function plainProperties(node) {
|
|
|
6828
6953
|
}
|
|
6829
6954
|
|
|
6830
6955
|
// src/rules/no-contradictory-type-predicate.ts
|
|
6831
|
-
var
|
|
6956
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6832
6957
|
var import_typescript19 = __toESM(require("typescript"), 1);
|
|
6833
6958
|
|
|
6834
6959
|
// src/rules/_has-separate-predicate-contract.ts
|
|
@@ -6844,7 +6969,7 @@ function hasSeparatePredicateContract(node, checker) {
|
|
|
6844
6969
|
}
|
|
6845
6970
|
|
|
6846
6971
|
// src/rules/_contradictory-array-predicate.ts
|
|
6847
|
-
var
|
|
6972
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6848
6973
|
var import_typescript18 = __toESM(require("typescript"), 1);
|
|
6849
6974
|
var import_ts_api_utils2 = require("ts-api-utils");
|
|
6850
6975
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
@@ -6857,12 +6982,12 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6857
6982
|
function matches(expression, parameter, input, target) {
|
|
6858
6983
|
if ((input.flags & import_typescript18.default.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
6859
6984
|
const call = unwrapExpression(expression);
|
|
6860
|
-
if (call.type !==
|
|
6985
|
+
if (call.type !== import_utils45.AST_NODE_TYPES.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
6861
6986
|
const argument = call.arguments[0];
|
|
6862
6987
|
const callee = unwrapExpression(call.callee);
|
|
6863
|
-
if (argument?.type !==
|
|
6864
|
-
const declared =
|
|
6865
|
-
if (declared === null || declared !==
|
|
6988
|
+
if (argument?.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.optional || import_utils45.ASTUtils.getPropertyName(callee) !== "isArray" || callee.object.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.object.name !== "Array") return false;
|
|
6989
|
+
const declared = import_utils45.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name);
|
|
6990
|
+
if (declared === null || declared !== import_utils45.ASTUtils.findVariable(sourceCode.getScope(argument), argument.name)) return false;
|
|
6866
6991
|
const binding3 = nativeBinding(callee.object, sourceCode);
|
|
6867
6992
|
if (binding3 === void 0 || !stableArray(binding3, sourceCode, stable2)) return false;
|
|
6868
6993
|
const signature = checker.getResolvedSignature(services.esTreeNodeToTSNodeMap.get(call));
|
|
@@ -6872,7 +6997,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
6872
6997
|
return {
|
|
6873
6998
|
matches,
|
|
6874
6999
|
observeConstructor(member3) {
|
|
6875
|
-
const name =
|
|
7000
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3, sourceCode.getScope(member3));
|
|
6876
7001
|
if (name === "constructor" || name === null && member3.computed) constructorCapability = true;
|
|
6877
7002
|
},
|
|
6878
7003
|
stable() {
|
|
@@ -6886,7 +7011,7 @@ function plainPrimitiveArray(target, checker) {
|
|
|
6886
7011
|
return element !== void 0 && (element.flags & PRIMITIVE_ELEMENTS) !== 0 && (element.flags & (import_typescript18.default.TypeFlags.Enum | import_typescript18.default.TypeFlags.EnumLiteral | import_typescript18.default.TypeFlags.Intersection)) === 0;
|
|
6887
7012
|
}
|
|
6888
7013
|
function nativeBinding(identifier, sourceCode) {
|
|
6889
|
-
const binding3 =
|
|
7014
|
+
const binding3 = import_utils45.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
6890
7015
|
return binding3 !== null && binding3.defs.length === 0 ? binding3 : void 0;
|
|
6891
7016
|
}
|
|
6892
7017
|
function stableArray(binding3, sourceCode, cache) {
|
|
@@ -6913,8 +7038,8 @@ function typeOnlyReference2(reference) {
|
|
|
6913
7038
|
}
|
|
6914
7039
|
function ordinaryObjectUse(node) {
|
|
6915
7040
|
const member3 = node.parent;
|
|
6916
|
-
if (member3?.type !==
|
|
6917
|
-
const name =
|
|
7041
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node) return false;
|
|
7042
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6918
7043
|
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
6919
7044
|
}
|
|
6920
7045
|
function ordinaryArrayReference(reference) {
|
|
@@ -6924,17 +7049,17 @@ function ordinaryArrayReference(reference) {
|
|
|
6924
7049
|
}
|
|
6925
7050
|
function ordinaryArrayUse(node) {
|
|
6926
7051
|
const member3 = node.parent;
|
|
6927
|
-
if (member3?.type ===
|
|
6928
|
-
if (member3?.type !==
|
|
6929
|
-
return member3.parent.type ===
|
|
7052
|
+
if (member3?.type === import_utils45.AST_NODE_TYPES.TSTypeQuery) return true;
|
|
7053
|
+
if (member3?.type !== import_utils45.AST_NODE_TYPES.MemberExpression || member3.object !== node || member3.optional || import_utils45.ASTUtils.getPropertyName(member3) !== "isArray") return false;
|
|
7054
|
+
return member3.parent.type === import_utils45.AST_NODE_TYPES.CallExpression && member3.parent.callee === member3 && !member3.parent.optional;
|
|
6930
7055
|
}
|
|
6931
7056
|
function ordinaryHostReference(reference) {
|
|
6932
7057
|
if (reference.isWrite()) return false;
|
|
6933
7058
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6934
7059
|
let node = reference.identifier;
|
|
6935
|
-
while (node.parent?.type ===
|
|
7060
|
+
while (node.parent?.type === import_utils45.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
6936
7061
|
const member3 = node.parent;
|
|
6937
|
-
const name =
|
|
7062
|
+
const name = import_utils45.ASTUtils.getPropertyName(member3);
|
|
6938
7063
|
if (name === null) return false;
|
|
6939
7064
|
if (name === "Array") return ordinaryArrayUse(member3);
|
|
6940
7065
|
if (name === "Reflect") return false;
|
|
@@ -7014,16 +7139,16 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
7014
7139
|
defaultOptions: [],
|
|
7015
7140
|
create(context) {
|
|
7016
7141
|
if (isGeneratedFile(context, context.sourceCode.text) || !context.sourceCode.parserServices?.program) return {};
|
|
7017
|
-
const services =
|
|
7142
|
+
const services = import_utils46.ESLintUtils.getParserServices(context);
|
|
7018
7143
|
const checker = services.program.getTypeChecker();
|
|
7019
7144
|
const uncheckedArray = contradictoryArrayPredicate(context.sourceCode, services);
|
|
7020
7145
|
const pendingArrays = [];
|
|
7021
7146
|
function inspect(node) {
|
|
7022
7147
|
const annotation = node.returnType?.typeAnnotation;
|
|
7023
|
-
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !==
|
|
7148
|
+
if (node.async || node.generator || node.typeParameters !== void 0 || annotation?.type !== import_utils46.AST_NODE_TYPES.TSTypePredicate || annotation.asserts || annotation.parameterName.type !== import_utils46.AST_NODE_TYPES.Identifier || annotation.typeAnnotation === void 0) return;
|
|
7024
7149
|
const name = annotation.parameterName.name;
|
|
7025
7150
|
if (hasSeparatePredicateContract(services.esTreeNodeToTSNodeMap.get(node), checker)) return;
|
|
7026
|
-
const parameter = node.params.find((candidate2) => candidate2.type ===
|
|
7151
|
+
const parameter = node.params.find((candidate2) => candidate2.type === import_utils46.AST_NODE_TYPES.Identifier && candidate2.name === name);
|
|
7027
7152
|
const expression = singleReturn(node);
|
|
7028
7153
|
if (parameter?.typeAnnotation === void 0 || expression === void 0) return;
|
|
7029
7154
|
const check = typeofCheck(expression);
|
|
@@ -7068,13 +7193,13 @@ function shallowRecordCheck(expression, parameter, input, target, sourceCode, ch
|
|
|
7068
7193
|
const value = unwrapExpression(expression);
|
|
7069
7194
|
const direct = typeofCheck(value);
|
|
7070
7195
|
if (direct !== void 0) return direct.kind === "object" && sameParameter(parameter, direct.parameter, sourceCode);
|
|
7071
|
-
if (value.type !==
|
|
7196
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.LogicalExpression || value.operator !== "&&") return false;
|
|
7072
7197
|
for (const [left, right] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7073
7198
|
const check = typeofCheck(left);
|
|
7074
7199
|
const excluded = unwrapExpression(right);
|
|
7075
|
-
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !==
|
|
7200
|
+
if (check?.kind !== "object" || !sameParameter(parameter, check.parameter, sourceCode) || excluded.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || excluded.operator !== "!==" && excluded.operator !== "!=") continue;
|
|
7076
7201
|
for (const [tested, sentinel] of [[excluded.left, excluded.right], [excluded.right, excluded.left]]) {
|
|
7077
|
-
if (tested.type ===
|
|
7202
|
+
if (tested.type === import_utils46.AST_NODE_TYPES.Identifier && sentinel.type === import_utils46.AST_NODE_TYPES.Literal && sentinel.value === null && sameParameter(parameter, tested, sourceCode)) return true;
|
|
7078
7203
|
}
|
|
7079
7204
|
}
|
|
7080
7205
|
return false;
|
|
@@ -7107,17 +7232,17 @@ function literalKind(type, checker) {
|
|
|
7107
7232
|
}
|
|
7108
7233
|
function singleReturn(node) {
|
|
7109
7234
|
if (node.body === void 0) return void 0;
|
|
7110
|
-
if (node.body.type !==
|
|
7235
|
+
if (node.body.type !== import_utils46.AST_NODE_TYPES.BlockStatement) return node.body;
|
|
7111
7236
|
const statement = node.body.body[0];
|
|
7112
|
-
return node.body.body.length === 1 && statement?.type ===
|
|
7237
|
+
return node.body.body.length === 1 && statement?.type === import_utils46.AST_NODE_TYPES.ReturnStatement && statement.argument !== null ? statement.argument : void 0;
|
|
7113
7238
|
}
|
|
7114
7239
|
function typeofCheck(expression) {
|
|
7115
7240
|
const value = unwrapExpression(expression);
|
|
7116
|
-
if (value.type !==
|
|
7241
|
+
if (value.type !== import_utils46.AST_NODE_TYPES.BinaryExpression || value.operator !== "===" && value.operator !== "==") return void 0;
|
|
7117
7242
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
7118
7243
|
const operand = unwrapExpression(tested);
|
|
7119
7244
|
const kind = staticString(expected);
|
|
7120
|
-
if (operand.type !==
|
|
7245
|
+
if (operand.type !== import_utils46.AST_NODE_TYPES.UnaryExpression || operand.operator !== "typeof" || operand.argument.type !== import_utils46.AST_NODE_TYPES.Identifier || kind === null || !isRuntimeKind(kind)) continue;
|
|
7121
7246
|
return { parameter: operand.argument, kind };
|
|
7122
7247
|
}
|
|
7123
7248
|
return void 0;
|
|
@@ -7126,8 +7251,8 @@ function isRuntimeKind(value) {
|
|
|
7126
7251
|
return RUNTIME_KINDS.has(value);
|
|
7127
7252
|
}
|
|
7128
7253
|
function sameParameter(declared, tested, sourceCode) {
|
|
7129
|
-
const parameter =
|
|
7130
|
-
return parameter !== null && parameter ===
|
|
7254
|
+
const parameter = import_utils46.ASTUtils.findVariable(sourceCode.getScope(declared), declared.name);
|
|
7255
|
+
return parameter !== null && parameter === import_utils46.ASTUtils.findVariable(sourceCode.getScope(tested), tested.name);
|
|
7131
7256
|
}
|
|
7132
7257
|
function inputKinds(type, checker) {
|
|
7133
7258
|
if ((type.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
@@ -7171,62 +7296,6 @@ var import_typescript21 = __toESM(require("typescript"), 1);
|
|
|
7171
7296
|
// src/rules/_uuid-predicate-witness.ts
|
|
7172
7297
|
var import_utils47 = require("@typescript-eslint/utils");
|
|
7173
7298
|
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
7299
|
function uuidPredicateWitness(expression, parameter, sourceCode, services) {
|
|
7231
7300
|
const success = unwrapExpression(expression);
|
|
7232
7301
|
if (!member(success, "success")) return void 0;
|
|
@@ -11451,14 +11520,21 @@ function canAutofixNextConfigLiteral(sourceCode) {
|
|
|
11451
11520
|
// src/rules/no-dangerously-allow-svg.ts
|
|
11452
11521
|
var NEXT_CONFIG_RE = /(?:^|\/)next\.config\.[cm]?[jt]s$/;
|
|
11453
11522
|
var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
11454
|
-
summary: "
|
|
11455
|
-
rationale: "SVG
|
|
11456
|
-
remediation: "
|
|
11523
|
+
summary: "Require an explicit hardening policy for Next Image SVG delivery",
|
|
11524
|
+
rationale: "SVG can contain scripts and other active content. This organizational rule requires a recognized explicit script-blocking sandbox CSP when SVG delivery is enabled, with attachment disposition. It does not establish that framework defaults are missing or that a reported configuration is exploitable.",
|
|
11525
|
+
remediation: "Disable dangerouslyAllowSVG, or configure an explicit literal image contentSecurityPolicy such as `script-src 'none'; sandbox;` and keep attachment disposition. Verify effective headers and defaults against the application's pinned Next version.",
|
|
11457
11526
|
category: "security",
|
|
11458
11527
|
autofix: "safe",
|
|
11528
|
+
references: [
|
|
11529
|
+
"https://www.w3.org/TR/2026/WD-CSP3-20261027/#parse-serialized-policy",
|
|
11530
|
+
"https://github.com/vercel/next.js/blob/v16.4.3/packages/next/src/shared/lib/image-config.ts#L255"
|
|
11531
|
+
],
|
|
11459
11532
|
limitations: [
|
|
11460
11533
|
"Automatic boolean changes are withheld when the module contains explicit TypeScript or JSDoc contracts; those contracts can constrain an aliased property to literal true. Plain objects and as const inference remain fixable.",
|
|
11461
|
-
"
|
|
11534
|
+
"This rule does not resolve the installed Next version or evaluate effective response headers. The inspected Next 16.4.3 defaults already block scripts, apply sandbox, and use attachment disposition. A report for omitted explicit CSP is a policy finding, not proof of XSS.",
|
|
11535
|
+
"Omitted contentDispositionType is treated as attachment. Older or customized runtime defaults are not established by this source-only check.",
|
|
11536
|
+
"Only a bounded literal CSP subset is recognized: the first script-src must contain only 'none', and the first sandbox must have no tokens. Directive names and separators use CSP ASCII syntax. Valid policy lists, default-src fallbacks and other equivalent policies are not proved; omitted, dynamic or unrecognized explicit policies can still report. This is not a general CSP validator or proof of runtime security.",
|
|
11537
|
+
"Automatic fixes disable SVG opt-in to satisfy this policy; recognized hardened configurations are preserved. Only literal effective properties of a directly exported object, unescaped const alias, or isolated module.exports object are analyzed. Wrappers, factories, spreads, dynamic computed keys and mutations are not inferred."
|
|
11462
11538
|
],
|
|
11463
11539
|
examples: [
|
|
11464
11540
|
{
|
|
@@ -11472,7 +11548,7 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11472
11548
|
},
|
|
11473
11549
|
{
|
|
11474
11550
|
id: "svg-enabled",
|
|
11475
|
-
title: "
|
|
11551
|
+
title: "SVG opt-in requires explicit hardening under this policy",
|
|
11476
11552
|
outcome: "match",
|
|
11477
11553
|
files: [{ path: "next.config.mjs", source: "export default { images: { dangerouslyAllowSVG: true } };\n" }],
|
|
11478
11554
|
focusPath: "next.config.mjs",
|
|
@@ -11481,12 +11557,34 @@ var NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION = {
|
|
|
11481
11557
|
},
|
|
11482
11558
|
{
|
|
11483
11559
|
id: "safe-autofix",
|
|
11484
|
-
title: "
|
|
11560
|
+
title: "Disable SVG delivery to satisfy this policy",
|
|
11485
11561
|
outcome: "match",
|
|
11486
11562
|
files: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: true } };" }],
|
|
11487
11563
|
fixedFiles: [{ path: "next.config.ts", source: "export default { images: { dangerouslyAllowSVG: false } };" }],
|
|
11488
11564
|
focusPath: "next.config.ts",
|
|
11489
11565
|
expectedCount: 1
|
|
11566
|
+
},
|
|
11567
|
+
{
|
|
11568
|
+
id: "svg-explicit-hardening",
|
|
11569
|
+
scenarioId: "explicit-hardening",
|
|
11570
|
+
title: "Allow SVG delivery with explicit hardening",
|
|
11571
|
+
outcome: "no-match",
|
|
11572
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'none'; sandbox;" } };
|
|
11573
|
+
` }],
|
|
11574
|
+
focusPath: "next.config.mjs",
|
|
11575
|
+
expectedCount: 0,
|
|
11576
|
+
public: true
|
|
11577
|
+
},
|
|
11578
|
+
{
|
|
11579
|
+
id: "svg-unsafe-first-directive",
|
|
11580
|
+
scenarioId: "explicit-hardening",
|
|
11581
|
+
title: "A later duplicate cannot replace the effective policy",
|
|
11582
|
+
outcome: "match",
|
|
11583
|
+
files: [{ path: "next.config.mjs", source: `export default { images: { dangerouslyAllowSVG: true, contentDispositionType: "attachment", contentSecurityPolicy: "script-src 'unsafe-inline'; script-src 'none'; sandbox;" } };
|
|
11584
|
+
` }],
|
|
11585
|
+
focusPath: "next.config.mjs",
|
|
11586
|
+
expectedCount: 1,
|
|
11587
|
+
public: true
|
|
11490
11588
|
}
|
|
11491
11589
|
]
|
|
11492
11590
|
};
|
|
@@ -11496,12 +11594,16 @@ function literalString2(node) {
|
|
|
11496
11594
|
return null;
|
|
11497
11595
|
}
|
|
11498
11596
|
function hasHardenedSvgPolicy(policy) {
|
|
11499
|
-
const directives =
|
|
11500
|
-
const
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11597
|
+
const directives = /* @__PURE__ */ new Map();
|
|
11598
|
+
for (const part of policy.split(";")) {
|
|
11599
|
+
const [name, ...values] = part.split(/[\t\n\f\r ]+/u).filter(Boolean);
|
|
11600
|
+
if (name === void 0 || !/^[A-Za-z0-9-]+$/u.test(name)) continue;
|
|
11601
|
+
const key = name.toLowerCase();
|
|
11602
|
+
if (!directives.has(key)) directives.set(key, values);
|
|
11603
|
+
}
|
|
11604
|
+
const scriptSource = directives.get("script-src");
|
|
11605
|
+
const sandbox = directives.get("sandbox");
|
|
11606
|
+
return scriptSource?.length === 1 && scriptSource[0]?.toLowerCase() === "'none'" && sandbox?.length === 0;
|
|
11505
11607
|
}
|
|
11506
11608
|
var no_dangerously_allow_svg_default = createRule({
|
|
11507
11609
|
name: "no-dangerously-allow-svg",
|
|
@@ -11512,7 +11614,7 @@ var no_dangerously_allow_svg_default = createRule({
|
|
|
11512
11614
|
docs: { description: NO_DANGEROUSLY_ALLOW_SVG_DOCUMENTATION.summary },
|
|
11513
11615
|
schema: [],
|
|
11514
11616
|
messages: {
|
|
11515
|
-
noDangerouslyAllowSvg: "
|
|
11617
|
+
noDangerouslyAllowSvg: "SVG opt-in requires a recognized explicit script-blocking sandbox CSP and attachment disposition under this policy."
|
|
11516
11618
|
}
|
|
11517
11619
|
},
|
|
11518
11620
|
defaultOptions: [],
|
|
@@ -17808,7 +17910,7 @@ var NO_RAW_FETCH_OUTSIDE_CLIENTS_DOCUMENTATION = {
|
|
|
17808
17910
|
rationale: "Scattered fetch calls bypass shared transport policy and are harder to stub and observe consistently.",
|
|
17809
17911
|
remediation: "Move the request into a client module and call that abstraction from application code.",
|
|
17810
17912
|
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."],
|
|
17913
|
+
limitations: ["Tests, client-layer paths, constructed handoffs, and pre-signed URL transfers are excluded. Configure the same literal Next.js basePath here and on prefer-server-actions so one rule owns each internal mutation.", "Effect and pre-signed-transfer exemptions use recognized syntax and naming conventions, not complete React or URL provenance. Those conservative exclusions are recall limitations, not evidence that every excluded request satisfies transport policy.", "Unshadowed native members and bounded stable const aliases or single-property destructuring are recognized. Visible writes, callable escapes, whole-global escapes and mutation capabilities anywhere in the file invalidate that proof, including earlier captures. Known unrelated global member writes and typeof global checks do not. Static constructor members and destructuring projections invalidate the proof; indirect reflection, external monkeypatches and arbitrary forwarding functions are not inferred."],
|
|
17812
17914
|
examples: [
|
|
17813
17915
|
{ id: "client-call", title: "Use a client abstraction", outcome: "no-match", files: [{ path: "src/routes/handler.ts", source: "const response = await billingClient.getInvoice(id);" }], focusPath: "src/routes/handler.ts", expectedCount: 0, public: true },
|
|
17814
17916
|
{ id: "raw-fetch", title: "Do not call global fetch here", outcome: "match", files: [{ path: "src/routes/handler.ts", source: "const response = await fetch('/api/invoices');" }], focusPath: "src/routes/handler.ts", expectedCount: 1, public: true }
|
|
@@ -17829,11 +17931,6 @@ var DEFAULT_ALLOW = [
|
|
|
17829
17931
|
"[\\\\/][^\\\\/]*(?:Client|client)\\.[cm]?[jt]sx?$"
|
|
17830
17932
|
];
|
|
17831
17933
|
var NON_PRODUCTION_TREE_RE = /[\\/](playwright|cypress|__testfixtures__)[\\/]/;
|
|
17832
|
-
var GLOBAL_RECEIVERS3 = /* @__PURE__ */ new Set([
|
|
17833
|
-
"globalThis",
|
|
17834
|
-
"window",
|
|
17835
|
-
"self"
|
|
17836
|
-
]);
|
|
17837
17934
|
var PRESIGNED_URL_NAME_RE = /(?:pre-?signed|signed|upload|download)Url$/i;
|
|
17838
17935
|
var INTERNAL_MUTATION_METHODS = /* @__PURE__ */ new Set([
|
|
17839
17936
|
"POST",
|
|
@@ -17857,23 +17954,13 @@ var BASE_PATH_RE = /^\/(?!$)(?!.*[?#])(?:[^/]+\/)*[^/]+$/u;
|
|
|
17857
17954
|
function isValidBasePath(basePath) {
|
|
17858
17955
|
return BASE_PATH_RE.test(basePath) && !basePath.split("/").some((segment) => segment === "." || segment === "..");
|
|
17859
17956
|
}
|
|
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
17957
|
function isConstructedArgumentHandoff(node, resolvesToGlobal) {
|
|
17871
17958
|
const [first] = node.arguments;
|
|
17872
17959
|
return node.arguments.length === 1 && first !== void 0 && first.type === import_utils108.AST_NODE_TYPES.NewExpression && first.callee.type === import_utils108.AST_NODE_TYPES.Identifier && (first.callee.name === "URL" || first.callee.name === "Request") && resolvesToGlobal(first.callee);
|
|
17873
17960
|
}
|
|
17874
17961
|
function effectOwns(node) {
|
|
17875
17962
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
17876
|
-
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier) return false;
|
|
17963
|
+
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || unwrappedNodeCallee.name !== "fetch") return false;
|
|
17877
17964
|
const method = readDirectMethod(node);
|
|
17878
17965
|
if (method !== null && method !== "GET") return false;
|
|
17879
17966
|
const first = node.arguments[0];
|
|
@@ -18010,7 +18097,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18010
18097
|
}
|
|
18011
18098
|
function serverActionOwns(node) {
|
|
18012
18099
|
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) {
|
|
18100
|
+
if (unwrappedNodeCallee.type !== import_utils108.AST_NODE_TYPES.Identifier || unwrappedNodeCallee.name !== "fetch" || !resolvesToGlobal(unwrappedNodeCallee) || !hasUseClientDirective || hasUseServerDirective2 || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
18014
18101
|
return false;
|
|
18015
18102
|
}
|
|
18016
18103
|
const url = node.arguments[0];
|
|
@@ -18067,7 +18154,7 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
18067
18154
|
}
|
|
18068
18155
|
return {
|
|
18069
18156
|
CallExpression(node) {
|
|
18070
|
-
if (!
|
|
18157
|
+
if (!nativeFetchReference(unwrapExpression(node.callee), context.sourceCode)) {
|
|
18071
18158
|
return;
|
|
18072
18159
|
}
|
|
18073
18160
|
if (isPresignedUrlTransfer(node) || isConstructedArgumentHandoff(node, resolvesToGlobal) || effectOwns(node) || serverActionOwns(node)) {
|
|
@@ -32689,6 +32776,7 @@ var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
|
32689
32776
|
limitations: [
|
|
32690
32777
|
"Signal presence establishes an explicit cancellation path, not a guaranteed timeout. Literal null, global undefined, and void 0 do not provide a signal. Erased TypeScript wrappers preserve the same analysis. Unknown spreads and dynamic values are not inferred. Forwarded Request objects retain their signal unless an init explicitly resets it to null.",
|
|
32691
32778
|
"Unshadowed native fetch members and bounded stable const aliases or destructuring are recognized. Reassigned, defaulted and unknown aliases and arbitrary forwarding functions are excluded.",
|
|
32779
|
+
"Visible writes, callable escapes, whole-global escapes and mutation capabilities anywhere in the file invalidate native fetch identity, including earlier captures. Known unrelated global member writes and typeof global checks do not. Static constructor members and destructuring projections invalidate the proof; indirect reflection and external monkeypatches are not inferred.",
|
|
32692
32780
|
"Accessors and unproved prototypes are excluded because native option conversion can attach or replace a signal before it is read."
|
|
32693
32781
|
],
|
|
32694
32782
|
examples: [
|
|
@@ -32735,7 +32823,7 @@ function emptySignal(expression, resolvesToGlobal) {
|
|
|
32735
32823
|
}
|
|
32736
32824
|
return null;
|
|
32737
32825
|
}
|
|
32738
|
-
function initSignalState(init, resolvesToGlobal) {
|
|
32826
|
+
function initSignalState(init, resolvesToGlobal, sourceCode) {
|
|
32739
32827
|
init = unwrapExpression(init);
|
|
32740
32828
|
if (init.type !== import_utils176.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
32741
32829
|
let state = "absent";
|
|
@@ -32745,12 +32833,12 @@ function initSignalState(init, resolvesToGlobal) {
|
|
|
32745
32833
|
continue;
|
|
32746
32834
|
}
|
|
32747
32835
|
if (prop.kind !== "init" || hasUnprovedPrototype(prop)) return "unknown";
|
|
32748
|
-
const
|
|
32749
|
-
if (
|
|
32836
|
+
const name = staticPropertyName(prop, sourceCode);
|
|
32837
|
+
if (name === "signal") {
|
|
32750
32838
|
state = !prop.method ? emptySignal(prop.value, resolvesToGlobal) ?? "unknown" : "unknown";
|
|
32751
|
-
} else if (!prop.computed &&
|
|
32839
|
+
} else if (!prop.computed && name === "__proto__" && state === "absent") {
|
|
32752
32840
|
state = "unknown";
|
|
32753
|
-
} else if (prop.computed &&
|
|
32841
|
+
} else if (prop.computed && name === null) {
|
|
32754
32842
|
state = "unknown";
|
|
32755
32843
|
}
|
|
32756
32844
|
}
|
|
@@ -32828,7 +32916,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32828
32916
|
return "unknown";
|
|
32829
32917
|
}
|
|
32830
32918
|
}
|
|
32831
|
-
return initSignalState(definition.node.init, resolvesToGlobal);
|
|
32919
|
+
return initSignalState(definition.node.init, resolvesToGlobal, context.sourceCode);
|
|
32832
32920
|
}
|
|
32833
32921
|
function isForwardedRequest(argument) {
|
|
32834
32922
|
let value = unwrapExpression(argument);
|
|
@@ -32856,7 +32944,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
32856
32944
|
}
|
|
32857
32945
|
const [first, rawInit] = node.arguments;
|
|
32858
32946
|
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);
|
|
32947
|
+
const state = init === void 0 ? "unknown" : init.type === import_utils176.AST_NODE_TYPES.Identifier ? localConstInitSignalState(init) : initSignalState(init, resolvesToGlobal, context.sourceCode);
|
|
32860
32948
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first) && state !== "null")) {
|
|
32861
32949
|
return;
|
|
32862
32950
|
}
|