Skip to content

Commit a74e8df

Browse files
committed
refactor: simpler string trimming after prettier format
1 parent 023e823 commit a74e8df

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/markdown.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
// General helpers for dealing with markdown files / content.
22

3-
function removeTrailingNewline(str: string) {
4-
return str.replace(/\s+$/, '');
5-
}
6-
73
export async function format(str: string, filePath: string): Promise<string> {
84
try {
95
const { default: prettier } = await import('prettier');
106
const options = await prettier.resolveConfig(filePath);
11-
// Trim the ending newline that prettier may add.
12-
return removeTrailingNewline(
13-
prettier.format(str, {
7+
return prettier
8+
.format(str, {
149
...options,
1510
parser: 'markdown',
1611
})
17-
);
12+
.trimEnd(); // Trim the ending newline that prettier may add.
1813
} catch {
1914
// Skip prettier formatting if not installed.
2015
/* istanbul ignore next -- TODO: Figure out how to test when prettier is not installed. */

0 commit comments

Comments
 (0)