Skip to content

Commit

Permalink
refactor: convert renderAssociations to functional
Browse files Browse the repository at this point in the history
  • Loading branch information
alvis committed Oct 15, 2023
1 parent 4510a5f commit 58b2b38
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions source/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ export function renderError(
* @returns a rendered string to print
*/
function renderAssociations(error: unknown): string | null {
const blocks: string[] = [];

if (error instanceof Xception && error.namespace) {
blocks.push(chalk.blue.underline(error.namespace));
}

if (error instanceof Xception && error.tags.length) {
blocks.push(...error.tags.map((tag) => chalk.cyan.bold(tag)));
}
const blocks: string[] =
error instanceof Xception
? [
...(error.namespace ? [chalk.blue.underline(error.namespace)] : []),
...error.tags.map((tag) => chalk.cyan.bold(tag)),
]
: [];

return blocks.length ? '\n ' + blocks.join(' ') : null;
}
Expand Down

0 comments on commit 58b2b38

Please sign in to comment.