-
Notifications
You must be signed in to change notification settings - Fork 402
chore(shared,clerk-react,types): Improve JSDoc comments #5296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
862b7ea
initial
LekoArts c2bc3cc
add changeset
LekoArts a3e75bb
linting
LekoArts 9944da2
improve md output
LekoArts a803cd4
add frontmatter plugin
LekoArts b957e29
fixes
LekoArts b295880
update deps
LekoArts e08ad3c
test refinements
LekoArts ae7e8f4
Merge branch 'main' into typedoc-markdown-refinements
LekoArts fce782f
wip
LekoArts 3209ad7
Merge main
LekoArts 213b00f
wip
LekoArts 9f489a4
adjust signatureReturns
LekoArts 3ab2bd1
wip jsdoc comments
LekoArts 1e02be1
Merge main
LekoArts 439e919
adjust typedoc
LekoArts 4ead247
adjust source code
LekoArts 4247c64
Merge main
LekoArts 133482d
add changeset
LekoArts 161868f
dedupe
LekoArts b17b865
remove obsolete changeset
LekoArts 8f5c1a2
revert obsolete changes
LekoArts 2786ce4
minor fixes
LekoArts 5c43d48
dedupe :scream:
LekoArts 5d2738f
revert autocomplete change
LekoArts ddf0be5
typo
LekoArts 4fb0ac7
Update packages/types/src/clerk.ts
LekoArts 6fb1a87
update comment
LekoArts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@clerk/shared': patch | ||
| '@clerk/clerk-react': patch | ||
| '@clerk/types': patch | ||
| --- | ||
|
|
||
| Improve JSDoc documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,4 +97,5 @@ scripts/.env | |
| !scripts/.env.example | ||
|
|
||
| # typedoc | ||
| .typedoc | ||
| .typedoc/docs | ||
| .typedoc/docs.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // @ts-check | ||
| import { MarkdownRendererEvent } from 'typedoc-plugin-markdown'; | ||
|
|
||
| /** | ||
| * @param {string} str | ||
| */ | ||
| function toKebabCase(str) { | ||
| return str.replace(/((?<=[a-z\d])[A-Z]|(?<=[A-Z\d])[A-Z](?=[a-z]))/g, '-$1').toLowerCase(); | ||
| } | ||
|
|
||
| /** | ||
| * @param {import('typedoc-plugin-markdown').MarkdownApplication} app | ||
| */ | ||
| export function load(app) { | ||
| app.renderer.on(MarkdownRendererEvent.BEGIN, output => { | ||
| // Do not output README.mdx files | ||
| output.urls = output.urls | ||
| ?.filter(e => !e.url.endsWith('README.mdx')) | ||
| .map(e => { | ||
| // Convert URLs (by default camelCase) to kebab-case | ||
| const kebabUrl = toKebabCase(e.url); | ||
|
|
||
| e.url = kebabUrl; | ||
| e.model.url = kebabUrl; | ||
|
|
||
| return e; | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,261 @@ | ||
| // @ts-check | ||
| import { ReflectionKind } from 'typedoc'; | ||
| import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown'; | ||
|
|
||
| /** | ||
| * @param {import('typedoc-plugin-markdown').MarkdownApplication} app | ||
| */ | ||
| export function load(app) { | ||
| app.renderer.defineTheme('clerkTheme', ClerkMarkdownTheme); | ||
| } | ||
|
|
||
| class ClerkMarkdownTheme extends MarkdownTheme { | ||
| /** | ||
| * @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page | ||
| */ | ||
| getRenderContext(page) { | ||
| return new ClerkMarkdownThemeContext(this, page, this.application.options); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Our custom Clerk theme | ||
| * @extends MarkdownThemeContext | ||
| */ | ||
| class ClerkMarkdownThemeContext extends MarkdownThemeContext { | ||
| /** | ||
| * @param {MarkdownTheme} theme | ||
| * @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page | ||
| * @param {MarkdownTheme["application"]["options"]} options | ||
| */ | ||
| constructor(theme, page, options) { | ||
| super(theme, page, options); | ||
|
|
||
| const superPartials = this.partials; | ||
|
|
||
| this.partials = { | ||
| ...superPartials, | ||
| /** | ||
| * Copied from default theme / source code. This hides the return type from the output | ||
| * https://github.com/typedoc2md/typedoc-plugin-markdown/blob/179a54c502b318cd4f3951e5e8b90f7f7a4752d8/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signatureReturns.ts | ||
| * @param {import('typedoc').SignatureReflection} model | ||
| * @param {{ headingLevel: number }} options | ||
| */ | ||
| signatureReturns: (model, options) => { | ||
| const md = []; | ||
|
|
||
| /** | ||
| * @type any | ||
| */ | ||
| const modelType = model.type; | ||
| /** | ||
| * @type {import('typedoc').DeclarationReflection} | ||
| */ | ||
| const typeDeclaration = modelType?.declaration; | ||
|
|
||
| md.push(heading(options.headingLevel, this.i18n.theme_returns())); | ||
|
|
||
| if (model.comment?.blockTags.length) { | ||
| const tags = model.comment.blockTags | ||
| .filter(tag => tag.tag === '@returns') | ||
| .map(tag => this.helpers.getCommentParts(tag.content)); | ||
| md.push(tags.join('\n\n')); | ||
| } | ||
|
|
||
| if (typeDeclaration?.signatures) { | ||
| typeDeclaration.signatures.forEach(signature => { | ||
| md.push( | ||
| this.partials.signature(signature, { | ||
| headingLevel: options.headingLevel + 1, | ||
| nested: true, | ||
| }), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| if (typeDeclaration?.children) { | ||
| md.push( | ||
| this.partials.typeDeclaration(typeDeclaration, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| return md.join('\n\n'); | ||
| }, | ||
| /** | ||
| * Copied from default theme / source code. This hides the "Type parameters" section and the signature title from the output | ||
| * https://github.com/typedoc2md/typedoc-plugin-markdown/blob/179a54c502b318cd4f3951e5e8b90f7f7a4752d8/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signature.ts | ||
| * @param {import('typedoc').SignatureReflection} model | ||
| * @param {{ headingLevel: number, nested?: boolean, accessor?: string, multipleSignatures?: boolean }} options | ||
| */ | ||
| signature: (model, options) => { | ||
| const md = []; | ||
|
|
||
| if (!options.nested && model.sources && !this.options.getValue('disableSources')) { | ||
| md.push(this.partials.sources(model)); | ||
| } | ||
|
|
||
| let modelComments = options.multipleSignatures ? model.comment : model.comment || model.parent?.comment; | ||
|
|
||
| if (modelComments && model.parent?.comment?.summary && !options.multipleSignatures) { | ||
| modelComments = Object.assign(modelComments, { | ||
| summary: model.parent.comment.summary, | ||
| }); | ||
| } | ||
|
|
||
| if (modelComments && model.parent?.comment?.blockTags) { | ||
| modelComments.blockTags = [...(model.parent?.comment?.blockTags || []), ...(model.comment?.blockTags || [])]; | ||
| } | ||
|
|
||
| if (modelComments) { | ||
| md.push( | ||
| this.partials.comment(modelComments, { | ||
| headingLevel: options.headingLevel, | ||
| showTags: false, | ||
| showSummary: true, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (!options.multipleSignatures && model.parent?.documents) { | ||
| md.push( | ||
| this.partials.documents(model?.parent, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (model.parameters?.length) { | ||
| md.push(heading(options.headingLevel, this.internationalization.kindPluralString(ReflectionKind.Parameter))); | ||
| if (this.helpers.useTableFormat('parameters')) { | ||
| md.push(this.partials.parametersTable(model.parameters)); | ||
| } else { | ||
| md.push( | ||
| this.partials.parametersList(model.parameters, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (model.type) { | ||
| md.push( | ||
| this.partials.signatureReturns(model, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (modelComments) { | ||
| md.push( | ||
| this.partials.comment(modelComments, { | ||
| headingLevel: options.headingLevel, | ||
| showTags: true, | ||
| showSummary: false, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| md.push(this.partials.inheritance(model, { headingLevel: options.headingLevel })); | ||
|
|
||
| return md.join('\n\n'); | ||
| }, | ||
| /** | ||
| * Copied from default theme / source code. This hides the "Type parameters" section from the output | ||
| * https://github.com/typedoc2md/typedoc-plugin-markdown/blob/179a54c502b318cd4f3951e5e8b90f7f7a4752d8/packages/typedoc-plugin-markdown/src/theme/context/partials/member.memberWithGroups.ts#L58 | ||
| * @param {import('typedoc').DeclarationReflection} model | ||
| * @param {{ headingLevel: number }} options | ||
| */ | ||
| memberWithGroups: (model, options) => { | ||
| const md = []; | ||
|
|
||
| if ( | ||
| ![ReflectionKind.Module, ReflectionKind.Namespace].includes(model.kind) && | ||
| model.sources && | ||
| !this.options.getValue('disableSources') | ||
| ) { | ||
| md.push(this.partials.sources(model)); | ||
| } | ||
|
|
||
| if (model.comment) { | ||
| md.push( | ||
| this.partials.comment(model.comment, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (model.typeHierarchy?.next) { | ||
| md.push( | ||
| this.partials.hierarchy(model.typeHierarchy, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| if (model.implementedTypes?.length) { | ||
| md.push(heading(options.headingLevel, this.i18n.theme_implements())); | ||
| md.push( | ||
| unorderedList(model.implementedTypes.map(implementedType => this.partials.someType(implementedType))), | ||
| ); | ||
| } | ||
|
|
||
| if (model.kind === ReflectionKind.Class && model.categories?.length) { | ||
| model.groups | ||
| ?.filter(group => group.title === this.i18n.kind_plural_constructor()) | ||
| .forEach(group => { | ||
| md.push(heading(options.headingLevel, this.i18n.kind_plural_constructor())); | ||
| group.children.forEach(child => { | ||
| md.push( | ||
| this.partials.constructor(/** @type {import('typedoc').DeclarationReflection} */ (child), { | ||
| headingLevel: options.headingLevel + 1, | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| if ('signatures' in model && model.signatures?.length) { | ||
| model.signatures.forEach(signature => { | ||
| md.push( | ||
| this.partials.signature(signature, { | ||
| headingLevel: options.headingLevel, | ||
| }), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| if (model.indexSignatures?.length) { | ||
| md.push(heading(options.headingLevel, this.i18n.theme_indexable())); | ||
| model.indexSignatures.forEach(indexSignature => { | ||
| md.push(this.partials.indexSignature(indexSignature)); | ||
| }); | ||
| } | ||
|
|
||
| md.push(this.partials.body(model, { headingLevel: options.headingLevel })); | ||
|
|
||
| return md.join('\n\n'); | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a heading in markdown format | ||
| * @param {number} level The level of the heading | ||
| * @param {string} text The text of the heading | ||
| */ | ||
| function heading(level, text) { | ||
| level = level > 6 ? 6 : level; | ||
| return `${[...Array(level)].map(() => '#').join('')} ${text}`; | ||
| } | ||
|
|
||
| /** | ||
| * Create an unordered list from an array of items | ||
| * @param {string[]} items | ||
| * @returns | ||
| */ | ||
| function unorderedList(items) { | ||
| return items.map(item => `- ${item}`).join('\n'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "noEmit": true, | ||
| "moduleResolution": "node16", | ||
| "module": "Node16" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍