-
-
Notifications
You must be signed in to change notification settings - Fork 529
Do not append trailing spaces to JSDoc tags #1231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-typescript": patch | ||
--- | ||
|
||
Do not append trailing spaces to JSDoc tags |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,13 @@ export function getSchemaObjectComment(v: CommentObject, indentLv?: number): str | |
const output: string[] = []; | ||
|
||
// * Not JSDOC tags: [title, format] | ||
if (v.title) output.push(`${v.title} `); | ||
if (v.summary) output.push(`${v.summary} `); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think some of these string escapes mostly came from fields that could contain non-strings, but I think that was really only |
||
if (v.format) output.push(`Format: ${v.format} `); | ||
if (v.title) output.push(v.title); | ||
if (v.summary) output.push(v.summary); | ||
if (v.format) output.push(`Format: ${v.format}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
// * JSDOC tags without value | ||
// 'Deprecated' without value | ||
if (v.deprecated) output.push(`@deprecated `); | ||
if (v.deprecated) output.push("@deprecated"); | ||
|
||
// * JSDOC tags with value | ||
const supportedJsDocTags: (keyof CommentObject)[] = ["description", "default", "example"]; | ||
|
@@ -74,11 +74,11 @@ export function getSchemaObjectComment(v: CommentObject, indentLv?: number): str | |
continue; | ||
} | ||
const serialized = typeof v[field] === "object" ? JSON.stringify(v[field], null, 2) : v[field]; | ||
output.push(`@${field} ${serialized} `); | ||
output.push(`@${field} ${serialized}`); | ||
} | ||
|
||
// * JSDOC 'Constant' without value | ||
if ("const" in v) output.push(`@constant `); | ||
if ("const" in v) output.push("@constant"); | ||
|
||
// * JSDOC 'Enum' with type | ||
if (v.enum) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { bench } from "vitest"; | ||
import { escObjKey, parseRef, tsIntersectionOf, tsUnionOf } from "../src/utils.js"; | ||
import { comment, escObjKey, getSchemaObjectComment, parseRef, tsIntersectionOf, tsUnionOf } from "../src/utils.js"; | ||
|
||
describe("utils", () => { | ||
describe("tsUnionOf", () => { | ||
|
@@ -112,4 +112,58 @@ describe("utils", () => { | |
expect(escObjKey("_ref_")).toStrictEqual("_ref_"); | ||
}); | ||
}); | ||
|
||
describe("comment", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great tests 👏 |
||
it("basic", () => { | ||
expect(comment("A comment")).toStrictEqual("/** A comment */"); | ||
expect(comment("A multi-line \n comment")).toStrictEqual( | ||
// prettier-ignore | ||
"/**\n" + | ||
" * A multi-line \n" + | ||
" * comment\n"+ | ||
" */" | ||
); | ||
}); | ||
}); | ||
|
||
describe("getSchemaObjectComment", () => { | ||
it("object with 1 property", () => { | ||
expect( | ||
getSchemaObjectComment({ | ||
title: "A title", | ||
}) | ||
).toStrictEqual("/** A title */"); | ||
}); | ||
|
||
it("object with 2 properties", () => { | ||
expect( | ||
getSchemaObjectComment({ | ||
title: "A title", | ||
description: "A description", | ||
}) | ||
).toStrictEqual( | ||
// prettier-ignore | ||
"/**\n" + | ||
" * A title\n" + | ||
" * @description A description\n"+ | ||
" */" | ||
); | ||
}); | ||
|
||
it("object with a multi-line property", () => { | ||
expect( | ||
getSchemaObjectComment({ | ||
title: "A title", | ||
description: "A multi-line \n description", | ||
}) | ||
).toStrictEqual( | ||
// prettier-ignore | ||
"/**\n" + | ||
" * A title\n" + | ||
" * @description A multi-line \n" + | ||
" * description\n" + | ||
" */" | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually want to keep the escaped double quotes. Though *nix and mac users can run this just fine, IIRC Windows contributors run into problems with single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is such a minor thing, I’ll revert this after merge, but won’t touch anything else. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that I always work on a UNIX OS and though the scripts without escaped quotes look nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh no worries at all. I did the same thing until I had Windows users complain 😛 (and I agree with you)