in eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts [491:536]
async execute(folder: string): Promise<RuleResult> {
const tspConfigPath = join(folder, "tspconfig.yaml");
const suppressions = await getSuppressions(tspConfigPath);
const shouldSuppressEntireRule = suppressions.some(
(s) => s.rules?.includes(this.name) === true && (!s.subRules || s.subRules.length === 0),
);
if (shouldSuppressEntireRule)
return { success: true, stdOutput: `[${this.name}]: validation skipped.` };
this.setSuppressedKeyPaths(suppressions);
const failedResults = [];
let success = true;
for (const subRule of this.subRules) {
// TODO: support wildcard
if (this.suppressedKeyPaths.has(subRule.getPathOfKeyToValidate())) continue;
const result = await subRule.execute(folder!);
if (!result.success) failedResults.push(result);
let isSubRuleSuccess = result.success;
// TODO: remove when @azure-tools/typespec-csharp is ready for validating tspconfig
if (subRule instanceof TspconfigEmitterOptionsSubRuleBase) {
const emitterOptionSubRule = subRule as TspconfigEmitterOptionsSubRuleBase;
const emitterName = emitterOptionSubRule.getEmitterName();
if (emitterName === "@azure-tools/typespec-csharp" && isSubRuleSuccess === false) {
console.warn(`Validation on option "${emitterOptionSubRule.getPathOfKeyToValidate()}" in "${emitterName}" are failed. However, per ${emitterName}’s decision, we will treat it as passed.`);
isSubRuleSuccess = true;
}
}
success &&= isSubRuleSuccess;
}
const stdOutputFailedResults =
failedResults.length > 0
? `${failedResults.map((r) => r.errorOutput).join("\n")}\nPlease see https://aka.ms/azsdk/spec-gen-sdk-config for more info.\nFor additional information on TypeSpec validation, please refer to https://aka.ms/azsdk/specs/typespec-validation.`
: "";
// NOTE: to avoid huge impact on existing PRs, we always return true with info/warning messages.
return {
success: true,
stdOutput: `[${this.name}]: validation ${success ? "passed" : "failed"}.\n${stdOutputFailedResults}`,
};
}