forked from TypeStrong/typedoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation.ts
38 lines (34 loc) · 1.23 KB
/
documentation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as path from "path";
import * as ts from "typescript";
import { ProjectReflection, ReflectionKind } from "../models";
import { Logger, normalizePath } from "../utils";
export function validateDocumentation(
project: ProjectReflection,
logger: Logger,
requiredToBeDocumented: readonly (keyof typeof ReflectionKind)[]
): void {
const kinds = requiredToBeDocumented.reduce(
(prev, cur) => (prev |= ReflectionKind[cur]),
0
);
for (const ref of project.getReflectionsByKind(kinds)) {
const symbol = project.getSymbolFromReflection(ref);
if (!ref.comment && symbol?.declarations) {
const decl = symbol.declarations[0];
const sourceFile = decl.getSourceFile();
const { line } = ts.getLineAndCharacterOfPosition(
sourceFile,
decl.getStart()
);
const file = normalizePath(
path.relative(process.cwd(), sourceFile.fileName)
);
if (file.startsWith(`node_modules${path.sep}`)) {
continue;
}
logger.warn(
`${ref.name}, defined at ${file}:${line+1}, does not have any documentation.`
);
}
}
}