Skip to content

Commit 20db9a5

Browse files
feat: Config option to exclude not explicitly documented symbols (#996)
Closes #995
1 parent 541fbcf commit 20db9a5

File tree

7 files changed

+4595
-1
lines changed

7 files changed

+4595
-1
lines changed

scripts/rebuild_specs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const conversions = [
4242
() => app.options.setValue('categorizeByGroup', false),
4343
() => app.options.setValue('categorizeByGroup', true)
4444
],
45+
['specs.nodoc',
46+
() => app.options.setValue('excludeNotDocumented', true),
47+
() => app.options.setValue('excludeNotDocumented', false)
48+
]
4549
];
4650

4751
/**

src/lib/converter/converter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
4949
@BindOption('excludeNotExported')
5050
excludeNotExported!: boolean;
5151

52+
@BindOption('excludeNotDocumented')
53+
excludeNotDocumented!: boolean;
54+
5255
@BindOption('excludePrivate')
5356
excludePrivate!: boolean;
5457

src/lib/converter/factories/declaration.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as ts from 'typescript';
33
import { ContainerReflection, DeclarationReflection, ReflectionFlag, ReflectionKind } from '../../models/index';
44
import { Context } from '../context';
55
import { Converter } from '../converter';
6+
import { getRawComment } from './comment.js';
67
import { createReferenceType } from './reference';
78

89
/**
@@ -69,10 +70,12 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
6970

7071
const modifiers = ts.getCombinedModifierFlags(node);
7172

73+
let hasComment: boolean = Boolean(getRawComment(node));
7274
// Test whether the node is exported
7375
let isExported: boolean;
7476
if (kind === ReflectionKind.ExternalModule || kind === ReflectionKind.Global) {
7577
isExported = true;
78+
hasComment = true;
7679
} else if (container.kind === ReflectionKind.Global) {
7780
// In file mode, everything is exported.
7881
isExported = true;
@@ -98,7 +101,11 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
98101
isExported = container.flags.isExported;
99102
}
100103

101-
if (!isExported && context.converter.excludeNotExported) {
104+
if (
105+
(!isExported && context.converter.excludeNotExported)
106+
||
107+
(context.converter.excludeNotDocumented && kind !== ReflectionKind.EnumMember && !hasComment)
108+
) {
102109
return;
103110
}
104111

src/lib/utils/options/sources/typedoc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export function addTypeDocOptions(options: Options) {
6161
help: 'Prevent symbols that are not exported from being documented.',
6262
type: ParameterType.Boolean
6363
});
64+
options.addDeclaration({
65+
name: 'excludeNotDocumented',
66+
help: 'Prevent symbols that are not explicitly documented from appearing in the results.',
67+
type: ParameterType.Boolean
68+
});
6469
options.addDeclaration({
6570
name: 'excludePrivate',
6671
help: 'Ignores private variables and methods',

src/test/converter.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,39 @@ describe('Serializer', () => {
7979
equal(json, typed);
8080
});
8181
});
82+
83+
// describe('Converter with excludeNotDocumented=true', function() {
84+
// const base = Path.join(__dirname, 'converter');
85+
// const fixtureDir = Path.join(base, 'exclude-not-documented');
86+
// let app: Application;
87+
//
88+
// before('constructs', function() {
89+
// app = new Application({
90+
// mode: 'Modules',
91+
// logger: 'none',
92+
// target: 'ES5',
93+
// module: 'CommonJS',
94+
// experimentalDecorators: true,
95+
// excludeNotDocumented: true,
96+
// jsx: 'react'
97+
// });
98+
// });
99+
//
100+
// let result: ProjectReflection | undefined;
101+
//
102+
// describe('Exclude not documented symbols', () => {
103+
// it('converts fixtures', function() {
104+
// resetReflectionID();
105+
// result = app.convert(app.expandInputFiles([fixtureDir]));
106+
// Assert(result instanceof ProjectReflection, 'No reflection returned');
107+
// });
108+
//
109+
// it('matches specs', function() {
110+
// const specs = JSON.parse(FS.readFileSync(Path.join(fixtureDir, 'specs-without-undocumented.json')).toString());
111+
// let data = JSON.stringify(result!.toObject(), null, ' ');
112+
// data = data.split(normalizePath(base)).join('%BASE%');
113+
//
114+
// compareReflections(JSON.parse(data), specs);
115+
// });
116+
// });
117+
// });

0 commit comments

Comments
 (0)