Skip to content

Commit 78db83f

Browse files
authored
Standardization of our documentation comments (#12912)
# Status quo Some of our documentation comments are [TypeDoc](http://typedoc.org/guides/doccomments/) and some of them are JSDoc with type description in the comments even though it is for typed TS code. # Standardization I decided the best way to go about this is to migrate to [TSDoc](https://github.com/Microsoft/tsdoc) and enforcing it using the [tsdoc eslint plugin](https://www.npmjs.com/package/eslint-plugin-tsdoc). Pros: - TSDoc is a proposal to standardize the doc comments used in TypeScript code, so that different tools can extract content without getting confused by each other’s markup. - It is being developed at Microsoft, with the TypeScript team. - It has an ESLint plugin that enforces it and will error when it sees unsupported tags (e.g. `@memberof`, `@class`, `@constructor`, `@type`, etc). Cons: - It is still in early stages (adoption is ongoing though, e.g. it is being used by the API extractor tool). - TSDoc != TypeDoc (the tool we currently use for generating our documentation). However, TypeDoc plans to officially support TSDoc in v1.1 (see TypeStrong/typedoc#1266). # Notable tag changes - `@ignore` is a JSDoc tag and was used in conjunction with `@internal`. These tags were needed because [TypeDoc does not yet support documenting only definitions exported by the entry point](TypeStrong/typedoc#1184 (comment)) and still documents everything exported from all files. I removed `@ignore` because [`@internal`](https://tsdoc.org/pages/tags/internal) only should suffice - `@ignore` when used alone is replaced with TypeDoc's [`hidden`](http://typedoc.org/guides/doccomments/#hidden-and-ignore). EDIT: I replaced `@ignore` with [`@hidden`](https://github.com/TypeStrong/typedoc/releases/tag/v0.12.0) because the TypeDoc version used for `docs.microsoft.com` is v0.15.0 which does not support `--stripInternal`. After, they upgrade, I will remove all `@hidden` tags. - `@summary` is gone because it is not part of TSDoc or TypeDoc This PR applies the changes to packages that respect our linting rules. Ones that do not yet will be migrated later when we start fixing their linting issues. Here are vanilla examples of TypeDoc 0.18.0 (version used by our EngSys) after the changes here as a sanity check: - random method: ![typedoc](https://user-images.githubusercontent.com/6074665/102302881-f6186380-3f27-11eb-8cc6-93e4c8f7d42d.PNG) - a class constructor that used to have type information in the documentation comments: ![constructor](https://user-images.githubusercontent.com/6074665/102357078-f8a4a880-3f7b-11eb-92d1-c086ecc39c0b.PNG) # `@hidden` works the same way as `@ignore` Here are the list of documented functions generated by `TypeDoc v0.15.0` for the text analytics package and there is no function that was marked `@hidden`, e.g. `combineSuccessfulAndErroneousDocumentsWithStatisticsAndModelVersion` ![image](https://user-images.githubusercontent.com/6074665/102426196-e018aa80-3fdc-11eb-8b69-1ac265391fad.png) # Things to consider - Our documentation must be generated using the TypeDoc flag [`--stripInternal`](http://typedoc.org/guides/options/#stripinternal) - Should we add a `docs` npm script to our `package.json`s (similar to [Cosmos's](https://github.com/Azure/azure-sdk-for-js/blob/2424b74f029273677f62433f28dd1390806f682c/sdk/cosmosdb/cosmos/package.json#L60)) so that we can see how our docs are generated as we write our comments? Fixes #3027.
1 parent 67f06a6 commit 78db83f

File tree

177 files changed

+1492
-1490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+1492
-1490
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/tools/eslint-plugin-azure-sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"@typescript-eslint/parser": "^4.9.0",
6363
"eslint": "^7.15.0",
6464
"eslint-plugin-no-only-tests": "^2.4.0",
65-
"eslint-plugin-promise": "^4.2.1"
65+
"eslint-plugin-promise": "^4.2.1",
66+
"eslint-plugin-tsdoc": "^0.2.10"
6667
},
6768
"dependencies": {
6869
"@typescript-eslint/typescript-estree": "^4.9.0",

common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
sourceType: "module",
1212
extraFileExtensions: [".json"]
1313
},
14-
plugins: ["@typescript-eslint", "no-only-tests", "promise"],
14+
plugins: ["@typescript-eslint", "no-only-tests", "promise", "eslint-plugin-tsdoc"],
1515
extends: [
1616
"plugin:@typescript-eslint/recommended",
1717
"eslint:recommended",
@@ -111,6 +111,7 @@ export default {
111111
// https://github.com/Azure/azure-sdk-for-js/issues/7609
112112
"@azure/azure-sdk/ts-pagination-list": "off",
113113
// https://github.com/Azure/azure-sdk-for-js/issues/7610
114-
"@azure/azure-sdk/ts-doc-internal": "off"
114+
"@azure/azure-sdk/ts-doc-internal": "off",
115+
"tsdoc/syntax": "error"
115116
}
116117
};

eng/tools/generate-doc/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const executeTypedoc = async (exclusionList, inclusionList, generateIndexWithTem
147147
"--excludeNotExported",
148148
'--exclude "node_modules/**/*"',
149149
"--ignoreCompilerErrors",
150+
"--stripInternal",
150151
"--mode file",
151152
docOutputFolder,
152153
]);

sdk/anomalydetector/ai-anomaly-detector/src/AnomalyDetectorClient.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class AnomalyDetectorClient {
4444

4545
/**
4646
* @internal
47-
* @ignore
47+
* @hidden
4848
* A reference to the auto-generated AnomalyDetector HTTP client.
4949
*/
5050
private client: GeneratedClient;
@@ -61,9 +61,9 @@ export class AnomalyDetectorClient {
6161
* new AzureKeyCredential("<api key>")
6262
* );
6363
* ```
64-
* @param string endpointUrl Url to an Azure Anomaly Detector service endpoint
65-
* @param {TokenCredential | KeyCredential} credential Used to authenticate requests to the service.
66-
* @param FormRecognizerClientOptions options Used to configure the Form Recognizer client.
64+
* @param endpointUrl - Url to an Azure Anomaly Detector service endpoint
65+
* @param credential - Used to authenticate requests to the service.
66+
* @param options - Used to configure the Form Recognizer client.
6767
*/
6868
constructor(
6969
endpointUrl: string,
@@ -107,9 +107,9 @@ export class AnomalyDetectorClient {
107107
* This operation generates a model using an entire series, each point is detected with the same model.
108108
* With this method, points before and after a certain point are used to determine whether it is an
109109
* anomaly. The entire detection can give user an overall status of the time series.
110-
* @param body Time series points and period if needed. Advanced model parameters can also be set in
110+
* @param body - Time series points and period if needed. Advanced model parameters can also be set in
111111
* the request.
112-
* @param options The options parameters.
112+
* @param options - The options parameters.
113113
*/
114114
public detectEntireSeries(
115115
body: DetectRequest,
@@ -138,9 +138,9 @@ export class AnomalyDetectorClient {
138138
* This operation generates a model using points before the latest one. With this method, only
139139
* historical points are used to determine whether the target point is an anomaly. The latest point
140140
* detecting operation matches the scenario of real-time monitoring of business metrics.
141-
* @param body Time series points and period if needed. Advanced model parameters can also be set in
141+
* @param body - Time series points and period if needed. Advanced model parameters can also be set in
142142
* the request.
143-
* @param options The options parameters.
143+
* @param options - The options parameters.
144144
*/
145145
public detectLastPoint(
146146
body: DetectRequest,
@@ -167,9 +167,9 @@ export class AnomalyDetectorClient {
167167

168168
/**
169169
* Evaluate change point score of every series point
170-
* @param body Time series points and granularity is needed. Advanced model parameters can also be set
170+
* @param body - Time series points and granularity is needed. Advanced model parameters can also be set
171171
* in the request if needed.
172-
* @param options The options parameters.
172+
* @param options - The options parameters.
173173
*/
174174
detectChangePoint(
175175
body: DetectChangePointRequest,

sdk/anomalydetector/ai-anomaly-detector/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
import { createClientLogger } from "@azure/logger";
55

66
/**
7-
* The @azure/logger configuration for this package.
7+
* The \@azure/logger configuration for this package.
88
*/
99
export const logger = createClientLogger("ai-anomaly-detector");

sdk/anomalydetector/ai-anomaly-detector/src/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface DetectRequest {
5050
*/
5151
granularity: TimeGranularity;
5252
/**
53-
* Custom Interval is used to set non-standard time interval, for example, if the series is 5 minutes, request can be set as {"granularity":"minutely", "customInterval":5}.
53+
* Custom Interval is used to set non-standard time interval, for example, if the series is 5 minutes, request can be set as `{"granularity":"minutely", "customInterval":5}`.
5454
*/
5555
customInterval?: number;
5656
/**
@@ -77,7 +77,7 @@ export interface DetectChangePointRequest {
7777
*/
7878
granularity: TimeGranularity;
7979
/**
80-
* Custom Interval is used to set non-standard time interval, for example, if the series is 5 minutes, request can be set as {"granularity":"minutely", "customInterval":5}.
80+
* Custom Interval is used to set non-standard time interval, for example, if the series is 5 minutes, request can be set as `{"granularity":"minutely", "customInterval":5}`.
8181
*/
8282
customInterval?: number;
8383
/**

sdk/anomalydetector/ai-anomaly-detector/src/tracing.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { OperationOptions } from "@azure/core-http";
77

88
/**
99
* Creates a span using the global tracer.
10-
* @ignore
11-
* @param name The name of the operation being performed.
12-
* @param tracingOptions The options for the underlying http request.
10+
* @internal
11+
* @hidden
12+
* @param name - The name of the operation being performed.
13+
* @param tracingOptions - The options for the underlying http request.
1314
*/
1415
export function createSpan<T extends OperationOptions>(
1516
operationName: string,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3+
"extends": ["../../../tsdoc.json"]
4+
}

sdk/core/abort-controller/src/AbortController.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal";
99
* error matches `"AbortError"`.
1010
*
1111
* @example
12+
* ```ts
1213
* const controller = new AbortController();
1314
* controller.abort();
1415
* try {
@@ -18,6 +19,7 @@ import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal";
1819
* // handle abort error here.
1920
* }
2021
* }
22+
* ```
2123
*/
2224
export class AbortError extends Error {
2325
constructor(message?: string) {
@@ -31,44 +33,44 @@ export class AbortError extends Error {
3133
* that an asynchronous operation should be aborted.
3234
*
3335
* @example
34-
* // Abort an operation when another event fires
36+
* Abort an operation when another event fires
37+
* ```ts
3538
* const controller = new AbortController();
3639
* const signal = controller.signal;
3740
* doAsyncWork(signal);
3841
* button.addEventListener('click', () => controller.abort());
42+
* ```
3943
*
4044
* @example
41-
* // Share aborter cross multiple operations in 30s
45+
* Share aborter cross multiple operations in 30s
46+
* ```ts
4247
* // Upload the same data to 2 different data centers at the same time,
4348
* // abort another when any of them is finished
4449
* const controller = AbortController.withTimeout(30 * 1000);
4550
* doAsyncWork(controller.signal).then(controller.abort);
4651
* doAsyncWork(controller.signal).then(controller.abort);
52+
*```
4753
*
4854
* @example
49-
* // Cascaded aborting
55+
* Cascaded aborting
56+
* ```ts
5057
* // All operations can't take more than 30 seconds
5158
* const aborter = Aborter.timeout(30 * 1000);
5259
*
5360
* // Following 2 operations can't take more than 25 seconds
5461
* await doAsyncWork(aborter.withTimeout(25 * 1000));
5562
* await doAsyncWork(aborter.withTimeout(25 * 1000));
56-
*
57-
* @export
58-
* @class AbortController
59-
* @implements {AbortSignalLike}
63+
* ```
6064
*/
6165
export class AbortController {
6266
private _signal: AbortSignal;
6367

6468
/**
65-
* @param {AbortSignalLike[]} [parentSignals] The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
66-
* @constructor
69+
* @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
6770
*/
6871
constructor(parentSignals?: AbortSignalLike[]);
6972
/**
70-
* @param {...AbortSignalLike} parentSignals The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
71-
* @constructor
73+
* @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
7274
*/
7375
constructor(...parentSignals: AbortSignalLike[]);
7476
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -102,8 +104,6 @@ export class AbortController {
102104
* when the abort method is called on this controller.
103105
*
104106
* @readonly
105-
* @type {AbortSignal}
106-
* @memberof AbortController
107107
*/
108108
public get signal(): AbortSignal {
109109
return this._signal;
@@ -112,19 +112,14 @@ export class AbortController {
112112
/**
113113
* Signal that any operations passed this controller's associated abort signal
114114
* to cancel any remaining work and throw an `AbortError`.
115-
*
116-
* @memberof AbortController
117115
*/
118116
abort(): void {
119117
abortSignal(this._signal);
120118
}
121119

122120
/**
123121
* Creates a new AbortSignal instance that will abort after the provided ms.
124-
*
125-
* @static
126-
* @params {number} ms Elapsed time in milliseconds to trigger an abort.
127-
* @returns {AbortSignal}
122+
* @param ms - Elapsed time in milliseconds to trigger an abort.
128123
*/
129124
public static timeout(ms: number): AbortSignal {
130125
const signal = new AbortSignal();

sdk/core/abort-controller/src/AbortSignal.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ export interface AbortSignalLike {
4444
* cannot or will not ever be cancelled.
4545
*
4646
* @example
47-
* // Abort without timeout
47+
* Abort without timeout
48+
* ```ts
4849
* await doAsyncWork(AbortSignal.none);
49-
*
50-
* @export
51-
* @class AbortSignal
52-
* @implements {AbortSignalLike}
50+
* ```
5351
*/
5452
export class AbortSignal implements AbortSignalLike {
5553
constructor() {
@@ -61,8 +59,6 @@ export class AbortSignal implements AbortSignalLike {
6159
* Status of whether aborted or not.
6260
*
6361
* @readonly
64-
* @type {boolean}
65-
* @memberof AbortSignal
6662
*/
6763
public get aborted(): boolean {
6864
if (!abortedMap.has(this)) {
@@ -76,27 +72,21 @@ export class AbortSignal implements AbortSignalLike {
7672
* Creates a new AbortSignal instance that will never be aborted.
7773
*
7874
* @readonly
79-
* @static
80-
* @type {AbortSignal}
81-
* @memberof AbortSignal
8275
*/
8376
public static get none(): AbortSignal {
8477
return new AbortSignal();
8578
}
8679

8780
/**
8881
* onabort event listener.
89-
*
90-
* @memberof AbortSignal
9182
*/
9283
public onabort: ((ev?: Event) => any) | null = null;
9384

9485
/**
9586
* Added new "abort" event listener, only support "abort" event.
9687
*
97-
* @param {"abort"} _type Only support "abort" event
98-
* @param {(this: AbortSignalLike, ev: any) => any} listener
99-
* @memberof AbortSignal
88+
* @param _type - Only support "abort" event
89+
* @param listener - The listener to be added
10090
*/
10191
public addEventListener(
10292
// tslint:disable-next-line:variable-name
@@ -114,9 +104,8 @@ export class AbortSignal implements AbortSignalLike {
114104
/**
115105
* Remove "abort" event listener, only support "abort" event.
116106
*
117-
* @param {"abort"} _type Only support "abort" event
118-
* @param {(this: AbortSignalLike, ev: any) => any} listener
119-
* @memberof AbortSignal
107+
* @param _type - Only support "abort" event
108+
* @param listener - The listener to be removed
120109
*/
121110
public removeEventListener(
122111
// tslint:disable-next-line:variable-name

sdk/core/core-auth/src/azureKeyCredential.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AzureKeyCredential implements KeyCredential {
2929
* Create an instance of an AzureKeyCredential for use
3030
* with a service client.
3131
*
32-
* @param key the initial value of the key to use in authentication
32+
* @param key - The initial value of the key to use in authentication
3333
*/
3434
constructor(key: string) {
3535
if (!key) {
@@ -45,7 +45,7 @@ export class AzureKeyCredential implements KeyCredential {
4545
* Updates will take effect upon the next request after
4646
* updating the key value.
4747
*
48-
* @param newKey the new key value to be used
48+
* @param newKey - The new key value to be used
4949
*/
5050
public update(newKey: string): void {
5151
this._key = newKey;

0 commit comments

Comments
 (0)