diff --git a/eng/tools/typespec-validation/src/rules/linter-ruleset.ts b/eng/tools/typespec-validation/src/rules/linter-ruleset.ts index 9cb783603942..b3e5b69aa258 100644 --- a/eng/tools/typespec-validation/src/rules/linter-ruleset.ts +++ b/eng/tools/typespec-validation/src/rules/linter-ruleset.ts @@ -27,10 +27,6 @@ export class LinterRulesetRule implements Rule { const configText = await readTspConfig(folder); const config = parse(configText); - const rpFolder = - config?.options?.["@azure-tools/typespec-autorest"]?.["azure-resource-provider-folder"]; - stdOutput += `azure-resource-provider-folder: ${JSON.stringify(rpFolder)}\n`; - const mainTspExists = await fileExists(join(folder, "main.tsp")); const clientTspExists = await fileExists(join(folder, "client.tsp")); const files = []; @@ -45,25 +41,21 @@ export class LinterRulesetRule implements Rule { const linterExtends = config?.linter?.extends; stdOutput += `linter.extends: ${JSON.stringify(linterExtends)}`; + // Normalize path separators + const normalizedFolder = folder.replace(/\\/g, "/"); + let requiredRuleset = ""; - if (rpFolder?.trim()?.endsWith("resource-manager")) { + if ( + normalizedFolder.includes("/resource-manager/") || + normalizedFolder.trim().endsWith(".Management") + ) { requiredRuleset = "@azure-tools/typespec-azure-rulesets/resource-manager"; - } else if (rpFolder?.trim()?.endsWith("data-plane")) { - requiredRuleset = "@azure-tools/typespec-azure-rulesets/data-plane"; } else if (clientTspExists && !mainTspExists) { // Assume folders with no autorest setting, containing only "client.tsp" but no "main.tsp", // are data-plane (e.g. HealthInsights.TrialMatcher) requiredRuleset = "@azure-tools/typespec-azure-rulesets/data-plane"; } else { - // Cannot determine if spec is data-plane or resource-manager, so cannot know - // which linter ruleset is required. - success = false; - errorOutput += - "tspconfig.yaml must define the following property:\n" + - "\n" + - "options:\n" + - ' "@azure-tools/typespec-autorest":\n' + - ' azure-resource-provider-folder: "data-plane" | "resource-manager"\n'; + requiredRuleset = "@azure-tools/typespec-azure-rulesets/data-plane"; } if (linterExtends) { diff --git a/eng/tools/typespec-validation/test/linter-ruleset.test.ts b/eng/tools/typespec-validation/test/linter-ruleset.test.ts index 90e995bdc843..ac8e4dae9a11 100644 --- a/eng/tools/typespec-validation/test/linter-ruleset.test.ts +++ b/eng/tools/typespec-validation/test/linter-ruleset.test.ts @@ -29,30 +29,24 @@ describe("linter-ruleset", function () { it("succeeds with resource-manager/resource-manager", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "resource-manager" linter: extends: - "@azure-tools/typespec-azure-rulesets/resource-manager" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/resource-manager/Foo"); assert(result.success); }); it("succeeds with data-plane/data-plane", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "data-plane" linter: extends: - "@azure-tools/typespec-azure-rulesets/data-plane" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/data-plane/Foo"); assert(result.success); }); @@ -80,76 +74,58 @@ linter: }); it("fails with resource-manager/no-linter", async function () { - readTspConfigSpy.mockImplementation(() => - Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "resource-manager" -`), - ); - const result = await new LinterRulesetRule().execute(mockFolder); + readTspConfigSpy.mockImplementation(() => Promise.resolve(``)); + const result = await new LinterRulesetRule().execute("specification/foo/resource-manager/Foo"); assert(!result.success); }); it("fails with resource-manager/data-plane", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "resource-manager" linter: extends: - "@azure-tools/typespec-azure-rulesets/data-plane" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/Foo.Management"); assert(!result.success); }); it("fails with data-plane/resource-manager", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "data-plane" linter: extends: - "@azure-tools/typespec-azure-rulesets/resource-manager" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/data-plane/Foo"); assert(!result.success); }); it("fails with data-plane/old-and-new", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "data-plane" linter: extends: - "@azure-tools/typespec-azure-core/all" - "@azure-tools/typespec-azure-rulesets/data-plane" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/data-plane/Foo"); assert(!result.success); }); it("fails with resource-manager/old-and-new", async function () { readTspConfigSpy.mockImplementation(() => Promise.resolve(` -options: - "@azure-tools/typespec-autorest": - azure-resource-provider-folder: "resource-manager" linter: extends: - "@azure-tools/typespec-azure-resource-manager/all" - "@azure-tools/typespec-azure-rulesets/resource-manager" `), ); - const result = await new LinterRulesetRule().execute(mockFolder); + const result = await new LinterRulesetRule().execute("specification/foo/resource-manager/Foo"); assert(!result.success); }); diff --git a/specification/widget/data-plane/WidgetAnalytics/tspconfig.yaml b/specification/widget/data-plane/WidgetAnalytics/tspconfig.yaml index 70b3aab03e5b..1b86a0e76f75 100644 --- a/specification/widget/data-plane/WidgetAnalytics/tspconfig.yaml +++ b/specification/widget/data-plane/WidgetAnalytics/tspconfig.yaml @@ -10,8 +10,6 @@ linter: - "@azure-tools/typespec-azure-rulesets/data-plane" options: "@azure-tools/typespec-autorest": - # TODO: Does anything need this set, if it's not used in output-file? - azure-resource-provider-folder: "data-plane" emit-lro-options: "none" emitter-output-dir: "{project-root}" output-file: "{version-status}/{version}/widgetanalytics.json" diff --git a/specification/widget/resource-manager/Microsoft.Widget/Widget/tspconfig.yaml b/specification/widget/resource-manager/Microsoft.Widget/Widget/tspconfig.yaml index 81c35056d002..9c97da201c09 100644 --- a/specification/widget/resource-manager/Microsoft.Widget/Widget/tspconfig.yaml +++ b/specification/widget/resource-manager/Microsoft.Widget/Widget/tspconfig.yaml @@ -7,8 +7,6 @@ options: "@azure-tools/typespec-autorest": use-read-only-status-schema: true emitter-output-dir: "{project-root}" - # TODO: Does anything need this set, if it's not used in output-file? Currently required by TSV. - azure-resource-provider-folder: "resource-manager" output-file: "{version-status}/{version}/widget.json" arm-types-dir: "{project-root}/../../../../common-types/resource-management" "@azure-typespec/http-client-csharp-mgmt":