Skip to content

Commit

Permalink
Merge pull request #13 from cometkim/compact-desc
Browse files Browse the repository at this point in the history
Suggestion: report description in more compact form
  • Loading branch information
lostfictions committed Nov 14, 2023
2 parents 4d63cc4 + 5cbc291 commit b1e0cb6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ export function reportErrors(
): string {
const formattedErrors = errors.map(
({ key, receivedValue, error, defaultUsed, defaultValue }) => {
const message: string[] = [`[${yellow(key)}]:`];
let title = `[${yellow(key)}]:`;

const desc = schemas[key]?.description;
if (desc) {
title += ` ${desc}`;
}

const message: string[] = [title];

if (error instanceof ZodError) {
const { formErrors, fieldErrors } = error.flatten();
Expand Down Expand Up @@ -80,14 +87,6 @@ export function reportErrors(
);
}

const desc = schemas[key]?.description;
if (desc) {
message.push("");
message.push(
`Description of [${yellow(key)}]: ${schemas[key]!.description}`,
);
}

return message.map((l) => indent(l, 2)).join("\n");
},
);
Expand Down

0 comments on commit b1e0cb6

Please sign in to comment.