@sarj/eslint-plugin 15.17.11 → 15.17.13
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 +853 -522
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +843 -509
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -16425,6 +16425,9 @@ var MODULE_LEVEL_RESHAPERS = /* @__PURE__ */ new Set([
|
|
|
16425
16425
|
"pipe",
|
|
16426
16426
|
"preprocess"
|
|
16427
16427
|
]);
|
|
16428
|
+
function isPreferZodInferModuleReshaper(name) {
|
|
16429
|
+
return MODULE_LEVEL_RESHAPERS.has(name);
|
|
16430
|
+
}
|
|
16428
16431
|
var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
16429
16432
|
"ZodType",
|
|
16430
16433
|
"ZodSchema",
|
|
@@ -16432,6 +16435,9 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
16432
16435
|
"ZodMiniType",
|
|
16433
16436
|
"Schema"
|
|
16434
16437
|
]);
|
|
16438
|
+
function isPreferZodInferTypeConstraintName(name) {
|
|
16439
|
+
return ZOD_TYPE_CONSTRAINTS.has(name);
|
|
16440
|
+
}
|
|
16435
16441
|
var LEAF_NODE_TYPES = {
|
|
16436
16442
|
string: [import_utils85.AST_NODE_TYPES.TSStringKeyword],
|
|
16437
16443
|
email: [import_utils85.AST_NODE_TYPES.TSStringKeyword],
|
|
@@ -16607,6 +16613,21 @@ function unwrapNullish(annotation) {
|
|
|
16607
16613
|
}
|
|
16608
16614
|
return { core: rest.length === 0 ? null : annotation, nullable };
|
|
16609
16615
|
}
|
|
16616
|
+
function preferZodInferOwnsDefaultTwin(input) {
|
|
16617
|
+
if (input.constrained || input.reshaped || normalizeSchemaName(input.schemaName) !== normalizeTypeName(input.typeName)) {
|
|
16618
|
+
return false;
|
|
16619
|
+
}
|
|
16620
|
+
const fields = twinSchemaFields(input.initializer, input.zodNamespaces);
|
|
16621
|
+
const members = twinTypeMembers(input.declaration);
|
|
16622
|
+
if (fields === null || members === null || fields.size !== members.size) return false;
|
|
16623
|
+
for (const [name, field] of fields) {
|
|
16624
|
+
const member = members.get(name);
|
|
16625
|
+
if (member === void 0 || field.reshaped || field.optional !== member.optional || field.nullable !== member.nullable || member.readonly || leafAgrees(field, member.annotation) !== true) {
|
|
16626
|
+
return false;
|
|
16627
|
+
}
|
|
16628
|
+
}
|
|
16629
|
+
return true;
|
|
16630
|
+
}
|
|
16610
16631
|
function leafAgrees(field, annotation) {
|
|
16611
16632
|
if (field.domain === null) {
|
|
16612
16633
|
return false;
|
|
@@ -16666,6 +16687,100 @@ function staticStringUnionDomain(node) {
|
|
|
16666
16687
|
const domain = exactDomain(keys);
|
|
16667
16688
|
return domain !== null && domain.size >= 2 ? domain : null;
|
|
16668
16689
|
}
|
|
16690
|
+
function twinCallChain(node, zodNamespaces) {
|
|
16691
|
+
const chain = [];
|
|
16692
|
+
let current = node;
|
|
16693
|
+
while (current.type === import_utils85.AST_NODE_TYPES.CallExpression) {
|
|
16694
|
+
const callee = current.callee;
|
|
16695
|
+
if (callee.type !== import_utils85.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16696
|
+
return null;
|
|
16697
|
+
}
|
|
16698
|
+
chain.push(current);
|
|
16699
|
+
if (callee.object.type === import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16700
|
+
return zodNamespaces.has(callee.object.name) ? chain.reverse() : null;
|
|
16701
|
+
}
|
|
16702
|
+
current = callee.object;
|
|
16703
|
+
}
|
|
16704
|
+
return null;
|
|
16705
|
+
}
|
|
16706
|
+
function twinMethodName(call) {
|
|
16707
|
+
const callee = call.callee;
|
|
16708
|
+
return callee.type === import_utils85.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils85.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
16709
|
+
}
|
|
16710
|
+
function twinSchemaFields(initializer, zodNamespaces) {
|
|
16711
|
+
const chain = twinCallChain(initializer, zodNamespaces);
|
|
16712
|
+
if (chain === null || chain.length === 0) return null;
|
|
16713
|
+
const [base, ...rest] = chain;
|
|
16714
|
+
if (base === void 0) return null;
|
|
16715
|
+
const baseMethod = twinMethodName(base);
|
|
16716
|
+
if (baseMethod !== "object" && baseMethod !== "strictObject") return null;
|
|
16717
|
+
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(twinMethodName(call)))) return null;
|
|
16718
|
+
const shape = base.arguments[0];
|
|
16719
|
+
if (shape === void 0 || shape.type !== import_utils85.AST_NODE_TYPES.ObjectExpression) return null;
|
|
16720
|
+
const fields = /* @__PURE__ */ new Map();
|
|
16721
|
+
for (const property of shape.properties) {
|
|
16722
|
+
if (property.type !== import_utils85.AST_NODE_TYPES.Property || property.computed) return null;
|
|
16723
|
+
const { key } = property;
|
|
16724
|
+
const name = key.type === import_utils85.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils85.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
16725
|
+
if (name === null) return null;
|
|
16726
|
+
fields.set(name, twinSchemaField(property.value, zodNamespaces));
|
|
16727
|
+
}
|
|
16728
|
+
return fields.size === 0 ? null : fields;
|
|
16729
|
+
}
|
|
16730
|
+
function twinSchemaField(node, zodNamespaces) {
|
|
16731
|
+
const modifiers = [];
|
|
16732
|
+
let current = node;
|
|
16733
|
+
let leaf = null;
|
|
16734
|
+
let leafCall = null;
|
|
16735
|
+
while (current.type === import_utils85.AST_NODE_TYPES.CallExpression) {
|
|
16736
|
+
const callee = current.callee;
|
|
16737
|
+
if (callee.type !== import_utils85.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16738
|
+
break;
|
|
16739
|
+
}
|
|
16740
|
+
const receiver = callee.object;
|
|
16741
|
+
if (receiver.type === import_utils85.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
16742
|
+
leaf = callee.property.name;
|
|
16743
|
+
leafCall = current;
|
|
16744
|
+
break;
|
|
16745
|
+
}
|
|
16746
|
+
modifiers.push(callee.property.name);
|
|
16747
|
+
current = receiver;
|
|
16748
|
+
}
|
|
16749
|
+
return {
|
|
16750
|
+
domain: modifiers.every((name) => DOMAIN_PRESERVING_MODIFIERS.has(name)) ? staticZodDomain(leaf, leafCall) : null,
|
|
16751
|
+
leaf,
|
|
16752
|
+
optional: modifiers.some((name) => OPTIONAL_MODIFIERS.has(name)),
|
|
16753
|
+
nullable: modifiers.some((name) => NULLABLE_MODIFIERS.has(name)),
|
|
16754
|
+
reshaped: modifiers.some((name) => RESHAPING_MODIFIERS.has(name))
|
|
16755
|
+
};
|
|
16756
|
+
}
|
|
16757
|
+
function twinTypeMembers(declaration) {
|
|
16758
|
+
let members;
|
|
16759
|
+
if (declaration.type === import_utils85.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
16760
|
+
if (declaration.typeParameters !== void 0 || (declaration.extends?.length ?? 0) > 0) return null;
|
|
16761
|
+
members = declaration.body.body;
|
|
16762
|
+
} else {
|
|
16763
|
+
if (declaration.typeParameters !== void 0 || declaration.typeAnnotation.type !== import_utils85.AST_NODE_TYPES.TSTypeLiteral) {
|
|
16764
|
+
return null;
|
|
16765
|
+
}
|
|
16766
|
+
members = declaration.typeAnnotation.members;
|
|
16767
|
+
}
|
|
16768
|
+
const result = /* @__PURE__ */ new Map();
|
|
16769
|
+
for (const member of members) {
|
|
16770
|
+
if (member.type !== import_utils85.AST_NODE_TYPES.TSPropertySignature || member.computed) return null;
|
|
16771
|
+
const { key } = member;
|
|
16772
|
+
const name = key.type === import_utils85.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils85.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
16773
|
+
if (name === null) return null;
|
|
16774
|
+
const annotation = member.typeAnnotation?.typeAnnotation ?? null;
|
|
16775
|
+
result.set(name, {
|
|
16776
|
+
optional: member.optional === true,
|
|
16777
|
+
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
16778
|
+
readonly: member.readonly === true,
|
|
16779
|
+
annotation
|
|
16780
|
+
});
|
|
16781
|
+
}
|
|
16782
|
+
return result.size === 0 ? null : result;
|
|
16783
|
+
}
|
|
16669
16784
|
function nameTokens(name) {
|
|
16670
16785
|
return name.replace(/([a-z\d])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2").split(/[^A-Za-z\d]+/u).filter((token) => token !== "").map((token) => token.toLowerCase());
|
|
16671
16786
|
}
|
|
@@ -16722,27 +16837,6 @@ var prefer_zod_infer_default = createRule({
|
|
|
16722
16837
|
const typeDeclarations = [];
|
|
16723
16838
|
const constrainedTypeNames = /* @__PURE__ */ new Set();
|
|
16724
16839
|
const reshapedSchemaNames = /* @__PURE__ */ new Set();
|
|
16725
|
-
function zodCallChain(node) {
|
|
16726
|
-
const chain = [];
|
|
16727
|
-
let current = node;
|
|
16728
|
-
while (current.type === import_utils85.AST_NODE_TYPES.CallExpression) {
|
|
16729
|
-
const callee = current.callee;
|
|
16730
|
-
if (callee.type !== import_utils85.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16731
|
-
return null;
|
|
16732
|
-
}
|
|
16733
|
-
chain.push(current);
|
|
16734
|
-
const receiver = callee.object;
|
|
16735
|
-
if (receiver.type === import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16736
|
-
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
16737
|
-
}
|
|
16738
|
-
current = receiver;
|
|
16739
|
-
}
|
|
16740
|
-
return null;
|
|
16741
|
-
}
|
|
16742
|
-
function methodName2(call) {
|
|
16743
|
-
const callee = call.callee;
|
|
16744
|
-
return callee.type === import_utils85.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils85.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
16745
|
-
}
|
|
16746
16840
|
function recordZodImport(node) {
|
|
16747
16841
|
if (!isZodModule(node.source.value)) {
|
|
16748
16842
|
return;
|
|
@@ -16753,42 +16847,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
16753
16847
|
}
|
|
16754
16848
|
}
|
|
16755
16849
|
}
|
|
16756
|
-
function schemaField(node) {
|
|
16757
|
-
const modifiers = [];
|
|
16758
|
-
let current = node;
|
|
16759
|
-
let leaf = null;
|
|
16760
|
-
let leafCall = null;
|
|
16761
|
-
while (current.type === import_utils85.AST_NODE_TYPES.CallExpression) {
|
|
16762
|
-
const callee = current.callee;
|
|
16763
|
-
if (callee.type !== import_utils85.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16764
|
-
break;
|
|
16765
|
-
}
|
|
16766
|
-
const receiver = callee.object;
|
|
16767
|
-
if (receiver.type === import_utils85.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
16768
|
-
leaf = callee.property.name;
|
|
16769
|
-
leafCall = current;
|
|
16770
|
-
break;
|
|
16771
|
-
}
|
|
16772
|
-
modifiers.push(callee.property.name);
|
|
16773
|
-
current = receiver;
|
|
16774
|
-
}
|
|
16775
|
-
return {
|
|
16776
|
-
domain: modifiers.every(
|
|
16777
|
-
(name) => DOMAIN_PRESERVING_MODIFIERS.has(name)
|
|
16778
|
-
) ? staticZodDomain(leaf, leafCall) : null,
|
|
16779
|
-
leaf,
|
|
16780
|
-
optional: modifiers.some((name) => OPTIONAL_MODIFIERS.has(name)),
|
|
16781
|
-
nullable: modifiers.some((name) => NULLABLE_MODIFIERS.has(name)),
|
|
16782
|
-
reshaped: modifiers.some((name) => RESHAPING_MODIFIERS.has(name))
|
|
16783
|
-
};
|
|
16784
|
-
}
|
|
16785
16850
|
function enumSchemaDomain(init) {
|
|
16786
|
-
const chain =
|
|
16851
|
+
const chain = twinCallChain(init, zodNamespaces);
|
|
16787
16852
|
if (chain === null || chain.length !== 1) {
|
|
16788
16853
|
return null;
|
|
16789
16854
|
}
|
|
16790
16855
|
const [call] = chain;
|
|
16791
|
-
if (call === void 0 ||
|
|
16856
|
+
if (call === void 0 || twinMethodName(call) !== "enum") {
|
|
16792
16857
|
return null;
|
|
16793
16858
|
}
|
|
16794
16859
|
const domain = staticZodDomain("enum", call);
|
|
@@ -16832,111 +16897,25 @@ var prefer_zod_infer_default = createRule({
|
|
|
16832
16897
|
});
|
|
16833
16898
|
}
|
|
16834
16899
|
}
|
|
16835
|
-
function
|
|
16836
|
-
const chain = zodCallChain(init);
|
|
16837
|
-
if (chain === null || chain.length === 0) {
|
|
16838
|
-
return null;
|
|
16839
|
-
}
|
|
16840
|
-
const [base, ...rest] = chain;
|
|
16841
|
-
if (base === void 0) {
|
|
16842
|
-
return null;
|
|
16843
|
-
}
|
|
16844
|
-
const baseMethod = methodName2(base);
|
|
16845
|
-
if (baseMethod !== "object" && baseMethod !== "strictObject") {
|
|
16846
|
-
return null;
|
|
16847
|
-
}
|
|
16848
|
-
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(methodName2(call)))) {
|
|
16849
|
-
return null;
|
|
16850
|
-
}
|
|
16851
|
-
const shape = base.arguments[0];
|
|
16852
|
-
if (shape === void 0 || shape.type !== import_utils85.AST_NODE_TYPES.ObjectExpression) {
|
|
16853
|
-
return null;
|
|
16854
|
-
}
|
|
16855
|
-
const fields = /* @__PURE__ */ new Map();
|
|
16856
|
-
for (const property of shape.properties) {
|
|
16857
|
-
if (property.type !== import_utils85.AST_NODE_TYPES.Property || property.computed) {
|
|
16858
|
-
return null;
|
|
16859
|
-
}
|
|
16860
|
-
const { key } = property;
|
|
16861
|
-
const name = key.type === import_utils85.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils85.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
16862
|
-
if (name === null) {
|
|
16863
|
-
return null;
|
|
16864
|
-
}
|
|
16865
|
-
fields.set(name, schemaField(property.value));
|
|
16866
|
-
}
|
|
16867
|
-
return fields.size === 0 ? null : fields;
|
|
16868
|
-
}
|
|
16869
|
-
function typeMembers(members) {
|
|
16870
|
-
const result = /* @__PURE__ */ new Map();
|
|
16871
|
-
for (const member of members) {
|
|
16872
|
-
if (member.type !== import_utils85.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
16873
|
-
return null;
|
|
16874
|
-
}
|
|
16875
|
-
const { key } = member;
|
|
16876
|
-
const name = key.type === import_utils85.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils85.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
16877
|
-
if (name === null) {
|
|
16878
|
-
return null;
|
|
16879
|
-
}
|
|
16880
|
-
const annotation = member.typeAnnotation?.typeAnnotation ?? null;
|
|
16881
|
-
result.set(name, {
|
|
16882
|
-
optional: member.optional === true,
|
|
16883
|
-
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
16884
|
-
readonly: member.readonly === true,
|
|
16885
|
-
annotation
|
|
16886
|
-
});
|
|
16887
|
-
}
|
|
16888
|
-
return result.size === 0 ? null : result;
|
|
16889
|
-
}
|
|
16890
|
-
function collectConstrainedNames(node) {
|
|
16900
|
+
function collectConstrainedNames2(node) {
|
|
16891
16901
|
if (node.type === import_utils85.AST_NODE_TYPES.TSTypeReference) {
|
|
16892
16902
|
if (node.typeName.type === import_utils85.AST_NODE_TYPES.Identifier) {
|
|
16893
16903
|
constrainedTypeNames.add(node.typeName.name);
|
|
16894
16904
|
}
|
|
16895
16905
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
16896
|
-
|
|
16906
|
+
collectConstrainedNames2(argument);
|
|
16897
16907
|
}
|
|
16898
16908
|
return;
|
|
16899
16909
|
}
|
|
16900
16910
|
if (node.type === import_utils85.AST_NODE_TYPES.TSArrayType) {
|
|
16901
|
-
|
|
16911
|
+
collectConstrainedNames2(node.elementType);
|
|
16902
16912
|
return;
|
|
16903
16913
|
}
|
|
16904
16914
|
if (node.type === import_utils85.AST_NODE_TYPES.TSUnionType || node.type === import_utils85.AST_NODE_TYPES.TSIntersectionType) {
|
|
16905
16915
|
for (const member of node.types) {
|
|
16906
|
-
|
|
16907
|
-
}
|
|
16908
|
-
}
|
|
16909
|
-
}
|
|
16910
|
-
function isTwin(fields, members) {
|
|
16911
|
-
if (!requireIdenticalShape) {
|
|
16912
|
-
return true;
|
|
16913
|
-
}
|
|
16914
|
-
if (fields.size !== members.size) {
|
|
16915
|
-
return false;
|
|
16916
|
-
}
|
|
16917
|
-
for (const [name, field] of fields) {
|
|
16918
|
-
const member = members.get(name);
|
|
16919
|
-
if (member === void 0) {
|
|
16920
|
-
return false;
|
|
16921
|
-
}
|
|
16922
|
-
if (field.reshaped) {
|
|
16923
|
-
return false;
|
|
16924
|
-
}
|
|
16925
|
-
if (field.optional !== member.optional) {
|
|
16926
|
-
return false;
|
|
16927
|
-
}
|
|
16928
|
-
if (field.nullable !== member.nullable) {
|
|
16929
|
-
return false;
|
|
16930
|
-
}
|
|
16931
|
-
if (member.readonly) {
|
|
16932
|
-
return false;
|
|
16933
|
-
}
|
|
16934
|
-
const agrees = leafAgrees(field, member.annotation);
|
|
16935
|
-
if (agrees !== true) {
|
|
16936
|
-
return false;
|
|
16916
|
+
collectConstrainedNames2(member);
|
|
16937
16917
|
}
|
|
16938
16918
|
}
|
|
16939
|
-
return true;
|
|
16940
16919
|
}
|
|
16941
16920
|
return {
|
|
16942
16921
|
Program(node) {
|
|
@@ -16953,9 +16932,9 @@ var prefer_zod_infer_default = createRule({
|
|
|
16953
16932
|
if (node.id.type !== import_utils85.AST_NODE_TYPES.Identifier || node.init == null || !isModuleLevelConst(node)) {
|
|
16954
16933
|
return;
|
|
16955
16934
|
}
|
|
16956
|
-
const fields =
|
|
16935
|
+
const fields = twinSchemaFields(node.init, zodNamespaces);
|
|
16957
16936
|
if (fields !== null) {
|
|
16958
|
-
schemas.push({ name: node.id.name, fields });
|
|
16937
|
+
schemas.push({ name: node.id.name, fields, initializer: node.init });
|
|
16959
16938
|
}
|
|
16960
16939
|
if (isModuleLevelConst(node)) {
|
|
16961
16940
|
const domain = enumSchemaDomain(node.init);
|
|
@@ -16967,7 +16946,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
16967
16946
|
},
|
|
16968
16947
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
16969
16948
|
"MemberExpression[computed=false]"(node) {
|
|
16970
|
-
if (node.object.type === import_utils85.AST_NODE_TYPES.Identifier && node.property.type === import_utils85.AST_NODE_TYPES.Identifier &&
|
|
16949
|
+
if (node.object.type === import_utils85.AST_NODE_TYPES.Identifier && node.property.type === import_utils85.AST_NODE_TYPES.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
16971
16950
|
reshapedSchemaNames.add(node.object.name);
|
|
16972
16951
|
}
|
|
16973
16952
|
},
|
|
@@ -16975,11 +16954,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
16975
16954
|
TSTypeReference(node) {
|
|
16976
16955
|
const { typeName } = node;
|
|
16977
16956
|
const referenced = typeName.type === import_utils85.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils85.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils85.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
16978
|
-
if (referenced === null || !
|
|
16957
|
+
if (referenced === null || !isPreferZodInferTypeConstraintName(referenced)) {
|
|
16979
16958
|
return;
|
|
16980
16959
|
}
|
|
16981
16960
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
16982
|
-
|
|
16961
|
+
collectConstrainedNames2(argument);
|
|
16983
16962
|
}
|
|
16984
16963
|
},
|
|
16985
16964
|
TSInterfaceDeclaration(node) {
|
|
@@ -16987,9 +16966,9 @@ var prefer_zod_infer_default = createRule({
|
|
|
16987
16966
|
if (node.typeParameters !== void 0 || (node.extends?.length ?? 0) > 0) {
|
|
16988
16967
|
return;
|
|
16989
16968
|
}
|
|
16990
|
-
const members =
|
|
16969
|
+
const members = twinTypeMembers(node);
|
|
16991
16970
|
if (members !== null) {
|
|
16992
|
-
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
16971
|
+
typeDeclarations.push({ declaration: node, name: node.id.name, node: node.id, members });
|
|
16993
16972
|
}
|
|
16994
16973
|
recordLiteralUnions(
|
|
16995
16974
|
node.body.body,
|
|
@@ -17011,9 +16990,9 @@ var prefer_zod_infer_default = createRule({
|
|
|
17011
16990
|
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils85.AST_NODE_TYPES.TSTypeLiteral) {
|
|
17012
16991
|
return;
|
|
17013
16992
|
}
|
|
17014
|
-
const members =
|
|
16993
|
+
const members = twinTypeMembers(node);
|
|
17015
16994
|
if (members !== null) {
|
|
17016
|
-
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
16995
|
+
typeDeclarations.push({ declaration: node, name: node.id.name, node: node.id, members });
|
|
17017
16996
|
}
|
|
17018
16997
|
recordLiteralUnions(
|
|
17019
16998
|
node.typeAnnotation.members,
|
|
@@ -17042,7 +17021,15 @@ var prefer_zod_infer_default = createRule({
|
|
|
17042
17021
|
if (schema === void 0 || reshapedSchemaNames.has(schema.name)) {
|
|
17043
17022
|
continue;
|
|
17044
17023
|
}
|
|
17045
|
-
if (!
|
|
17024
|
+
if (requireIdenticalShape ? !preferZodInferOwnsDefaultTwin({
|
|
17025
|
+
constrained: constrainedTypeNames.has(declaration.name),
|
|
17026
|
+
declaration: declaration.declaration,
|
|
17027
|
+
initializer: schema.initializer,
|
|
17028
|
+
reshaped: reshapedSchemaNames.has(schema.name),
|
|
17029
|
+
schemaName: schema.name,
|
|
17030
|
+
typeName: declaration.name,
|
|
17031
|
+
zodNamespaces
|
|
17032
|
+
}) : false) {
|
|
17046
17033
|
continue;
|
|
17047
17034
|
}
|
|
17048
17035
|
twinTypeNames.add(declaration.name);
|
|
@@ -17106,9 +17093,349 @@ var prefer_zod_infer_default = createRule({
|
|
|
17106
17093
|
}
|
|
17107
17094
|
});
|
|
17108
17095
|
|
|
17109
|
-
// src/rules/
|
|
17096
|
+
// src/rules/prefer-zod-parse-output-type.ts
|
|
17110
17097
|
var import_utils86 = require("@typescript-eslint/utils");
|
|
17111
17098
|
var import_typescript2 = __toESM(require("typescript"), 1);
|
|
17099
|
+
var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
17100
|
+
summary: "Derive a function's return contract from the local Zod schema whose parsed output it returns.",
|
|
17101
|
+
rationale: "A hand-written contract can drift from the runtime-validated value even while each declaration remains locally valid.",
|
|
17102
|
+
remediation: "Export or colocate the schema and derive the contract with `z.output<typeof Schema>`.",
|
|
17103
|
+
category: "correctness",
|
|
17104
|
+
autofix: "none",
|
|
17105
|
+
limitations: [
|
|
17106
|
+
"Requires TypeScript type information and a direct return of a module-level local Zod object schema's `.parse()` result.",
|
|
17107
|
+
"Same-module name-correlated twins that `prefer-zod-infer` can prove are left to that established rule; this companion owns richer or renamed same-module and cross-module contracts proven by parse-return data flow.",
|
|
17108
|
+
"Only a single plain non-generic object interface or object type alias with exact property keys and bidirectional assignability is reported.",
|
|
17109
|
+
"Nullish conditional branches are followed; aliases, assignments, helper calls, imported schemas, and other indirect data flow are intentionally excluded.",
|
|
17110
|
+
"Contracts returned from more than one distinct local schema are excluded because no single schema has unambiguous ownership.",
|
|
17111
|
+
"Readonly, augmented, indexed, callable, generated, constrained, any, unknown, and never contracts are excluded rather than guessed.",
|
|
17112
|
+
"The rule is report-only because moving or exporting a schema changes module ownership and requires human review."
|
|
17113
|
+
],
|
|
17114
|
+
examples: [
|
|
17115
|
+
{
|
|
17116
|
+
id: "schema-derived-return",
|
|
17117
|
+
title: "Derive the validated return contract",
|
|
17118
|
+
outcome: "no-match",
|
|
17119
|
+
files: [
|
|
17120
|
+
{
|
|
17121
|
+
path: "src/row.ts",
|
|
17122
|
+
source: 'import { z } from "zod"; const RowSchema = z.object({ id: z.string() }); type Row = z.output<typeof RowSchema>; function load(): Row { return RowSchema.parse({}); }'
|
|
17123
|
+
}
|
|
17124
|
+
],
|
|
17125
|
+
focusPath: "src/row.ts",
|
|
17126
|
+
expectedCount: 0,
|
|
17127
|
+
public: true
|
|
17128
|
+
},
|
|
17129
|
+
{
|
|
17130
|
+
id: "hand-written-parsed-return",
|
|
17131
|
+
title: "Do not hand-write the parsed return shape",
|
|
17132
|
+
outcome: "match",
|
|
17133
|
+
files: [
|
|
17134
|
+
{
|
|
17135
|
+
path: "src/contracts.ts",
|
|
17136
|
+
source: "export interface ParsedRow { id: string }"
|
|
17137
|
+
},
|
|
17138
|
+
{
|
|
17139
|
+
path: "src/row.ts",
|
|
17140
|
+
source: 'import { z } from "zod"; import type { ParsedRow } from "./contracts.js"; const RowSchema = z.object({ id: z.string() }); function load(): ParsedRow { return RowSchema.parse({}); }'
|
|
17141
|
+
}
|
|
17142
|
+
],
|
|
17143
|
+
focusPath: "src/row.ts",
|
|
17144
|
+
expectedCount: 1,
|
|
17145
|
+
public: true
|
|
17146
|
+
}
|
|
17147
|
+
]
|
|
17148
|
+
};
|
|
17149
|
+
function isModuleLevelConst2(node) {
|
|
17150
|
+
const declaration = node.parent;
|
|
17151
|
+
if (declaration.type !== import_utils86.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const") {
|
|
17152
|
+
return false;
|
|
17153
|
+
}
|
|
17154
|
+
const container = declaration.parent;
|
|
17155
|
+
return container.type === import_utils86.AST_NODE_TYPES.Program || container.type === import_utils86.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils86.AST_NODE_TYPES.Program;
|
|
17156
|
+
}
|
|
17157
|
+
function isLocalZodObjectSchema(node, namespaces) {
|
|
17158
|
+
let current = node;
|
|
17159
|
+
while (current.type === import_utils86.AST_NODE_TYPES.CallExpression) {
|
|
17160
|
+
const { callee } = current;
|
|
17161
|
+
if (callee.type !== import_utils86.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils86.AST_NODE_TYPES.Identifier) {
|
|
17162
|
+
return false;
|
|
17163
|
+
}
|
|
17164
|
+
if (callee.object.type === import_utils86.AST_NODE_TYPES.Identifier) {
|
|
17165
|
+
return namespaces.has(callee.object.name) && (callee.property.name === "object" || callee.property.name === "strictObject");
|
|
17166
|
+
}
|
|
17167
|
+
current = callee.object;
|
|
17168
|
+
}
|
|
17169
|
+
return false;
|
|
17170
|
+
}
|
|
17171
|
+
function parsedReturnCandidate(node) {
|
|
17172
|
+
const { callee } = node;
|
|
17173
|
+
if (callee.type !== import_utils86.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils86.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils86.AST_NODE_TYPES.Identifier || callee.property.name !== "parse") {
|
|
17174
|
+
return null;
|
|
17175
|
+
}
|
|
17176
|
+
const owner = directReturnOwner(node);
|
|
17177
|
+
const annotation = owner?.returnType?.typeAnnotation;
|
|
17178
|
+
if (annotation === void 0) return null;
|
|
17179
|
+
const typeReference = returnContractReference(annotation);
|
|
17180
|
+
if (typeReference === null || typeReference.typeName.type !== import_utils86.AST_NODE_TYPES.Identifier) {
|
|
17181
|
+
return null;
|
|
17182
|
+
}
|
|
17183
|
+
return {
|
|
17184
|
+
call: node,
|
|
17185
|
+
schema: callee.object,
|
|
17186
|
+
typeName: typeReference.typeName.name,
|
|
17187
|
+
typeReference
|
|
17188
|
+
};
|
|
17189
|
+
}
|
|
17190
|
+
function directReturnOwner(node) {
|
|
17191
|
+
let current = node;
|
|
17192
|
+
while (current.parent !== void 0) {
|
|
17193
|
+
const parent = current.parent;
|
|
17194
|
+
if (parent.type === import_utils86.AST_NODE_TYPES.ReturnStatement) {
|
|
17195
|
+
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
17196
|
+
}
|
|
17197
|
+
if (parent.type === import_utils86.AST_NODE_TYPES.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
17198
|
+
return parent;
|
|
17199
|
+
}
|
|
17200
|
+
if (parent.type === import_utils86.AST_NODE_TYPES.AwaitExpression && parent.argument === current) {
|
|
17201
|
+
current = parent;
|
|
17202
|
+
continue;
|
|
17203
|
+
}
|
|
17204
|
+
if (parent.type === import_utils86.AST_NODE_TYPES.ConditionalExpression) {
|
|
17205
|
+
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
17206
|
+
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
17207
|
+
if (parsedWhenTrue || parsedWhenFalse) {
|
|
17208
|
+
current = parent;
|
|
17209
|
+
continue;
|
|
17210
|
+
}
|
|
17211
|
+
}
|
|
17212
|
+
return null;
|
|
17213
|
+
}
|
|
17214
|
+
return null;
|
|
17215
|
+
}
|
|
17216
|
+
function isNullishExpression(node) {
|
|
17217
|
+
return node.type === import_utils86.AST_NODE_TYPES.Literal && node.value === null || node.type === import_utils86.AST_NODE_TYPES.Identifier && node.name === "undefined";
|
|
17218
|
+
}
|
|
17219
|
+
function enclosingFunction4(node) {
|
|
17220
|
+
let current = node.parent;
|
|
17221
|
+
while (current !== void 0) {
|
|
17222
|
+
if (current.type === import_utils86.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils86.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils86.AST_NODE_TYPES.FunctionExpression) {
|
|
17223
|
+
return current;
|
|
17224
|
+
}
|
|
17225
|
+
current = current.parent;
|
|
17226
|
+
}
|
|
17227
|
+
return null;
|
|
17228
|
+
}
|
|
17229
|
+
function returnContractReference(node) {
|
|
17230
|
+
if (node.type === import_utils86.AST_NODE_TYPES.TSUnionType) {
|
|
17231
|
+
const substantive = node.types.filter(
|
|
17232
|
+
(member) => member.type !== import_utils86.AST_NODE_TYPES.TSNullKeyword && member.type !== import_utils86.AST_NODE_TYPES.TSUndefinedKeyword
|
|
17233
|
+
);
|
|
17234
|
+
const [only] = substantive;
|
|
17235
|
+
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
17236
|
+
}
|
|
17237
|
+
if (node.type === import_utils86.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils86.AST_NODE_TYPES.Identifier && node.typeName.name === "Promise") {
|
|
17238
|
+
const parameters = node.typeArguments?.params ?? [];
|
|
17239
|
+
const [only] = parameters;
|
|
17240
|
+
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
17241
|
+
}
|
|
17242
|
+
return node.type === import_utils86.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils86.AST_NODE_TYPES.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
17243
|
+
}
|
|
17244
|
+
function recordZodNamespaces(node, namespaces) {
|
|
17245
|
+
for (const statement of node.body) {
|
|
17246
|
+
if (statement.type !== import_utils86.AST_NODE_TYPES.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
17247
|
+
continue;
|
|
17248
|
+
}
|
|
17249
|
+
for (const specifier of statement.specifiers) {
|
|
17250
|
+
if (specifier.type === import_utils86.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils86.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils86.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils86.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
17251
|
+
namespaces.add(specifier.local.name);
|
|
17252
|
+
}
|
|
17253
|
+
}
|
|
17254
|
+
}
|
|
17255
|
+
}
|
|
17256
|
+
function collectConstrainedNames(node, names) {
|
|
17257
|
+
if (node.type === import_utils86.AST_NODE_TYPES.TSTypeReference) {
|
|
17258
|
+
if (node.typeName.type === import_utils86.AST_NODE_TYPES.Identifier) names.add(node.typeName.name);
|
|
17259
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
17260
|
+
collectConstrainedNames(argument, names);
|
|
17261
|
+
}
|
|
17262
|
+
return;
|
|
17263
|
+
}
|
|
17264
|
+
if (node.type === import_utils86.AST_NODE_TYPES.TSArrayType) {
|
|
17265
|
+
collectConstrainedNames(node.elementType, names);
|
|
17266
|
+
return;
|
|
17267
|
+
}
|
|
17268
|
+
if (node.type === import_utils86.AST_NODE_TYPES.TSUnionType || node.type === import_utils86.AST_NODE_TYPES.TSIntersectionType) {
|
|
17269
|
+
for (const member of node.types) collectConstrainedNames(member, names);
|
|
17270
|
+
}
|
|
17271
|
+
}
|
|
17272
|
+
function reportCandidates(context, services, schemas, candidates, zodNamespaces, reshapedSchemas, constrainedTypeNames) {
|
|
17273
|
+
const checker = services.program.getTypeChecker();
|
|
17274
|
+
const schemaSymbols = /* @__PURE__ */ new Map();
|
|
17275
|
+
for (const schema of schemas) {
|
|
17276
|
+
const tsIdentifier = services.esTreeNodeToTSNodeMap.get(schema.identifier);
|
|
17277
|
+
const symbol = checker.getSymbolAtLocation(tsIdentifier);
|
|
17278
|
+
if (symbol !== void 0) schemaSymbols.set(symbol, schema);
|
|
17279
|
+
}
|
|
17280
|
+
const eligible2 = [];
|
|
17281
|
+
const reported = /* @__PURE__ */ new Set();
|
|
17282
|
+
for (const candidate2 of candidates) {
|
|
17283
|
+
const tsSchema = services.esTreeNodeToTSNodeMap.get(candidate2.schema);
|
|
17284
|
+
const schemaSymbol = checker.getSymbolAtLocation(tsSchema);
|
|
17285
|
+
if (schemaSymbol === void 0) continue;
|
|
17286
|
+
const schema = schemaSymbols.get(schemaSymbol);
|
|
17287
|
+
if (schema === void 0) continue;
|
|
17288
|
+
const tsReference = services.esTreeNodeToTSNodeMap.get(candidate2.typeReference);
|
|
17289
|
+
const contract = checker.getTypeAtLocation(tsReference);
|
|
17290
|
+
const contractSymbol = contract.aliasSymbol ?? contract.getSymbol();
|
|
17291
|
+
if (contractSymbol === void 0) continue;
|
|
17292
|
+
const declaration = handWrittenObjectDeclaration(contractSymbol);
|
|
17293
|
+
if (declaration === null || declaration.getSourceFile().isDeclarationFile) continue;
|
|
17294
|
+
const source = declaration.getSourceFile();
|
|
17295
|
+
if (isGeneratedFile(source.fileName, source.text)) continue;
|
|
17296
|
+
const tsCall = services.esTreeNodeToTSNodeMap.get(candidate2.call);
|
|
17297
|
+
const parsed = checker.getTypeAtLocation(tsCall);
|
|
17298
|
+
const constrained = constrainedTypeNames.has(candidate2.typeName) || (parsed.aliasSymbol ?? parsed.getSymbol()) === contractSymbol;
|
|
17299
|
+
if (constrained) continue;
|
|
17300
|
+
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
17301
|
+
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
17302
|
+
if ((estreeDeclaration.type === import_utils86.AST_NODE_TYPES.TSInterfaceDeclaration || estreeDeclaration.type === import_utils86.AST_NODE_TYPES.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
17303
|
+
constrained,
|
|
17304
|
+
declaration: estreeDeclaration,
|
|
17305
|
+
initializer: schema.initializer,
|
|
17306
|
+
reshaped: reshapedSchemas.has(schema.name),
|
|
17307
|
+
schemaName: schema.name,
|
|
17308
|
+
typeName: candidate2.typeName,
|
|
17309
|
+
zodNamespaces
|
|
17310
|
+
})) {
|
|
17311
|
+
continue;
|
|
17312
|
+
}
|
|
17313
|
+
}
|
|
17314
|
+
if (!exactObjectTypes(
|
|
17315
|
+
checker,
|
|
17316
|
+
checker.getNonNullableType(parsed),
|
|
17317
|
+
checker.getNonNullableType(contract)
|
|
17318
|
+
)) {
|
|
17319
|
+
continue;
|
|
17320
|
+
}
|
|
17321
|
+
eligible2.push({ candidate: candidate2, contractSymbol, schema, schemaSymbol });
|
|
17322
|
+
}
|
|
17323
|
+
const schemasByContract = /* @__PURE__ */ new Map();
|
|
17324
|
+
for (const { contractSymbol, schemaSymbol } of eligible2) {
|
|
17325
|
+
const contractSchemas = schemasByContract.get(contractSymbol) ?? /* @__PURE__ */ new Set();
|
|
17326
|
+
contractSchemas.add(schemaSymbol);
|
|
17327
|
+
schemasByContract.set(contractSymbol, contractSchemas);
|
|
17328
|
+
}
|
|
17329
|
+
for (const { candidate: candidate2, contractSymbol, schema } of eligible2) {
|
|
17330
|
+
if (reported.has(contractSymbol) || schemasByContract.get(contractSymbol)?.size !== 1) continue;
|
|
17331
|
+
reported.add(contractSymbol);
|
|
17332
|
+
context.report({
|
|
17333
|
+
node: candidate2.typeReference,
|
|
17334
|
+
messageId: "handWrittenParsedOutput",
|
|
17335
|
+
data: { schemaName: schema.name, typeName: candidate2.typeName }
|
|
17336
|
+
});
|
|
17337
|
+
}
|
|
17338
|
+
}
|
|
17339
|
+
function handWrittenObjectDeclaration(symbol) {
|
|
17340
|
+
const declarations = symbol.getDeclarations() ?? [];
|
|
17341
|
+
const [declaration] = declarations;
|
|
17342
|
+
if (declarations.length !== 1 || declaration === void 0) return null;
|
|
17343
|
+
const plainMembers = (members) => members.length > 0 && members.every(
|
|
17344
|
+
(member) => import_typescript2.default.isPropertySignature(member) && member.type !== void 0 && member.modifiers?.some((modifier) => modifier.kind === import_typescript2.default.SyntaxKind.ReadonlyKeyword) !== true
|
|
17345
|
+
);
|
|
17346
|
+
if (import_typescript2.default.isInterfaceDeclaration(declaration) && declaration.typeParameters === void 0 && declaration.heritageClauses === void 0 && plainMembers(declaration.members)) {
|
|
17347
|
+
return declaration;
|
|
17348
|
+
}
|
|
17349
|
+
if (import_typescript2.default.isTypeAliasDeclaration(declaration) && declaration.typeParameters === void 0 && import_typescript2.default.isTypeLiteralNode(declaration.type) && plainMembers(declaration.type.members)) {
|
|
17350
|
+
return declaration;
|
|
17351
|
+
}
|
|
17352
|
+
return null;
|
|
17353
|
+
}
|
|
17354
|
+
function exactObjectTypes(checker, parsed, contract) {
|
|
17355
|
+
const unsafeFlags = import_typescript2.default.TypeFlags.Any | import_typescript2.default.TypeFlags.Unknown | import_typescript2.default.TypeFlags.Never;
|
|
17356
|
+
if ((parsed.flags & unsafeFlags) !== 0 || (contract.flags & unsafeFlags) !== 0) return false;
|
|
17357
|
+
if (checker.getIndexInfosOfType(parsed).length > 0 || checker.getIndexInfosOfType(contract).length > 0 || checker.getSignaturesOfType(parsed, import_typescript2.default.SignatureKind.Call).length > 0 || checker.getSignaturesOfType(contract, import_typescript2.default.SignatureKind.Call).length > 0) {
|
|
17358
|
+
return false;
|
|
17359
|
+
}
|
|
17360
|
+
const names = (type) => checker.getPropertiesOfType(type).map((property) => property.getName()).sort();
|
|
17361
|
+
const parsedNames = names(parsed);
|
|
17362
|
+
const contractNames = names(contract);
|
|
17363
|
+
return parsedNames.length > 0 && parsedNames.length === contractNames.length && parsedNames.every((name, index) => name === contractNames[index]) && checker.isTypeAssignableTo(parsed, contract) && checker.isTypeAssignableTo(contract, parsed);
|
|
17364
|
+
}
|
|
17365
|
+
var prefer_zod_parse_output_type_default = createRule({
|
|
17366
|
+
name: "prefer-zod-parse-output-type",
|
|
17367
|
+
documentation: PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION,
|
|
17368
|
+
meta: {
|
|
17369
|
+
type: "problem",
|
|
17370
|
+
docs: {
|
|
17371
|
+
description: "Derive a function's return contract from the local Zod schema whose parsed output it returns."
|
|
17372
|
+
},
|
|
17373
|
+
schema: [],
|
|
17374
|
+
messages: {
|
|
17375
|
+
handWrittenParsedOutput: "`{{typeName}}` exactly restates the validated output returned by `{{schemaName}}.parse()`. Export or colocate the schema and derive the contract with `z.output<typeof {{schemaName}}>` so the runtime and compile-time shapes cannot drift."
|
|
17376
|
+
}
|
|
17377
|
+
},
|
|
17378
|
+
defaultOptions: [],
|
|
17379
|
+
create(context) {
|
|
17380
|
+
if (isTestFile(context.filename) || isStoryFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
17381
|
+
return {};
|
|
17382
|
+
}
|
|
17383
|
+
let services;
|
|
17384
|
+
try {
|
|
17385
|
+
services = import_utils86.ESLintUtils.getParserServices(context);
|
|
17386
|
+
} catch {
|
|
17387
|
+
services = null;
|
|
17388
|
+
}
|
|
17389
|
+
if (services === null) return {};
|
|
17390
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
17391
|
+
const constrainedTypeNames = /* @__PURE__ */ new Set();
|
|
17392
|
+
const reshapedSchemas = /* @__PURE__ */ new Set();
|
|
17393
|
+
const schemas = [];
|
|
17394
|
+
const candidates = [];
|
|
17395
|
+
return {
|
|
17396
|
+
Program(node) {
|
|
17397
|
+
recordZodNamespaces(node, namespaces);
|
|
17398
|
+
},
|
|
17399
|
+
VariableDeclarator(node) {
|
|
17400
|
+
if (node.id.type === import_utils86.AST_NODE_TYPES.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
17401
|
+
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
17402
|
+
}
|
|
17403
|
+
},
|
|
17404
|
+
CallExpression(node) {
|
|
17405
|
+
const candidate2 = parsedReturnCandidate(node);
|
|
17406
|
+
if (candidate2 !== null) candidates.push(candidate2);
|
|
17407
|
+
},
|
|
17408
|
+
"MemberExpression[computed=false]"(node) {
|
|
17409
|
+
if (node.object.type === import_utils86.AST_NODE_TYPES.Identifier && node.property.type === import_utils86.AST_NODE_TYPES.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
17410
|
+
reshapedSchemas.add(node.object.name);
|
|
17411
|
+
}
|
|
17412
|
+
},
|
|
17413
|
+
TSTypeReference(node) {
|
|
17414
|
+
const { typeName } = node;
|
|
17415
|
+
const name = typeName.type === import_utils86.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils86.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils86.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
17416
|
+
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
17417
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
17418
|
+
collectConstrainedNames(argument, constrainedTypeNames);
|
|
17419
|
+
}
|
|
17420
|
+
},
|
|
17421
|
+
"Program:exit"() {
|
|
17422
|
+
reportCandidates(
|
|
17423
|
+
context,
|
|
17424
|
+
services,
|
|
17425
|
+
schemas,
|
|
17426
|
+
candidates,
|
|
17427
|
+
namespaces,
|
|
17428
|
+
reshapedSchemas,
|
|
17429
|
+
constrainedTypeNames
|
|
17430
|
+
);
|
|
17431
|
+
}
|
|
17432
|
+
};
|
|
17433
|
+
}
|
|
17434
|
+
});
|
|
17435
|
+
|
|
17436
|
+
// src/rules/require-assert-never.ts
|
|
17437
|
+
var import_utils87 = require("@typescript-eslint/utils");
|
|
17438
|
+
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
17112
17439
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
17113
17440
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
17114
17441
|
rationale: "An empty default silently accepts new union members instead of making the compiler identify the missing case.",
|
|
@@ -17121,14 +17448,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
17121
17448
|
]
|
|
17122
17449
|
};
|
|
17123
17450
|
var isRuntimeHandlingStatement = (statement) => {
|
|
17124
|
-
if (statement.type ===
|
|
17125
|
-
if (statement.type ===
|
|
17451
|
+
if (statement.type === import_utils87.AST_NODE_TYPES.EmptyStatement) return false;
|
|
17452
|
+
if (statement.type === import_utils87.AST_NODE_TYPES.BreakStatement) {
|
|
17126
17453
|
return statement.label !== null;
|
|
17127
17454
|
}
|
|
17128
|
-
if (statement.type ===
|
|
17455
|
+
if (statement.type === import_utils87.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils87.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
17129
17456
|
return false;
|
|
17130
17457
|
}
|
|
17131
|
-
if (statement.type ===
|
|
17458
|
+
if (statement.type === import_utils87.AST_NODE_TYPES.BlockStatement) {
|
|
17132
17459
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
17133
17460
|
}
|
|
17134
17461
|
return true;
|
|
@@ -17144,7 +17471,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
17144
17471
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
17145
17472
|
}
|
|
17146
17473
|
const only = defaultCase.consequent[0];
|
|
17147
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
17474
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils87.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
17148
17475
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
17149
17476
|
}
|
|
17150
17477
|
return false;
|
|
@@ -17156,7 +17483,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
17156
17483
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
17157
17484
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
17158
17485
|
if (constituents.every(
|
|
17159
|
-
(constituent) => (constituent.flags &
|
|
17486
|
+
(constituent) => (constituent.flags & import_typescript3.default.TypeFlags.BooleanLiteral) !== 0
|
|
17160
17487
|
)) {
|
|
17161
17488
|
return false;
|
|
17162
17489
|
}
|
|
@@ -17178,7 +17505,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
17178
17505
|
return [...expected].every((key) => handled.has(key));
|
|
17179
17506
|
}
|
|
17180
17507
|
function finiteTypeKey(type, checker) {
|
|
17181
|
-
const finiteFlags =
|
|
17508
|
+
const finiteFlags = import_typescript3.default.TypeFlags.StringLiteral | import_typescript3.default.TypeFlags.NumberLiteral | import_typescript3.default.TypeFlags.BooleanLiteral | import_typescript3.default.TypeFlags.EnumLiteral | import_typescript3.default.TypeFlags.UniqueESSymbol | import_typescript3.default.TypeFlags.Null | import_typescript3.default.TypeFlags.Undefined;
|
|
17182
17509
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
17183
17510
|
}
|
|
17184
17511
|
var require_assert_never_default = createRule({
|
|
@@ -17198,7 +17525,7 @@ var require_assert_never_default = createRule({
|
|
|
17198
17525
|
create(context) {
|
|
17199
17526
|
let services;
|
|
17200
17527
|
try {
|
|
17201
|
-
services =
|
|
17528
|
+
services = import_utils87.ESLintUtils.getParserServices(context);
|
|
17202
17529
|
} catch {
|
|
17203
17530
|
services = null;
|
|
17204
17531
|
}
|
|
@@ -17225,7 +17552,7 @@ var require_assert_never_default = createRule({
|
|
|
17225
17552
|
});
|
|
17226
17553
|
|
|
17227
17554
|
// src/rules/require-fetch-timeout.ts
|
|
17228
|
-
var
|
|
17555
|
+
var import_utils88 = require("@typescript-eslint/utils");
|
|
17229
17556
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
17230
17557
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
17231
17558
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -17252,14 +17579,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
17252
17579
|
return false;
|
|
17253
17580
|
}
|
|
17254
17581
|
function initProvablyLacksSignal(init) {
|
|
17255
|
-
if (init.type !==
|
|
17582
|
+
if (init.type !== import_utils88.AST_NODE_TYPES.ObjectExpression) {
|
|
17256
17583
|
return false;
|
|
17257
17584
|
}
|
|
17258
17585
|
for (const prop of init.properties) {
|
|
17259
|
-
if (prop.type ===
|
|
17586
|
+
if (prop.type === import_utils88.AST_NODE_TYPES.SpreadElement) {
|
|
17260
17587
|
return false;
|
|
17261
17588
|
}
|
|
17262
|
-
if (prop.key.type ===
|
|
17589
|
+
if (prop.key.type === import_utils88.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils88.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
17263
17590
|
return false;
|
|
17264
17591
|
}
|
|
17265
17592
|
if (prop.computed) {
|
|
@@ -17269,7 +17596,7 @@ function initProvablyLacksSignal(init) {
|
|
|
17269
17596
|
return true;
|
|
17270
17597
|
}
|
|
17271
17598
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
17272
|
-
return node.type ===
|
|
17599
|
+
return node.type === import_utils88.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils88.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils88.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils88.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
17273
17600
|
}
|
|
17274
17601
|
var require_fetch_timeout_default = createRule({
|
|
17275
17602
|
name: "require-fetch-timeout",
|
|
@@ -17307,30 +17634,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
17307
17634
|
}
|
|
17308
17635
|
function resolvesToGlobal(identifier) {
|
|
17309
17636
|
const scope = context.sourceCode.getScope(identifier);
|
|
17310
|
-
const variable =
|
|
17637
|
+
const variable = import_utils88.ASTUtils.findVariable(scope, identifier.name);
|
|
17311
17638
|
return variable === null || variable.defs.length === 0;
|
|
17312
17639
|
}
|
|
17313
17640
|
function isGlobalFetchCall2(callee) {
|
|
17314
|
-
if (callee.type ===
|
|
17641
|
+
if (callee.type === import_utils88.AST_NODE_TYPES.Identifier) {
|
|
17315
17642
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
17316
17643
|
}
|
|
17317
|
-
return callee.type ===
|
|
17644
|
+
return callee.type === import_utils88.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils88.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils88.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
17318
17645
|
}
|
|
17319
17646
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
17320
|
-
const variable =
|
|
17647
|
+
const variable = import_utils88.ASTUtils.findVariable(
|
|
17321
17648
|
context.sourceCode.getScope(identifier),
|
|
17322
17649
|
identifier.name
|
|
17323
17650
|
);
|
|
17324
17651
|
if (variable?.defs.length !== 1) return false;
|
|
17325
17652
|
const definition = variable.defs[0];
|
|
17326
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
17653
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== import_utils88.AST_NODE_TYPES.ObjectExpression || !initProvablyLacksSignal(definition.node.init)) {
|
|
17327
17654
|
return false;
|
|
17328
17655
|
}
|
|
17329
17656
|
for (const reference of variable.references) {
|
|
17330
17657
|
const ref = reference.identifier;
|
|
17331
17658
|
if (ref === identifier || ref === definition.name) continue;
|
|
17332
17659
|
const member = ref.parent;
|
|
17333
|
-
if (member.type !==
|
|
17660
|
+
if (member.type !== import_utils88.AST_NODE_TYPES.MemberExpression || member.object !== ref || member.computed || member.property.type !== import_utils88.AST_NODE_TYPES.Identifier || member.property.name === "signal" || member.parent.type !== import_utils88.AST_NODE_TYPES.AssignmentExpression || member.parent.left !== member) {
|
|
17334
17661
|
return false;
|
|
17335
17662
|
}
|
|
17336
17663
|
}
|
|
@@ -17338,13 +17665,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
17338
17665
|
}
|
|
17339
17666
|
function isForwardedRequest(argument) {
|
|
17340
17667
|
let value = argument;
|
|
17341
|
-
if (value.type ===
|
|
17342
|
-
const binding =
|
|
17668
|
+
if (value.type === import_utils88.AST_NODE_TYPES.Identifier) {
|
|
17669
|
+
const binding = import_utils88.ASTUtils.findVariable(context.sourceCode.getScope(value), value.name);
|
|
17343
17670
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
17344
17671
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
17345
17672
|
value = definition.node.init;
|
|
17346
17673
|
}
|
|
17347
|
-
return value.type ===
|
|
17674
|
+
return value.type === import_utils88.AST_NODE_TYPES.NewExpression && value.callee.type === import_utils88.AST_NODE_TYPES.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
17348
17675
|
}
|
|
17349
17676
|
return {
|
|
17350
17677
|
CallExpression(node) {
|
|
@@ -17355,7 +17682,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
17355
17682
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
17356
17683
|
return;
|
|
17357
17684
|
}
|
|
17358
|
-
if (init === void 0 || initProvablyLacksSignal(init) || init.type ===
|
|
17685
|
+
if (init === void 0 || initProvablyLacksSignal(init) || init.type === import_utils88.AST_NODE_TYPES.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
17359
17686
|
context.report({ node, messageId: "missingSignal" });
|
|
17360
17687
|
}
|
|
17361
17688
|
}
|
|
@@ -17364,7 +17691,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
17364
17691
|
});
|
|
17365
17692
|
|
|
17366
17693
|
// src/rules/require-interface-for-exported-class.ts
|
|
17367
|
-
var
|
|
17694
|
+
var import_utils89 = require("@typescript-eslint/utils");
|
|
17368
17695
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
17369
17696
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
17370
17697
|
rationale: "An explicit contract names the intended public capability separately from implementation details. TypeScript already supports structural compatibility; this is an architecture policy, not a prerequisite for substitution.",
|
|
@@ -17410,23 +17737,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
17410
17737
|
};
|
|
17411
17738
|
function hasPublicInstanceBehavior(node) {
|
|
17412
17739
|
return node.body.body.some((member) => {
|
|
17413
|
-
if (member.type ===
|
|
17414
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
17740
|
+
if (member.type === import_utils89.AST_NODE_TYPES.MethodDefinition) {
|
|
17741
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== import_utils89.AST_NODE_TYPES.PrivateIdentifier;
|
|
17415
17742
|
}
|
|
17416
|
-
if (member.type !==
|
|
17743
|
+
if (member.type !== import_utils89.AST_NODE_TYPES.PropertyDefinition || member.static)
|
|
17417
17744
|
return false;
|
|
17418
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
17419
|
-
return member.value?.type ===
|
|
17745
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === import_utils89.AST_NODE_TYPES.PrivateIdentifier) return false;
|
|
17746
|
+
return member.value?.type === import_utils89.AST_NODE_TYPES.ArrowFunctionExpression || member.value?.type === import_utils89.AST_NODE_TYPES.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === import_utils89.AST_NODE_TYPES.TSFunctionType;
|
|
17420
17747
|
});
|
|
17421
17748
|
}
|
|
17422
17749
|
function classBindings(statement) {
|
|
17423
|
-
const declaration = statement.type ===
|
|
17424
|
-
if (declaration?.type ===
|
|
17750
|
+
const declaration = statement.type === import_utils89.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
17751
|
+
if (declaration?.type === import_utils89.AST_NODE_TYPES.ClassDeclaration) {
|
|
17425
17752
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
17426
17753
|
}
|
|
17427
|
-
if (declaration?.type !==
|
|
17754
|
+
if (declaration?.type !== import_utils89.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
17428
17755
|
return declaration.declarations.flatMap(
|
|
17429
|
-
(item) => item.id.type ===
|
|
17756
|
+
(item) => item.id.type === import_utils89.AST_NODE_TYPES.Identifier && item.init?.type === import_utils89.AST_NODE_TYPES.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
17430
17757
|
);
|
|
17431
17758
|
}
|
|
17432
17759
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -17457,7 +17784,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
17457
17784
|
}
|
|
17458
17785
|
const exported = /* @__PURE__ */ new Map();
|
|
17459
17786
|
for (const statement of program.body) {
|
|
17460
|
-
if (statement.type ===
|
|
17787
|
+
if (statement.type === import_utils89.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
17461
17788
|
for (const binding of classBindings(statement)) {
|
|
17462
17789
|
exported.set(binding.declaration, binding.name);
|
|
17463
17790
|
}
|
|
@@ -17466,18 +17793,18 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
17466
17793
|
if (specifier.exportKind === "type") continue;
|
|
17467
17794
|
const candidate2 = classes.get(specifier.local.name);
|
|
17468
17795
|
if (candidate2 === void 0) continue;
|
|
17469
|
-
const exportedName = specifier.exported.type ===
|
|
17796
|
+
const exportedName = specifier.exported.type === import_utils89.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
17470
17797
|
exported.set(candidate2, exportedName);
|
|
17471
17798
|
}
|
|
17472
17799
|
continue;
|
|
17473
17800
|
}
|
|
17474
|
-
if (statement.type !==
|
|
17475
|
-
if (statement.declaration.type ===
|
|
17801
|
+
if (statement.type !== import_utils89.AST_NODE_TYPES.ExportDefaultDeclaration) continue;
|
|
17802
|
+
if (statement.declaration.type === import_utils89.AST_NODE_TYPES.ClassDeclaration || statement.declaration.type === import_utils89.AST_NODE_TYPES.ClassExpression) {
|
|
17476
17803
|
exported.set(
|
|
17477
17804
|
statement.declaration,
|
|
17478
17805
|
statement.declaration.id?.name ?? "default"
|
|
17479
17806
|
);
|
|
17480
|
-
} else if (statement.declaration.type ===
|
|
17807
|
+
} else if (statement.declaration.type === import_utils89.AST_NODE_TYPES.Identifier) {
|
|
17481
17808
|
const candidate2 = classes.get(statement.declaration.name);
|
|
17482
17809
|
if (candidate2 !== void 0) {
|
|
17483
17810
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -17485,7 +17812,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
17485
17812
|
}
|
|
17486
17813
|
}
|
|
17487
17814
|
for (const [declaration, exportedName] of exported) {
|
|
17488
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
17815
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === import_utils89.AST_NODE_TYPES.Identifier && abstractBases.has(declaration.superClass.name);
|
|
17489
17816
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
17490
17817
|
context.report({
|
|
17491
17818
|
node: declaration.id ?? declaration,
|
|
@@ -17499,7 +17826,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
17499
17826
|
});
|
|
17500
17827
|
|
|
17501
17828
|
// src/rules/require-port-for-service.ts
|
|
17502
|
-
var
|
|
17829
|
+
var import_utils90 = require("@typescript-eslint/utils");
|
|
17503
17830
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
17504
17831
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
17505
17832
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -17524,45 +17851,45 @@ var ROUTER_FACTORY_NAME = "Router";
|
|
|
17524
17851
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
17525
17852
|
var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "&&=", "??=", "||="]);
|
|
17526
17853
|
var staticMemberName6 = (member) => {
|
|
17527
|
-
if (member.property.type ===
|
|
17528
|
-
if (!member.computed && member.property.type ===
|
|
17529
|
-
return member.computed && member.property.type ===
|
|
17854
|
+
if (member.property.type === import_utils90.AST_NODE_TYPES.PrivateIdentifier) return `#${member.property.name}`;
|
|
17855
|
+
if (!member.computed && member.property.type === import_utils90.AST_NODE_TYPES.Identifier) return member.property.name;
|
|
17856
|
+
return member.computed && member.property.type === import_utils90.AST_NODE_TYPES.Literal && typeof member.property.value === "string" ? member.property.value : null;
|
|
17530
17857
|
};
|
|
17531
17858
|
var detachedValueExports = (program) => {
|
|
17532
17859
|
const names = /* @__PURE__ */ new Set();
|
|
17533
17860
|
for (const statement of program.body) {
|
|
17534
|
-
if (statement.type ===
|
|
17861
|
+
if (statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
17535
17862
|
for (const specifier of statement.specifiers) {
|
|
17536
17863
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
17537
17864
|
}
|
|
17538
|
-
} else if (statement.type ===
|
|
17865
|
+
} else if (statement.type === import_utils90.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17539
17866
|
names.add(statement.declaration.name);
|
|
17540
|
-
} else if (statement.type ===
|
|
17867
|
+
} else if (statement.type === import_utils90.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17541
17868
|
names.add(statement.expression.name);
|
|
17542
17869
|
}
|
|
17543
17870
|
}
|
|
17544
17871
|
return names;
|
|
17545
17872
|
};
|
|
17546
|
-
var isExportedClass2 = (node, detached) => node.parent.type ===
|
|
17873
|
+
var isExportedClass2 = (node, detached) => node.parent.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils90.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
17547
17874
|
var readTypeReference = (annotation) => {
|
|
17548
|
-
if (annotation?.type ===
|
|
17875
|
+
if (annotation?.type === import_utils90.AST_NODE_TYPES.TSUnionType) {
|
|
17549
17876
|
const members = annotation.types.filter(
|
|
17550
|
-
(member) => member.type !==
|
|
17877
|
+
(member) => member.type !== import_utils90.AST_NODE_TYPES.TSUndefinedKeyword && member.type !== import_utils90.AST_NODE_TYPES.TSNullKeyword
|
|
17551
17878
|
);
|
|
17552
17879
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
17553
17880
|
}
|
|
17554
|
-
if (annotation === void 0 || annotation.type !==
|
|
17881
|
+
if (annotation === void 0 || annotation.type !== import_utils90.AST_NODE_TYPES.TSTypeReference) return null;
|
|
17555
17882
|
const { typeName } = annotation;
|
|
17556
|
-
const rightmost = typeName.type ===
|
|
17883
|
+
const rightmost = typeName.type === import_utils90.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils90.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
17557
17884
|
if (rightmost === null) return null;
|
|
17558
17885
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
17559
17886
|
};
|
|
17560
|
-
var qualifiedName = (name) => name.type ===
|
|
17887
|
+
var qualifiedName = (name) => name.type === import_utils90.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils90.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
17561
17888
|
var propertySignatureTypes = (members) => {
|
|
17562
17889
|
const types = /* @__PURE__ */ new Map();
|
|
17563
17890
|
for (const member of members) {
|
|
17564
|
-
if (member.type !==
|
|
17565
|
-
if (member.computed || member.key.type !==
|
|
17891
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
17892
|
+
if (member.computed || member.key.type !== import_utils90.AST_NODE_TYPES.Identifier) continue;
|
|
17566
17893
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
17567
17894
|
if (reference === null) continue;
|
|
17568
17895
|
types.set(member.key.name, reference);
|
|
@@ -17573,18 +17900,18 @@ var fileTypeIndex = (program) => {
|
|
|
17573
17900
|
const objects = /* @__PURE__ */ new Map();
|
|
17574
17901
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
17575
17902
|
for (const statement of program.body) {
|
|
17576
|
-
const declaration = statement.type ===
|
|
17577
|
-
if (declaration?.type ===
|
|
17903
|
+
const declaration = statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
17904
|
+
if (declaration?.type === import_utils90.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
17578
17905
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
17579
17906
|
continue;
|
|
17580
17907
|
}
|
|
17581
|
-
if (declaration?.type !==
|
|
17908
|
+
if (declaration?.type !== import_utils90.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
17582
17909
|
const aliased = declaration.typeAnnotation;
|
|
17583
|
-
if (aliased.type ===
|
|
17910
|
+
if (aliased.type === import_utils90.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils90.AST_NODE_TYPES.TSConstructorType) {
|
|
17584
17911
|
functionAliases.add(declaration.id.name);
|
|
17585
17912
|
continue;
|
|
17586
17913
|
}
|
|
17587
|
-
const literals = aliased.type ===
|
|
17914
|
+
const literals = aliased.type === import_utils90.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils90.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils90.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
17588
17915
|
if (literals.length === 0) continue;
|
|
17589
17916
|
const merged = /* @__PURE__ */ new Map();
|
|
17590
17917
|
for (const literal of literals) {
|
|
@@ -17613,10 +17940,10 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
17613
17940
|
while (pending.length > 0) {
|
|
17614
17941
|
const current = pending.pop();
|
|
17615
17942
|
if (current === void 0) break;
|
|
17616
|
-
if (current.type ===
|
|
17617
|
-
const expression = current.type ===
|
|
17618
|
-
const storedField = expression?.type ===
|
|
17619
|
-
if (expression?.type !==
|
|
17943
|
+
if (current.type === import_utils90.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils90.AST_NODE_TYPES.FunctionExpression || current.type === import_utils90.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils90.AST_NODE_TYPES.ClassExpression || current.type === import_utils90.AST_NODE_TYPES.ClassDeclaration) continue;
|
|
17944
|
+
const expression = current.type === import_utils90.AST_NODE_TYPES.ExpressionStatement ? current.expression : null;
|
|
17945
|
+
const storedField = expression?.type === import_utils90.AST_NODE_TYPES.AssignmentExpression && expression.left.type === import_utils90.AST_NODE_TYPES.MemberExpression && expression.left.object.type === import_utils90.AST_NODE_TYPES.ThisExpression ? staticMemberName6(expression.left) : null;
|
|
17946
|
+
if (expression?.type !== import_utils90.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils90.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils90.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
17620
17947
|
for (const key of Object.keys(current)) {
|
|
17621
17948
|
if (key === "parent") continue;
|
|
17622
17949
|
const value = current[key];
|
|
@@ -17629,14 +17956,14 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
17629
17956
|
continue;
|
|
17630
17957
|
}
|
|
17631
17958
|
let source = expression.right;
|
|
17632
|
-
while (source.type ===
|
|
17633
|
-
if (source.type ===
|
|
17959
|
+
while (source.type === import_utils90.AST_NODE_TYPES.TSNonNullExpression || source.type === import_utils90.AST_NODE_TYPES.TSAsExpression || source.type === import_utils90.AST_NODE_TYPES.TSSatisfiesExpression || source.type === import_utils90.AST_NODE_TYPES.TSTypeAssertion) source = source.expression;
|
|
17960
|
+
if (source.type === import_utils90.AST_NODE_TYPES.NewExpression) {
|
|
17634
17961
|
constructedFields += 1;
|
|
17635
|
-
} else if (source.type ===
|
|
17962
|
+
} else if (source.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17636
17963
|
const fields = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
17637
17964
|
fields.add(storedField);
|
|
17638
17965
|
storedFieldsFrom.set(source.name, fields);
|
|
17639
|
-
} else if (source.type ===
|
|
17966
|
+
} else if (source.type === import_utils90.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17640
17967
|
const fields = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
17641
17968
|
fields.add(storedField);
|
|
17642
17969
|
storedFieldsFrom.set(source.object.name, fields);
|
|
@@ -17654,7 +17981,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
17654
17981
|
const collaborators = [];
|
|
17655
17982
|
for (const parameter of ctor.value.params) {
|
|
17656
17983
|
for (const reference of parameterCollaborators(parameter, declared, storedMemberFieldsFrom)) {
|
|
17657
|
-
const fields = parameter.type ===
|
|
17984
|
+
const fields = parameter.type === import_utils90.AST_NODE_TYPES.TSParameterProperty ? [reference.name] : reference.fields.length > 0 ? reference.fields : [...storedFieldsFrom.get(reference.name) ?? []];
|
|
17658
17985
|
if (fields.length === 0) continue;
|
|
17659
17986
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
17660
17987
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -17669,8 +17996,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
17669
17996
|
};
|
|
17670
17997
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
17671
17998
|
let target = parameter;
|
|
17672
|
-
if (target.type ===
|
|
17673
|
-
if (target.type ===
|
|
17999
|
+
if (target.type === import_utils90.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
18000
|
+
if (target.type === import_utils90.AST_NODE_TYPES.ObjectPattern) {
|
|
17674
18001
|
return objectPatternCollaborators(target, declared);
|
|
17675
18002
|
}
|
|
17676
18003
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -17679,9 +18006,9 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
17679
18006
|
};
|
|
17680
18007
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
17681
18008
|
let target = annotated;
|
|
17682
|
-
if (target.type ===
|
|
17683
|
-
if (target.type ===
|
|
17684
|
-
if (target.type !==
|
|
18009
|
+
if (target.type === import_utils90.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
18010
|
+
if (target.type === import_utils90.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
18011
|
+
if (target.type !== import_utils90.AST_NODE_TYPES.Identifier) return [];
|
|
17685
18012
|
const members = bagMemberTypes(target.typeAnnotation?.typeAnnotation, declared);
|
|
17686
18013
|
if (members === null) return [];
|
|
17687
18014
|
const storedMembers = storedMemberFieldsFrom.get(target.name);
|
|
@@ -17697,9 +18024,9 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
17697
18024
|
};
|
|
17698
18025
|
var namedParameterCollaborator = (annotated) => {
|
|
17699
18026
|
let target = annotated;
|
|
17700
|
-
if (target.type ===
|
|
17701
|
-
if (target.type ===
|
|
17702
|
-
if (target.type !==
|
|
18027
|
+
if (target.type === import_utils90.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
18028
|
+
if (target.type === import_utils90.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
18029
|
+
if (target.type !== import_utils90.AST_NODE_TYPES.Identifier) return null;
|
|
17703
18030
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
17704
18031
|
if (reference === null) return null;
|
|
17705
18032
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -17711,11 +18038,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
17711
18038
|
if (members === null) return [];
|
|
17712
18039
|
const collaborators = [];
|
|
17713
18040
|
for (const property of pattern.properties) {
|
|
17714
|
-
if (property.type !==
|
|
17715
|
-
if (property.key.type !==
|
|
18041
|
+
if (property.type !== import_utils90.AST_NODE_TYPES.Property || property.computed) continue;
|
|
18042
|
+
if (property.key.type !== import_utils90.AST_NODE_TYPES.Identifier) continue;
|
|
17716
18043
|
const key = property.key.name;
|
|
17717
|
-
const bound = property.value.type ===
|
|
17718
|
-
if (bound.type !==
|
|
18044
|
+
const bound = property.value.type === import_utils90.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
18045
|
+
if (bound.type !== import_utils90.AST_NODE_TYPES.Identifier) continue;
|
|
17719
18046
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
17720
18047
|
const reference = members.get(key);
|
|
17721
18048
|
if (reference === void 0) continue;
|
|
@@ -17725,21 +18052,21 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
17725
18052
|
};
|
|
17726
18053
|
var bagMemberTypes = (annotation, declared) => {
|
|
17727
18054
|
if (annotation === void 0) return null;
|
|
17728
|
-
if (annotation.type ===
|
|
18055
|
+
if (annotation.type === import_utils90.AST_NODE_TYPES.TSTypeLiteral) {
|
|
17729
18056
|
return propertySignatureTypes(annotation.members);
|
|
17730
18057
|
}
|
|
17731
|
-
if (annotation.type !==
|
|
18058
|
+
if (annotation.type !== import_utils90.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17732
18059
|
return null;
|
|
17733
18060
|
}
|
|
17734
18061
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
17735
18062
|
};
|
|
17736
18063
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
17737
|
-
if (node.type ===
|
|
18064
|
+
if (node.type === import_utils90.AST_NODE_TYPES.CallExpression) {
|
|
17738
18065
|
const { callee } = node;
|
|
17739
|
-
if (callee.type ===
|
|
17740
|
-
return callee.type ===
|
|
18066
|
+
if (callee.type === import_utils90.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
18067
|
+
return callee.type === import_utils90.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils90.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
17741
18068
|
}
|
|
17742
|
-
return node.type ===
|
|
18069
|
+
return node.type === import_utils90.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils90.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
17743
18070
|
});
|
|
17744
18071
|
var subtreeHas = (root, found) => {
|
|
17745
18072
|
let hit = false;
|
|
@@ -17766,19 +18093,19 @@ var invokedInstanceField = (call) => {
|
|
|
17766
18093
|
const direct = instanceField(call.callee);
|
|
17767
18094
|
if (direct !== null) return direct;
|
|
17768
18095
|
let callee = call.callee;
|
|
17769
|
-
while (callee.type ===
|
|
17770
|
-
return callee.type ===
|
|
18096
|
+
while (callee.type === import_utils90.AST_NODE_TYPES.ChainExpression || callee.type === import_utils90.AST_NODE_TYPES.TSAsExpression || callee.type === import_utils90.AST_NODE_TYPES.TSNonNullExpression || callee.type === import_utils90.AST_NODE_TYPES.TSSatisfiesExpression || callee.type === import_utils90.AST_NODE_TYPES.TSTypeAssertion) callee = callee.expression;
|
|
18097
|
+
return callee.type === import_utils90.AST_NODE_TYPES.MemberExpression ? instanceField(callee.object) : null;
|
|
17771
18098
|
};
|
|
17772
18099
|
var instanceField = (candidate2) => {
|
|
17773
18100
|
let node = candidate2;
|
|
17774
|
-
while (node.type ===
|
|
17775
|
-
return node.type ===
|
|
18101
|
+
while (node.type === import_utils90.AST_NODE_TYPES.ChainExpression || node.type === import_utils90.AST_NODE_TYPES.TSAsExpression || node.type === import_utils90.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils90.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils90.AST_NODE_TYPES.TSTypeAssertion) node = node.expression;
|
|
18102
|
+
return node.type === import_utils90.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils90.AST_NODE_TYPES.ThisExpression ? staticMemberName6(node) : null;
|
|
17776
18103
|
};
|
|
17777
18104
|
var behaviorallyInvokedFields = (body2) => {
|
|
17778
18105
|
const invoked = /* @__PURE__ */ new Set();
|
|
17779
18106
|
const visit = (current) => {
|
|
17780
|
-
if (current.type ===
|
|
17781
|
-
if (current.type ===
|
|
18107
|
+
if (current.type === import_utils90.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils90.AST_NODE_TYPES.ClassExpression || current.type === import_utils90.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils90.AST_NODE_TYPES.FunctionExpression) return;
|
|
18108
|
+
if (current.type === import_utils90.AST_NODE_TYPES.CallExpression) {
|
|
17782
18109
|
const field = invokedInstanceField(current);
|
|
17783
18110
|
if (field !== null) invoked.add(field);
|
|
17784
18111
|
}
|
|
@@ -17791,14 +18118,14 @@ var behaviorallyInvokedFields = (body2) => {
|
|
|
17791
18118
|
}
|
|
17792
18119
|
};
|
|
17793
18120
|
for (const member of body2.body) {
|
|
17794
|
-
if (member.type ===
|
|
17795
|
-
if (member.type ===
|
|
18121
|
+
if (member.type === import_utils90.AST_NODE_TYPES.StaticBlock || member.static) continue;
|
|
18122
|
+
if (member.type === import_utils90.AST_NODE_TYPES.MethodDefinition) {
|
|
17796
18123
|
if (member.value.body !== null && member.value.body !== void 0) visit(member.value.body);
|
|
17797
18124
|
continue;
|
|
17798
18125
|
}
|
|
17799
|
-
if (member.type !==
|
|
18126
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.PropertyDefinition || member.value === null) continue;
|
|
17800
18127
|
visit(
|
|
17801
|
-
member.value.type ===
|
|
18128
|
+
member.value.type === import_utils90.AST_NODE_TYPES.ArrowFunctionExpression ? member.value.body : member.value
|
|
17802
18129
|
);
|
|
17803
18130
|
}
|
|
17804
18131
|
return invoked;
|
|
@@ -17818,25 +18145,25 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
17818
18145
|
var fileInterfaceNames = (program) => {
|
|
17819
18146
|
const names = [];
|
|
17820
18147
|
for (const statement of program.body) {
|
|
17821
|
-
const declaration = statement.type ===
|
|
17822
|
-
if (declaration?.type ===
|
|
18148
|
+
const declaration = statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
18149
|
+
if (declaration?.type === import_utils90.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
17823
18150
|
}
|
|
17824
18151
|
return names;
|
|
17825
18152
|
};
|
|
17826
18153
|
var publicMethodNames = (body2, functionAliases) => {
|
|
17827
18154
|
const names = [];
|
|
17828
18155
|
for (const member of body2.body) {
|
|
17829
|
-
if (member.type ===
|
|
18156
|
+
if (member.type === import_utils90.AST_NODE_TYPES.PropertyDefinition) {
|
|
17830
18157
|
if (member.static || member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
17831
|
-
if (member.key.type ===
|
|
17832
|
-
if (member.value?.type !==
|
|
18158
|
+
if (member.key.type === import_utils90.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
18159
|
+
if (member.value?.type !== import_utils90.AST_NODE_TYPES.ArrowFunctionExpression && member.value?.type !== import_utils90.AST_NODE_TYPES.FunctionExpression && member.typeAnnotation?.typeAnnotation.type !== import_utils90.AST_NODE_TYPES.TSFunctionType && !(member.typeAnnotation?.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils90.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name))) continue;
|
|
17833
18160
|
names.push(declaredMemberName(member) ?? "\u2026");
|
|
17834
18161
|
continue;
|
|
17835
18162
|
}
|
|
17836
|
-
if (member.type !==
|
|
18163
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.MethodDefinition) continue;
|
|
17837
18164
|
if (member.kind !== "method" || member.static) continue;
|
|
17838
18165
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
17839
|
-
if (member.key.type ===
|
|
18166
|
+
if (member.key.type === import_utils90.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
17840
18167
|
names.push(declaredMemberName(member) ?? "\u2026");
|
|
17841
18168
|
}
|
|
17842
18169
|
return names;
|
|
@@ -17844,13 +18171,13 @@ var publicMethodNames = (body2, functionAliases) => {
|
|
|
17844
18171
|
var isFluentConstructionObject = (node, getText) => {
|
|
17845
18172
|
if (node.id === null) return false;
|
|
17846
18173
|
const methods = node.body.body.filter(
|
|
17847
|
-
(member) => member.type ===
|
|
18174
|
+
(member) => member.type === import_utils90.AST_NODE_TYPES.MethodDefinition && member.kind === "method" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.value.body !== null
|
|
17848
18175
|
);
|
|
17849
18176
|
if (methods.length === 0) return false;
|
|
17850
18177
|
return methods.every((member) => {
|
|
17851
18178
|
const result = member.value.returnType?.typeAnnotation;
|
|
17852
18179
|
if (result === void 0) return false;
|
|
17853
|
-
const returnsOwnType = result.type ===
|
|
18180
|
+
const returnsOwnType = result.type === import_utils90.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils90.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
17854
18181
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
17855
18182
|
});
|
|
17856
18183
|
};
|
|
@@ -17858,10 +18185,10 @@ function localClassAbstractness(program) {
|
|
|
17858
18185
|
const classes = /* @__PURE__ */ new Map();
|
|
17859
18186
|
const parents = /* @__PURE__ */ new Map();
|
|
17860
18187
|
for (const statement of program.body) {
|
|
17861
|
-
const declaration = statement.type ===
|
|
17862
|
-
if (declaration?.type ===
|
|
18188
|
+
const declaration = statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils90.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
18189
|
+
if (declaration?.type === import_utils90.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
17863
18190
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
17864
|
-
if (declaration.superClass?.type ===
|
|
18191
|
+
if (declaration.superClass?.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17865
18192
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
17866
18193
|
}
|
|
17867
18194
|
}
|
|
@@ -17879,8 +18206,8 @@ function localClassAbstractness(program) {
|
|
|
17879
18206
|
return classes;
|
|
17880
18207
|
}
|
|
17881
18208
|
function declaredMemberName(member) {
|
|
17882
|
-
if (!member.computed && member.key.type ===
|
|
17883
|
-
if (member.key.type ===
|
|
18209
|
+
if (!member.computed && member.key.type === import_utils90.AST_NODE_TYPES.Identifier) return member.key.name;
|
|
18210
|
+
if (member.key.type === import_utils90.AST_NODE_TYPES.Literal && typeof member.key.value === "string") return member.key.value;
|
|
17884
18211
|
return null;
|
|
17885
18212
|
}
|
|
17886
18213
|
function localInterfaceSurfaces(program) {
|
|
@@ -17888,45 +18215,45 @@ function localInterfaceSurfaces(program) {
|
|
|
17888
18215
|
const parents = /* @__PURE__ */ new Map();
|
|
17889
18216
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
17890
18217
|
for (const statement of program.body) {
|
|
17891
|
-
const declaration = statement.type ===
|
|
17892
|
-
if (declaration?.type ===
|
|
18218
|
+
const declaration = statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
18219
|
+
if (declaration?.type === import_utils90.AST_NODE_TYPES.TSTypeAliasDeclaration && (declaration.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSFunctionType || declaration.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSConstructorType)) functionAliases.add(declaration.id.name);
|
|
17893
18220
|
}
|
|
17894
18221
|
for (const statement of program.body) {
|
|
17895
|
-
const declaration = statement.type ===
|
|
17896
|
-
if (declaration?.type ===
|
|
18222
|
+
const declaration = statement.type === import_utils90.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
18223
|
+
if (declaration?.type === import_utils90.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
17897
18224
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
17898
|
-
const parts = declaration.typeAnnotation.type ===
|
|
18225
|
+
const parts = declaration.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
17899
18226
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
17900
18227
|
for (const part of parts) {
|
|
17901
|
-
if (part.type ===
|
|
18228
|
+
if (part.type === import_utils90.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils90.AST_NODE_TYPES.Identifier) {
|
|
17902
18229
|
inherited.push(part.typeName.name);
|
|
17903
18230
|
continue;
|
|
17904
18231
|
}
|
|
17905
|
-
if (part.type !==
|
|
18232
|
+
if (part.type !== import_utils90.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
17906
18233
|
for (const member of part.members) {
|
|
17907
|
-
if (member.type !==
|
|
18234
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils90.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
17908
18235
|
const name = declaredMemberName(member);
|
|
17909
18236
|
if (name === null) continue;
|
|
17910
|
-
if (member.type ===
|
|
18237
|
+
if (member.type === import_utils90.AST_NODE_TYPES.TSMethodSignature) {
|
|
17911
18238
|
callables2.add(name);
|
|
17912
18239
|
continue;
|
|
17913
18240
|
}
|
|
17914
|
-
if (member.type !==
|
|
18241
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
17915
18242
|
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
17916
|
-
if (annotation?.type ===
|
|
18243
|
+
if (annotation?.type === import_utils90.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils90.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils90.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)) callables2.add(name);
|
|
17917
18244
|
}
|
|
17918
18245
|
}
|
|
17919
18246
|
interfaces.set(declaration.id.name, callables2);
|
|
17920
18247
|
parents.set(declaration.id.name, inherited);
|
|
17921
18248
|
continue;
|
|
17922
18249
|
}
|
|
17923
|
-
if (declaration?.type !==
|
|
18250
|
+
if (declaration?.type !== import_utils90.AST_NODE_TYPES.TSInterfaceDeclaration) continue;
|
|
17924
18251
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
17925
18252
|
for (const member of declaration.body.body) {
|
|
17926
|
-
if (member.type !==
|
|
18253
|
+
if (member.type !== import_utils90.AST_NODE_TYPES.TSMethodSignature && member.type !== import_utils90.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
17927
18254
|
const name = declaredMemberName(member);
|
|
17928
18255
|
if (name === null) continue;
|
|
17929
|
-
if (member.type ===
|
|
18256
|
+
if (member.type === import_utils90.AST_NODE_TYPES.TSMethodSignature || member.typeAnnotation?.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSFunctionType || member.typeAnnotation?.typeAnnotation.type === import_utils90.AST_NODE_TYPES.TSTypeReference && member.typeAnnotation.typeAnnotation.typeName.type === import_utils90.AST_NODE_TYPES.Identifier && functionAliases.has(member.typeAnnotation.typeAnnotation.typeName.name)) callables.add(name);
|
|
17930
18257
|
}
|
|
17931
18258
|
interfaces.set(declaration.id.name, callables);
|
|
17932
18259
|
parents.set(
|
|
@@ -17934,7 +18261,7 @@ function localInterfaceSurfaces(program) {
|
|
|
17934
18261
|
[
|
|
17935
18262
|
...parents.get(declaration.id.name) ?? [],
|
|
17936
18263
|
...declaration.extends.flatMap(
|
|
17937
|
-
(heritage) => heritage.expression.type ===
|
|
18264
|
+
(heritage) => heritage.expression.type === import_utils90.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
17938
18265
|
)
|
|
17939
18266
|
]
|
|
17940
18267
|
);
|
|
@@ -17961,7 +18288,7 @@ function localInterfaceSurfaces(program) {
|
|
|
17961
18288
|
}
|
|
17962
18289
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
17963
18290
|
if (node.superClass !== null) {
|
|
17964
|
-
if (node.superClass.type !==
|
|
18291
|
+
if (node.superClass.type !== import_utils90.AST_NODE_TYPES.Identifier) return true;
|
|
17965
18292
|
const localAbstract = classes.get(node.superClass.name);
|
|
17966
18293
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
17967
18294
|
}
|
|
@@ -17973,7 +18300,7 @@ function hasServicePort(node, methods, classes, interfaces) {
|
|
|
17973
18300
|
if (node.implements.length === 0) return false;
|
|
17974
18301
|
const combined = /* @__PURE__ */ new Set();
|
|
17975
18302
|
for (const implementation of node.implements) {
|
|
17976
|
-
if (implementation.expression.type !==
|
|
18303
|
+
if (implementation.expression.type !== import_utils90.AST_NODE_TYPES.Identifier) return true;
|
|
17977
18304
|
const name = implementation.expression.name;
|
|
17978
18305
|
const localAbstract = classes.get(name);
|
|
17979
18306
|
if (localAbstract === true) return true;
|
|
@@ -18016,7 +18343,7 @@ var require_port_for_service_default = createRule({
|
|
|
18016
18343
|
if (node.abstract === true) return;
|
|
18017
18344
|
if (node.decorators.length > 0) return;
|
|
18018
18345
|
const ctor = node.body.body.find(
|
|
18019
|
-
(member) => member.type ===
|
|
18346
|
+
(member) => member.type === import_utils90.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor" && member.value.body !== null && member.value.body !== void 0
|
|
18020
18347
|
);
|
|
18021
18348
|
if (ctor === void 0) return;
|
|
18022
18349
|
const constructorFacts = readConstructor(
|
|
@@ -18051,7 +18378,7 @@ var require_port_for_service_default = createRule({
|
|
|
18051
18378
|
});
|
|
18052
18379
|
|
|
18053
18380
|
// src/rules/require-sql-access-class.ts
|
|
18054
|
-
var
|
|
18381
|
+
var import_utils91 = require("@typescript-eslint/utils");
|
|
18055
18382
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
18056
18383
|
"all",
|
|
18057
18384
|
"batch",
|
|
@@ -18146,9 +18473,9 @@ var REQUIRE_SQL_ACCESS_CLASS_DOCUMENTATION = {
|
|
|
18146
18473
|
]
|
|
18147
18474
|
};
|
|
18148
18475
|
function memberName6(node) {
|
|
18149
|
-
if (!node.computed && node.property.type ===
|
|
18476
|
+
if (!node.computed && node.property.type === import_utils91.AST_NODE_TYPES.Identifier)
|
|
18150
18477
|
return node.property.name;
|
|
18151
|
-
if (node.computed && node.property.type ===
|
|
18478
|
+
if (node.computed && node.property.type === import_utils91.AST_NODE_TYPES.Literal && typeof node.property.value === "string")
|
|
18152
18479
|
return node.property.value;
|
|
18153
18480
|
return null;
|
|
18154
18481
|
}
|
|
@@ -18160,89 +18487,89 @@ function isDatabaseOperation(method, receiver) {
|
|
|
18160
18487
|
return BUILDER_SHORT_TERMINALS.has(method) && expressionCallsBuilder(receiver);
|
|
18161
18488
|
}
|
|
18162
18489
|
function databaseReceiver(node) {
|
|
18163
|
-
if (node.type ===
|
|
18490
|
+
if (node.type === import_utils91.AST_NODE_TYPES.Identifier)
|
|
18164
18491
|
return DATABASE_NAMES.test(node.name);
|
|
18165
|
-
if (node.type !==
|
|
18492
|
+
if (node.type !== import_utils91.AST_NODE_TYPES.MemberExpression) return false;
|
|
18166
18493
|
const name = memberName6(node);
|
|
18167
18494
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
18168
18495
|
}
|
|
18169
18496
|
function databaseRootMember(node) {
|
|
18170
18497
|
let current = node;
|
|
18171
18498
|
for (; ; ) {
|
|
18172
|
-
if (current.type ===
|
|
18499
|
+
if (current.type === import_utils91.AST_NODE_TYPES.ChainExpression) {
|
|
18173
18500
|
current = current.expression;
|
|
18174
18501
|
continue;
|
|
18175
18502
|
}
|
|
18176
|
-
if (current.type ===
|
|
18503
|
+
if (current.type === import_utils91.AST_NODE_TYPES.TSAsExpression || current.type === import_utils91.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils91.AST_NODE_TYPES.TSTypeAssertion) {
|
|
18177
18504
|
current = current.expression;
|
|
18178
18505
|
continue;
|
|
18179
18506
|
}
|
|
18180
|
-
if (current.type ===
|
|
18181
|
-
if (current.callee.type !==
|
|
18507
|
+
if (current.type === import_utils91.AST_NODE_TYPES.CallExpression) {
|
|
18508
|
+
if (current.callee.type !== import_utils91.AST_NODE_TYPES.MemberExpression) return null;
|
|
18182
18509
|
current = current.callee.object;
|
|
18183
18510
|
continue;
|
|
18184
18511
|
}
|
|
18185
|
-
if (current.type ===
|
|
18186
|
-
if (current.object.type ===
|
|
18512
|
+
if (current.type === import_utils91.AST_NODE_TYPES.MemberExpression) {
|
|
18513
|
+
if (current.object.type === import_utils91.AST_NODE_TYPES.ThisExpression)
|
|
18187
18514
|
return memberName6(current);
|
|
18188
18515
|
current = current.object;
|
|
18189
18516
|
continue;
|
|
18190
18517
|
}
|
|
18191
|
-
return current.type ===
|
|
18518
|
+
return current.type === import_utils91.AST_NODE_TYPES.Identifier ? current.name : null;
|
|
18192
18519
|
}
|
|
18193
18520
|
}
|
|
18194
18521
|
function expressionHasDatabaseMarker(node) {
|
|
18195
18522
|
let current = node;
|
|
18196
18523
|
for (; ; ) {
|
|
18197
|
-
if (current.type ===
|
|
18524
|
+
if (current.type === import_utils91.AST_NODE_TYPES.ChainExpression) {
|
|
18198
18525
|
current = current.expression;
|
|
18199
18526
|
continue;
|
|
18200
18527
|
}
|
|
18201
|
-
if (current.type ===
|
|
18528
|
+
if (current.type === import_utils91.AST_NODE_TYPES.TSAsExpression || current.type === import_utils91.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils91.AST_NODE_TYPES.TSTypeAssertion) {
|
|
18202
18529
|
current = current.expression;
|
|
18203
18530
|
continue;
|
|
18204
18531
|
}
|
|
18205
|
-
if (current.type ===
|
|
18206
|
-
if (current.callee.type !==
|
|
18532
|
+
if (current.type === import_utils91.AST_NODE_TYPES.CallExpression) {
|
|
18533
|
+
if (current.callee.type !== import_utils91.AST_NODE_TYPES.MemberExpression) return false;
|
|
18207
18534
|
current = current.callee.object;
|
|
18208
18535
|
continue;
|
|
18209
18536
|
}
|
|
18210
|
-
if (current.type ===
|
|
18537
|
+
if (current.type === import_utils91.AST_NODE_TYPES.MemberExpression) {
|
|
18211
18538
|
const name = memberName6(current);
|
|
18212
18539
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
18213
18540
|
return true;
|
|
18214
18541
|
current = current.object;
|
|
18215
18542
|
continue;
|
|
18216
18543
|
}
|
|
18217
|
-
return current.type ===
|
|
18544
|
+
return current.type === import_utils91.AST_NODE_TYPES.Identifier && DATABASE_NAMES.test(current.name);
|
|
18218
18545
|
}
|
|
18219
18546
|
}
|
|
18220
18547
|
function expressionCallsBuilder(node) {
|
|
18221
18548
|
let current = node;
|
|
18222
18549
|
for (; ; ) {
|
|
18223
|
-
if (current.type ===
|
|
18550
|
+
if (current.type === import_utils91.AST_NODE_TYPES.ChainExpression) {
|
|
18224
18551
|
current = current.expression;
|
|
18225
18552
|
continue;
|
|
18226
18553
|
}
|
|
18227
|
-
if (current.type ===
|
|
18554
|
+
if (current.type === import_utils91.AST_NODE_TYPES.TSAsExpression || current.type === import_utils91.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils91.AST_NODE_TYPES.TSTypeAssertion) {
|
|
18228
18555
|
current = current.expression;
|
|
18229
18556
|
continue;
|
|
18230
18557
|
}
|
|
18231
|
-
if (current.type ===
|
|
18232
|
-
if (current.callee.type !==
|
|
18558
|
+
if (current.type === import_utils91.AST_NODE_TYPES.CallExpression) {
|
|
18559
|
+
if (current.callee.type !== import_utils91.AST_NODE_TYPES.MemberExpression) return false;
|
|
18233
18560
|
const name = memberName6(current.callee);
|
|
18234
18561
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
18235
18562
|
current = current.callee.object;
|
|
18236
18563
|
continue;
|
|
18237
18564
|
}
|
|
18238
|
-
if (current.type !==
|
|
18565
|
+
if (current.type !== import_utils91.AST_NODE_TYPES.MemberExpression) return false;
|
|
18239
18566
|
current = current.object;
|
|
18240
18567
|
}
|
|
18241
18568
|
}
|
|
18242
18569
|
function owningClass2(node) {
|
|
18243
18570
|
let current = node.parent;
|
|
18244
18571
|
while (current != null) {
|
|
18245
|
-
if (current.type ===
|
|
18572
|
+
if (current.type === import_utils91.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils91.AST_NODE_TYPES.ClassExpression)
|
|
18246
18573
|
return current;
|
|
18247
18574
|
current = current.parent;
|
|
18248
18575
|
}
|
|
@@ -18251,25 +18578,25 @@ function owningClass2(node) {
|
|
|
18251
18578
|
function injectedMembers(owner) {
|
|
18252
18579
|
const injected = /* @__PURE__ */ new Set();
|
|
18253
18580
|
const constructor = owner.body.body.find(
|
|
18254
|
-
(member) => member.type ===
|
|
18581
|
+
(member) => member.type === import_utils91.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
18255
18582
|
);
|
|
18256
18583
|
if (constructor === void 0) return injected;
|
|
18257
18584
|
const parameters = /* @__PURE__ */ new Set();
|
|
18258
18585
|
for (const parameter of constructor.value.params) {
|
|
18259
18586
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
18260
|
-
if (parameter.type !==
|
|
18261
|
-
const value = parameter.parameter.type ===
|
|
18262
|
-
if (value.type ===
|
|
18587
|
+
if (parameter.type !== import_utils91.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
18588
|
+
const value = parameter.parameter.type === import_utils91.AST_NODE_TYPES.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
18589
|
+
if (value.type === import_utils91.AST_NODE_TYPES.Identifier) injected.add(value.name);
|
|
18263
18590
|
}
|
|
18264
18591
|
const body2 = constructor.value.body;
|
|
18265
18592
|
if (body2 === null) return injected;
|
|
18266
18593
|
for (const statement of body2.body) {
|
|
18267
|
-
if (statement.type !==
|
|
18594
|
+
if (statement.type !== import_utils91.AST_NODE_TYPES.ExpressionStatement || statement.expression.type !== import_utils91.AST_NODE_TYPES.AssignmentExpression || statement.expression.operator !== "=") continue;
|
|
18268
18595
|
const { left, right } = statement.expression;
|
|
18269
|
-
if (left.type !==
|
|
18596
|
+
if (left.type !== import_utils91.AST_NODE_TYPES.MemberExpression) continue;
|
|
18270
18597
|
const target = thisRootMember(left);
|
|
18271
18598
|
if (target === null) continue;
|
|
18272
|
-
const source = right.type ===
|
|
18599
|
+
const source = right.type === import_utils91.AST_NODE_TYPES.Identifier ? right.name : right.type === import_utils91.AST_NODE_TYPES.MemberExpression && right.object.type === import_utils91.AST_NODE_TYPES.Identifier ? right.object.name : null;
|
|
18273
18600
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
18274
18601
|
}
|
|
18275
18602
|
return injected;
|
|
@@ -18277,26 +18604,26 @@ function injectedMembers(owner) {
|
|
|
18277
18604
|
function thisRootMember(node) {
|
|
18278
18605
|
let current = node;
|
|
18279
18606
|
let root = null;
|
|
18280
|
-
while (current.type ===
|
|
18607
|
+
while (current.type === import_utils91.AST_NODE_TYPES.MemberExpression) {
|
|
18281
18608
|
const name = memberName6(current);
|
|
18282
18609
|
if (name === null) return null;
|
|
18283
18610
|
root = name;
|
|
18284
18611
|
current = current.object;
|
|
18285
18612
|
}
|
|
18286
|
-
return current.type ===
|
|
18613
|
+
return current.type === import_utils91.AST_NODE_TYPES.ThisExpression ? root : null;
|
|
18287
18614
|
}
|
|
18288
18615
|
function parameterNames(parameter) {
|
|
18289
18616
|
let value = parameter;
|
|
18290
|
-
if (value.type ===
|
|
18291
|
-
if (value.type ===
|
|
18292
|
-
if (value.type ===
|
|
18293
|
-
if (value.type !==
|
|
18617
|
+
if (value.type === import_utils91.AST_NODE_TYPES.TSParameterProperty) value = value.parameter;
|
|
18618
|
+
if (value.type === import_utils91.AST_NODE_TYPES.AssignmentPattern) value = value.left;
|
|
18619
|
+
if (value.type === import_utils91.AST_NODE_TYPES.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
18620
|
+
if (value.type !== import_utils91.AST_NODE_TYPES.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
18294
18621
|
return new Set(
|
|
18295
18622
|
value.properties.flatMap((property) => {
|
|
18296
|
-
if (property.type ===
|
|
18297
|
-
return property.argument.type ===
|
|
18298
|
-
const target = property.value.type ===
|
|
18299
|
-
return target.type ===
|
|
18623
|
+
if (property.type === import_utils91.AST_NODE_TYPES.RestElement)
|
|
18624
|
+
return property.argument.type === import_utils91.AST_NODE_TYPES.Identifier ? [property.argument.name] : [];
|
|
18625
|
+
const target = property.value.type === import_utils91.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
18626
|
+
return target.type === import_utils91.AST_NODE_TYPES.Identifier ? [target.name] : [];
|
|
18300
18627
|
})
|
|
18301
18628
|
);
|
|
18302
18629
|
}
|
|
@@ -18320,17 +18647,17 @@ var require_sql_access_class_default = createRule({
|
|
|
18320
18647
|
function knownNonDatabase(node, seen = /* @__PURE__ */ new Set()) {
|
|
18321
18648
|
if (seen.has(node)) return false;
|
|
18322
18649
|
seen.add(node);
|
|
18323
|
-
if (node.type ===
|
|
18324
|
-
const binding =
|
|
18650
|
+
if (node.type === import_utils91.AST_NODE_TYPES.Identifier) {
|
|
18651
|
+
const binding = import_utils91.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
18325
18652
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
18326
18653
|
const definition = binding.defs[0];
|
|
18327
18654
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
18328
18655
|
}
|
|
18329
|
-
return node.type ===
|
|
18656
|
+
return node.type === import_utils91.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils91.AST_NODE_TYPES.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(node.callee.name) && (import_utils91.ASTUtils.findVariable(context.sourceCode.getScope(node.callee), node.callee.name)?.defs.length ?? 0) === 0;
|
|
18330
18657
|
}
|
|
18331
18658
|
return {
|
|
18332
18659
|
CallExpression(node) {
|
|
18333
|
-
if (node.callee.type !==
|
|
18660
|
+
if (node.callee.type !== import_utils91.AST_NODE_TYPES.MemberExpression)
|
|
18334
18661
|
return;
|
|
18335
18662
|
const method = memberName6(node.callee);
|
|
18336
18663
|
if (knownNonDatabase(node.callee.object)) return;
|
|
@@ -18348,7 +18675,7 @@ var require_sql_access_class_default = createRule({
|
|
|
18348
18675
|
});
|
|
18349
18676
|
|
|
18350
18677
|
// src/rules/require-static-next-matcher.ts
|
|
18351
|
-
var
|
|
18678
|
+
var import_utils92 = require("@typescript-eslint/utils");
|
|
18352
18679
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
18353
18680
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
18354
18681
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -18363,34 +18690,34 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
18363
18690
|
};
|
|
18364
18691
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
18365
18692
|
function unwrapExpression3(node) {
|
|
18366
|
-
if (node.type ===
|
|
18693
|
+
if (node.type === import_utils92.AST_NODE_TYPES.TSAsExpression || node.type === import_utils92.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils92.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils92.AST_NODE_TYPES.TSTypeAssertion) {
|
|
18367
18694
|
return unwrapExpression3(node.expression);
|
|
18368
18695
|
}
|
|
18369
18696
|
return node;
|
|
18370
18697
|
}
|
|
18371
18698
|
function isStaticValue(node) {
|
|
18372
18699
|
const value = unwrapExpression3(node);
|
|
18373
|
-
if (value.type ===
|
|
18700
|
+
if (value.type === import_utils92.AST_NODE_TYPES.Literal) {
|
|
18374
18701
|
return true;
|
|
18375
18702
|
}
|
|
18376
|
-
if (value.type ===
|
|
18703
|
+
if (value.type === import_utils92.AST_NODE_TYPES.TemplateLiteral) {
|
|
18377
18704
|
return value.expressions.length === 0;
|
|
18378
18705
|
}
|
|
18379
|
-
if (value.type ===
|
|
18706
|
+
if (value.type === import_utils92.AST_NODE_TYPES.ArrayExpression) {
|
|
18380
18707
|
return value.elements.every(
|
|
18381
|
-
(element) => element !== null && element.type !==
|
|
18708
|
+
(element) => element !== null && element.type !== import_utils92.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
18382
18709
|
);
|
|
18383
18710
|
}
|
|
18384
|
-
if (value.type ===
|
|
18711
|
+
if (value.type === import_utils92.AST_NODE_TYPES.ObjectExpression) {
|
|
18385
18712
|
return value.properties.every(
|
|
18386
|
-
(property) => property.type ===
|
|
18713
|
+
(property) => property.type === import_utils92.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils92.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
18387
18714
|
);
|
|
18388
18715
|
}
|
|
18389
18716
|
return false;
|
|
18390
18717
|
}
|
|
18391
18718
|
function propertyName5(property) {
|
|
18392
18719
|
if (property.computed) return null;
|
|
18393
|
-
if (property.key.type ===
|
|
18720
|
+
if (property.key.type === import_utils92.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
18394
18721
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
18395
18722
|
}
|
|
18396
18723
|
var require_static_next_matcher_default = createRule({
|
|
@@ -18413,19 +18740,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
18413
18740
|
}
|
|
18414
18741
|
return {
|
|
18415
18742
|
ExportNamedDeclaration(node) {
|
|
18416
|
-
if (node.declaration?.type !==
|
|
18743
|
+
if (node.declaration?.type !== import_utils92.AST_NODE_TYPES.VariableDeclaration) {
|
|
18417
18744
|
return;
|
|
18418
18745
|
}
|
|
18419
18746
|
for (const declaration of node.declaration.declarations) {
|
|
18420
|
-
if (declaration.id.type !==
|
|
18747
|
+
if (declaration.id.type !== import_utils92.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
18421
18748
|
continue;
|
|
18422
18749
|
}
|
|
18423
18750
|
const config = unwrapExpression3(declaration.init);
|
|
18424
|
-
if (config.type !==
|
|
18751
|
+
if (config.type !== import_utils92.AST_NODE_TYPES.ObjectExpression) {
|
|
18425
18752
|
continue;
|
|
18426
18753
|
}
|
|
18427
18754
|
for (const property of config.properties) {
|
|
18428
|
-
if (property.type !==
|
|
18755
|
+
if (property.type !== import_utils92.AST_NODE_TYPES.Property || propertyName5(property) !== "matcher" || property.value.type === import_utils92.AST_NODE_TYPES.AssignmentPattern) {
|
|
18429
18756
|
continue;
|
|
18430
18757
|
}
|
|
18431
18758
|
if (!isStaticValue(property.value)) {
|
|
@@ -18439,7 +18766,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
18439
18766
|
});
|
|
18440
18767
|
|
|
18441
18768
|
// src/rules/require-use-form-default-values.ts
|
|
18442
|
-
var
|
|
18769
|
+
var import_utils93 = require("@typescript-eslint/utils");
|
|
18443
18770
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
18444
18771
|
summary: "react-hook-form useForm call without explicit initial or reactive values",
|
|
18445
18772
|
rationale: "Without an explicit initial value, fields can change from uncontrolled to controlled as data arrives, reset behavior becomes ambiguous, and the form's initial shape no longer documents the values users can edit.",
|
|
@@ -18493,13 +18820,13 @@ var require_use_form_default_values_default = createRule({
|
|
|
18493
18820
|
if (node.source.value !== "react-hook-form") return;
|
|
18494
18821
|
for (const specifier of node.specifiers) {
|
|
18495
18822
|
if (specifier.type !== "ImportSpecifier" || (specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) !== "useForm") continue;
|
|
18496
|
-
const variable =
|
|
18823
|
+
const variable = import_utils93.ASTUtils.findVariable(context.sourceCode.getScope(specifier.local), specifier.local.name);
|
|
18497
18824
|
if (variable) importedHooks.add(variable);
|
|
18498
18825
|
}
|
|
18499
18826
|
},
|
|
18500
18827
|
CallExpression(node) {
|
|
18501
18828
|
if (node.callee.type !== "Identifier") return;
|
|
18502
|
-
const variable =
|
|
18829
|
+
const variable = import_utils93.ASTUtils.findVariable(context.sourceCode.getScope(node.callee), node.callee.name);
|
|
18503
18830
|
const options = node.arguments[0];
|
|
18504
18831
|
if (!variable || !importedHooks.has(variable) || options !== void 0 && options.type !== "ObjectExpression" || hasInitializationOrUnknownOptions(options)) return;
|
|
18505
18832
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
@@ -18509,7 +18836,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
18509
18836
|
});
|
|
18510
18837
|
|
|
18511
18838
|
// src/rules/require-use-server-in-actions-file.ts
|
|
18512
|
-
var
|
|
18839
|
+
var import_utils94 = require("@typescript-eslint/utils");
|
|
18513
18840
|
var ACTION_MODULE_RE = /(?:^|\/)app\/.*\/(?:actions|[^/]+-actions)\.[cm]?[jt]s$/u;
|
|
18514
18841
|
var REQUIRE_USE_SERVER_IN_ACTIONS_FILE_DOCUMENTATION = {
|
|
18515
18842
|
summary: "route action module missing the use server directive",
|
|
@@ -18576,7 +18903,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
18576
18903
|
});
|
|
18577
18904
|
|
|
18578
18905
|
// src/rules/require-zod-form-validation.ts
|
|
18579
|
-
var
|
|
18906
|
+
var import_utils95 = require("@typescript-eslint/utils");
|
|
18580
18907
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
18581
18908
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
18582
18909
|
rationale: "FormData values are untrusted strings or files and need runtime validation before use.",
|
|
@@ -18602,14 +18929,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
18602
18929
|
var zodReceiverRoot = (node) => {
|
|
18603
18930
|
let current = node;
|
|
18604
18931
|
while (true) {
|
|
18605
|
-
if (current.type ===
|
|
18932
|
+
if (current.type === import_utils95.AST_NODE_TYPES.Identifier) {
|
|
18606
18933
|
return current;
|
|
18607
18934
|
}
|
|
18608
|
-
if (current.type ===
|
|
18935
|
+
if (current.type === import_utils95.AST_NODE_TYPES.CallExpression) {
|
|
18609
18936
|
current = current.callee;
|
|
18610
18937
|
continue;
|
|
18611
18938
|
}
|
|
18612
|
-
if (current.type ===
|
|
18939
|
+
if (current.type === import_utils95.AST_NODE_TYPES.MemberExpression) {
|
|
18613
18940
|
current = current.object;
|
|
18614
18941
|
continue;
|
|
18615
18942
|
}
|
|
@@ -18618,12 +18945,12 @@ var zodReceiverRoot = (node) => {
|
|
|
18618
18945
|
};
|
|
18619
18946
|
var isFormDataMethodCall = (node) => {
|
|
18620
18947
|
let current = node;
|
|
18621
|
-
if (current.type ===
|
|
18948
|
+
if (current.type === import_utils95.AST_NODE_TYPES.AwaitExpression) {
|
|
18622
18949
|
current = current.argument;
|
|
18623
18950
|
}
|
|
18624
|
-
if (current.type !==
|
|
18951
|
+
if (current.type !== import_utils95.AST_NODE_TYPES.CallExpression) return false;
|
|
18625
18952
|
const callee = current.callee;
|
|
18626
|
-
return callee.type ===
|
|
18953
|
+
return callee.type === import_utils95.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils95.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
18627
18954
|
};
|
|
18628
18955
|
var require_zod_form_validation_default = createRule({
|
|
18629
18956
|
name: "require-zod-form-validation",
|
|
@@ -18644,7 +18971,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18644
18971
|
return {};
|
|
18645
18972
|
}
|
|
18646
18973
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
18647
|
-
const resolvedBinding = (identifier) =>
|
|
18974
|
+
const resolvedBinding = (identifier) => import_utils95.ASTUtils.findVariable(
|
|
18648
18975
|
context.sourceCode.getScope(identifier),
|
|
18649
18976
|
identifier.name
|
|
18650
18977
|
);
|
|
@@ -18654,16 +18981,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
18654
18981
|
return false;
|
|
18655
18982
|
}
|
|
18656
18983
|
const definition = binding.defs[0];
|
|
18657
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
18984
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils95.AST_NODE_TYPES.VariableDeclarator) {
|
|
18658
18985
|
return false;
|
|
18659
18986
|
}
|
|
18660
18987
|
const init = definition.node.init;
|
|
18661
|
-
return init?.type ===
|
|
18988
|
+
return init?.type === import_utils95.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils95.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils95.AST_NODE_TYPES.Literal || init?.type === import_utils95.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils95.AST_NODE_TYPES.FunctionExpression;
|
|
18662
18989
|
};
|
|
18663
18990
|
const isZodParseCall = (node) => {
|
|
18664
|
-
if (node.type !==
|
|
18991
|
+
if (node.type !== import_utils95.AST_NODE_TYPES.CallExpression) return false;
|
|
18665
18992
|
const callee = node.callee;
|
|
18666
|
-
if (callee.type !==
|
|
18993
|
+
if (callee.type !== import_utils95.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils95.AST_NODE_TYPES.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
18667
18994
|
return false;
|
|
18668
18995
|
}
|
|
18669
18996
|
const root = zodReceiverRoot(callee.object);
|
|
@@ -18672,14 +18999,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
18672
18999
|
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
18673
19000
|
};
|
|
18674
19001
|
const isFormSourceIdentifier = (node) => {
|
|
18675
|
-
if (node.type !==
|
|
19002
|
+
if (node.type !== import_utils95.AST_NODE_TYPES.Identifier) return false;
|
|
18676
19003
|
const conventionalName = /formdata/i.test(node.name);
|
|
18677
19004
|
let scope = context.sourceCode.getScope(node);
|
|
18678
19005
|
while (scope !== null) {
|
|
18679
19006
|
const variable = scope.set.get(node.name);
|
|
18680
19007
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
18681
19008
|
const def = variable.defs[0];
|
|
18682
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
19009
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils95.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
18683
19010
|
return isFormDataMethodCall(def.node.init);
|
|
18684
19011
|
}
|
|
18685
19012
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -18690,8 +19017,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
18690
19017
|
};
|
|
18691
19018
|
const isFormDataGetCall = (node) => {
|
|
18692
19019
|
const callee = node.callee;
|
|
18693
|
-
if (callee.type !==
|
|
18694
|
-
if (callee.property.type !==
|
|
19020
|
+
if (callee.type !== import_utils95.AST_NODE_TYPES.MemberExpression) return false;
|
|
19021
|
+
if (callee.property.type !== import_utils95.AST_NODE_TYPES.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
18695
19022
|
return false;
|
|
18696
19023
|
}
|
|
18697
19024
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -18700,15 +19027,15 @@ var require_zod_form_validation_default = createRule({
|
|
|
18700
19027
|
let parent = node.parent;
|
|
18701
19028
|
while (parent !== null && parent !== void 0) {
|
|
18702
19029
|
if (isZodParseCall(parent)) return parent;
|
|
18703
|
-
if (parent.type ===
|
|
19030
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils95.AST_NODE_TYPES.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
18704
19031
|
parent = parent.parent;
|
|
18705
19032
|
continue;
|
|
18706
19033
|
}
|
|
18707
|
-
if (parent.type ===
|
|
19034
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils95.AST_NODE_TYPES.MemberExpression && !parent.callee.computed && parent.callee.object.type === import_utils95.AST_NODE_TYPES.Identifier && parent.callee.object.name === "Object" && parent.callee.property.type === import_utils95.AST_NODE_TYPES.Identifier && parent.callee.property.name === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
18708
19035
|
parent = parent.parent;
|
|
18709
19036
|
continue;
|
|
18710
19037
|
}
|
|
18711
|
-
if (parent.type ===
|
|
19038
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.CallExpression || parent.type === import_utils95.AST_NODE_TYPES.NewExpression || parent.type === import_utils95.AST_NODE_TYPES.TaggedTemplateExpression || parent.type === import_utils95.AST_NODE_TYPES.ArrowFunctionExpression || parent.type === import_utils95.AST_NODE_TYPES.FunctionExpression || parent.type === import_utils95.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
18712
19039
|
parent = parent.parent;
|
|
18713
19040
|
}
|
|
18714
19041
|
return null;
|
|
@@ -18716,16 +19043,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
18716
19043
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
18717
19044
|
const isInstanceofNarrowing = (node) => {
|
|
18718
19045
|
const parent = node.parent;
|
|
18719
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
19046
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils95.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils95.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
18720
19047
|
};
|
|
18721
19048
|
const boundDeclarator = (node) => {
|
|
18722
19049
|
let current = node;
|
|
18723
19050
|
let parent = current.parent;
|
|
18724
|
-
while ((parent.type ===
|
|
19051
|
+
while ((parent.type === import_utils95.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils95.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils95.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils95.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
18725
19052
|
current = parent;
|
|
18726
19053
|
parent = current.parent;
|
|
18727
19054
|
}
|
|
18728
|
-
if (parent.type ===
|
|
19055
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils95.AST_NODE_TYPES.Identifier) {
|
|
18729
19056
|
return parent;
|
|
18730
19057
|
}
|
|
18731
19058
|
return null;
|
|
@@ -18734,7 +19061,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18734
19061
|
let current = node;
|
|
18735
19062
|
while (current.parent !== void 0) {
|
|
18736
19063
|
const parent = current.parent;
|
|
18737
|
-
if (parent.type ===
|
|
19064
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.BlockStatement || parent.type === import_utils95.AST_NODE_TYPES.Program) {
|
|
18738
19065
|
return current;
|
|
18739
19066
|
}
|
|
18740
19067
|
current = parent;
|
|
@@ -18743,12 +19070,12 @@ var require_zod_form_validation_default = createRule({
|
|
|
18743
19070
|
};
|
|
18744
19071
|
const zodParseMethod = (call) => {
|
|
18745
19072
|
const callee = call.callee;
|
|
18746
|
-
return callee.type ===
|
|
19073
|
+
return callee.type === import_utils95.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils95.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
18747
19074
|
};
|
|
18748
19075
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
18749
19076
|
let current = node.parent;
|
|
18750
19077
|
while (current !== void 0 && current !== statement) {
|
|
18751
|
-
if (current.type ===
|
|
19078
|
+
if (current.type === import_utils95.AST_NODE_TYPES.LogicalExpression || current.type === import_utils95.AST_NODE_TYPES.ConditionalExpression) {
|
|
18752
19079
|
return true;
|
|
18753
19080
|
}
|
|
18754
19081
|
current = current.parent;
|
|
@@ -18758,7 +19085,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18758
19085
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
18759
19086
|
let current = node.parent;
|
|
18760
19087
|
while (current !== void 0 && current !== statement) {
|
|
18761
|
-
if (current.type ===
|
|
19088
|
+
if (current.type === import_utils95.AST_NODE_TYPES.AwaitExpression) return true;
|
|
18762
19089
|
current = current.parent;
|
|
18763
19090
|
}
|
|
18764
19091
|
return false;
|
|
@@ -18771,7 +19098,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18771
19098
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
18772
19099
|
return null;
|
|
18773
19100
|
}
|
|
18774
|
-
if (validationStatement.type !==
|
|
19101
|
+
if (validationStatement.type !== import_utils95.AST_NODE_TYPES.VariableDeclaration && validationStatement.type !== import_utils95.AST_NODE_TYPES.ExpressionStatement) {
|
|
18775
19102
|
return null;
|
|
18776
19103
|
}
|
|
18777
19104
|
const method = zodParseMethod(parse2);
|
|
@@ -18783,16 +19110,16 @@ var require_zod_form_validation_default = createRule({
|
|
|
18783
19110
|
};
|
|
18784
19111
|
const isSafePrevalidationInspection = (identifier) => {
|
|
18785
19112
|
const parent = identifier.parent;
|
|
18786
|
-
if (parent.type ===
|
|
19113
|
+
if (parent.type === import_utils95.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
18787
19114
|
return true;
|
|
18788
19115
|
}
|
|
18789
|
-
if (parent.type !==
|
|
19116
|
+
if (parent.type !== import_utils95.AST_NODE_TYPES.BinaryExpression || parent.left !== identifier) {
|
|
18790
19117
|
return false;
|
|
18791
19118
|
}
|
|
18792
19119
|
if (parent.operator === "instanceof") {
|
|
18793
|
-
return parent.right.type ===
|
|
19120
|
+
return parent.right.type === import_utils95.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
18794
19121
|
}
|
|
18795
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
19122
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === import_utils95.AST_NODE_TYPES.Literal && parent.right.value === null || parent.right.type === import_utils95.AST_NODE_TYPES.Identifier && parent.right.name === "undefined");
|
|
18796
19123
|
};
|
|
18797
19124
|
const isDescendantOf = (node, ancestor) => {
|
|
18798
19125
|
let current = node;
|
|
@@ -18803,23 +19130,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
18803
19130
|
return false;
|
|
18804
19131
|
};
|
|
18805
19132
|
const blockTerminates = (node) => {
|
|
18806
|
-
if (node.type ===
|
|
19133
|
+
if (node.type === import_utils95.AST_NODE_TYPES.ReturnStatement || node.type === import_utils95.AST_NODE_TYPES.ThrowStatement) {
|
|
18807
19134
|
return true;
|
|
18808
19135
|
}
|
|
18809
|
-
if (node.type !==
|
|
19136
|
+
if (node.type !== import_utils95.AST_NODE_TYPES.BlockStatement || node.body.length === 0) return false;
|
|
18810
19137
|
const last = node.body.at(-1);
|
|
18811
19138
|
return last !== void 0 && blockTerminates(last);
|
|
18812
19139
|
};
|
|
18813
19140
|
const narrowingIf = (identifier) => {
|
|
18814
19141
|
const comparison = identifier.parent;
|
|
18815
|
-
if (comparison?.type !==
|
|
19142
|
+
if (comparison?.type !== import_utils95.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== import_utils95.AST_NODE_TYPES.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
18816
19143
|
return null;
|
|
18817
19144
|
}
|
|
18818
19145
|
const maybeNegation = comparison.parent;
|
|
18819
|
-
const negated = maybeNegation?.type ===
|
|
19146
|
+
const negated = maybeNegation?.type === import_utils95.AST_NODE_TYPES.UnaryExpression && maybeNegation.operator === "!";
|
|
18820
19147
|
const test = negated ? maybeNegation : comparison;
|
|
18821
19148
|
const branch = test.parent;
|
|
18822
|
-
return branch?.type ===
|
|
19149
|
+
return branch?.type === import_utils95.AST_NODE_TYPES.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
18823
19150
|
};
|
|
18824
19151
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
18825
19152
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -18839,7 +19166,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18839
19166
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
18840
19167
|
if (variable === void 0) return false;
|
|
18841
19168
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
18842
|
-
(identifier) => identifier.type ===
|
|
19169
|
+
(identifier) => identifier.type === import_utils95.AST_NODE_TYPES.Identifier
|
|
18843
19170
|
);
|
|
18844
19171
|
if (references.length === 0) return false;
|
|
18845
19172
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -18865,7 +19192,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18865
19192
|
ImportDeclaration(node) {
|
|
18866
19193
|
if (!isZodModule(node.source.value)) return;
|
|
18867
19194
|
for (const specifier of node.specifiers) {
|
|
18868
|
-
if (specifier.type ===
|
|
19195
|
+
if (specifier.type === import_utils95.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils95.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils95.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils95.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
18869
19196
|
const binding = resolvedBinding(specifier.local);
|
|
18870
19197
|
if (binding !== null) zodBindings.add(binding);
|
|
18871
19198
|
}
|
|
@@ -18886,7 +19213,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
18886
19213
|
});
|
|
18887
19214
|
|
|
18888
19215
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
18889
|
-
var
|
|
19216
|
+
var import_utils96 = require("@typescript-eslint/utils");
|
|
18890
19217
|
var STORE_INSERT_REQUIRES_ON_CONFLICT_DOCUMENTATION = {
|
|
18891
19218
|
summary: "Review conflict handling for embedded inserts in replay-named callables.",
|
|
18892
19219
|
rationale: "Names such as seed, enqueue, or upsert suggest that repeated execution deserves a conflict-policy review, but do not prove a replay contract.",
|
|
@@ -18955,7 +19282,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
18955
19282
|
});
|
|
18956
19283
|
|
|
18957
19284
|
// src/rules/stepdown.ts
|
|
18958
|
-
var
|
|
19285
|
+
var import_utils97 = require("@typescript-eslint/utils");
|
|
18959
19286
|
var STEPDOWN_DOCUMENTATION = {
|
|
18960
19287
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
18961
19288
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -18973,7 +19300,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
18973
19300
|
]
|
|
18974
19301
|
};
|
|
18975
19302
|
function isFunction(node) {
|
|
18976
|
-
return node.type ===
|
|
19303
|
+
return node.type === import_utils97.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils97.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils97.AST_NODE_TYPES.FunctionExpression;
|
|
18977
19304
|
}
|
|
18978
19305
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
18979
19306
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.name, definition]));
|
|
@@ -19068,8 +19395,8 @@ function moduleScope(context, program) {
|
|
|
19068
19395
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
19069
19396
|
const overloadNames = new Set(
|
|
19070
19397
|
program.body.flatMap((statement) => {
|
|
19071
|
-
const node = statement.type ===
|
|
19072
|
-
return node?.type ===
|
|
19398
|
+
const node = statement.type === import_utils97.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
19399
|
+
return node?.type === import_utils97.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
19073
19400
|
})
|
|
19074
19401
|
);
|
|
19075
19402
|
const exported = exportedNames(program);
|
|
@@ -19093,7 +19420,7 @@ function moduleScope(context, program) {
|
|
|
19093
19420
|
const nearestFunction2 = [...ancestors].reverse().find(isFunction);
|
|
19094
19421
|
const parent = identifier.parent;
|
|
19095
19422
|
const callerDefinition = nearestFunction2 === void 0 ? void 0 : byFunction.get(nearestFunction2);
|
|
19096
|
-
if (callerDefinition === void 0 || parent.type !==
|
|
19423
|
+
if (callerDefinition === void 0 || parent.type !== import_utils97.AST_NODE_TYPES.CallExpression || parent.callee !== identifier) {
|
|
19097
19424
|
pinned.add(definition.name);
|
|
19098
19425
|
continue;
|
|
19099
19426
|
}
|
|
@@ -19108,38 +19435,38 @@ function moduleScope(context, program) {
|
|
|
19108
19435
|
function exportedNames(program) {
|
|
19109
19436
|
const names = /* @__PURE__ */ new Set();
|
|
19110
19437
|
for (const statement of program.body) {
|
|
19111
|
-
if (statement.type !==
|
|
19112
|
-
if (statement.declaration?.type ===
|
|
19438
|
+
if (statement.type !== import_utils97.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) continue;
|
|
19439
|
+
if (statement.declaration?.type === import_utils97.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
19113
19440
|
names.add(statement.declaration.id.name);
|
|
19114
19441
|
}
|
|
19115
|
-
if (statement.declaration?.type ===
|
|
19442
|
+
if (statement.declaration?.type === import_utils97.AST_NODE_TYPES.VariableDeclaration) {
|
|
19116
19443
|
for (const declarator of statement.declaration.declarations) {
|
|
19117
|
-
if (declarator.id.type ===
|
|
19444
|
+
if (declarator.id.type === import_utils97.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
19118
19445
|
}
|
|
19119
19446
|
}
|
|
19120
19447
|
for (const specifier of statement.specifiers) {
|
|
19121
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
19448
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils97.AST_NODE_TYPES.Identifier) {
|
|
19122
19449
|
names.add(specifier.local.name);
|
|
19123
19450
|
}
|
|
19124
19451
|
}
|
|
19125
19452
|
}
|
|
19126
19453
|
for (const statement of program.body) {
|
|
19127
|
-
if (statement.type ===
|
|
19128
|
-
if (statement.type ===
|
|
19454
|
+
if (statement.type === import_utils97.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils97.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
19455
|
+
if (statement.type === import_utils97.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils97.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
19129
19456
|
}
|
|
19130
19457
|
return names;
|
|
19131
19458
|
}
|
|
19132
19459
|
function moduleDefinitions(program) {
|
|
19133
19460
|
const definitions = [];
|
|
19134
19461
|
for (const statement of program.body) {
|
|
19135
|
-
const node = statement.type ===
|
|
19136
|
-
if (node?.type ===
|
|
19462
|
+
const node = statement.type === import_utils97.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils97.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
19463
|
+
if (node?.type === import_utils97.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
19137
19464
|
definitions.push({ name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
19138
19465
|
continue;
|
|
19139
19466
|
}
|
|
19140
|
-
if (node?.type !==
|
|
19467
|
+
if (node?.type !== import_utils97.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const") continue;
|
|
19141
19468
|
for (const declarator of node.declarations) {
|
|
19142
|
-
if (declarator.id.type ===
|
|
19469
|
+
if (declarator.id.type === import_utils97.AST_NODE_TYPES.Identifier && declarator.init !== null && isFunction(declarator.init)) {
|
|
19143
19470
|
definitions.push({
|
|
19144
19471
|
name: declarator.id.name,
|
|
19145
19472
|
node: declarator,
|
|
@@ -19152,21 +19479,21 @@ function moduleDefinitions(program) {
|
|
|
19152
19479
|
return definitions;
|
|
19153
19480
|
}
|
|
19154
19481
|
function methodName(node) {
|
|
19155
|
-
if (node.key.type ===
|
|
19156
|
-
return !node.computed && node.key.type ===
|
|
19482
|
+
if (node.key.type === import_utils97.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
19483
|
+
return !node.computed && node.key.type === import_utils97.AST_NODE_TYPES.Identifier ? node.key.name : null;
|
|
19157
19484
|
}
|
|
19158
19485
|
function referencedMethod(context, node, classVariables) {
|
|
19159
|
-
const objectVariable = node.object.type ===
|
|
19486
|
+
const objectVariable = node.object.type === import_utils97.AST_NODE_TYPES.Identifier ? import_utils97.ASTUtils.findVariable(context.sourceCode.getScope(node.object), node.object.name) : null;
|
|
19160
19487
|
const isClassReference = objectVariable !== null && classVariables.has(objectVariable);
|
|
19161
|
-
if (node.object.type !==
|
|
19162
|
-
if (node.property.type ===
|
|
19163
|
-
if (!node.computed && node.property.type ===
|
|
19164
|
-
return node.computed && node.property.type ===
|
|
19488
|
+
if (node.object.type !== import_utils97.AST_NODE_TYPES.ThisExpression && !isClassReference) return null;
|
|
19489
|
+
if (node.property.type === import_utils97.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
19490
|
+
if (!node.computed && node.property.type === import_utils97.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
19491
|
+
return node.computed && node.property.type === import_utils97.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
19165
19492
|
}
|
|
19166
19493
|
function referencedPropertyName(node) {
|
|
19167
|
-
if (node.property.type ===
|
|
19168
|
-
if (!node.computed && node.property.type ===
|
|
19169
|
-
return node.computed && node.property.type ===
|
|
19494
|
+
if (node.property.type === import_utils97.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
19495
|
+
if (!node.computed && node.property.type === import_utils97.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
19496
|
+
return node.computed && node.property.type === import_utils97.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
19170
19497
|
}
|
|
19171
19498
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
19172
19499
|
visit(node, nestedFunction);
|
|
@@ -19182,7 +19509,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
19182
19509
|
}
|
|
19183
19510
|
function classScope(context, node, computedReferenceNames) {
|
|
19184
19511
|
const methods = node.body.body.filter(
|
|
19185
|
-
(member) => member.type ===
|
|
19512
|
+
(member) => member.type === import_utils97.AST_NODE_TYPES.MethodDefinition
|
|
19186
19513
|
);
|
|
19187
19514
|
const counts = /* @__PURE__ */ new Map();
|
|
19188
19515
|
for (const method of methods) {
|
|
@@ -19190,8 +19517,8 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19190
19517
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
19191
19518
|
}
|
|
19192
19519
|
for (const member of node.body.body) {
|
|
19193
|
-
if (member.type !==
|
|
19194
|
-
const name = !member.computed && member.key.type ===
|
|
19520
|
+
if (member.type !== import_utils97.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
19521
|
+
const name = !member.computed && member.key.type === import_utils97.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
19195
19522
|
if (name !== null) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
19196
19523
|
}
|
|
19197
19524
|
const scopeDefinitions = methods.flatMap((method) => {
|
|
@@ -19200,7 +19527,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19200
19527
|
});
|
|
19201
19528
|
const definitions = methods.flatMap((method) => {
|
|
19202
19529
|
const name = methodName(method);
|
|
19203
|
-
const isPrivate = method.accessibility === "private" || method.key.type ===
|
|
19530
|
+
const isPrivate = method.accessibility === "private" || method.key.type === import_utils97.AST_NODE_TYPES.PrivateIdentifier;
|
|
19204
19531
|
return name !== null && isPrivate && counts.get(name) === 1 && method.decorators.length === 0 ? [{ name, node: method }] : [];
|
|
19205
19532
|
});
|
|
19206
19533
|
if (definitions.length === 0) return;
|
|
@@ -19209,11 +19536,11 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19209
19536
|
const pinned = /* @__PURE__ */ new Set();
|
|
19210
19537
|
const classVariables = /* @__PURE__ */ new Set();
|
|
19211
19538
|
if (node.id !== null) {
|
|
19212
|
-
const internal =
|
|
19539
|
+
const internal = import_utils97.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
19213
19540
|
if (internal !== null) classVariables.add(internal);
|
|
19214
19541
|
}
|
|
19215
|
-
if (node.type ===
|
|
19216
|
-
const outer =
|
|
19542
|
+
if (node.type === import_utils97.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils97.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils97.AST_NODE_TYPES.Identifier) {
|
|
19543
|
+
const outer = import_utils97.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
19217
19544
|
if (outer !== null) classVariables.add(outer);
|
|
19218
19545
|
}
|
|
19219
19546
|
for (const method of methods) {
|
|
@@ -19229,27 +19556,27 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19229
19556
|
}
|
|
19230
19557
|
const thisValue = (value) => {
|
|
19231
19558
|
let current = value;
|
|
19232
|
-
while (current?.type ===
|
|
19233
|
-
return current?.type ===
|
|
19559
|
+
while (current?.type === import_utils97.AST_NODE_TYPES.TSAsExpression || current?.type === import_utils97.AST_NODE_TYPES.TSSatisfiesExpression || current?.type === import_utils97.AST_NODE_TYPES.TSNonNullExpression) current = current.expression;
|
|
19560
|
+
return current?.type === import_utils97.AST_NODE_TYPES.ThisExpression;
|
|
19234
19561
|
};
|
|
19235
19562
|
const collectAlias = (current, nestedFunction) => {
|
|
19236
|
-
if (nestedFunction || current.type !==
|
|
19237
|
-
if (current.type ===
|
|
19238
|
-
const binding = current.type ===
|
|
19239
|
-
const value = current.type ===
|
|
19563
|
+
if (nestedFunction || current.type !== import_utils97.AST_NODE_TYPES.VariableDeclarator && current.type !== import_utils97.AST_NODE_TYPES.AssignmentPattern) return;
|
|
19564
|
+
if (current.type === import_utils97.AST_NODE_TYPES.VariableDeclarator && (current.parent.type !== import_utils97.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const")) return;
|
|
19565
|
+
const binding = current.type === import_utils97.AST_NODE_TYPES.VariableDeclarator ? current.id : current.left;
|
|
19566
|
+
const value = current.type === import_utils97.AST_NODE_TYPES.VariableDeclarator ? current.init : current.right;
|
|
19240
19567
|
if (!thisValue(value)) return;
|
|
19241
|
-
if (binding.type ===
|
|
19568
|
+
if (binding.type === import_utils97.AST_NODE_TYPES.ObjectPattern) {
|
|
19242
19569
|
for (const property of binding.properties) {
|
|
19243
|
-
if (property.type ===
|
|
19570
|
+
if (property.type === import_utils97.AST_NODE_TYPES.RestElement) {
|
|
19244
19571
|
for (const name of privateNames) pinned.add(name);
|
|
19245
|
-
} else if (property.key.type ===
|
|
19572
|
+
} else if (property.key.type === import_utils97.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) {
|
|
19246
19573
|
pinned.add(property.key.name);
|
|
19247
19574
|
}
|
|
19248
19575
|
}
|
|
19249
19576
|
return;
|
|
19250
19577
|
}
|
|
19251
|
-
if (binding.type !==
|
|
19252
|
-
const variable =
|
|
19578
|
+
if (binding.type !== import_utils97.AST_NODE_TYPES.Identifier) return;
|
|
19579
|
+
const variable = import_utils97.ASTUtils.findVariable(context.sourceCode.getScope(binding), binding.name);
|
|
19253
19580
|
if (variable !== null) {
|
|
19254
19581
|
methodClassVariables.add(variable);
|
|
19255
19582
|
methodAliases.add(variable);
|
|
@@ -19262,16 +19589,16 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19262
19589
|
walk(statement, context.sourceCode.visitorKeys, collectAlias);
|
|
19263
19590
|
}
|
|
19264
19591
|
const visitCall = (current, nestedFunction) => {
|
|
19265
|
-
if (current.type ===
|
|
19592
|
+
if (current.type === import_utils97.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils97.AST_NODE_TYPES.ObjectPattern && thisValue(current.init)) {
|
|
19266
19593
|
for (const property of current.id.properties) {
|
|
19267
|
-
if (property.type ===
|
|
19594
|
+
if (property.type === import_utils97.AST_NODE_TYPES.RestElement) {
|
|
19268
19595
|
for (const name of privateNames) pinned.add(name);
|
|
19269
19596
|
continue;
|
|
19270
19597
|
}
|
|
19271
|
-
if (property.type ===
|
|
19598
|
+
if (property.type === import_utils97.AST_NODE_TYPES.Property && property.key.type === import_utils97.AST_NODE_TYPES.Identifier && privateNames.has(property.key.name)) pinned.add(property.key.name);
|
|
19272
19599
|
}
|
|
19273
19600
|
}
|
|
19274
|
-
if (current.type !==
|
|
19601
|
+
if (current.type !== import_utils97.AST_NODE_TYPES.MemberExpression) return;
|
|
19275
19602
|
const target = referencedMethod(context, current, methodClassVariables);
|
|
19276
19603
|
if (target === null) {
|
|
19277
19604
|
const possibleTarget = referencedPropertyName(current);
|
|
@@ -19279,12 +19606,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19279
19606
|
return;
|
|
19280
19607
|
}
|
|
19281
19608
|
if (!privateNames.has(target)) return;
|
|
19282
|
-
const objectVariable = current.object.type ===
|
|
19609
|
+
const objectVariable = current.object.type === import_utils97.AST_NODE_TYPES.Identifier ? import_utils97.ASTUtils.findVariable(context.sourceCode.getScope(current.object), current.object.name) : null;
|
|
19283
19610
|
if (objectVariable !== null && methodAliases.has(objectVariable)) {
|
|
19284
19611
|
pinned.add(target);
|
|
19285
19612
|
return;
|
|
19286
19613
|
}
|
|
19287
|
-
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !==
|
|
19614
|
+
if (current.computed || nestedFunction || parameterDecoratorNodes.has(current) || current.parent.type !== import_utils97.AST_NODE_TYPES.CallExpression || current.parent.callee !== current) {
|
|
19288
19615
|
pinned.add(target);
|
|
19289
19616
|
return;
|
|
19290
19617
|
}
|
|
@@ -19304,9 +19631,9 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19304
19631
|
}
|
|
19305
19632
|
}
|
|
19306
19633
|
for (const member of node.body.body) {
|
|
19307
|
-
if (member.type ===
|
|
19634
|
+
if (member.type === import_utils97.AST_NODE_TYPES.MethodDefinition || member.type === import_utils97.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
19308
19635
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
19309
|
-
if (current.type !==
|
|
19636
|
+
if (current.type !== import_utils97.AST_NODE_TYPES.MemberExpression) return;
|
|
19310
19637
|
const target = referencedMethod(context, current, classVariables);
|
|
19311
19638
|
const possibleTarget = target ?? referencedPropertyName(current);
|
|
19312
19639
|
if (possibleTarget !== null && privateNames.has(possibleTarget)) pinned.add(possibleTarget);
|
|
@@ -19328,12 +19655,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
19328
19655
|
}
|
|
19329
19656
|
function isClassRuntimeBarrier(member) {
|
|
19330
19657
|
switch (member.type) {
|
|
19331
|
-
case
|
|
19658
|
+
case import_utils97.AST_NODE_TYPES.StaticBlock:
|
|
19332
19659
|
return true;
|
|
19333
|
-
case
|
|
19334
|
-
case
|
|
19660
|
+
case import_utils97.AST_NODE_TYPES.PropertyDefinition:
|
|
19661
|
+
case import_utils97.AST_NODE_TYPES.AccessorProperty:
|
|
19335
19662
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
19336
|
-
case
|
|
19663
|
+
case import_utils97.AST_NODE_TYPES.MethodDefinition:
|
|
19337
19664
|
return member.computed || member.decorators.length > 0;
|
|
19338
19665
|
default:
|
|
19339
19666
|
return false;
|
|
@@ -19365,7 +19692,7 @@ var stepdown_default = createRule({
|
|
|
19365
19692
|
moduleScope(context, program);
|
|
19366
19693
|
const computedReferenceNames = /* @__PURE__ */ new Set();
|
|
19367
19694
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
19368
|
-
if (node.type ===
|
|
19695
|
+
if (node.type === import_utils97.AST_NODE_TYPES.MemberExpression && node.computed && node.property.type === import_utils97.AST_NODE_TYPES.Literal && typeof node.property.value === "string") computedReferenceNames.add(node.property.value);
|
|
19369
19696
|
});
|
|
19370
19697
|
for (const node of classes) classScope(context, node, computedReferenceNames);
|
|
19371
19698
|
}
|
|
@@ -19374,7 +19701,7 @@ var stepdown_default = createRule({
|
|
|
19374
19701
|
});
|
|
19375
19702
|
|
|
19376
19703
|
// src/rules/source-coupled-test.ts
|
|
19377
|
-
var
|
|
19704
|
+
var import_utils98 = require("@typescript-eslint/utils");
|
|
19378
19705
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc|py|[cm]?[jt]s)$/iu;
|
|
19379
19706
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
19380
19707
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -19443,21 +19770,21 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
19443
19770
|
]
|
|
19444
19771
|
};
|
|
19445
19772
|
function staticMemberName7(node) {
|
|
19446
|
-
if (!node.computed && node.property.type ===
|
|
19447
|
-
if (node.computed && node.property.type ===
|
|
19773
|
+
if (!node.computed && node.property.type === import_utils98.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
19774
|
+
if (node.computed && node.property.type === import_utils98.AST_NODE_TYPES.Literal && typeof node.property.value === "string") return node.property.value;
|
|
19448
19775
|
return null;
|
|
19449
19776
|
}
|
|
19450
19777
|
function unwrap7(node) {
|
|
19451
|
-
if (node.type ===
|
|
19452
|
-
if (node.type ===
|
|
19453
|
-
if (node.type ===
|
|
19778
|
+
if (node.type === import_utils98.AST_NODE_TYPES.AwaitExpression) return unwrap7(node.argument);
|
|
19779
|
+
if (node.type === import_utils98.AST_NODE_TYPES.ChainExpression) return unwrap7(node.expression);
|
|
19780
|
+
if (node.type === import_utils98.AST_NODE_TYPES.TSAsExpression || node.type === import_utils98.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils98.AST_NODE_TYPES.TSTypeAssertion) return unwrap7(node.expression);
|
|
19454
19781
|
return node;
|
|
19455
19782
|
}
|
|
19456
19783
|
function stringValue(node) {
|
|
19457
19784
|
const current = unwrap7(node);
|
|
19458
|
-
if (current.type ===
|
|
19459
|
-
if (current.type ===
|
|
19460
|
-
if (current.type ===
|
|
19785
|
+
if (current.type === import_utils98.AST_NODE_TYPES.Literal && typeof current.value === "string") return current.value;
|
|
19786
|
+
if (current.type === import_utils98.AST_NODE_TYPES.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
19787
|
+
if (current.type === import_utils98.AST_NODE_TYPES.BinaryExpression && current.operator === "+") {
|
|
19461
19788
|
const left = stringValue(current.left);
|
|
19462
19789
|
const right = stringValue(current.right);
|
|
19463
19790
|
return left === null || right === null ? null : left + right;
|
|
@@ -19469,7 +19796,7 @@ function importSource(node) {
|
|
|
19469
19796
|
}
|
|
19470
19797
|
function requireSource(node) {
|
|
19471
19798
|
const current = unwrap7(node);
|
|
19472
|
-
if (current.type !==
|
|
19799
|
+
if (current.type !== import_utils98.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils98.AST_NODE_TYPES.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === import_utils98.AST_NODE_TYPES.SpreadElement) return null;
|
|
19473
19800
|
return stringValue(current.arguments[0]);
|
|
19474
19801
|
}
|
|
19475
19802
|
function newScope() {
|
|
@@ -19491,7 +19818,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19491
19818
|
const scopes = [newScope()];
|
|
19492
19819
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
19493
19820
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
19494
|
-
const bindingOf = (node) =>
|
|
19821
|
+
const bindingOf = (node) => import_utils98.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
19495
19822
|
const visible = (kind, node) => {
|
|
19496
19823
|
const name2 = bindingOf(node);
|
|
19497
19824
|
if (name2 === null || name2.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
@@ -19514,37 +19841,37 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19514
19841
|
const current = unwrap7(node);
|
|
19515
19842
|
const value = stringValue(current);
|
|
19516
19843
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
19517
|
-
if (current.type ===
|
|
19518
|
-
if (current.type ===
|
|
19844
|
+
if (current.type === import_utils98.AST_NODE_TYPES.Identifier) return visible("paths", current);
|
|
19845
|
+
if (current.type === import_utils98.AST_NODE_TYPES.CallExpression || current.type === import_utils98.AST_NODE_TYPES.NewExpression) {
|
|
19519
19846
|
const callee = current.callee;
|
|
19520
19847
|
const first = current.arguments[0];
|
|
19521
|
-
if (first === void 0 || first.type ===
|
|
19522
|
-
if (current.type ===
|
|
19523
|
-
if (callee.type ===
|
|
19848
|
+
if (first === void 0 || first.type === import_utils98.AST_NODE_TYPES.SpreadElement) return false;
|
|
19849
|
+
if (current.type === import_utils98.AST_NODE_TYPES.NewExpression && callee.type === import_utils98.AST_NODE_TYPES.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
19850
|
+
if (callee.type === import_utils98.AST_NODE_TYPES.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === import_utils98.AST_NODE_TYPES.ImportSpecifier && definition.node.imported.type === import_utils98.AST_NODE_TYPES.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === import_utils98.AST_NODE_TYPES.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
19524
19851
|
}
|
|
19525
19852
|
return false;
|
|
19526
19853
|
};
|
|
19527
19854
|
const rawRead = (node) => {
|
|
19528
19855
|
const current = unwrap7(node);
|
|
19529
|
-
if (current.type !==
|
|
19856
|
+
if (current.type !== import_utils98.AST_NODE_TYPES.CallExpression || current.arguments.length === 0) return false;
|
|
19530
19857
|
const callee = unwrap7(current.callee);
|
|
19531
|
-
if (callee.type ===
|
|
19858
|
+
if (callee.type === import_utils98.AST_NODE_TYPES.Identifier) {
|
|
19532
19859
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
19533
19860
|
}
|
|
19534
|
-
if (callee.type !==
|
|
19861
|
+
if (callee.type !== import_utils98.AST_NODE_TYPES.MemberExpression) return false;
|
|
19535
19862
|
const name2 = staticMemberName7(callee);
|
|
19536
19863
|
const object = unwrap7(callee.object);
|
|
19537
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
19864
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === import_utils98.AST_NODE_TYPES.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
19538
19865
|
};
|
|
19539
19866
|
const rawOrigins = (node) => {
|
|
19540
19867
|
const current = unwrap7(node);
|
|
19541
|
-
if (current.type ===
|
|
19868
|
+
if (current.type === import_utils98.AST_NODE_TYPES.Identifier) return visibleRawOrigins(current);
|
|
19542
19869
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
19543
|
-
if (current.type ===
|
|
19544
|
-
if (current.type ===
|
|
19545
|
-
if (current.type !==
|
|
19870
|
+
if (current.type === import_utils98.AST_NODE_TYPES.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
19871
|
+
if (current.type === import_utils98.AST_NODE_TYPES.MemberExpression && staticMemberName7(current) === "length") return rawOrigins(current.object);
|
|
19872
|
+
if (current.type !== import_utils98.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
19546
19873
|
const callee = unwrap7(current.callee);
|
|
19547
|
-
if (callee.type !==
|
|
19874
|
+
if (callee.type !== import_utils98.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
19548
19875
|
const name2 = staticMemberName7(callee);
|
|
19549
19876
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(callee.object) : /* @__PURE__ */ new Set();
|
|
19550
19877
|
};
|
|
@@ -19552,32 +19879,32 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19552
19879
|
const current = unwrap7(node);
|
|
19553
19880
|
const direct = rawOrigins(current);
|
|
19554
19881
|
if (direct.size > 0) return direct;
|
|
19555
|
-
if (current.type ===
|
|
19556
|
-
if (current.type ===
|
|
19557
|
-
if (current.type !==
|
|
19882
|
+
if (current.type === import_utils98.AST_NODE_TYPES.BinaryExpression || current.type === import_utils98.AST_NODE_TYPES.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
19883
|
+
if (current.type === import_utils98.AST_NODE_TYPES.UnaryExpression) return evidenceOrigins(current.argument);
|
|
19884
|
+
if (current.type !== import_utils98.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
19558
19885
|
const callee = unwrap7(current.callee);
|
|
19559
|
-
if (callee.type !==
|
|
19886
|
+
if (callee.type !== import_utils98.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
19560
19887
|
const name2 = staticMemberName7(callee);
|
|
19561
19888
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(callee.object);
|
|
19562
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
19889
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === import_utils98.AST_NODE_TYPES.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
19563
19890
|
return /* @__PURE__ */ new Set();
|
|
19564
19891
|
};
|
|
19565
19892
|
const rawAssertionOrigins = (node) => {
|
|
19566
19893
|
const callee = unwrap7(node.callee);
|
|
19567
|
-
if (callee.type ===
|
|
19568
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
19894
|
+
if (callee.type === import_utils98.AST_NODE_TYPES.Identifier && callee.name === "assert") {
|
|
19895
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils98.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
19569
19896
|
}
|
|
19570
|
-
if (callee.type !==
|
|
19897
|
+
if (callee.type !== import_utils98.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
19571
19898
|
const matcher = staticMemberName7(callee);
|
|
19572
19899
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
19573
19900
|
let receiver = unwrap7(callee.object);
|
|
19574
|
-
while (receiver.type ===
|
|
19575
|
-
if (receiver.type ===
|
|
19901
|
+
while (receiver.type === import_utils98.AST_NODE_TYPES.MemberExpression && EXPECT_MODIFIERS2.has(staticMemberName7(receiver) ?? "")) receiver = unwrap7(receiver.object);
|
|
19902
|
+
if (receiver.type === import_utils98.AST_NODE_TYPES.CallExpression && receiver.callee.type === import_utils98.AST_NODE_TYPES.Identifier && receiver.callee.name === "expect") {
|
|
19576
19903
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
19577
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
19904
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === import_utils98.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
19578
19905
|
}
|
|
19579
|
-
if (receiver.type !==
|
|
19580
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
19906
|
+
if (receiver.type !== import_utils98.AST_NODE_TYPES.Identifier || receiver.name !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
19907
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils98.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
19581
19908
|
};
|
|
19582
19909
|
const declare = (node, state) => {
|
|
19583
19910
|
const name2 = bindingOf(node);
|
|
@@ -19599,7 +19926,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19599
19926
|
};
|
|
19600
19927
|
const sourceCollection = (node) => {
|
|
19601
19928
|
const current = unwrap7(node);
|
|
19602
|
-
return current.type ===
|
|
19929
|
+
return current.type === import_utils98.AST_NODE_TYPES.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== import_utils98.AST_NODE_TYPES.SpreadElement && sourcePath(element));
|
|
19603
19930
|
};
|
|
19604
19931
|
const enterFunction = () => {
|
|
19605
19932
|
scopes.push(newScope());
|
|
@@ -19612,8 +19939,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19612
19939
|
const source = importSource(node);
|
|
19613
19940
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
19614
19941
|
for (const specifier of node.specifiers) {
|
|
19615
|
-
if (specifier.type ===
|
|
19616
|
-
const imported = specifier.imported.type ===
|
|
19942
|
+
if (specifier.type === import_utils98.AST_NODE_TYPES.ImportSpecifier) {
|
|
19943
|
+
const imported = specifier.imported.type === import_utils98.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
19617
19944
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
19618
19945
|
} else {
|
|
19619
19946
|
declare(specifier.local, { fsObject: true });
|
|
@@ -19626,30 +19953,30 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
19626
19953
|
if (node.init === null) return;
|
|
19627
19954
|
const required = requireSource(node.init);
|
|
19628
19955
|
const initializer = unwrap7(node.init);
|
|
19629
|
-
if (required !== null && initializer.type ===
|
|
19630
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
19956
|
+
if (required !== null && initializer.type === import_utils98.AST_NODE_TYPES.CallExpression && initializer.callee.type === import_utils98.AST_NODE_TYPES.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
19957
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === import_utils98.AST_NODE_TYPES.Identifier) {
|
|
19631
19958
|
declare(node.id, { fsObject: true });
|
|
19632
19959
|
return;
|
|
19633
19960
|
}
|
|
19634
|
-
if (node.id.type ===
|
|
19961
|
+
if (node.id.type === import_utils98.AST_NODE_TYPES.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
19635
19962
|
for (const property of node.id.properties) {
|
|
19636
|
-
if (property.type !==
|
|
19637
|
-
const key = property.key.type ===
|
|
19963
|
+
if (property.type !== import_utils98.AST_NODE_TYPES.Property || property.value.type !== import_utils98.AST_NODE_TYPES.Identifier) continue;
|
|
19964
|
+
const key = property.key.type === import_utils98.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils98.AST_NODE_TYPES.Literal ? String(property.key.value) : "";
|
|
19638
19965
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
19639
19966
|
}
|
|
19640
19967
|
return;
|
|
19641
19968
|
}
|
|
19642
|
-
if (node.id.type !==
|
|
19969
|
+
if (node.id.type !== import_utils98.AST_NODE_TYPES.Identifier) return;
|
|
19643
19970
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
19644
19971
|
},
|
|
19645
19972
|
AssignmentExpression(node) {
|
|
19646
|
-
if (node.left.type ===
|
|
19973
|
+
if (node.left.type === import_utils98.AST_NODE_TYPES.Identifier) declare(node.left, {});
|
|
19647
19974
|
},
|
|
19648
19975
|
ForOfStatement(node) {
|
|
19649
19976
|
const right = unwrap7(node.right);
|
|
19650
|
-
const collection = right.type ===
|
|
19651
|
-
const left = node.left.type ===
|
|
19652
|
-
if (collection && left?.type ===
|
|
19977
|
+
const collection = right.type === import_utils98.AST_NODE_TYPES.Identifier && visible("collections", right);
|
|
19978
|
+
const left = node.left.type === import_utils98.AST_NODE_TYPES.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
19979
|
+
if (collection && left?.type === import_utils98.AST_NODE_TYPES.Identifier) declare(left, { path: true });
|
|
19653
19980
|
},
|
|
19654
19981
|
CallExpression(node) {
|
|
19655
19982
|
const origins = rawAssertionOrigins(node);
|
|
@@ -19668,7 +19995,7 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
19668
19995
|
);
|
|
19669
19996
|
|
|
19670
19997
|
// src/rules/sole-export-matches-filename.ts
|
|
19671
|
-
var
|
|
19998
|
+
var import_utils99 = require("@typescript-eslint/utils");
|
|
19672
19999
|
var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
19673
20000
|
summary: "Match a module filename to its sole named public runtime export.",
|
|
19674
20001
|
rationale: "When a module owns one runtime responsibility, matching names make that responsibility directly discoverable.",
|
|
@@ -19712,10 +20039,10 @@ function kebabCase(name) {
|
|
|
19712
20039
|
function declarationExport(statement) {
|
|
19713
20040
|
const declaration = statement.declaration;
|
|
19714
20041
|
if (declaration === null || declaration.declare === true) return [];
|
|
19715
|
-
if (declaration.type ===
|
|
19716
|
-
if (declaration.type !==
|
|
20042
|
+
if (declaration.type === import_utils99.AST_NODE_TYPES.ClassDeclaration || declaration.type === import_utils99.AST_NODE_TYPES.FunctionDeclaration || declaration.type === import_utils99.AST_NODE_TYPES.TSEnumDeclaration) return declaration.id === null ? [] : [{ name: declaration.id.name, node: declaration }];
|
|
20043
|
+
if (declaration.type !== import_utils99.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
19717
20044
|
return declaration.declarations.flatMap(
|
|
19718
|
-
(item) => item.id.type ===
|
|
20045
|
+
(item) => item.id.type === import_utils99.AST_NODE_TYPES.Identifier ? [{ name: item.id.name, node: item }] : []
|
|
19719
20046
|
);
|
|
19720
20047
|
}
|
|
19721
20048
|
var sole_export_matches_filename_default = createRule({
|
|
@@ -19739,32 +20066,32 @@ var sole_export_matches_filename_default = createRule({
|
|
|
19739
20066
|
const exports2 = [];
|
|
19740
20067
|
const publicExports = /* @__PURE__ */ new Set();
|
|
19741
20068
|
for (const statement of program.body) {
|
|
19742
|
-
if (statement.type ===
|
|
19743
|
-
if (statement.type ===
|
|
20069
|
+
if (statement.type === import_utils99.AST_NODE_TYPES.ExportAllDeclaration || statement.type === import_utils99.AST_NODE_TYPES.ExportNamedDeclaration && statement.source !== null) return;
|
|
20070
|
+
if (statement.type === import_utils99.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
19744
20071
|
publicExports.add("default");
|
|
19745
20072
|
const declaration2 = statement.declaration;
|
|
19746
|
-
if ((declaration2.type ===
|
|
20073
|
+
if ((declaration2.type === import_utils99.AST_NODE_TYPES.ClassDeclaration || declaration2.type === import_utils99.AST_NODE_TYPES.FunctionDeclaration) && declaration2.id !== null) exports2.push({ name: declaration2.id.name, node: declaration2 });
|
|
19747
20074
|
else return;
|
|
19748
20075
|
}
|
|
19749
|
-
if (statement.type !==
|
|
20076
|
+
if (statement.type !== import_utils99.AST_NODE_TYPES.ExportNamedDeclaration) continue;
|
|
19750
20077
|
const declaration = statement.declaration;
|
|
19751
|
-
if (declaration !== null && "id" in declaration && declaration.id?.type ===
|
|
20078
|
+
if (declaration !== null && "id" in declaration && declaration.id?.type === import_utils99.AST_NODE_TYPES.Identifier) {
|
|
19752
20079
|
publicExports.add(declaration.id.name);
|
|
19753
20080
|
}
|
|
19754
|
-
if (declaration?.type ===
|
|
19755
|
-
if (declaration.declarations.some((item) => item.id.type !==
|
|
20081
|
+
if (declaration?.type === import_utils99.AST_NODE_TYPES.VariableDeclaration) {
|
|
20082
|
+
if (declaration.declarations.some((item) => item.id.type !== import_utils99.AST_NODE_TYPES.Identifier)) return;
|
|
19756
20083
|
for (const item of declaration.declarations) {
|
|
19757
|
-
if (item.id.type ===
|
|
20084
|
+
if (item.id.type === import_utils99.AST_NODE_TYPES.Identifier) publicExports.add(item.id.name);
|
|
19758
20085
|
}
|
|
19759
20086
|
}
|
|
19760
20087
|
for (const specifier of statement.specifiers) {
|
|
19761
|
-
const exported = specifier.exported.type ===
|
|
20088
|
+
const exported = specifier.exported.type === import_utils99.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
19762
20089
|
publicExports.add(String(exported));
|
|
19763
20090
|
}
|
|
19764
20091
|
if (statement.exportKind === "type") continue;
|
|
19765
20092
|
exports2.push(...declarationExport(statement));
|
|
19766
20093
|
for (const specifier of statement.specifiers) {
|
|
19767
|
-
const exported = specifier.exported.type ===
|
|
20094
|
+
const exported = specifier.exported.type === import_utils99.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
19768
20095
|
publicExports.add(String(exported));
|
|
19769
20096
|
if (specifier.exportKind === "type") continue;
|
|
19770
20097
|
if (exported === "default") exports2.push({ name: specifier.local.name, node: specifier });
|
|
@@ -19776,7 +20103,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
19776
20103
|
const only = [...unique.values()][0];
|
|
19777
20104
|
if (only === void 0) return;
|
|
19778
20105
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
19779
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
20106
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === import_utils99.AST_NODE_TYPES.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
19780
20107
|
const exportedStem = kebabCase(only.name);
|
|
19781
20108
|
if (exportedStem === "") return;
|
|
19782
20109
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -19826,7 +20153,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
19826
20153
|
);
|
|
19827
20154
|
|
|
19828
20155
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
19829
|
-
var
|
|
20156
|
+
var import_utils100 = require("@typescript-eslint/utils");
|
|
19830
20157
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
19831
20158
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
19832
20159
|
rationale: "A reusable Zod schema is a runtime type contract. PascalCase mirrors that role; SCREAMING_SNAKE_CASE should remain reserved for scalar values and lookup tables.",
|
|
@@ -19958,18 +20285,18 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
19958
20285
|
"superRefine",
|
|
19959
20286
|
"transform"
|
|
19960
20287
|
]);
|
|
19961
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
20288
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils100.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
19962
20289
|
var calleeChainRoot2 = (node) => {
|
|
19963
20290
|
let current = node;
|
|
19964
20291
|
for (; ; ) {
|
|
19965
|
-
if (current.type ===
|
|
20292
|
+
if (current.type === import_utils100.AST_NODE_TYPES.Identifier) {
|
|
19966
20293
|
return current;
|
|
19967
20294
|
}
|
|
19968
|
-
if (current.type ===
|
|
20295
|
+
if (current.type === import_utils100.AST_NODE_TYPES.MemberExpression) {
|
|
19969
20296
|
current = current.object;
|
|
19970
20297
|
continue;
|
|
19971
20298
|
}
|
|
19972
|
-
if (current.type ===
|
|
20299
|
+
if (current.type === import_utils100.AST_NODE_TYPES.CallExpression) {
|
|
19973
20300
|
current = current.callee;
|
|
19974
20301
|
continue;
|
|
19975
20302
|
}
|
|
@@ -19980,13 +20307,13 @@ var chainMemberNames2 = (node) => {
|
|
|
19980
20307
|
const names = [];
|
|
19981
20308
|
let current = node;
|
|
19982
20309
|
for (; ; ) {
|
|
19983
|
-
if (current.type ===
|
|
19984
|
-
if (current.computed || current.property.type !==
|
|
20310
|
+
if (current.type === import_utils100.AST_NODE_TYPES.MemberExpression) {
|
|
20311
|
+
if (current.computed || current.property.type !== import_utils100.AST_NODE_TYPES.Identifier) return [];
|
|
19985
20312
|
names.push(current.property.name);
|
|
19986
20313
|
current = current.object;
|
|
19987
20314
|
continue;
|
|
19988
20315
|
}
|
|
19989
|
-
if (current.type ===
|
|
20316
|
+
if (current.type === import_utils100.AST_NODE_TYPES.CallExpression) {
|
|
19990
20317
|
current = current.callee;
|
|
19991
20318
|
continue;
|
|
19992
20319
|
}
|
|
@@ -19997,16 +20324,16 @@ var chainMemberNames2 = (node) => {
|
|
|
19997
20324
|
};
|
|
19998
20325
|
var unwrapExpression4 = (node) => {
|
|
19999
20326
|
let current = node;
|
|
20000
|
-
while (current.type ===
|
|
20327
|
+
while (current.type === import_utils100.AST_NODE_TYPES.TSAsExpression || current.type === import_utils100.AST_NODE_TYPES.TSSatisfiesExpression || current.type === import_utils100.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils100.AST_NODE_TYPES.TSTypeAssertion) {
|
|
20001
20328
|
current = current.expression;
|
|
20002
20329
|
}
|
|
20003
20330
|
return current;
|
|
20004
20331
|
};
|
|
20005
20332
|
var isModuleDeclarator = (node) => {
|
|
20006
20333
|
const declaration = node.parent;
|
|
20007
|
-
if (declaration.type !==
|
|
20334
|
+
if (declaration.type !== import_utils100.AST_NODE_TYPES.VariableDeclaration) return false;
|
|
20008
20335
|
const owner = declaration.parent;
|
|
20009
|
-
return owner.type ===
|
|
20336
|
+
return owner.type === import_utils100.AST_NODE_TYPES.Program || owner.type === import_utils100.AST_NODE_TYPES.ExportNamedDeclaration && owner.parent.type === import_utils100.AST_NODE_TYPES.Program;
|
|
20010
20337
|
};
|
|
20011
20338
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
20012
20339
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -20026,7 +20353,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
20026
20353
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
20027
20354
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
20028
20355
|
function resolvedBinding(identifier) {
|
|
20029
|
-
return
|
|
20356
|
+
return import_utils100.ASTUtils.findVariable(
|
|
20030
20357
|
context.sourceCode.getScope(identifier),
|
|
20031
20358
|
identifier.name
|
|
20032
20359
|
);
|
|
@@ -20047,8 +20374,8 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
20047
20374
|
}
|
|
20048
20375
|
function isConfirmedSchema(expression) {
|
|
20049
20376
|
const init = unwrapExpression4(expression);
|
|
20050
|
-
if (init.type ===
|
|
20051
|
-
if (init.type !==
|
|
20377
|
+
if (init.type === import_utils100.AST_NODE_TYPES.Identifier) return isSchemaBinding(init);
|
|
20378
|
+
if (init.type !== import_utils100.AST_NODE_TYPES.CallExpression || init.callee.type !== import_utils100.AST_NODE_TYPES.MemberExpression) {
|
|
20052
20379
|
return false;
|
|
20053
20380
|
}
|
|
20054
20381
|
const terminal = terminalMethodName(init.callee);
|
|
@@ -20068,7 +20395,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
20068
20395
|
ImportDeclaration(node) {
|
|
20069
20396
|
if (!isZodModule(node.source.value)) return;
|
|
20070
20397
|
for (const specifier of node.specifiers) {
|
|
20071
|
-
if (specifier.type ===
|
|
20398
|
+
if (specifier.type === import_utils100.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils100.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils100.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils100.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
20072
20399
|
recordZodBinding(specifier.local);
|
|
20073
20400
|
}
|
|
20074
20401
|
}
|
|
@@ -20077,7 +20404,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
20077
20404
|
if (!isModuleDeclarator(node)) return;
|
|
20078
20405
|
const init = node.init;
|
|
20079
20406
|
if (init === null || init === void 0) return;
|
|
20080
|
-
if (node.id.type !==
|
|
20407
|
+
if (node.id.type !== import_utils100.AST_NODE_TYPES.Identifier) return;
|
|
20081
20408
|
if (!isConfirmedSchema(init)) return;
|
|
20082
20409
|
const binding = resolvedBinding(node.id);
|
|
20083
20410
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -20256,6 +20583,7 @@ var RULES = {
|
|
|
20256
20583
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
20257
20584
|
"repeated-static-call-cases": repeated_static_call_cases_default,
|
|
20258
20585
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
20586
|
+
"prefer-zod-parse-output-type": prefer_zod_parse_output_type_default,
|
|
20259
20587
|
"require-assert-never": require_assert_never_default,
|
|
20260
20588
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
20261
20589
|
"require-interface-for-exported-class": require_interface_for_exported_class_default,
|
|
@@ -20271,7 +20599,7 @@ var RULES = {
|
|
|
20271
20599
|
};
|
|
20272
20600
|
var meta = {
|
|
20273
20601
|
name: "@sarj/eslint-plugin",
|
|
20274
|
-
version: "15.17.
|
|
20602
|
+
version: "15.17.13"
|
|
20275
20603
|
};
|
|
20276
20604
|
var APPLICATION_ONLY_RULES = [];
|
|
20277
20605
|
var LIBRARY_IMPORT_POLICY = ["error", {
|
|
@@ -20294,6 +20622,7 @@ var ADVISORY_RULES = [
|
|
|
20294
20622
|
"@sarj/prefer-shared-zod-enum",
|
|
20295
20623
|
"@sarj/prefer-switch-for-repeated-equality",
|
|
20296
20624
|
"@sarj/prefer-whole-object-assertion",
|
|
20625
|
+
"@sarj/prefer-zod-parse-output-type",
|
|
20297
20626
|
"@sarj/require-interface-for-exported-class",
|
|
20298
20627
|
"@sarj/require-sql-access-class",
|
|
20299
20628
|
"@sarj/sole-export-matches-filename"
|
|
@@ -20375,6 +20704,7 @@ var RECOMMENDED_RULES = {
|
|
|
20375
20704
|
"@sarj/prefer-whole-object-assertion": "warn",
|
|
20376
20705
|
"@sarj/repeated-static-call-cases": "error",
|
|
20377
20706
|
"@sarj/prefer-zod-infer": "error",
|
|
20707
|
+
"@sarj/prefer-zod-parse-output-type": "warn",
|
|
20378
20708
|
"@sarj/require-assert-never": "error",
|
|
20379
20709
|
"@sarj/require-fetch-timeout": "error",
|
|
20380
20710
|
"@sarj/require-interface-for-exported-class": "warn",
|
|
@@ -20472,6 +20802,7 @@ var STRICT_RULES = {
|
|
|
20472
20802
|
"@sarj/prefer-whole-object-assertion": "warn",
|
|
20473
20803
|
"@sarj/repeated-static-call-cases": "error",
|
|
20474
20804
|
"@sarj/prefer-zod-infer": "error",
|
|
20805
|
+
"@sarj/prefer-zod-parse-output-type": "warn",
|
|
20475
20806
|
"@sarj/require-assert-never": "error",
|
|
20476
20807
|
"@sarj/require-fetch-timeout": "error",
|
|
20477
20808
|
"@sarj/require-interface-for-exported-class": "warn",
|