Skip to content

Commit

Permalink
Merge PR nblockchain#133 from webwarrior-ws/body-max-line-length-exce…
Browse files Browse the repository at this point in the history
…ption

Fixes nblockchain#124
  • Loading branch information
knocte authored Aug 2, 2023
2 parents 467b047 + 8e4b640 commit b2965b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
18 changes: 18 additions & 0 deletions commitlint/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion commitlint/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,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;
}
Expand Down

0 comments on commit b2965b5

Please sign in to comment.