Skip to content

Commit

Permalink
Add a new message "ae-undocumented" to support logging of undocumente…
Browse files Browse the repository at this point in the history
…d API items
  • Loading branch information
octogonz committed Sep 28, 2023
1 parent 328826c commit ee4e53f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
20 changes: 20 additions & 0 deletions apps/api-extractor/src/api/ExtractorMessageId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ export const enum ExtractorMessageId {
*/
ExtraReleaseTag = 'ae-extra-release-tag',

/**
* "Missing documentation for ___."
* @remarks
* The `ae-undocumented` message is only generated if the API report feature is enabled.
*
* Because the API report file already annotates undocumented items with `// (undocumented)`,
* the `ae-undocumented` message is not logged by default. To see it, add a setting such as:
* ```json
* "messages": {
* "extractorMessageReporting": {
* "ae-undocumented": {
* "logLevel": "warning"
* }
* }
* }
* ```
*/
Undocumented = 'ae-undocumented',

/**
* "This symbol has another declaration with a different release tag."
*/
Expand Down Expand Up @@ -106,6 +125,7 @@ export const enum ExtractorMessageId {

export const allExtractorMessageIds: Set<string> = new Set<string>([
'ae-extra-release-tag',
'ae-undocumented',
'ae-different-release-tags',
'ae-incompatible-release-tags',
'ae-missing-release-tag',
Expand Down
2 changes: 1 addition & 1 deletion apps/api-extractor/src/collector/ApiItemMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ApiItemMetadata {
public tsdocComment: tsdoc.DocComment | undefined;

// Assigned by DocCommentEnhancer
public needsDocumentation: boolean = true;
public undocumented: boolean = true;

public docCommentEnhancerVisitorState: VisitorState = VisitorState.Unvisited;

Expand Down
6 changes: 3 additions & 3 deletions apps/api-extractor/src/enhancers/DocCommentEnhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DocCommentEnhancer {
// Constructors always do pretty much the same thing, so it's annoying to require people to write
// descriptions for them. Instead, if the constructor lacks a TSDoc summary, then API Extractor
// will auto-generate one.
metadata.needsDocumentation = false;
metadata.undocumented = false;

// The class that contains this constructor
const classDeclaration: AstDeclaration = astDeclaration.parent!;
Expand Down Expand Up @@ -135,12 +135,12 @@ export class DocCommentEnhancer {

if (metadata.tsdocComment) {
// Require the summary to contain at least 10 non-spacing characters
metadata.needsDocumentation = !tsdoc.PlainTextEmitter.hasAnyTextContent(
metadata.undocumented = !tsdoc.PlainTextEmitter.hasAnyTextContent(
metadata.tsdocComment.summarySection,
10
);
} else {
metadata.needsDocumentation = true;
metadata.undocumented = true;
}
}

Expand Down
9 changes: 8 additions & 1 deletion apps/api-extractor/src/generators/ApiReportGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AstNamespaceImport } from '../analyzer/AstNamespaceImport';
import type { AstEntity } from '../analyzer/AstEntity';
import type { AstModuleExportInfo } from '../analyzer/AstModule';
import { SourceFileLocationFormatter } from '../analyzer/SourceFileLocationFormatter';
import { ExtractorMessageId } from '../api/ExtractorMessageId';

export class ApiReportGenerator {
private static _trimSpacesRegExp: RegExp = / +$/gm;
Expand Down Expand Up @@ -522,8 +523,14 @@ export class ApiReportGenerator {
}
}

if (apiItemMetadata.needsDocumentation) {
if (apiItemMetadata.undocumented) {
footerParts.push('(undocumented)');

collector.messageRouter.addAnalyzerIssue(
ExtractorMessageId.Undocumented,
`Missing documentation for "${astDeclaration.astSymbol.localName}".`,
astDeclaration
);
}

if (footerParts.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions apps/api-extractor/src/schemas/api-extractor-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
"logLevel": "warning",
"addToApiReportFile": true
},
"ae-undocumented": {
"logLevel": "none"
},
"ae-unresolved-inheritdoc-reference": {
"logLevel": "warning",
"addToApiReportFile": true
Expand Down
1 change: 1 addition & 0 deletions common/reviews/api/api-extractor.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const enum ExtractorMessageId {
PreapprovedBadReleaseTag = "ae-preapproved-bad-release-tag",
PreapprovedUnsupportedType = "ae-preapproved-unsupported-type",
SetterWithDocs = "ae-setter-with-docs",
Undocumented = "ae-undocumented",
UnresolvedInheritDocBase = "ae-unresolved-inheritdoc-base",
UnresolvedInheritDocReference = "ae-unresolved-inheritdoc-reference",
UnresolvedLink = "ae-unresolved-link",
Expand Down

0 comments on commit ee4e53f

Please sign in to comment.