Skip to content
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

fix: private method identifiers included in generated doc #46

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ To generate links to the documented source code, you can also provide the `--rep

This library generates Markdown documentation from TypeScript source code for `Functions`, `Constants` and `Classes`. Documentation for `Interfaces` and `Types` is not generated by default. To opt-in for types use the parameter `--types`.

You can also opt-out of generating titles with emojis by using the option `--noemoji`.
You can also opt-out of generating titles with emojis by using the option `--noemoji`.

Using above script is of course optional. You can also develop your own JavaScript script and use one of the functions here under.

Expand Down Expand Up @@ -149,7 +149,7 @@ Parameters:
- `params.inputFiles`: The list of files to scan and for which the documentation should be build.
- `params.options`: Optional compiler options to generate the docs

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/docs.ts#L398)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/docs.ts#L402)

### :gear: documentationToMarkdown

Expand Down
8 changes: 6 additions & 2 deletions src/lib/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import type {
TypeChecker,
Symbol as TypeScriptSymbol,
VariableDeclaration,
VariableStatement
} from 'typescript';
VariableStatement} from 'typescript';
import {
ModifierFlags,
ModuleKind,
Expand Down Expand Up @@ -116,6 +115,11 @@ const serializeClass = ({
const isNodeExportedOrPublic = (node: Node): boolean => {
const flags = getCombinedModifierFlags(node as Declaration);

// Check for '#' methods or properties
if (isMethodDeclaration(node) && node.name.kind === SyntaxKind.PrivateIdentifier) {
return false;
}

return (
(flags & ModifierFlags.Export) !== 0 ||
(flags & ModifierFlags.Public) !== 0 ||
Expand Down
2 changes: 1 addition & 1 deletion src/test/markdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('markdown', () => {
expect(markdown).toEqual(expectedDoc);
});

it.each([35, 86, 114])('should generate a markdown link to line %s', (line) => {
it.each([35, 101, 129])('should generate a markdown link to line %s', (line) => {
const doc = buildDocumentation({
inputFiles: ['./src/test/mock.ts'],
options: {
Expand Down
7 changes: 7 additions & 0 deletions src/test/mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@
}
],
"doc_type": "function"
},
{
"name": "shouldBeDocumented",
"documentation": "Public method.",
"type": "() => void",
"jsDocs": [],
"doc_type": "method"
}
],
"fileName": "src/test/mock.ts"
Expand Down
31 changes: 21 additions & 10 deletions src/test/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function submit() {
```


[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L206)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L221)


## :wrench: Constants
Expand Down Expand Up @@ -125,6 +125,7 @@ Parameters:

- [create](#gear-create)
- [accountBalance](#gear-accountbalance)
- [shouldBeDocumented](#gear-shouldbedocumented)

#### :gear: create

Expand All @@ -146,10 +147,20 @@ Returns the balance of the specified account identifier.

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L69)

#### :gear: shouldBeDocumented

Public method.

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

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L80)


## :factory: SnsLedgerCanister

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L86)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L101)

### Constructors

Expand All @@ -170,7 +181,7 @@ This create function is public as well.
| ---------- | ---------- |
| `create` | `(options: { canisterId?: string or undefined; }) => SnsLedgerCanister` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L101)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L116)

#### :gear: metadata

Expand All @@ -180,12 +191,12 @@ The token metadata (name, symbol, etc.).
| ---------- | ---------- |
| `metadata` | `(params: QueryParams) => Promise<SnsTokenMetadataResponse>` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L110)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L125)


## :factory: default

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L114)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L129)

### Methods

Expand All @@ -199,7 +210,7 @@ Description
| ---------- | ---------- |
| `bar` | `() => void` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L118)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L133)


## :nut_and_bolt: Enum
Expand Down Expand Up @@ -270,7 +281,7 @@ A type yolo
| ---------- | ---------- |
| `yolo` | `'string'` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L143)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L158)

### :gear: Abc

Expand All @@ -280,21 +291,21 @@ A type yolo
| ---------- | ---------- |
| `Abc` | `Foo and {hello: string}` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L148)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L163)

### :gear: StorageConfigSourceGlob

| Type | Type |
| ---------- | ---------- |
| `StorageConfigSourceGlob` | |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L219)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L234)

### :gear: SatelliteConfig

| Type | Type |
| ---------- | ---------- |
| `SatelliteConfig` | `Either<SatelliteId, SatelliteIds> and CliConfig and SatelliteConfigOptions` |

[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L245)
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L260)

15 changes: 15 additions & 0 deletions src/test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,28 @@ export class LedgerCanister {
return {icp: 1n};
};

/**
* Public method.
*/
shouldBeDocumented() {
console.log('hello');
}

/**
* Private method.
* @private
*/
private shouldNoBeDocumented() {
console.log('hello');
}

/**
* Private identifier method.
* @private
*/
#shouldNoBeDocumentedNeither() {
console.log('hello');
}
}

export class SnsLedgerCanister extends Canister<SnsLedgerService> {
Expand Down