From a8e8ea6e163ddaac9f062b774af7d4136ffb2031 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 17 Jul 2023 10:39:35 +0200 Subject: [PATCH 1/2] commitlint(plugins.test): add tests for issue#124 Add tests that cover cases described in [1]. This commit has failing test. [1] https://github.com/nblockchain/conventions/issues/124 --- commitlint/plugins.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/commitlint/plugins.test.ts b/commitlint/plugins.test.ts index 7a2475248..3dd6bc56f 100644 --- a/commitlint/plugins.test.ts +++ b/commitlint/plugins.test.ts @@ -323,6 +323,24 @@ test("body-max-line-length8", () => { expect(bodyMaxLineLength8.status).toBe(1); }); +test("body-max-line-length9", () => { + // see https://github.com/nblockchain/conventions/issues/124 + let commitMsgWithLargeBody = + "GrpcService: fix some logging nits\n\n" + + "These mistakes were made in 45faeca2f0e7c9c5545f54fb3fcc815f52b8a7cf."; + let bodyMaxLineLength9 = runCommitLintOnMsg(commitMsgWithLargeBody); + expect(bodyMaxLineLength9.status).toBe(0); +}); + +test("body-max-line-length10", () => { + // see https://github.com/nblockchain/conventions/issues/124 + let commitMsgWithLargeBody = + "GrpcService: fix some logging nits\n\n" + + "These mistakes were made in this GrpcService's RunIntoMeService commit: 45faeca2f0e7c9c5545f54fb3fcc815f52b8a7cf."; + let bodyMaxLineLength10 = runCommitLintOnMsg(commitMsgWithLargeBody); + expect(bodyMaxLineLength10.status).toBe(1); +}); + test("body-paragraph-line-min-length1", () => { let tenChars = "1234 67890"; let fortyChars = tenChars + tenChars + tenChars + tenChars; From 8e4b640cf473ee4e551bca6d7a36588a882a1829 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 17 Jul 2023 11:03:18 +0200 Subject: [PATCH 2/2] commitlint(plugins): fix issue#124 Add exception to bodySoftMaxLineLength when line exceeds max length but ends with a git commit hash. Fixes https://github.com/nblockchain/conventions/issues/124. --- commitlint/plugins.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/commitlint/plugins.ts b/commitlint/plugins.ts index f772d83ef..16f950595 100644 --- a/commitlint/plugins.ts +++ b/commitlint/plugins.ts @@ -399,7 +399,21 @@ export abstract class Plugins { let lineIsFooterNote = Helpers.isFooterNote(line); - if (!isUrl && !lineIsFooterNote) { + let commitHashPattern = `([0-9a-f]{40})`; + let anySinglePunctuationCharOrNothing = `[\.\,\:\;\?\!]?`; + let index = line.search( + commitHashPattern + + anySinglePunctuationCharOrNothing + + `$` + ); + let endsWithCommitHashButRestIsNotTooLong = + index != -1 && index < bodyMaxLineLength; + + if ( + !isUrl && + !lineIsFooterNote && + !endsWithCommitHashButRestIsNotTooLong + ) { offence = true; break; }