Skip to content

Commit f4e8f51

Browse files
committed
Implement "ae-incompatible-release-tags" warning
1 parent f2c9ca3 commit f4e8f51

8 files changed

Lines changed: 68 additions & 26 deletions

File tree

‎apps/api-extractor/src/api/ExtractorMessageId.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const enum ExtractorMessageId {
2222
*/
2323
DifferentReleaseTags = 'ae-different-release-tags',
2424

25+
/**
26+
* The symbol ___ is marked as ___, but its signature references ___ which is marked as ___.
27+
*/
28+
IncompatibleReleaseTags = 'ae-incompatible-release-tags',
29+
2530
/**
2631
* The doc comment should not contain more than one release tag.
2732
*/
@@ -41,6 +46,7 @@ export const enum ExtractorMessageId {
4146
export const allExtractorMessageIds: Set<string> = new Set<string>([
4247
'ae-extra-release-tag',
4348
'ae-different-release-tags',
49+
'ae-incompatible-release-tags',
4450
'ae-missing-release-tag',
4551
'ae-misplaced-package-tag',
4652
'ae-forgotten-export'

‎apps/api-extractor/src/collector/VisibilityChecker.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import * as ts from 'typescript';
44
import { Collector } from './Collector';
55
import { AstSymbol } from '../analyzer/AstSymbol';
66
import { AstDeclaration } from '../analyzer/AstDeclaration';
7-
// import { SymbolMetadata } from './SymbolMetadata';
7+
import { SymbolMetadata } from './SymbolMetadata';
88
import { CollectorEntity } from './CollectorEntity';
99
import { ExtractorMessageId } from '../api/ExtractorMessageId';
10+
import { ReleaseTag } from '@microsoft/api-extractor-model';
1011

1112
export class VisibilityChecker {
1213

@@ -28,6 +29,9 @@ export class VisibilityChecker {
2829
private static _checkReferences(collector: Collector, astDeclaration: AstDeclaration,
2930
alreadyWarnedSymbols: Set<AstSymbol>): void {
3031

32+
const astSymbolMetadata: SymbolMetadata = collector.fetchMetadata(astDeclaration.astSymbol);
33+
const astSymbolReleaseTag: ReleaseTag = astSymbolMetadata.releaseTag;
34+
3135
for (const referencedEntity of astDeclaration.referencedAstEntities) {
3236

3337
if (referencedEntity instanceof AstSymbol) {
@@ -41,8 +45,17 @@ export class VisibilityChecker {
4145
const collectorEntity: CollectorEntity | undefined = collector.tryGetCollectorEntity(rootSymbol);
4246

4347
if (collectorEntity && collectorEntity.exported) {
44-
// const metadata: SymbolMetadata = collector.fetchMetadata(referencedEntity);
45-
return;
48+
const referencedMetadata: SymbolMetadata = collector.fetchMetadata(referencedEntity);
49+
const referencedReleaseTag: ReleaseTag = referencedMetadata.releaseTag;
50+
51+
if (ReleaseTag.compare(astSymbolReleaseTag, referencedReleaseTag) > 0) {
52+
collector.messageRouter.addAnalyzerIssue(ExtractorMessageId.IncompatibleReleaseTags,
53+
`The symbol "${astDeclaration.astSymbol.localName}"`
54+
+ ` is marked as ${ReleaseTag.getTagName(astSymbolReleaseTag)},`
55+
+ ` but its signature references "${referencedEntity.localName}"`
56+
+ ` which is marked as ${ReleaseTag.getTagName(referencedReleaseTag)}`,
57+
astDeclaration);
58+
}
4659
} else {
4760
const entryPointFilename: string = path.basename(collector.workingPackage.entryPointSourceFile.fileName);
4861

‎apps/api-extractor/src/generators/ReviewFileGenerator.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,8 @@ export class ReviewFileGenerator {
245245
const footerParts: string[] = [];
246246

247247
if (!symbolMetadata.releaseTagSameAsParent) {
248-
switch (symbolMetadata.releaseTag) {
249-
case ReleaseTag.Internal:
250-
footerParts.push('@internal');
251-
break;
252-
case ReleaseTag.Alpha:
253-
footerParts.push('@alpha');
254-
break;
255-
case ReleaseTag.Beta:
256-
footerParts.push('@beta');
257-
break;
258-
case ReleaseTag.Public:
259-
footerParts.push('@public');
260-
break;
248+
if (symbolMetadata.releaseTag !== ReleaseTag.None) {
249+
footerParts.push(ReleaseTag.getTagName(symbolMetadata.releaseTag));
261250
}
262251
}
263252

‎apps/api-extractor/src/schemas/api-extractor-defaults.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"ae-forgotten-export": {
5656
"logLevel": "warning",
5757
"addToApiReviewFile": true
58+
},
59+
"ae-incompatible-release-tags": {
60+
"logLevel": "warning",
61+
"addToApiReviewFile": true
5862
}
5963
},
6064
"tsdocMessageReporting": {

‎build-tests/api-extractor-scenarios/etc/test-outputs/inconsistentReleaseTags/api-extractor-scenarios.api.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@
6969
},
7070
{
7171
"kind": "Function",
72-
"canonicalReference": "(publicClassReturnsBeta:0)",
73-
"docComment": "/**\n * @public\n */\n",
72+
"canonicalReference": "(publicFunctionReturnsBeta:0)",
73+
"docComment": "/**\n * It's not okay for a \"public\" function to reference a \"beta\" symbol, because \"beta\" is less public than \"public\".\n *\n * @public\n */\n",
7474
"excerptTokens": [
7575
{
7676
"kind": "Content",
7777
"text": "export declare function "
7878
},
7979
{
8080
"kind": "Reference",
81-
"text": "publicClassReturnsBeta"
81+
"text": "publicFunctionReturnsBeta"
8282
},
8383
{
8484
"kind": "Content",
@@ -100,7 +100,7 @@
100100
"releaseTag": "Public",
101101
"overloadIndex": 0,
102102
"parameters": [],
103-
"name": "publicClassReturnsBeta"
103+
"name": "publicFunctionReturnsBeta"
104104
}
105105
]
106106
}

‎build-tests/api-extractor-scenarios/etc/test-outputs/inconsistentReleaseTags/api-extractor-scenarios.api.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
55
```ts
66

7+
// @alpha
8+
declare function alphaFunctionReturnsBeta(): IBeta;
9+
710
// @beta (undocumented)
811
interface IBeta {
912
// (undocumented)
1013
x: number;
1114
}
1215

13-
// @public (undocumented)
14-
declare function publicClassReturnsBeta(): IBeta;
16+
// Warning: (ae-incompatible-release-tags) The symbol "publicFunctionReturnsBeta" is marked as @public, but its signature references "IBeta" which is marked as @beta
17+
//
18+
// @public
19+
declare function publicFunctionReturnsBeta(): IBeta;
1520

1621

1722
// (No @packageDocumentation comment for this package)
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11

2+
/**
3+
* It's okay for an "alpha" function to reference a "beta" symbol,
4+
* because "beta" is more public than "alpha".
5+
* @alpha
6+
*/
7+
export declare function alphaFunctionReturnsBeta(): IBeta;
8+
29
/** @beta */
310
export declare interface IBeta {
411
x: number;
512
}
613

7-
/** @public */
8-
export declare function publicClassReturnsBeta(): IBeta;
14+
/**
15+
* It's not okay for a "public" function to reference a "beta" symbol,
16+
* because "beta" is less public than "public".
17+
* @public
18+
*/
19+
export declare function publicFunctionReturnsBeta(): IBeta;
920

1021
export { }

‎build-tests/api-extractor-scenarios/src/inconsistentReleaseTags/index.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ export interface IBeta {
66
x: number;
77
}
88

9-
/** @public */
10-
export function publicClassReturnsBeta(): IBeta {
9+
/**
10+
* It's okay for an "alpha" function to reference a "beta" symbol,
11+
* because "beta" is more public than "alpha".
12+
* @alpha
13+
*/
14+
export function alphaFunctionReturnsBeta(): IBeta {
1115
return { x: 123 };
1216
}
17+
18+
/**
19+
* It's not okay for a "public" function to reference a "beta" symbol,
20+
* because "beta" is less public than "public".
21+
* @public
22+
*/
23+
export function publicFunctionReturnsBeta(): IBeta {
24+
return { x: 123 };
25+
}
26+

0 commit comments

Comments
 (0)