Skip to content

Commit 8388f9b

Browse files
committed
Added unit tests for the new warnings
1 parent f3ab510 commit 8388f9b

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ abstract class ApiItem {
403403
}
404404
} else {
405405
if (this.documentation.releaseTag === ReleaseTag.Internal) {
406-
this.reportWarning('Because this definition is marked as @internal, an underscore prefix ("_") should'
407-
+ ' be added to its name');
406+
this.reportWarning('Because this definition is explicitly marked as @internal, an underscore prefix ("_")'
407+
+ ' should be added to its name');
408408
}
409409
}
410410
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ___proto__ {
66
// WARNING: propertyWithNoType has incomplete type information
77
// @internal
88
class _InternalClass {
9+
public _internalMethodWithRedundantUnderscore(): void;
910
// (undocumented)
1011
public test(): void;
1112
}
@@ -42,10 +43,16 @@ class AlphaTaggedClass {
4243

4344
// @beta
4445
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;
4549
// @internal
4650
public _internalMethod(): void;
4751
// @alpha
4852
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;
4956
public plainMethod(): void;
5057
}
5158

‎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
/**

0 commit comments

Comments
 (0)