From 67c2fa9dfd3d05b9a00a2553b509d194b2b15162 Mon Sep 17 00:00:00 2001 From: sverweij Date: Sat, 2 Sep 2023 10:36:18 +0200 Subject: [PATCH] feat(generate): adds support for inline comments in rule lines --- dist/generate-codeowners.js | 5 ++++- src/generate-codeowners.test.ts | 13 +++++++++++++ src/generate-codeowners.ts | 7 ++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dist/generate-codeowners.js b/dist/generate-codeowners.js index 0070ac0..050b328 100644 --- a/dist/generate-codeowners.js +++ b/dist/generate-codeowners.js @@ -22,7 +22,10 @@ function generateLine(pCSTLine, pTeamMap) { const lUserNames = uniq(pCSTLine.users.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap))) .sort(compareUserNames) .join(" "); - return pCSTLine.filesPattern + pCSTLine.spaces + lUserNames; + return (pCSTLine.filesPattern + + pCSTLine.spaces + + lUserNames + + (pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "")); } return pCSTLine.raw; } diff --git a/src/generate-codeowners.test.ts b/src/generate-codeowners.test.ts index 5db4ef9..8b081f4 100644 --- a/src/generate-codeowners.test.ts +++ b/src/generate-codeowners.test.ts @@ -208,6 +208,19 @@ tools/ @team-tgif`; ); }); + it("re-adds any inline comment", () => { + const lFixture = "no-plan-b/ @team # this is a comment"; + const lTeamMapFixture = { + team: ["b.a.barackus", "face", "hannibal", "murdock"], + }; + const lExpected = + "no-plan-b/ @b.a.barackus @face @hannibal @murdock # this is a comment"; + equal( + generateCodeOwnersFromString(lFixture, lTeamMapFixture, ""), + lExpected, + ); + }); + it("writes the kitchensink", () => { const lTeamMap = readTeamMap( new URL("./__mocks__/virtual-teams.yml", import.meta.url).pathname, diff --git a/src/generate-codeowners.ts b/src/generate-codeowners.ts index 3b0ca02..5c3dd6e 100644 --- a/src/generate-codeowners.ts +++ b/src/generate-codeowners.ts @@ -43,7 +43,12 @@ function generateLine( ) .sort(compareUserNames) .join(" "); - return pCSTLine.filesPattern + pCSTLine.spaces + lUserNames; + return ( + pCSTLine.filesPattern + + pCSTLine.spaces + + lUserNames + + (pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "") + ); } return pCSTLine.raw; }