Skip to content

Commit

Permalink
feat: ignore constructors without documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Jul 2, 2023
1 parent 124faeb commit 3f3abcd
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/lib/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down Expand Up @@ -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;
};

Expand Down
11 changes: 8 additions & 3 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -23,7 +28,7 @@ export const generateDocumentation = ({
inputFiles,
outputFile,
markdownOptions,
buildOptions
buildOptions
}: {
inputFiles: string[];
outputFile: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
18 changes: 18 additions & 0 deletions src/test/mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
17 changes: 15 additions & 2 deletions src/test/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ Returns the balance of the specified account identifier.

## :factory: SnsLedgerCanister



### Constructors

`public`: The constructor is public as well.
Expand Down Expand Up @@ -115,3 +113,18 @@ The token metadata (name, symbol, etc.).
| ---------- | ---------- |
| `metadata` | `(params: QueryParams) => Promise<SnsTokenMetadataResponse>` |


## :factory: default

### Methods

- [bar](#gear-bar)

#### :gear: bar

Description

| Method | Type |
| ---------- | ---------- |
| `bar` | `() => void` |

7 changes: 7 additions & 0 deletions src/test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,10 @@ export class SnsLedgerCanister extends Canister<SnsLedgerService> {
metadata = (params: QueryParams): Promise<SnsTokenMetadataResponse> =>
this.caller(params).icrc1_metadata();
}

export default class foo {
/**
* Description
*/
bar() {}
}

0 comments on commit 3f3abcd

Please sign in to comment.