Skip to content

Commit

Permalink
Merge branch 'main' into update-functionAppConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
naveedaz authored May 31, 2024
2 parents 8f7b086 + 01d1832 commit a6d248c
Show file tree
Hide file tree
Showing 535 changed files with 97,291 additions and 2,351 deletions.
60 changes: 47 additions & 13 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,38 +291,38 @@
"freemium"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-02-01-preview/ManagedInstances.json",
"words": [
"freemium"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-05-01-preview/ManagedInstances.json",
"words": [
"freemium"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-08-01-preview/ManagedInstances.json",
"words": [
"freemium"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-08-01-preview/ServerTrustCertificates.json",
"words": [
"freemium"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-08-01-preview/ManagedInstanceDtcs.json",
"words": [
"msdtcdns",
"msdtc's"
]
},
{
{
"filename": "**/specification/sql/resource-manager/Microsoft.Sql/preview/2023-08-01-preview/TimeZones.json",
"words": [
"freemium"
Expand Down Expand Up @@ -505,7 +505,7 @@
"Idms",
"Cluter",
"Mfamily",
"Datacentre"
"Datacentre"
]
},
{
Expand Down Expand Up @@ -865,7 +865,6 @@
"psqldb"
]
},

{
"filename": "**/specification/maps/data-plane/Weather/stable/1.1/weather.json",
"words": [
Expand Down Expand Up @@ -1183,7 +1182,7 @@
{
"filename": "**/specification/containerservice/resource-manager/Microsoft.ContainerService/**/*.json",
"words": [
"containerd"
"containerd"
]
},

Expand Down Expand Up @@ -1225,8 +1224,8 @@
]
},
{
"filename": "**/specification/confidentialledger/data-plane/Microsoft.CodeTransparency/preview/**/*.json",
"words": [
"filename": "**/specification/confidentialledger/data-plane/Microsoft.CodeTransparency/preview/**/*.json",
"words": [
"cbor",
"txids",
"operationid",
Expand Down Expand Up @@ -1254,8 +1253,23 @@
{
"filename": "**/specification/sqlvirtualmachine/resource-manager/Microsoft.SqlVirtualMachine/**/*.json",
"words": [
"WUMU",
"WSUS"
"WUMU",
"WSUS"
]
},
{
"filename": "**/specification/riskiq/data-plane/Microsoft.Easm/preview/2024-03-01-preview/easm.json",
"words": [
"Cisa",
"cisa",
"affected",
"AUTOCONFIRMED"
]
},
{
"filename": "**/specification/hybridcompute/resource-manager/Microsoft.HybridCompute/preview/**/*.json",
"words": [
"hotpatch"
]
},
{
Expand All @@ -1277,6 +1291,18 @@
"spoofface"
]
},
{
"filename": "**/specification/developerhub/resource-manager/Microsoft.DevHub/**/*.json",
"words": [
"iacProfiles",
"iacProfile",
"IacProfiles",
"IacProfile",
"HCI",
"HCIAKS",
"HCIARCVM"
]
},
{
"filename": "**/specification/securityinsights/data-plane/Microsoft.SecurityInsights/**/*.json",
"words": [
Expand All @@ -1289,6 +1315,14 @@
"words": [
"rerank"
]
},
{
"filename": "**/specification/communication/data-plane/CallAutomation/**/*.json",
"words": [
"unhold",
"Unhold",
"transferor's"
]
}
],
"enableFiletypes": [
Expand Down
39 changes: 34 additions & 5 deletions eng/tools/typespec-validation/src/rules/linter-ruleset.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { readFile } from "fs/promises";
import { join } from "path";
import { parse as yamlParse } from "yaml";
import { Rule } from "../rule.js";
import { RuleResult } from "../rule-result.js";
import { TsvHost } from "../tsv-host.js";

// Maps deprecated rulesets to the replacement rulesets
const deprecatedRulesets = new Map<string, string>([
["@azure-tools/typespec-azure-core/all", "@azure-tools/typespec-azure-rulesets/data-plane"],
[
"@azure-tools/typespec-azure-resource-manager/all",
"@azure-tools/typespec-azure-rulesets/resource-manager",
],
]);

export class LinterRulesetRule implements Rule {
readonly name = "LinterRuleset";

Expand All @@ -16,12 +24,11 @@ export class LinterRulesetRule implements Rule {
let stdOutput = "";
let errorOutput = "";

const configFile = join(folder, "tspconfig.yaml");
const configText = await readFile(configFile, "utf8");
const configText = await host.readTspConfig(folder);
const config = yamlParse(configText);

const rpFolder =
config.options?.["@azure-tools/typespec-autorest"]?.["azure-resource-provider-folder"];
config?.options?.["@azure-tools/typespec-autorest"]?.["azure-resource-provider-folder"];
stdOutput += `azure-resource-provider-folder: ${JSON.stringify(rpFolder)}\n`;

const mainTspExists = await host.checkFileExists(join(folder, "main.tsp"));
Expand All @@ -35,7 +42,7 @@ export class LinterRulesetRule implements Rule {
}
stdOutput += `files: ${JSON.stringify(files)}\n`;

const linterExtends = config.linter?.extends;
const linterExtends: string[] = config?.linter?.extends;
stdOutput += `linter.extends: ${JSON.stringify(linterExtends)}`;

let requiredRuleset = "";
Expand All @@ -59,6 +66,28 @@ export class LinterRulesetRule implements Rule {
' azure-resource-provider-folder: "data-plane" | "resource-manager"\n';
}

if (linterExtends) {
for (const ruleset of linterExtends) {
if (deprecatedRulesets.has(ruleset)) {
const newRuleset = deprecatedRulesets.get(ruleset);

success = false;
errorOutput +=
"tspconfig.yaml references the following ruleset which is deprecated:\n" +
"\n" +
"linter:\n" +
" extends:\n" +
` - "${ruleset}"\n` +
"\n" +
"It should be replaced with the following:\n" +
"\n" +
"linter:\n" +
" extends:\n" +
` - "${newRuleset}"`;
}
}
}

if (requiredRuleset && !linterExtends?.includes(requiredRuleset)) {
success = false;
errorOutput +=
Expand Down
130 changes: 130 additions & 0 deletions eng/tools/typespec-validation/test/linter-ruleset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { describe, it } from "vitest";
import { join } from "path";
import { LinterRulesetRule } from "../src/rules/linter-ruleset.js";
import { TsvTestHost } from "./tsv-test-host.js";
import { strict as assert } from "node:assert";

describe("linter-ruleset", function () {
it("succeeds with default config", async function () {
const host = new TsvTestHost();
const result = await new LinterRulesetRule().execute(host, TsvTestHost.folder);
assert(result.success);
});

it("succeeds with resource-manager/resource-manager", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);
assert(result.success);
});

it("succeeds with data-plane/data-plane", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);
assert(result.success);
});

it("succeeds with client.tsp/data-plane", async function () {
const host = new TsvTestHost();
host.checkFileExists = async (file: string) => file === join(TsvTestHost.folder, "client.tsp");
host.readTspConfig = async (_folder: string) => `
linter:
extends:
- "@azure-tools/typespec-azure-rulesets/data-plane"
`;
const result = await new LinterRulesetRule().execute(host, TsvTestHost.folder);
assert(result.success);
});

it("fails with no-config", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => "";
const result = await new LinterRulesetRule().execute(host, TsvTestHost.folder);
assert(!result.success);
});

it("fails with resource-manager/no-linter", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
options:
"@azure-tools/typespec-autorest":
azure-resource-provider-folder: "resource-manager"
`;
const result = await new LinterRulesetRule().execute(host, TsvTestHost.folder);
assert(!result.success);
});

it("fails with resource-manager/data-plane", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);
assert(!result.success);
});

it("fails with data-plane/resource-manager", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);
assert(!result.success);
});

it("fails with data-plane/old-and-new", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);
assert(!result.success);
});

it("fails with resource-manager/old-and-new", async function () {
const host = new TsvTestHost();
host.readTspConfig = async (_folder: string) => `
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(host, TsvTestHost.folder);

assert(!result.success);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ options:
emitter-output-dir: "{java-sdk-folder}/sdk/{service-directory-name}/azure-health-insights-radiologyinsights"
flavor: azure
stream-style-serialization: false
polling:
inferRadiologyInsights:
final-type: com.azure.health.insights.radiologyinsights.models.RadiologyInsightsInferenceResult
"@azure-tools/typespec-csharp":
save-inputs: false
clear-output-folder: true
Expand Down
Loading

0 comments on commit a6d248c

Please sign in to comment.