Skip to content

Commit 63aef44

Browse files
committed
ApiItem now reports an error if a top-level definition is missing a release tag
- Implemented ApiDocumentation.failedToParse - Rename onAddToContainer -> notifyAddedToContainer
1 parent 3fbe864 commit 63aef44

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,26 @@ export default class ApiDocumentation {
186186
*/
187187
public extractor: Extractor;
188188

189-
public reportError: (message: string) => void;
189+
/**
190+
* True if any errors were encountered while parsing the AEDoc tokens.
191+
* This is used to suppress other "collateral damage" errors, e.g. if "@public" was
192+
* misspelled then we shouldn't also complain that the "@public" tag is missing.
193+
*/
194+
public failedToParse: boolean;
195+
196+
public readonly reportError: (message: string) => void;
190197

191198
constructor(docComment: string,
192199
referenceResolver: IReferenceResolver,
193200
extractor: Extractor,
194201
errorLogger: (message: string) => void,
195202
warnings: string[]) {
203+
204+
this.reportError = (message: string) => {
205+
errorLogger(message);
206+
this.failedToParse = true;
207+
};
208+
196209
this.originalAedoc = docComment;
197210
this.referenceResolver = referenceResolver;
198211
this.extractor = extractor;
@@ -381,7 +394,7 @@ export default class ApiDocumentation {
381394
}
382395
}
383396

384-
/**
397+
/**
385398
* A processing of linkDocElements that refer to an ApiDefinitionReference. This method
386399
* ensures that the reference is to an API item that is not 'Internal'.
387400
*/

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ abstract class ApiItem {
202202
*/
203203
public jsdocNode: ts.Node;
204204

205+
/**
206+
* The parsed AEDoc comment for this item.
207+
*/
205208
public documentation: ApiDocumentation;
206209

207210
/**
@@ -283,7 +286,10 @@ abstract class ApiItem {
283286
);
284287
}
285288

286-
public onAddToContainer(parentContainer: ApiItemContainer): void {
289+
/**
290+
* Called by ApiItemContainer.addMemberItem(). Other code should NOT call this method.
291+
*/
292+
public notifyAddedToContainer(parentContainer: ApiItemContainer): void {
287293
if (this._parentContainer) {
288294
// This would indicate a program bug
289295
throw new Error('The API item has already been added to another container: ' + this._parentContainer.name);
@@ -366,7 +372,7 @@ abstract class ApiItem {
366372
this.extractor.reportError(message, this._errorNode.getSourceFile(), this._errorNode.getStart());
367373
}
368374

369-
/**
375+
/**
370376
* Adds a warning to the ApiItem.warnings list. These warnings will be emtted in the API file
371377
* produced by ApiFileGenerator.
372378
*/
@@ -425,6 +431,20 @@ abstract class ApiItem {
425431
+ ' should be added to its name');
426432
}
427433
}
434+
435+
// Is it missing a release tag?
436+
if (this.documentation.releaseTag === ReleaseTag.None) {
437+
// Only warn about top-level exports
438+
if (this.parentContainer && this.parentContainer.kind === ApiItemKind.Package) {
439+
// Don't warn about items that failed to parse.
440+
if (!this.documentation.failedToParse) {
441+
// If there is no release tag, and this is a top-level export of the package, then
442+
// report an error
443+
this.reportError(`A release tag (@alpha, @beta, @public, @internal) must be specified`
444+
+ ` for ${this.name}`);
445+
}
446+
}
447+
}
428448
}
429449

430450
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class ApiItemContainer extends ApiItem {
4242
} else {
4343
this.innerItems.push(apiItem);
4444
this._memberItems.set(apiItem.name, apiItem);
45-
apiItem.onAddToContainer(this);
45+
apiItem.notifyAddedToContainer(this);
4646
}
4747
}
4848

0 commit comments

Comments
 (0)