Skip to content

Commit 73c78fb

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into pgonzal/ae-pipe-bug
# Conflicts: # libraries/api-extractor/testInputs/example3/example3-output.json
2 parents ae1b617 + edbb57a commit 73c78fb

13 files changed

Lines changed: 110 additions & 43 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "API Extractor now issues warnings for @internal definitions that are not prefixed with an underscore",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,13 @@ export default class ApiDocumentation {
404404

405405
// If the apiDefinitionRef can not be found the resolvedApiItem will be
406406
// undefined and an error will have been reported via this.reportError
407-
if (resolvedApiItem && resolvedApiItem.releaseTag === ReleaseTag.Internal
408-
|| resolvedApiItem.releaseTag === ReleaseTag.Alpha) {
409-
this.reportError('The {@link} tag references an @internal or @alpha API item, '
410-
+ 'which will not appear in the generated documentation');
407+
if (resolvedApiItem) {
408+
if (resolvedApiItem.releaseTag === ReleaseTag.Internal
409+
|| resolvedApiItem.releaseTag === ReleaseTag.Alpha) {
410+
411+
this.reportError('The {@link} tag references an @internal or @alpha API item, '
412+
+ 'which will not appear in the generated documentation');
413+
}
411414
}
412415
}
413416
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,19 @@ abstract class ApiItem {
394394
this.reportError('The @inheritdoc target has been marked as @deprecated. ' +
395395
'Add a @deprecated message here, or else remove the @inheritdoc relationship.');
396396
}
397+
398+
if (this.name.substr(0, 1) === '_') {
399+
if (this.documentation.releaseTag !== ReleaseTag.Internal
400+
&& this.documentation.releaseTag !== ReleaseTag.None) {
401+
this.reportWarning('The underscore prefix ("_") should only be used with definitions'
402+
+ ' that are explicitly marked as @internal');
403+
}
404+
} else {
405+
if (this.documentation.releaseTag === ReleaseTag.Internal) {
406+
this.reportWarning('Because this definition is explicitly marked as @internal, an underscore prefix ("_")'
407+
+ ' should be added to its name');
408+
}
409+
}
397410
}
398411

399412
/**

‎libraries/api-extractor/src/test/DocItemLoader.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function testErrorHandler(message: string, fileName: string, lineNumber: number)
1919
capturedErrors.push({ message, fileName, lineNumber });
2020
}
2121

22+
function assertCapturedErrors(expectedMessages: string[]): void {
23+
assert.deepEqual(capturedErrors.map(x => x.message), expectedMessages,
24+
'The captured errors did not match the expected output.');
25+
}
26+
2227
// These warnings would normally be printed at the bottom
2328
// of the source package's '*.api.ts' file.
2429
const warnings: string[] = [];
@@ -61,10 +66,11 @@ describe('DocItemLoader tests', function (): void {
6166
const apiFileGenerator: ApiFileGenerator = new ApiFileGenerator();
6267
apiFileGenerator.writeApiFile(outputApiFile, extractor);
6368

64-
assert.equal(capturedErrors.length, 2);
65-
assert.equal(capturedErrors[0].message, 'circular reference');
66-
assert.equal(capturedErrors[1].message, 'The {@link} tag references an @internal or @alpha API item,'
67-
+ ' which will not appear in the generated documentation');
69+
assertCapturedErrors([
70+
'circular reference',
71+
'The {@link} tag references an @internal or @alpha API item,'
72+
+ ' which will not appear in the generated documentation'
73+
]);
6874
TestFileComparer.assertFileMatchesExpected(outputJsonFile, expectedJsonFile);
6975
TestFileComparer.assertFileMatchesExpected(outputApiFile, expectedApiFile);
7076
});

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ class ___proto__ {
33
public propertyIsEnumerable: string;
44
}
55

6+
// WARNING: propertyWithNoType has incomplete type information
7+
// @internal
8+
class _InternalClass {
9+
public _internalMethodWithRedundantUnderscore(): void;
10+
// (undocumented)
11+
public test(): void;
12+
}
13+
14+
// @internal (preapproved)
15+
class _PreapprovedInternalClass {
16+
}
17+
18+
619
// (undocumented)
720
class A extends __proto__, implements hasOwnProperty {
821
// (undocumented)
@@ -13,10 +26,10 @@ class A extends __proto__, implements hasOwnProperty {
1326

1427
// @public
1528
class AliasClass4 {
29+
// @internal
30+
public _aliasFunc(): void;
1631
// (undocumented)
1732
public aliasField: number;
18-
// @internal
19-
public aliasFunc(): void;
2033
// (undocumented)
2134
public readonly shouldBeReadOnly: number;
2235
}
@@ -30,10 +43,16 @@ class AlphaTaggedClass {
3043

3144
// @beta
3245
class BetaTaggedClass {
46+
// WARNING: The underscore prefix ("_") should only be used with definitions that are explicitly marked as @internal
47+
// @alpha
48+
public _alphaMethodWithBadUnderscore(): void;
3349
// @internal
3450
public _internalMethod(): void;
3551
// @alpha
3652
public alphaMethod(): void;
53+
// WARNING: Because this definition is explicitly marked as @internal, an underscore prefix ("_") should be added to its name
54+
// @internal
55+
public internalMethodMissingUnderscore(): void;
3756
public plainMethod(): void;
3857
}
3958

@@ -43,13 +62,6 @@ interface hasOwnProperty {
4362
___lookupSetter__: __proto__;
4463
}
4564

46-
// WARNING: propertyWithNoType has incomplete type information
47-
// @internal
48-
class InternalClass {
49-
// (undocumented)
50-
public test(): void;
51-
}
52-
5365
// (undocumented)
5466
class MyClass {
5567
// (undocumented)
@@ -60,11 +72,6 @@ class MyClass {
6072
public test(): void;
6173
}
6274

63-
// @internal (preapproved)
64-
class PreapprovedInternalClass {
65-
}
66-
67-
6875
// (undocumented)
6976
export function publicFunction(param: number): string;
7077

‎libraries/api-extractor/testInputs/example1/folder/AliasClass.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ export class AliasClass {
1010
* AEDoc for aliasFunc()
1111
* @internal
1212
*/
13-
public aliasFunc(): void {
14-
console.log('this is a public API');
13+
public _aliasFunc(): void {
14+
console.log('this is an internal API');
1515
}
16-
public aliasField: number;
17-
1816

17+
public aliasField: number;
1918

2019
public get shouldBeReadOnly(): number {
2120
return this.readOnlyNumber;

‎libraries/api-extractor/testInputs/example1/folder/MyClass.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ export class InternalClass {
4444
public test(): void {
4545
console.log('this is a public API');
4646
}
47+
48+
/**
49+
* This *implicitly* internal method should NOT have an underscore.
50+
* API Extractor currently does NOT issue a warning for this case.
51+
*/
52+
public _internalMethodWithRedundantUnderscore(): void {
53+
}
4754
}
4855

4956
/**

‎libraries/api-extractor/testInputs/example1/folder/ReleaseTagTests.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ export class BetaTaggedClass {
4242
*/
4343
public alphaMethod(): void {
4444
}
45+
46+
/**
47+
* This internal method should have an underscore.
48+
* @internal
49+
*/
50+
public internalMethodMissingUnderscore(): void {
51+
}
52+
53+
/**
54+
* This alpha method should have an underscore.
55+
* @alpha
56+
*/
57+
public _alphaMethodWithBadUnderscore(): void {
58+
}
4559
}
4660

4761
/**

‎libraries/api-extractor/testInputs/example1/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import OtherName from './folder/AliasClass2';
22

3-
export { default as MyClass, InternalClass, PreapprovedInternalClass, __proto__, hasOwnProperty, A } from './folder/MyClass';
3+
export {
4+
default as MyClass, InternalClass as _InternalClass,
5+
PreapprovedInternalClass as _PreapprovedInternalClass,
6+
__proto__,
7+
hasOwnProperty,
8+
A
9+
} from './folder/MyClass';
10+
411
export { AliasClass3 as AliasClass4 } from './folder/AliasClass3';
512

613
function privateFunction(): number {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// @internal
2+
enum _internalEnum {
3+
}
4+
15
enum inheritEnumValues {
26
index_one = 1,
37
index_zero = 0
@@ -17,10 +21,6 @@ enum inheritLocalOptionOne {
1721
// WARNING: Unable to find referenced member "MyClass.methodWithTwoParams"
1822
export function inheritLocalOptionTwoFunction(): void;
1923

20-
// @internal
21-
enum internalEnum {
22-
}
23-
2424
interface IStructuredTypeInherit {
2525
thisIsTypeLiteral: [{name: string, age: number}];
2626
}

0 commit comments

Comments
 (0)