Skip to content

Commit

Permalink
commitlint(body-prose): make new test pass
Browse files Browse the repository at this point in the history
For paragraphs ending in footer refs.
  • Loading branch information
knocte committed Mar 19, 2024
1 parent 63beb68 commit 680a4f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 11 additions & 2 deletions commitlint/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
);
Expand Down
10 changes: 6 additions & 4 deletions commitlint/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 680a4f5

Please sign in to comment.