Skip to content

Commit

Permalink
fix(go): invalid output for multi-line @return and @deprecated comments
Browse files Browse the repository at this point in the history
Split multi-line comments and prefix with `//` so they are rendered correctly.

Fixes #2457
  • Loading branch information
Elad Ben-Israel committed Jan 21, 2021
1 parent 92e98b1 commit 626ca45
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 47 deletions.
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.
*
* @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
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}`);
}
}

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.

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

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

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

0 comments on commit 626ca45

Please sign in to comment.