Skip to content

Commit b6d28a1

Browse files
committed
chore: improve trailing string
1 parent 16208bc commit b6d28a1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/commit-message-checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,19 @@ const debugRegexMatching = (regexes: (string | string[])[], str: string): string
146146
const paddingRight = Math.min(matchesUntil + 10, copyStr.length);
147147
const rightDots = paddingRight !== copyStr.length ? '…' : '';
148148
const leftDots = paddingLeft !== 0 ? '…' : '';
149+
const errorArrow = `${' '.repeat(leftDots.length)}${" ".repeat(matchesUntil - paddingLeft)}^${"~".repeat(paddingRight - matchesUntil)}`;
150+
const context = `${leftDots}${copyStr.slice(paddingLeft, paddingRight).replaceAll('\n', '␤')}${rightDots}`;
149151

150152
if (str.length > 0 && regexes.length === 0) {
151153
return `Trailing characters: "${str}"
152154
--------------------------------
153-
Context: "${leftDots}${copyStr.slice(paddingLeft, Math.min(copyStr.length, matchesUntil + 10)).replaceAll('\n', '␤')}${rightDots}"
154-
${' '.repeat(leftDots.length)}${" ".repeat(matchesUntil - paddingLeft)}^`;
155+
Context: "${context}"
156+
${errorArrow}`;
155157
} else {
156-
return `The regex stopped matching at index: ${matchesUntil}.
158+
return `The regex stopped matching at index: ${matchesUntil}
157159
Expected: ${rgx}
158-
Context: "${leftDots}${copyStr.slice(paddingLeft, paddingRight).replaceAll('\n', '␤')}${rightDots}"
159-
${' '.repeat(leftDots.length)}${" ".repeat(matchesUntil - paddingLeft)}^${"~".repeat(paddingRight - matchesUntil)}`;
160+
Context: "${context}"
161+
${errorArrow}`;
160162
}
161163
}
162164
}

0 commit comments

Comments
 (0)