Skip to content

Commit 7389ba3

Browse files
authored
chore(*): Improve @default, @deprecated JSDoc (#5630)
1 parent d676836 commit 7389ba3

40 files changed

Lines changed: 181 additions & 85 deletions

.changeset/fast-lands-smash.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@clerk/react-router': patch
3+
'@clerk/clerk-js': patch
4+
'@clerk/backend': patch
5+
'@clerk/shared': patch
6+
'@clerk/astro': patch
7+
'@clerk/clerk-react': patch
8+
'@clerk/remix': patch
9+
'@clerk/types': patch
10+
'@clerk/clerk-expo': patch
11+
'@clerk/vue': patch
12+
---
13+
14+
Improve JSDoc comments

.typedoc/custom-plugin.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const LINK_REPLACEMENTS = [
2929
['sign-up-resource', '/docs/references/javascript/sign-up'],
3030
['user-resource', '/docs/references/javascript/user'],
3131
['session-status-claim', '/docs/references/javascript/types/session-status'],
32-
['user-organization-invitation-resource', '/docs/references/javascript/types/organization-invitation'],
32+
['user-organization-invitation-resource', '/docs/references/javascript/types/user-organization-invitation'],
3333
['organization-membership-resource', '/docs/references/javascript/types/organization-membership'],
3434
['organization-suggestion-resource', '/docs/references/javascript/types/organization-suggestion'],
3535
['organization-resource', '/docs/references/javascript/organization'],
@@ -62,7 +62,7 @@ function getRelativeLinkReplacements() {
6262
});
6363
}
6464

65-
function getUnlinkedTypesReplacements() {
65+
function getCatchAllReplacements() {
6666
return [
6767
{
6868
pattern: /\(setActiveParams\)/g,
@@ -80,6 +80,20 @@ function getUnlinkedTypesReplacements() {
8080
pattern: /\(CreateOrganizationParams\)/g,
8181
replace: '([CreateOrganizationParams](#create-organization-params))',
8282
},
83+
{
84+
/**
85+
* By default, `@deprecated` is output with `**Deprecated**`. We want to add a full stop to it.
86+
*/
87+
pattern: /\*\*Deprecated\*\*/g,
88+
replace: '**Deprecated.**',
89+
},
90+
{
91+
/**
92+
* By default, `@default` is output with "**Default** `value`". We want to capture the value and place it inside "Defaults to `value`."
93+
*/
94+
pattern: /\*\*Default\*\* `([^`]+)`/g,
95+
replace: 'Defaults to `$1`.',
96+
},
8397
];
8498
}
8599

@@ -97,9 +111,9 @@ export function load(app) {
97111
}
98112
}
99113

100-
const unlinkedTypesReplacements = getUnlinkedTypesReplacements();
114+
const catchAllReplacements = getCatchAllReplacements();
101115

102-
for (const { pattern, replace } of unlinkedTypesReplacements) {
116+
for (const { pattern, replace } of catchAllReplacements) {
103117
if (output.contents) {
104118
output.contents = output.contents.replace(pattern, replace);
105119
}

.typedoc/custom-theme.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,63 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
6363

6464
return output;
6565
},
66+
/**
67+
* This condenses the output if only a "simple" return type + `@returns` is given.
68+
* @param {import('typedoc').SignatureReflection} model
69+
* @param {{ headingLevel: number }} options
70+
*/
71+
signatureReturns: (model, options) => {
72+
const defaultOutput = superPartials.signatureReturns(model, options);
73+
const hasReturnsTag = model.comment?.getTag('@returns');
74+
75+
/**
76+
* @type {any}
77+
*/
78+
const type = model.type;
79+
/**
80+
* @type {import('typedoc').DeclarationReflection}
81+
*/
82+
const typeDeclaration = type?.declaration;
83+
84+
/**
85+
* Early return for non "simple" cases
86+
*/
87+
if (!typeDeclaration?.signatures) {
88+
if (model.type && this.helpers.hasUsefulTypeDetails(model.type)) {
89+
return defaultOutput;
90+
}
91+
}
92+
if (!hasReturnsTag) {
93+
return defaultOutput;
94+
}
95+
96+
/**
97+
* Now the default output would be in this format:
98+
*
99+
* `Type`
100+
*
101+
* Contents of `@returns` tag
102+
*
103+
* It should be condensed to:
104+
*
105+
* `Type` — Contents of `@returns` tag
106+
*/
107+
108+
const o = defaultOutput.split('\n\n');
109+
110+
/**
111+
* At this stage the output can be:
112+
* - ['## Returns', '`Type`', 'Contents of `@returns` tag']
113+
* - ['## Returns', '`Type`', '']
114+
*
115+
* We want to condense the first case by combining the second and third item with ` — `
116+
*/
117+
if (o.length === 3 && o[2] !== '') {
118+
return `${o[0]}\n\n${o[1]}${o[2]}`;
119+
}
120+
121+
return defaultOutput;
122+
},
66123
/**
67124
* This hides the "Type parameters" section from the output
68125
* @param {import('typedoc').DeclarationReflection} model

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"turbo-ignore": "^2.4.4",
133133
"typedoc": "0.28.2",
134134
"typedoc-plugin-markdown": "4.6.2",
135-
"typedoc-plugin-replace-text": "4.1.0",
135+
"typedoc-plugin-replace-text": "4.2.0",
136136
"typescript": "catalog:repo",
137137
"typescript-eslint": "8.28.0",
138138
"uuid": "8.3.2",

packages/astro/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export type { AstroClerkUpdateOptions, AstroClerkIntegrationParams, AstroClerkCr
7373

7474
export type ButtonProps<Tag> = {
7575
/**
76-
* @deprecated The 'as' prop is deprecated and will be removed in a future version.
77-
* Use the default slot with the 'asChild' prop instead.
76+
* @deprecated The `'as'` prop will be removed in a future version.
77+
* Use the default slot with the `'asChild'` prop instead.
7878
* @example
7979
* <SignInButton asChild>
8080
* <button>Sign in</button>

packages/backend/src/api/endpoints/UserApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class UserAPI extends AbstractAPI {
234234
});
235235
}
236236

237-
/** @deprecated Please use getUserOauthAccessToken without the `oauth_` provider prefix . */
237+
/** @deprecated Use `getUserOauthAccessToken` without the `oauth_` provider prefix . */
238238
public async getUserOauthAccessToken(
239239
userId: string,
240240
provider: `oauth_${OAuthProvider}`,

packages/backend/src/api/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type BuildRequestOptions = {
5454
userAgent?: string;
5555
/**
5656
* Allow requests without specifying a secret key. In most cases this should be set to `false`.
57-
* Defaults to `true`.
57+
* @default true
5858
*/
5959
requireSecretKey?: boolean;
6060
};

packages/backend/src/jwt/verifyJwt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export type VerifyJwtOptions = {
108108
*/
109109
authorizedParties?: string[];
110110
/**
111-
* Specifies the allowed time difference (in milliseconds) between the Clerk server (which generates the token) and the clock of the user's application server when validating a token. Defaults to 5000 ms (5 seconds).
111+
* Specifies the allowed time difference (in milliseconds) between the Clerk server (which generates the token) and the clock of the user's application server when validating a token.
112+
* @default 5000
112113
*/
113114
clockSkewInMs?: number;
114115
/**

packages/backend/src/tokens/keys.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export type LoadClerkJWKFromRemoteOptions = {
9090
*/
9191
kid: string;
9292
/**
93-
* @deprecated This cache TTL is deprecated and will be removed in the next major version. Specifying a cache TTL is now a no-op.
93+
* @deprecated This cache TTL will be removed in the next major version. Specifying a cache TTL is a no-op.
9494
*/
9595
jwksCacheTtlInMs?: number;
9696
/**
@@ -102,11 +102,13 @@ export type LoadClerkJWKFromRemoteOptions = {
102102
*/
103103
secretKey?: string;
104104
/**
105-
* The [Clerk Backend API](https://clerk.com/docs/reference/backend-api) endpoint. Defaults to `'https://api.clerk.com'`.
105+
* The [Clerk Backend API](https://clerk.com/docs/reference/backend-api) endpoint.
106+
* @default 'https://api.clerk.com'
106107
*/
107108
apiUrl?: string;
108109
/**
109-
* The version passed to the Clerk API. Defaults to `'v1'`.
110+
* The version passed to the Clerk API.
111+
* @default 'v1'
110112
*/
111113
apiVersion?: string;
112114
};

packages/backend/src/tokens/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export type AuthenticateRequestOptions = {
1111
*/
1212
domain?: string;
1313
/**
14-
* Whether the instance is a satellite domain in a multi-domain setup. Defaults to `false`.
14+
* Whether the instance is a satellite domain in a multi-domain setup.
15+
* @default false
1516
*/
1617
isSatellite?: boolean;
1718
/**
@@ -27,11 +28,13 @@ export type AuthenticateRequestOptions = {
2728
*/
2829
signUpUrl?: string;
2930
/**
30-
* Full URL or path to navigate to after successful sign in. Defaults to `/`.
31+
* Full URL or path to navigate to after successful sign in.
32+
* @default '/'
3133
*/
3234
afterSignInUrl?: string;
3335
/**
34-
* Full URL or path to navigate to after successful sign up. Defaults to `/`.
36+
* Full URL or path to navigate to after successful sign up.
37+
* @default '/'
3538
*/
3639
afterSignUpUrl?: string;
3740
/**

0 commit comments

Comments
 (0)