Skip to content
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

fix(go): invalid output for multi-line @return and @deprecated comments #2462

Merged
merged 5 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/jsii-calc/lib/documented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export class DocumentedClass {
/**
* Greet the indicated person.
*
* This will print out a friendly greeting intended for
* the indicated person.
* This will print out a friendly greeting intended for the indicated person.
eladb marked this conversation as resolved.
Show resolved Hide resolved
*
* @param greetee The person to be greeted.
* @returns A number that everyone knows very well
* @returns A number that everyone knows very well and represents the answer
* to the ultimate question
*/
public greet(greetee: Greetee = {}): number {
process.stdout.write(`Hello, ${greetee.name ?? 'world'}\n`);
Expand Down Expand Up @@ -48,7 +48,8 @@ export interface Greetee {
/**
* Old class
*
* @deprecated Use the new class
* @deprecated Use the new class or the old class whatever you want because
* whatever you like is always the best
*/
export class Old {
/**
Expand Down
12 changes: 6 additions & 6 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -4163,8 +4163,8 @@
"methods": [
{
"docs": {
"remarks": "This will print out a friendly greeting intended for\nthe indicated person.",
"returns": "A number that everyone knows very well",
"remarks": "This will print out a friendly greeting intended for the indicated person.",
"returns": "A number that everyone knows very well and represents the answer\nto the ultimate question",
"stability": "stable",
"summary": "Greet the indicated person."
},
Expand Down Expand Up @@ -9379,7 +9379,7 @@
"jsii-calc.Old": {
"assembly": "jsii-calc",
"docs": {
"deprecated": "Use the new class",
"deprecated": "Use the new class or the old class whatever you want because\nwhatever you like is always the best",
"stability": "deprecated",
"summary": "Old class."
},
Expand All @@ -9392,7 +9392,7 @@
"kind": "class",
"locationInModule": {
"filename": "lib/documented.ts",
"line": 53
"line": 54
},
"methods": [
{
Expand All @@ -9402,7 +9402,7 @@
},
"locationInModule": {
"filename": "lib/documented.ts",
"line": 57
"line": 58
},
"name": "doAThing"
}
Expand Down Expand Up @@ -14441,5 +14441,5 @@
}
},
"version": "0.0.0",
"fingerprint": "8y6c87ScX7dJInuohtU3oLM8TCUz8yoYZ+j14fnHG9s="
"fingerprint": "4fJXgLfvFXFeZPUflIUswNxZKtt1vgIANXs/lWot+qg="
}
29 changes: 16 additions & 13 deletions packages/jsii-pacmak/lib/targets/go/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@ export class Documentation {
*/
public emit(docs: Docs): void {
if (docs.toString() !== '') {
const lines = docs.toString().split('\n');
for (const line of lines) {
this.code.line(`// ${line}`);
}
this.emitComment(docs.toString());
}

if (docs.returns !== '') {
this.code.line(`//`);
this.code.line(`// Returns: ${docs.returns}`);
this.emitComment();
this.emitComment(`Returns: ${docs.returns}`);
}

if (docs.example !== '') {
this.code.line(`//`);
this.emitComment();
// TODO: Translate code examples to Go with Rosetta (not implemented there yet)
this.code.line('// TODO: EXAMPLE');
this.code.line(`//`);
this.emitComment('TODO: EXAMPLE');
this.emitComment();
}

if (docs.link !== '') {
this.code.line(`// See: ${docs.link}`);
this.code.line(`//`);
this.emitComment(`See: ${docs.link}`);
this.emitComment();
}

this.emitStability(docs);
Expand All @@ -49,13 +46,19 @@ export class Documentation {
const stability = docs.stability;
if (stability && this.shouldMentionStability(docs)) {
if (docs.deprecated) {
this.code.line(`// Deprecated: ${docs.deprecationReason}`);
this.emitComment(`Deprecated: ${docs.deprecationReason}`);
} else {
this.code.line(`// ${this.code.toPascalCase(stability)}.`);
this.emitComment(`${this.code.toPascalCase(stability)}.`);
}
}
}

private emitComment(text = '') {
for (const line of text.split('\n')) {
this.code.line(`// ${line}`.trim());
}
}

private shouldMentionStability(docs: Docs): boolean {
const s = docs.stability;
// Don't render "stable" or "external", those are both stable by implication
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading