Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeSpec Validation] verify folder structure #25712

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions eng/tools/TypeSpecValidation/src/rules/folder-structure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { globby } from "globby";
import path from "path";
import { Rule } from "../rule.js";
import { RuleResult } from "../rule-result.js";
import { checkFileExists } from "../utils.js";

export class FolderStructureRule implements Rule {
readonly name = "FolderStructure";
Expand All @@ -18,6 +20,37 @@ export class FolderStructureRule implements Rule {
}
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
});

// Verify top level folder is lower case
let folderStruct = folder.split(path.sep)
if (folderStruct[1].match(/[A-Z]/g)) {
success = false;
errorOutput += `Invalid folder name. Folders under specification/ must be lower case.\n`
}

// Verify second level folder is capitalized after each '.'
ckairen marked this conversation as resolved.
Show resolved Hide resolved
if (/(^|\. *)([a-z])/g.test(folderStruct[2]) && !["data-plane", "resource-manager"].includes(folderStruct[2])) {
success = false;
errorOutput += `Invalid folder name. Folders under specification/${folderStruct[1]} must be capitalized after each '.'\n`
}

// Verify 'Shared' follows 'Management'
if (folderStruct[2].includes("Management") && folderStruct[2].includes("Shared")) {
if (!folderStruct[2].includes("Management.Shared")) {
success = false;
errorOutput += `Invalid folder name. For management libraries with a shared component, 'Shared' should follow 'Management'.`
}
}

// Verify tspconfig, main.tsp, examples/
let containsMinStruct = await checkFileExists(path.join(folder, "main.tsp")) && await checkFileExists(path.join(folder, "examples"))
ckairen marked this conversation as resolved.
Show resolved Hide resolved
if (!folderStruct[2].includes("Shared")) {
containsMinStruct = containsMinStruct && await checkFileExists(path.join(folder, "tspconfig.yaml"))
}
if (!containsMinStruct) {
success = false;
errorOutput += `Invalid folder structure. Package must contain tspconfig.yaml, main.tsp, and examples folder.`
}

return {
success: success,
stdOutput: stdOutput,
Expand Down
Loading