From 680a4f58d2b6a8c29cb1f2ae9ccc52e03da64326 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Tue, 19 Mar 2024 20:12:23 +0100 Subject: [PATCH] commitlint(body-prose): make new test pass For paragraphs ending in footer refs. --- commitlint/helpers.ts | 13 +++++++++++-- commitlint/plugins.ts | 10 ++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/commitlint/helpers.ts b/commitlint/helpers.ts index 3134e621..28f12ac4 100644 --- a/commitlint/helpers.ts +++ b/commitlint/helpers.ts @@ -155,11 +155,20 @@ export abstract class Helpers { ); } - public static isFooterReference(line: string) { + public static lineStartsWithFooterReference(line: string) { Helpers.assertLine(line); return line[0] === "[" && line.indexOf("]") > 1; } + public static wordIsFooterReference(word: string) { + if (word.length == 0) { + return false; + } + Helpers.assertWord(word); + // TODO: check intermediate chars are numbers + return word[word.length - 1] === "]" && word[0] === "["; + } + public static isFixesOrClosesSentence(line: string) { Helpers.assertLine(line); return line.indexOf("Fixes ") == 0 || line.indexOf("Closes ") == 0; @@ -173,7 +182,7 @@ export abstract class Helpers { public static isFooterNote(line: string): boolean { Helpers.assertLine(line); return ( - Helpers.isFooterReference(line) || + Helpers.lineStartsWithFooterReference(line) || Helpers.isCoAuthoredByTag(line) || Helpers.isFixesOrClosesSentence(line) ); diff --git a/commitlint/plugins.ts b/commitlint/plugins.ts index ebb2b1f2..2f5ab788 100644 --- a/commitlint/plugins.ts +++ b/commitlint/plugins.ts @@ -6,9 +6,11 @@ export abstract class Plugins { function paragraphHasValidEnding(paragraph: string): boolean { let paragraphWords = paragraph.split(" "); let lastWordInParagraph = paragraphWords[paragraphWords.length - 1]; - let isParagraphEndingWithUrl = - Helpers.isValidUrl(lastWordInParagraph); - if (isParagraphEndingWithUrl) { + + let isParagraphEndingWithLink = + Helpers.isValidUrl(lastWordInParagraph) || + Helpers.wordIsFooterReference(lastWordInParagraph); + if (isParagraphEndingWithLink) { return true; } @@ -207,7 +209,7 @@ export abstract class Plugins { if (Helpers.isEmptyFooterReference(line)) { offence = true; hasEmptyFooter = true; - } else if (Helpers.isFooterReference(line)) { + } else if (Helpers.lineStartsWithFooterReference(line)) { references.add(match); } else { bodyReferences.add(match);