Skip to content

Commit 9971340

Browse files
authored
[TypeSpec Validation] exclude trailing slash when calculating folder depth (#26626)
* trailing slash tsv folder rule * Update eng/tools/typespec-validation/src/rules/folder-structure.ts
1 parent 90115af commit 9971340

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

eng/tools/typespec-validation/src/rules/folder-structure.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class FolderStructureRule implements Rule {
3131
}
3232
});
3333

34-
// Verify top level folder is lower case
35-
let folderStruct = relativePath.split("/");
34+
// Verify top level folder is lower case and remove empty entries when splitting by slash
35+
let folderStruct = relativePath.split("/").filter(Boolean);
3636
if (folderStruct[1].match(/[A-Z]/g)) {
3737
success = false;
3838
errorOutput += `Invalid folder name. Folders under specification/ must be lower case.\n`;

eng/tools/typespec-validation/test/folder-structure.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ describe("folder-structure", function () {
2828
assert(result.errorOutput.includes("must be lower case"));
2929
});
3030

31+
it("should succeed if package folder has trailing slash", async function () {
32+
let host = new TsvTestHost();
33+
host.globby = async () => {
34+
return ["/foo/bar/tspconfig.yaml"];
35+
};
36+
host.normalizePath = () => {
37+
return "/gitroot";
38+
};
39+
40+
const result = await new FolderStructureRule().execute(
41+
host,
42+
"/gitroot/specification/foo/Foo/Foo/",
43+
);
44+
assert(result.success);
45+
});
46+
3147
it("should fail if package folder is more than 3 levels deep", async function () {
3248
let host = new TsvTestHost();
3349
host.globby = async () => {

0 commit comments

Comments
 (0)