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 1 commit
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
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}`);
eladb marked this conversation as resolved.
Show resolved Hide resolved
}
}

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.