Skip to content

Commit 37fe883

Browse files
committed
Ignore parameters of parameters
Resolves #2154
1 parent 0a52e74 commit 37fe883

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- Fix crash when converting `export default undefined`, #2175.
1111
- Fix error in console when clicking on headings in the readme, #2170.
12+
- TypeDoc will now ignore parameters of callback parameters when validating that all parameters have documentation, #2154.
1213

1314
### Thanks!
1415

src/lib/validation/documentation.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DeclarationReflection,
3+
ParameterReflection,
34
ProjectReflection,
45
Reflection,
56
ReflectionKind,
@@ -38,11 +39,24 @@ export function validateDocumentation(
3839
const toProcess = project.getReflectionsByKind(kinds);
3940
const seen = new Set<Reflection>();
4041

41-
while (toProcess.length) {
42+
outer: while (toProcess.length) {
4243
const ref = toProcess.shift()!;
4344
if (seen.has(ref)) continue;
4445
seen.add(ref);
4546

47+
// If there is a parameter inside another parameter, this is probably a callback function.
48+
// TypeDoc doesn't support adding comments with @param to nested parameters, so it seems
49+
// silly to warn about these.
50+
if (ref.kindOf(ReflectionKind.Parameter)) {
51+
let r: Reflection | undefined = ref.parent;
52+
while (r) {
53+
if (r.kindOf(ReflectionKind.Parameter)) {
54+
continue outer;
55+
}
56+
r = r.parent;
57+
}
58+
}
59+
4660
if (ref instanceof DeclarationReflection) {
4761
const signatures =
4862
ref.type instanceof ReflectionType
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Test case from https://github.com/TypeStrong/typedoc/issues/2154
3+
* @param data The data object to add equality to
4+
* @param equals The equality function
5+
* @param hashCode The hash code function
6+
*/
7+
export function gh2154(
8+
data: unknown,
9+
equals: (a: 1, b: 2) => boolean,
10+
hashCode: (data: 3) => number
11+
) {}
12+
13+
export class AnotherTest {
14+
/**
15+
* Property is documented
16+
* @param a test
17+
* @param b another
18+
*/
19+
equals!: (a: 1, b: 2) => boolean;
20+
}

src/test/validation.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,12 @@ describe("validateDocumentation", () => {
206206
);
207207
logger.expectNoOtherMessages();
208208
});
209+
210+
it("Should correctly handle callback parameters", () => {
211+
const project = convertValidationFile("callbackParameters.ts");
212+
const logger = new TestLogger();
213+
validateDocumentation(project, logger, ["Parameter", "Property"]);
214+
215+
logger.expectNoOtherMessages();
216+
});
209217
});

0 commit comments

Comments
 (0)