Skip to content

Commit

Permalink
Ignore parameters of parameters
Browse files Browse the repository at this point in the history
Resolves #2154
  • Loading branch information
Gerrit0 committed Feb 26, 2023
1 parent 0a52e74 commit 37fe883
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@

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

### Thanks!

Expand Down
16 changes: 15 additions & 1 deletion src/lib/validation/documentation.ts
@@ -1,5 +1,6 @@
import {
DeclarationReflection,
ParameterReflection,
ProjectReflection,
Reflection,
ReflectionKind,
Expand Down Expand Up @@ -38,11 +39,24 @@ export function validateDocumentation(
const toProcess = project.getReflectionsByKind(kinds);
const seen = new Set<Reflection>();

while (toProcess.length) {
outer: while (toProcess.length) {
const ref = toProcess.shift()!;
if (seen.has(ref)) continue;
seen.add(ref);

// If there is a parameter inside another parameter, this is probably a callback function.
// TypeDoc doesn't support adding comments with @param to nested parameters, so it seems
// silly to warn about these.
if (ref.kindOf(ReflectionKind.Parameter)) {
let r: Reflection | undefined = ref.parent;
while (r) {
if (r.kindOf(ReflectionKind.Parameter)) {
continue outer;
}
r = r.parent;
}
}

if (ref instanceof DeclarationReflection) {
const signatures =
ref.type instanceof ReflectionType
Expand Down
20 changes: 20 additions & 0 deletions src/test/converter2/validation/callbackParameters.ts
@@ -0,0 +1,20 @@
/**
* Test case from https://github.com/TypeStrong/typedoc/issues/2154
* @param data The data object to add equality to
* @param equals The equality function
* @param hashCode The hash code function
*/
export function gh2154(
data: unknown,
equals: (a: 1, b: 2) => boolean,
hashCode: (data: 3) => number
) {}

export class AnotherTest {
/**
* Property is documented
* @param a test
* @param b another
*/
equals!: (a: 1, b: 2) => boolean;
}
8 changes: 8 additions & 0 deletions src/test/validation.test.ts
Expand Up @@ -206,4 +206,12 @@ describe("validateDocumentation", () => {
);
logger.expectNoOtherMessages();
});

it("Should correctly handle callback parameters", () => {
const project = convertValidationFile("callbackParameters.ts");
const logger = new TestLogger();
validateDocumentation(project, logger, ["Parameter", "Property"]);

logger.expectNoOtherMessages();
});
});

0 comments on commit 37fe883

Please sign in to comment.