diff --git a/src/lib/docs.ts b/src/lib/docs.ts index fc26a2a..1b8b9f9 100644 --- a/src/lib/docs.ts +++ b/src/lib/docs.ts @@ -28,8 +28,7 @@ import { ScriptTarget, SyntaxKind } from 'typescript'; -import type {DocEntry, DocEntryConstructor, DocEntryType} from './types'; -import {BuildOptions} from './types'; +import type {BuildOptions, DocEntry, DocEntryConstructor, DocEntryType} from './types'; /** Serialize a symbol into a json object */ const serializeSymbol = ({ @@ -65,7 +64,9 @@ const serializeClass = ({ details.constructors = constructorType .getConstructSignatures() - .map((signature: Signature) => serializeSignature({checker, signature})); + .map((signature: Signature) => serializeSignature({checker, signature})) + .filter(({documentation}) => documentation !== undefined && documentation !== ''); + return details; }; diff --git a/src/lib/index.ts b/src/lib/index.ts index 419b57f..f102346 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,8 +1,13 @@ import {existsSync, readFileSync, writeFileSync} from 'fs'; import {buildDocumentation} from './docs'; import {documentationToMarkdown} from './markdown'; -import type {BuildOptions, DocEntry, DocEntryConstructor, DocEntryType} from './types'; -import {MarkdownOptions} from './types'; +import type { + BuildOptions, + DocEntry, + DocEntryConstructor, + DocEntryType, + MarkdownOptions +} from './types'; export {buildDocumentation}; export {documentationToMarkdown}; @@ -23,7 +28,7 @@ export const generateDocumentation = ({ inputFiles, outputFile, markdownOptions, - buildOptions + buildOptions }: { inputFiles: string[]; outputFile: string; diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index b2b4abb..af680e2 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -37,7 +37,7 @@ const classesToMarkdown = ({ const {name, documentation, methods, constructors} = entry; const markdown: string[] = [`${headingLevel}${emojiTitle({emoji, key: 'classes'})} ${name}\n`]; - markdown.push(`${documentation}\n`); + (documentation !== undefined && documentation !== '') && markdown.push(`${documentation}\n`); const publicConstructors: DocEntryConstructor[] = (constructors ?? []).filter( ({visibility}) => visibility === 'public' diff --git a/src/lib/types.ts b/src/lib/types.ts index b165adc..596f5dc 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,5 +1,4 @@ -import type {JSDocTagInfo} from 'typescript'; -import {CompilerOptions} from 'typescript'; +import type {CompilerOptions, JSDocTagInfo} from 'typescript'; export type DocEntryType = 'function' | 'method' | 'class' | 'const'; diff --git a/src/test/mock.json b/src/test/mock.json index a02e601..7bf5abf 100644 --- a/src/test/mock.json +++ b/src/test/mock.json @@ -164,5 +164,23 @@ ], "name": "SnsLedgerCanister", "type": "typeof SnsLedgerCanister" + }, + { + "constructors": [], + "doc_type": "class", + "documentation": "", + "fileName": "src/test/mock.ts", + "jsDocs": [], + "methods": [ + { + "doc_type": "method", + "documentation": "Description", + "jsDocs": [], + "name": "bar", + "type": "() => void" + } + ], + "name": "default", + "type": "typeof foo" } ] diff --git a/src/test/mock.md b/src/test/mock.md index 9cf1c32..e8819e2 100644 --- a/src/test/mock.md +++ b/src/test/mock.md @@ -86,8 +86,6 @@ Returns the balance of the specified account identifier. ## :factory: SnsLedgerCanister - - ### Constructors `public`: The constructor is public as well. @@ -115,3 +113,18 @@ The token metadata (name, symbol, etc.). | ---------- | ---------- | | `metadata` | `(params: QueryParams) => Promise` | + +## :factory: default + +### Methods + +- [bar](#gear-bar) + +#### :gear: bar + +Description + +| Method | Type | +| ---------- | ---------- | +| `bar` | `() => void` | + diff --git a/src/test/mock.ts b/src/test/mock.ts index 342975a..852860e 100644 --- a/src/test/mock.ts +++ b/src/test/mock.ts @@ -110,3 +110,10 @@ export class SnsLedgerCanister extends Canister { metadata = (params: QueryParams): Promise => this.caller(params).icrc1_metadata(); } + +export default class foo { + /** + * Description + */ + bar() {} +}