Skip to content

Commit 138a52b

Browse files
committed
Add excludeNotDocumentedKinds option
Resolves #2162
1 parent d82c01b commit 138a52b

File tree

6 files changed

+139
-15
lines changed

6 files changed

+139
-15
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Unreleased
22

3+
### Breaking Changes
4+
5+
- Upgraded Shiki, if your highlight theme was set to `material-<theme>`, the value will need to be changed to
6+
`material-theme-<theme>`, see the [Shiki release notes](https://github.com/shikijs/shiki/blob/main/CHANGELOG.md#0130--2023-01-27).
7+
8+
### Features
9+
10+
- Added new `excludeNotDocumentedKinds` variable to control which reflection types can be removed
11+
by the `excludeNotDocumented` option, #2162.
12+
- Added `typedoc.jsonc`, `typedoc.config.js`, `typedoc.config.cjs`, `typedoc.cjs` to the list of files
13+
which TypeDoc will automatically use as configuration files.
14+
15+
### Bug Fixes
16+
17+
- Entry points under `node_modules` will no longer be ignored, #2151.
18+
19+
### Thanks!
20+
21+
- @boneskull
22+
- @Mikkal24
23+
- @zamiell
24+
325
## v0.23.24 (2023-01-07)
426

527
### Bug Fixes

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ export class CommentPlugin extends ConverterComponent {
118118
@BindOption("excludeNotDocumented")
119119
excludeNotDocumented!: boolean;
120120

121+
private _excludeKinds: number | undefined;
122+
private get excludeNotDocumentedKinds(): number {
123+
this._excludeKinds ??= this.application.options
124+
.getValue("excludeNotDocumentedKinds")
125+
.reduce((a, b) => a | ReflectionKind[b], 0);
126+
return this._excludeKinds;
127+
}
128+
121129
/**
122130
* Create a new CommentPlugin instance.
123131
*/
@@ -128,6 +136,9 @@ export class CommentPlugin extends ConverterComponent {
128136
[Converter.EVENT_CREATE_TYPE_PARAMETER]: this.onCreateTypeParameter,
129137
[Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,
130138
[Converter.EVENT_RESOLVE]: this.onResolve,
139+
[Converter.EVENT_END]: () => {
140+
this._excludeKinds = undefined;
141+
},
131142
});
132143
}
133144

@@ -462,6 +473,10 @@ export class CommentPlugin extends ConverterComponent {
462473
return false;
463474
}
464475

476+
if (!reflection.kindOf(this.excludeNotDocumentedKinds)) {
477+
return false;
478+
}
479+
465480
// excludeNotDocumented should hide a module only if it has no visible children
466481
if (reflection.kindOf(ReflectionKind.SomeModule)) {
467482
if (!(reflection as DeclarationReflection).children) {
@@ -472,11 +487,6 @@ export class CommentPlugin extends ConverterComponent {
472487
).children!.every((child) => this.isHidden(child));
473488
}
474489

475-
// enum members should all be included if the parent enum is documented
476-
if (reflection.kind === ReflectionKind.EnumMember) {
477-
return false;
478-
}
479-
480490
// signature containers should only be hidden if all their signatures are hidden
481491
if (reflection.kindOf(ReflectionKind.SignatureContainer)) {
482492
return (reflection as DeclarationReflection)

src/lib/utils/options/declaration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface TypeDocOptionMap {
8585
externalPattern: string[];
8686
excludeExternals: boolean;
8787
excludeNotDocumented: boolean;
88+
excludeNotDocumentedKinds: Array<keyof typeof ReflectionKind>;
8889
excludeInternal: boolean;
8990
excludePrivate: boolean;
9091
excludeProtected: boolean;

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

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,58 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
8585
help: "Prevent symbols that are not explicitly documented from appearing in the results.",
8686
type: ParameterType.Boolean,
8787
});
88+
options.addDeclaration({
89+
name: "excludeNotDocumentedKinds",
90+
help: "Specify the type of reflections that can be removed by excludeNotDocumented.",
91+
type: ParameterType.Array,
92+
validate(value) {
93+
const invalid = new Set(value);
94+
const valid = new Set(getEnumKeys(ReflectionKind));
95+
for (const notPermitted of [
96+
ReflectionKind.Project,
97+
ReflectionKind.TypeLiteral,
98+
ReflectionKind.TypeParameter,
99+
ReflectionKind.Parameter,
100+
ReflectionKind.ObjectLiteral,
101+
]) {
102+
valid.delete(ReflectionKind[notPermitted]);
103+
}
104+
for (const v of valid) {
105+
invalid.delete(v);
106+
}
107+
108+
if (invalid.size !== 0) {
109+
throw new Error(
110+
`excludeNotDocumentedKinds may only specify known values, and invalid values were provided (${Array.from(
111+
invalid
112+
).join(", ")}). The valid kinds are:\n${Array.from(
113+
valid
114+
).join(", ")}`
115+
);
116+
}
117+
},
118+
defaultValue: [
119+
ReflectionKind[ReflectionKind.Module],
120+
ReflectionKind[ReflectionKind.Namespace],
121+
ReflectionKind[ReflectionKind.Enum],
122+
// Not including enum member here by default
123+
ReflectionKind[ReflectionKind.Variable],
124+
ReflectionKind[ReflectionKind.Function],
125+
ReflectionKind[ReflectionKind.Class],
126+
ReflectionKind[ReflectionKind.Interface],
127+
ReflectionKind[ReflectionKind.Constructor],
128+
ReflectionKind[ReflectionKind.Property],
129+
ReflectionKind[ReflectionKind.Method],
130+
ReflectionKind[ReflectionKind.CallSignature],
131+
ReflectionKind[ReflectionKind.IndexSignature],
132+
ReflectionKind[ReflectionKind.ConstructorSignature],
133+
ReflectionKind[ReflectionKind.Accessor],
134+
ReflectionKind[ReflectionKind.GetSignature],
135+
ReflectionKind[ReflectionKind.SetSignature],
136+
ReflectionKind[ReflectionKind.TypeAlias],
137+
ReflectionKind[ReflectionKind.Reference],
138+
],
139+
});
88140
options.addDeclaration({
89141
name: "excludeInternal",
90142
help: "Prevent symbols that are marked with @internal from being documented.",
@@ -631,16 +683,16 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
631683
}
632684
},
633685
defaultValue: [
634-
"Enum",
635-
"EnumMember",
636-
"Variable",
637-
"Function",
638-
"Class",
639-
"Interface",
640-
"Property",
641-
"Method",
642-
"Accessor",
643-
"TypeAlias",
686+
ReflectionKind[ReflectionKind.Enum],
687+
ReflectionKind[ReflectionKind.EnumMember],
688+
ReflectionKind[ReflectionKind.Variable],
689+
ReflectionKind[ReflectionKind.Function],
690+
ReflectionKind[ReflectionKind.Class],
691+
ReflectionKind[ReflectionKind.Interface],
692+
ReflectionKind[ReflectionKind.Property],
693+
ReflectionKind[ReflectionKind.Method],
694+
ReflectionKind[ReflectionKind.Accessor],
695+
ReflectionKind[ReflectionKind.TypeAlias],
644696
],
645697
});
646698

src/test/behaviorTests.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CommentTag,
1111
Reflection,
1212
SignatureReflection,
13+
ContainerReflection,
1314
} from "../lib/models";
1415
import { Chars, filterMap } from "../lib/utils";
1516
import { CommentStyle } from "../lib/utils/options/declaration";
@@ -21,6 +22,20 @@ function query(project: ProjectReflection, name: string) {
2122
return reflection;
2223
}
2324

25+
type NameTree = { [name: string]: NameTree };
26+
27+
function buildNameTree(
28+
refl: ContainerReflection,
29+
tree: NameTree = {}
30+
): NameTree {
31+
for (const child of refl.children || []) {
32+
tree[child.name] ||= {};
33+
buildNameTree(child, tree[child.name]);
34+
}
35+
36+
return tree;
37+
}
38+
2439
type Letters = Chars<"abcdefghijklmnopqrstuvwxyz">;
2540

2641
export const behaviorTests: {
@@ -201,6 +216,19 @@ export const behaviorTests: {
201216
logger.expectNoOtherMessages();
202217
},
203218

219+
_excludeNotDocumentedKinds(app) {
220+
app.options.setValue("excludeNotDocumented", true);
221+
app.options.setValue("excludeNotDocumentedKinds", ["Property"]);
222+
},
223+
excludeNotDocumentedKinds(project) {
224+
equal(buildNameTree(project), {
225+
NotDoc: {
226+
prop: {},
227+
},
228+
identity: {},
229+
});
230+
},
231+
204232
exportComments(project) {
205233
const abc = query(project, "abc");
206234
equal(abc.kind, ReflectionKind.Variable);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface NotDoc {
2+
/** Doc */
3+
prop: 123;
4+
5+
notDoc: 456;
6+
}
7+
8+
/** Doc */
9+
export function identity<T>(x: T): T {
10+
return x;
11+
}

0 commit comments

Comments
 (0)