From 0f33e64e166d93c1247c07be021ab283126529b8 Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Mon, 22 Jan 2024 12:05:00 +0330 Subject: [PATCH 1/2] commitlint: failing test for issue 148 --- commitlint/plugins.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/commitlint/plugins.test.ts b/commitlint/plugins.test.ts index 62ba9dfb..09d2cdbe 100644 --- a/commitlint/plugins.test.ts +++ b/commitlint/plugins.test.ts @@ -778,6 +778,24 @@ test("footer-refs-validity8", () => { expect(footerRefsValidity8.status).toBe(0); }); +// This test reflects this issue: https://github.com/nblockchain/conventions/issues/148 +test("footer-refs-validity9", () => { + let commitMsgWithTwoCodeBlocksAtBodyWithRef = + "foo: blah blah" + + "\n\n" + + "Blah blah [1]:" + + "\n\n" + + "```\nsomeCodeBlock\n```" + + "\n\n" + + "[1] Stack trace:" + + "\n\n" + + "```\nsomeCodeBlock\n```"; + let footerRefsValidity9 = runCommitLintOnMsg( + commitMsgWithTwoCodeBlocksAtBodyWithRef + ); + expect(footerRefsValidity9.status).toBe(0); +}); + test("prefer-slash-over-backslash1", () => { let commitMsgWithBackslash = "foo\\bar: bla bla bla"; let preferSlashOverBackslash1 = runCommitLintOnMsg(commitMsgWithBackslash); From 7d1c81572371e35994aa4b51f98a72d9149a913d Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Mon, 22 Jan 2024 12:07:27 +0330 Subject: [PATCH 2/2] commitlint: apply fix This commit rectifies a problem in the removeAllCodeBlocks function that was unintentionally deleting all text between two code blocks. The modification guarantees that only the code blocks are substituted, leaving the remaining text unaffected. Fixes https://github.com/nblockchain/conventions/issues/148 --- commitlint/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint/helpers.ts b/commitlint/helpers.ts index f6d886b6..3134e621 100644 --- a/commitlint/helpers.ts +++ b/commitlint/helpers.ts @@ -221,7 +221,7 @@ export abstract class Helpers { } public static removeAllCodeBlocks(text: string) { - return text.replace(/```[^]*```/g, ""); + return text.replace(/```[\s\S]*?```/g, ""); } public static splitByEOLs(text: string, numberOfEols: number) {