Skip to content

Commit

Permalink
fix: private method identifiers included in generated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Dec 16, 2024
1 parent 952f9b1 commit a8411c3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
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 a8411c3

Please sign in to comment.