Skip to content

Commit 122fd72

Browse files
Nokel81Gerrit0
andauthored
Add option to warn on undocumented items (#1819)
* Add option to warn on undocumented items * Fix skip node_modules * fix off by one error Signed-off-by: Sebastian Malton <[email protected]> * Fix off by one error on reporting * Fix changelog, change ignore node_modules check Signed-off-by: Sebastian Malton <[email protected]> * fix formatting Signed-off-by: Sebastian Malton <[email protected]> * fix circular dep Signed-off-by: Sebastian Malton <[email protected]> * Fix circular reference * Actually fix circular dep * Improve errors for invalid requiredToBeDocumented values Co-authored-by: Gerrit Birkeland <[email protected]>
1 parent 4af6289 commit 122fd72

File tree

19 files changed

+190
-97
lines changed

19 files changed

+190
-97
lines changed

.config/regconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"core": {
33
"workingDir": "dist/tmp/.reg",
44
"actualDir": "dist/tmp/__screenshots__",
5-
"thresholdRate": 0.001,
5+
"thresholdRate": 0.01,
66
"addIgnore": true,
77
"ximgdiff": {
88
"invocationType": "client"

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
### Features
66

7+
- Added `--validation.notDocumented` option to warn on items that are not documented, #1817.
8+
- Added new `cname` option for GitHub Pages custom domain support, #1803.
79
- `ReferenceType`s which reference an external symbol will now include `qualifiedName` and `package` in their serialized JSON.
810
- Added clickable anchor link for member titles, #1842.
9-
- Added new `cname` option for GitHub Pages custom domain support, #1803
1011

1112
### Bug Fixes
1213

src/lib/application.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from "./utils/entry-point";
3535
import { nicePath } from "./utils/paths";
3636
import { hasBeenLoadedMultipleTimes } from "./utils/general";
37+
import { validateDocumentation } from "./validation/documentation";
3738

3839
// eslint-disable-next-line @typescript-eslint/no-var-requires
3940
const packageInfo = require("../../package.json") as {
@@ -416,6 +417,14 @@ export class Application extends ChildableComponent<
416417
);
417418
}
418419

420+
if (checks.notDocumented) {
421+
validateDocumentation(
422+
project,
423+
this.logger,
424+
this.options.getValue("requiredToBeDocumented")
425+
);
426+
}
427+
419428
// checks.invalidLink is currently handled when rendering by the MarkedLinksPlugin.
420429
// It should really move here, but I'm putting that off until done refactoring the comment
421430
// parsing so that we don't have duplicate parse logic all over the place.

src/lib/models/ReflectionGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReflectionKind } from "./reflections/abstract";
1+
import type { ReflectionKind } from "./reflections/kind";
22
import type { ReflectionCategory } from "./ReflectionCategory";
33
import type { DeclarationReflection } from ".";
44

src/lib/models/reflections/abstract.ts

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Comment } from "../comments/comment";
55
import { splitUnquotedString } from "./utils";
66
import type { ProjectReflection } from "./project";
77
import type { NeverIfInternal } from "../../utils";
8+
import { ReflectionKind } from "./kind";
89

910
/**
1011
* Holds all data models used by TypeDoc.
@@ -32,79 +33,6 @@ export function resetReflectionID() {
3233
REFLECTION_ID = 0;
3334
}
3435

35-
/**
36-
* Defines the available reflection kinds.
37-
*/
38-
export enum ReflectionKind {
39-
Project = 0x1,
40-
Module = 0x2,
41-
Namespace = 0x4,
42-
Enum = 0x8,
43-
EnumMember = 0x10,
44-
Variable = 0x20,
45-
Function = 0x40,
46-
Class = 0x80,
47-
Interface = 0x100,
48-
Constructor = 0x200,
49-
Property = 0x400,
50-
Method = 0x800,
51-
CallSignature = 0x1000,
52-
IndexSignature = 0x2000,
53-
ConstructorSignature = 0x4000,
54-
Parameter = 0x8000,
55-
TypeLiteral = 0x10000,
56-
TypeParameter = 0x20000,
57-
Accessor = 0x40000,
58-
GetSignature = 0x80000,
59-
SetSignature = 0x100000,
60-
ObjectLiteral = 0x200000,
61-
TypeAlias = 0x400000,
62-
Event = 0x800000,
63-
Reference = 0x1000000,
64-
}
65-
66-
/** @hidden */
67-
export namespace ReflectionKind {
68-
export const All = ReflectionKind.Reference * 2 - 1;
69-
70-
export const ClassOrInterface =
71-
ReflectionKind.Class | ReflectionKind.Interface;
72-
export const VariableOrProperty =
73-
ReflectionKind.Variable | ReflectionKind.Property;
74-
export const FunctionOrMethod =
75-
ReflectionKind.Function | ReflectionKind.Method;
76-
export const ClassMember =
77-
ReflectionKind.Accessor |
78-
ReflectionKind.Constructor |
79-
ReflectionKind.Method |
80-
ReflectionKind.Property |
81-
ReflectionKind.Event;
82-
export const SomeSignature =
83-
ReflectionKind.CallSignature |
84-
ReflectionKind.IndexSignature |
85-
ReflectionKind.ConstructorSignature |
86-
ReflectionKind.GetSignature |
87-
ReflectionKind.SetSignature;
88-
export const SomeModule = ReflectionKind.Namespace | ReflectionKind.Module;
89-
export const SomeType =
90-
ReflectionKind.Interface |
91-
ReflectionKind.TypeLiteral |
92-
ReflectionKind.TypeParameter |
93-
ReflectionKind.TypeAlias;
94-
export const SomeValue =
95-
ReflectionKind.Variable |
96-
ReflectionKind.Function |
97-
ReflectionKind.ObjectLiteral;
98-
99-
/** @internal */
100-
export const Inheritable =
101-
ReflectionKind.Accessor |
102-
ReflectionKind.IndexSignature |
103-
ReflectionKind.Property |
104-
ReflectionKind.Method |
105-
ReflectionKind.Constructor;
106-
}
107-
10836
export enum ReflectionFlag {
10937
None = 0,
11038
Private = 1,

src/lib/models/reflections/container.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import {
2-
Reflection,
3-
ReflectionKind,
4-
TraverseCallback,
5-
TraverseProperty,
6-
} from "./abstract";
1+
import { Reflection, TraverseCallback, TraverseProperty } from "./abstract";
72
import type { ReflectionCategory } from "../ReflectionCategory";
83
import type { ReflectionGroup } from "../ReflectionGroup";
94
import type { DeclarationReflection } from "./declaration";
5+
import type { ReflectionKind } from "./kind";
106

117
export class ContainerReflection extends Reflection {
128
/**

src/lib/models/reflections/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export {
22
Reflection,
3-
ReflectionKind,
43
ReflectionFlag,
5-
TraverseProperty,
64
ReflectionFlags,
5+
TraverseProperty,
76
} from "./abstract";
87
export type { Decorator, TraverseCallback } from "./abstract";
98
export { ContainerReflection } from "./container";
109
export { DeclarationReflection } from "./declaration";
1110
export type { DeclarationHierarchy } from "./declaration";
11+
export { ReflectionKind } from "./kind";
1212
export { ParameterReflection } from "./parameter";
1313
export { ProjectReflection } from "./project";
1414
export { ReferenceReflection } from "./reference";

src/lib/models/reflections/kind.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Defines the available reflection kinds.
3+
*/
4+
export enum ReflectionKind {
5+
Project = 0x1,
6+
Module = 0x2,
7+
Namespace = 0x4,
8+
Enum = 0x8,
9+
EnumMember = 0x10,
10+
Variable = 0x20,
11+
Function = 0x40,
12+
Class = 0x80,
13+
Interface = 0x100,
14+
Constructor = 0x200,
15+
Property = 0x400,
16+
Method = 0x800,
17+
CallSignature = 0x1000,
18+
IndexSignature = 0x2000,
19+
ConstructorSignature = 0x4000,
20+
Parameter = 0x8000,
21+
TypeLiteral = 0x10000,
22+
TypeParameter = 0x20000,
23+
Accessor = 0x40000,
24+
GetSignature = 0x80000,
25+
SetSignature = 0x100000,
26+
ObjectLiteral = 0x200000,
27+
TypeAlias = 0x400000,
28+
Event = 0x800000,
29+
Reference = 0x1000000,
30+
}
31+
32+
/** @hidden */
33+
export namespace ReflectionKind {
34+
export const All = ReflectionKind.Reference * 2 - 1;
35+
36+
export const ClassOrInterface =
37+
ReflectionKind.Class | ReflectionKind.Interface;
38+
export const VariableOrProperty =
39+
ReflectionKind.Variable | ReflectionKind.Property;
40+
export const FunctionOrMethod =
41+
ReflectionKind.Function | ReflectionKind.Method;
42+
export const ClassMember =
43+
ReflectionKind.Accessor |
44+
ReflectionKind.Constructor |
45+
ReflectionKind.Method |
46+
ReflectionKind.Property |
47+
ReflectionKind.Event;
48+
export const SomeSignature =
49+
ReflectionKind.CallSignature |
50+
ReflectionKind.IndexSignature |
51+
ReflectionKind.ConstructorSignature |
52+
ReflectionKind.GetSignature |
53+
ReflectionKind.SetSignature;
54+
export const SomeModule = ReflectionKind.Namespace | ReflectionKind.Module;
55+
export const SomeType =
56+
ReflectionKind.Interface |
57+
ReflectionKind.TypeLiteral |
58+
ReflectionKind.TypeParameter |
59+
ReflectionKind.TypeAlias;
60+
export const SomeValue =
61+
ReflectionKind.Variable |
62+
ReflectionKind.Function |
63+
ReflectionKind.ObjectLiteral;
64+
65+
/** @internal */
66+
export const Inheritable =
67+
ReflectionKind.Accessor |
68+
ReflectionKind.IndexSignature |
69+
ReflectionKind.Property |
70+
ReflectionKind.Method |
71+
ReflectionKind.Constructor;
72+
}

src/lib/models/reflections/project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SourceFile, SourceDirectory } from "../sources/index";
2-
import { Reflection, ReflectionKind, TraverseProperty } from "./abstract";
2+
import { Reflection, TraverseProperty } from "./abstract";
33
import { ContainerReflection } from "./container";
44
import { splitUnquotedString } from "./utils";
55
import { ReferenceReflection } from "./reference";
@@ -10,6 +10,7 @@ import { IntrinsicType } from "../types";
1010
import type { TypeParameterReflection } from "./type-parameter";
1111
import { removeIfPresent } from "../../utils";
1212
import type * as ts from "typescript";
13+
import { ReflectionKind } from "./kind";
1314

1415
/**
1516
* A reflection that represents the root of the project.

src/lib/models/reflections/reference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type * as ts from "typescript";
2-
import { Reflection, ReflectionKind } from "./abstract";
2+
import { Reflection } from "./abstract";
33
import { DeclarationReflection } from "./declaration";
4+
import { ReflectionKind } from "./kind";
45
import type { ProjectReflection } from "./project";
56

67
/**

src/lib/models/reflections/signature.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { Type, ReflectionType, ReferenceType } from "../types";
2-
import {
3-
Reflection,
4-
TraverseProperty,
5-
TraverseCallback,
6-
ReflectionKind,
7-
} from "./abstract";
2+
import { Reflection, TraverseProperty, TraverseCallback } from "./abstract";
83
import type { ParameterReflection } from "./parameter";
94
import type { TypeParameterReflection } from "./type-parameter";
105
import type { DeclarationReflection } from "./declaration";
6+
import type { ReflectionKind } from "./kind";
117

128
export class SignatureReflection extends Reflection {
139
/**

src/lib/models/reflections/type-parameter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Type } from "../types";
2-
import { Reflection, ReflectionKind } from "./abstract";
2+
import { Reflection } from "./abstract";
33
import type { DeclarationReflection } from "./declaration";
4+
import { ReflectionKind } from "./kind";
45

56
export class TypeParameterReflection extends Reflection {
67
override parent?: DeclarationReflection;

src/lib/utils/options/declaration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { LogLevel } from "../loggers";
33
import type { SortStrategy } from "../sort";
44
import { isAbsolute, join, resolve } from "path";
55
import type { EntryPointStrategy } from "../entry-point";
6+
import type { ReflectionKind } from "../../models/reflections/kind";
67

78
export const EmitStrategy = {
89
true: true, // Alias for both, for backwards compatibility until 0.23
@@ -116,6 +117,7 @@ export interface TypeDocOptionMap {
116117
/** @deprecated use validation.invalidLink */
117118
listInvalidSymbolLinks: boolean;
118119
validation: ValidationOptions;
120+
requiredToBeDocumented: (keyof typeof ReflectionKind)[];
119121
}
120122

121123
export type ValidationOptions = {
@@ -128,6 +130,10 @@ export type ValidationOptions = {
128130
* If set, TypeDoc will produce warnings about \{&amp;link\} tags which will produce broken links.
129131
*/
130132
invalidLink: boolean;
133+
/**
134+
* If set, TypeDoc will produce warnings about declarations that do not have doc comments
135+
*/
136+
notDocumented: boolean;
131137
};
132138

133139
/**

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ParameterType, ParameterHint, EmitStrategy } from "../declaration";
44
import { BUNDLED_THEMES, Theme } from "shiki";
55
import { SORT_STRATEGIES } from "../../sort";
66
import { EntryPointStrategy } from "../../entry-point";
7+
import { ReflectionKind } from "../../../models/reflections/kind";
78

89
export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
910
options.addDeclaration({
@@ -342,6 +343,40 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
342343
help: "A list of types which should not produce 'referenced but not documented' warnings.",
343344
type: ParameterType.Array,
344345
});
346+
options.addDeclaration({
347+
name: "requiredToBeDocumented",
348+
help: "A list of reflection kinds that must be documented",
349+
type: ParameterType.Array,
350+
validate(values) {
351+
// this is good enough because the values of the ReflectionKind enum are all numbers
352+
const validValues = Object.values(ReflectionKind).filter(
353+
(v) => typeof v === "string"
354+
);
355+
356+
for (const kind of values) {
357+
if (validValues.includes(kind)) {
358+
throw new Error(
359+
`'${kind}' is an invalid value for 'requiredToBeDocumented'. Must be one of: ${validValues.join(
360+
", "
361+
)}`
362+
);
363+
}
364+
}
365+
},
366+
defaultValue: [
367+
"Enum",
368+
"EnumMember",
369+
"Variable",
370+
"Function",
371+
"Class",
372+
"Interface",
373+
"Property",
374+
"Method",
375+
"GetSignature",
376+
"SetSignature",
377+
"TypeAlias",
378+
],
379+
});
345380

346381
options.addDeclaration({
347382
name: "validation",
@@ -350,6 +385,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
350385
defaults: {
351386
notExported: true,
352387
invalidLink: false,
388+
notDocumented: false,
353389
},
354390
});
355391
}

src/lib/utils/sort.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module
44
*/
55

6-
import { ReflectionKind } from "../models/reflections/abstract";
6+
import { ReflectionKind } from "../models/reflections/kind";
77
import type { DeclarationReflection } from "../models/reflections/declaration";
88

99
export const SORT_STRATEGIES = [

0 commit comments

Comments
 (0)