Skip to content

Commit

Permalink
fix: private method identifiers included in generated doc (#46)
Browse files Browse the repository at this point in the history
* fix: private method identifiers included in generated doc

* 🤖 Documentation auto-update

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
peterpeterparker and github-actions[bot] authored Dec 16, 2024
1 parent 952f9b1 commit 666a69d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
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

0 comments on commit 666a69d

Please sign in to comment.