Skip to content

Commit

Permalink
Fix notDocumented validation false positive
Browse files Browse the repository at this point in the history
Resolves #2291
  • Loading branch information
Gerrit0 committed Dec 28, 2023
1 parent a2739c7 commit 800b97e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### Bug Fixes

- `notDocumented` validation will no longer require documentation for data within parameters that cannot be documented via `@param`, #2291.
- Type parameters will now be resolved for arrow-methods on classes like regular class methods, #2320.
- TypeDoc now inherits `typedocOptions` fields from extended tsconfig files, #2334.
- Methods which return function types no longer have duplicated comments, #2336.
Expand Down
16 changes: 6 additions & 10 deletions src/lib/validation/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ export function validateDocumentation(
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 we're a non-parameter inside a parameter, we shouldn't care. Parameters don't get deeply documented
let r: Reflection | undefined = ref.parent;
while (r) {
if (r.kindOf(ReflectionKind.Parameter)) {
continue outer;
}
r = r.parent;
}

// Type aliases own their comments, even if they're function-likes.
Expand Down
14 changes: 14 additions & 0 deletions src/test/converter2/issues/gh2291.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Parses a JSON string to the specified type.
*/
export function safeParse<T>(
guard: (o: unknown) => o is T,
json: string,
): T | undefined {
try {
const o = JSON.parse(json) as unknown;
return guard(o) ? o : undefined;
} catch {
return undefined;
}
}
7 changes: 7 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,13 @@ describe("Issue Tests", () => {
);
});

it("Does not warn on notDocumented edge case #2291", () => {
app.options.setValue("validation", { notDocumented: true });
const project = convert();
app.validate(project);
logger.expectNoOtherMessages();
});

it("Supports TS 5.0 #2296", () => {
const project = convert();
const names = query(project, "names");
Expand Down
16 changes: 12 additions & 4 deletions src/test/utils/options/readers/tsconfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ describe("Options - TSConfigReader", () => {
options.addReader(new TSConfigReader());
const logger = new TestLogger();

async function readWithProject(project: Project, reset = true) {
async function readWithProject(
project: Project,
reset = true,
noErrors = true,
) {
if (reset) {
options.reset();
}
logger.reset();
options.setValue("tsconfig", project.cwd);
project.addFile("temp.ts", "export {}");
project.write();
await options.read(logger);
if (noErrors) {
logger.expectNoOtherMessages();
}
project.rm();
}

Expand All @@ -39,7 +47,7 @@ describe("Options - TSConfigReader", () => {
it(name, async () => {
const project = tempdirProject();
project.addJsonFile("tsconfig.json", file);
await readWithProject(project);
await readWithProject(project, true, false);
equal(logger.hasErrors(), true, "No error was logged");
});
}
Expand Down Expand Up @@ -69,7 +77,7 @@ describe("Options - TSConfigReader", () => {
it("Errors if a tsconfig file cannot be parsed", async () => {
const project = tempdirProject();
project.addFile("tsconfig.json", '{"test}');
await readWithProject(project);
await readWithProject(project, true, false);
logger.expectMessage("error: *");
});

Expand Down Expand Up @@ -164,7 +172,7 @@ describe("Options - TSConfigReader", () => {
project.addJsonFile("tsconfig.json", {});
project.addJsonFile("tsdoc.json", tsdoc);

await readWithProject(project, reset);
await readWithProject(project, reset, false);
cb?.();
logger.expectNoOtherMessages();
}
Expand Down

0 comments on commit 800b97e

Please sign in to comment.