Skip to content

Commit

Permalink
commitlint/plugins: make recent test pass
Browse files Browse the repository at this point in the history
Fixes part of #120
(Numbered bullets not fixed yet.)
  • Loading branch information
knocte committed Jan 19, 2024
1 parent 734420b commit 3c0876a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions commitlint/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,20 @@ export abstract class Plugins {
];
}

private static lineStartsWithBullet(line: string) {
let allowedBulletChars = ['*', '-'];
for (let bulletChar of allowedBulletChars) {
let simplePattern = bulletChar + " ";
if (line.startsWith(simplePattern) && line.length > simplePattern.length)
return true;

let pattern = " " + bulletChar + " ";
if (line.startsWith(pattern) && line.length > pattern.length)
return true;
}
return false;
}

public static bodyParagraphLineMinLength(
bodyStr: string | null,
paragraphLineMinLength: number,
Expand All @@ -445,6 +459,9 @@ export abstract class Plugins {
for (let paragraph of paragraphs) {
let lines = Helpers.splitByEOLs(paragraph, 1);

let bulletsAllowedNow = false;
let alwaysBulletsSoFar = false;

// NOTE: we don't iterate over the last line, on purpose
for (let i = 0; i < lines.length - 1; i++) {
let line = lines[i];
Expand All @@ -453,6 +470,14 @@ export abstract class Plugins {
continue;
}

if ((!allowBulletAhead) &&
((i == 0 && lineStartsWithBullet(line) || line.endsWith(":")))) {
bulletsAllowedNow = true;
alwaysBulletsSoFar = true;
} else if (bulletsAllowedNow) {
alwaysBulletsSoFar = alwaysBulletsSoFar && lineStartsWithBullet(line);
}

if (line.length < paragraphLineMinLength) {
// this ref doesn't go out of bounds because we didn't iter on last line
let nextLine = lines[i + 1];
Expand All @@ -473,6 +498,7 @@ export abstract class Plugins {
nextLine[0].toUpperCase() == nextLine[0];

if (
!alwaysBulletsSoFar &&
!isUrl &&
!lineIsFooterNote &&
!isNextWordTooLong &&
Expand Down

0 comments on commit 3c0876a

Please sign in to comment.