Skip to content

Commit e19d8fa

Browse files
committed
We now generate a default summary for constructors with missing documentation, rather than flagging them as "undocumented"
1 parent 9111fb0 commit e19d8fa

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎libraries/api-extractor/src/definitions/ApiMethod.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ApiItemKind, IApiItemOptions } from './ApiItem';
33
import ApiMember from './ApiMember';
44
import ApiParameter from './ApiParameter';
55
import TypeScriptHelpers from '../TypeScriptHelpers';
6+
import { ITextElement } from '../IDocElement';
67

78
/**
89
* This class is part of the ApiItem abstract syntax tree. It represents functions that are members of
@@ -12,8 +13,9 @@ import TypeScriptHelpers from '../TypeScriptHelpers';
1213
* @see ApiFunction for functions that are defined inside of a package
1314
*/
1415
export default class ApiMethod extends ApiMember {
15-
public returnType: string;
16-
public params: ApiParameter[];
16+
public readonly returnType: string;
17+
public readonly params: ApiParameter[];
18+
private readonly _isConstructor: boolean;
1719

1820
constructor(options: IApiItemOptions) {
1921
super(options);
@@ -38,8 +40,11 @@ export default class ApiMethod extends ApiMember {
3840
}
3941
}
4042

43+
// tslint:disable-next-line:no-bitwise
44+
this._isConstructor = (options.declarationSymbol.flags & ts.SymbolFlags.Constructor) !== 0;
45+
4146
// Return type
42-
if (!(this.name === '__constructor')) {
47+
if (!this.isConstructor) {
4348
if (methodDeclaration.type) {
4449
this.returnType = methodDeclaration.type.getText();
4550
} else {
@@ -48,4 +53,28 @@ export default class ApiMethod extends ApiMember {
4853
}
4954
}
5055
}
56+
57+
/**
58+
* Returns true if this member represents a class constructor.
59+
*/
60+
public get isConstructor(): boolean {
61+
return this._isConstructor;
62+
}
63+
64+
protected onCompleteInitialization(): void {
65+
super.onCompleteInitialization();
66+
67+
// If this is a class constructor, and if the documentation summary was omitted, then
68+
// we fill in a default summary versus flagging it as "undocumented".
69+
// Generally class constructors have uninteresting documentation.
70+
if (this.isConstructor) {
71+
if (this.documentation.summary.length === 0) {
72+
this.documentation.summary.push({
73+
kind: 'textDocElement',
74+
value: 'Constructs a new instance of the class'
75+
} as ITextElement);
76+
}
77+
this.needsDocumentation = false;
78+
}
79+
}
5180
}

‎libraries/api-extractor/testInputs/example2/example2-output.api.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ enum inheritDisplayModeNoErrorDeprecated {
2424
// WARNING: methodWithIncompleteReturnType has incomplete type information
2525
// @public
2626
class MyDocumentedClass {
27-
// (undocumented)
2827
constructor();
2928
// WARNING: The name "$unallowedName" contains unsupported characters; API names should use only letters, numbers, and underscores
3029
public $unallowedName: string;

‎libraries/api-extractor/testInputs/example2/example2-output.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@
155155
"signature": "constructor();",
156156
"parameters": {},
157157
"deprecatedMessage": [],
158-
"summary": [],
158+
"summary": [
159+
{
160+
"kind": "textDocElement",
161+
"value": "Constructs a new instance of the class"
162+
}
163+
],
159164
"remarks": []
160165
},
161166
"betaTagMissingParam": {

0 commit comments

Comments
 (0)