Skip to content

Commit b8cc515

Browse files
skywing918Kyle Zhang
andauthored
make csharp optional (Azure#34284)
Co-authored-by: Kyle Zhang <v-zhanh@microsoft.com>
1 parent 58f5114 commit b8cc515

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class TspconfigEmitterOptionsSubRuleBase extends TspconfigSubRuleBase {
111111
this.emitterName = emitterName;
112112
}
113113

114+
public getEmitterName() {
115+
return this.emitterName;
116+
}
117+
114118
protected tryFindOption(config: any): Record<string, any> | undefined {
115119
let option: Record<string, any> | undefined = config?.options?.[this.emitterName];
116120
for (const segment of this.keyToValidate.split(".")) {
@@ -503,7 +507,20 @@ export class SdkTspConfigValidationRule implements Rule {
503507
if (this.suppressedKeyPaths.has(subRule.getPathOfKeyToValidate())) continue;
504508
const result = await subRule.execute(folder!);
505509
if (!result.success) failedResults.push(result);
506-
success &&= result.success;
510+
511+
let isSubRuleSuccess = result.success;
512+
513+
// TODO: remove when @azure-tools/typespec-csharp is ready for validating tspconfig
514+
if (subRule instanceof TspconfigEmitterOptionsSubRuleBase) {
515+
const emitterOptionSubRule = subRule as TspconfigEmitterOptionsSubRuleBase;
516+
const emitterName = emitterOptionSubRule.getEmitterName();
517+
if (emitterName === "@azure-tools/typespec-csharp" && isSubRuleSuccess === false) {
518+
console.warn(`Validation on option "${emitterOptionSubRule.getPathOfKeyToValidate()}" in "${emitterName}" are failed. However, per ${emitterName}’s decision, we will treat it as passed.`);
519+
isSubRuleSuccess = true;
520+
}
521+
}
522+
523+
success &&= isSubRuleSuccess;
507524
}
508525

509526
const stdOutputFailedResults =

eng/tools/typespec-validation/test/sdk-tspconfig-validation.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export function createEmitterOptionExample(
7070
return content;
7171
}
7272

73+
// TODO: remove when @azure-tools/typespec-csharp is ready for validating tspconfig
74+
function shouldBeTrueOnFailSubRuleValidation(emitterName: string) {
75+
return emitterName === "@azure-tools/typespec-csharp" ? true : false;
76+
}
77+
7378
function createParameterTestCases(
7479
folder: string,
7580
key: string,
@@ -130,15 +135,15 @@ function createEmitterOptionTestCases(
130135
key: key,
131136
value: invalidValue,
132137
}),
133-
success: false,
138+
success: shouldBeTrueOnFailSubRuleValidation(emitterName),
134139
subRules,
135140
});
136141

137142
cases.push({
138143
description: `Validate ${language}'s option:${key} with undefined value`,
139144
folder,
140145
tspconfigContent: createEmitterOptionExample(emitterName),
141-
success: allowUndefined ? true : false,
146+
success: allowUndefined ? true : shouldBeTrueOnFailSubRuleValidation(emitterName),
142147
subRules,
143148
});
144149

@@ -150,7 +155,7 @@ function createEmitterOptionTestCases(
150155
key: key.split(".").slice(0, -1).join("."),
151156
value: validValue,
152157
}),
153-
success: false,
158+
success: shouldBeTrueOnFailSubRuleValidation(emitterName),
154159
subRules,
155160
});
156161
}
@@ -460,7 +465,7 @@ const csharpAzNamespaceWithPackageDirTestCases: Case[] = [
460465
{ key: "namespace", value: "namespace" },
461466
{ key: "package-dir", value: "Azure.AAA" },
462467
),
463-
success: false,
468+
success: shouldBeTrueOnFailSubRuleValidation("@azure-tools/typespec-csharp"),
464469
subRules: [new TspConfigCsharpAzNamespaceEqualStringSubRule()],
465470
},
466471
];

0 commit comments

Comments
 (0)