Skip to content

Commit 9274c5e

Browse files
committed
Further remove trailing spaces
1 parent 3a9b1bb commit 9274c5e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/openapi-typescript/src/utils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ export function comment(text: string, indentLv?: number): string {
9999
if (!commentText.includes("\n")) return `/** ${commentText} */`;
100100

101101
// if multi-line comment
102-
const ln = indent(" * ", indentLv ?? 0);
103-
return ["/**", `${ln}${commentText.replace(LB_RE, `\n${ln}`)}`, indent(" */", indentLv ?? 0)].join("\n");
102+
const star = indent(" *", indentLv ?? 0);
103+
104+
const body = commentText.split(LB_RE).map((ln) => {
105+
ln = ln.trimEnd();
106+
return ln.length > 0 ? `${star} ${ln}` : star;
107+
});
108+
109+
return ["/**", body.join("\n"), indent(" */", indentLv ?? 0)].join("\n");
104110
}
105111

106112
/** handle any valid $ref */

packages/openapi-typescript/test/utils.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ describe("utils", () => {
116116
describe("comment", () => {
117117
it("basic", () => {
118118
expect(comment("A comment")).toStrictEqual("/** A comment */");
119-
expect(comment("A multi-line \n comment")).toStrictEqual(
119+
expect(comment("A multi-line \n\n comment")).toStrictEqual(
120120
// prettier-ignore
121121
"/**\n" +
122-
" * A multi-line \n" +
122+
" * A multi-line\n" +
123+
" *\n" +
123124
" * comment\n"+
124125
" */"
125126
);
@@ -154,13 +155,14 @@ describe("utils", () => {
154155
expect(
155156
getSchemaObjectComment({
156157
title: "A title",
157-
description: "A multi-line \n description",
158+
description: "A multi-line \n\n description",
158159
})
159160
).toStrictEqual(
160161
// prettier-ignore
161162
"/**\n" +
162163
" * A title\n" +
163-
" * @description A multi-line \n" +
164+
" * @description A multi-line\n" +
165+
" *\n" +
164166
" * description\n" +
165167
" */"
166168
);

0 commit comments

Comments
 (0)