From c37dbf6ee9e2e670be1ee1b97b586ef37c35c621 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 8 Aug 2022 15:22:02 -0400 Subject: [PATCH] refactor(diagnostics): simplify some conditionals (#402) - reduce the complexity of the code by decreasing the amount of nesting - note that `print` returns `void` anyway, so calling it within the `return` statement doesn't change anything - and this is within a `void` `forEach` at that too --- src/print-diagnostics.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/print-diagnostics.ts b/src/print-diagnostics.ts index ad319ae..ef49895 100644 --- a/src/print-diagnostics.ts +++ b/src/print-diagnostics.ts @@ -34,13 +34,11 @@ export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], const type = diagnostic.type + " "; if (pretty) - print.call(context, `${diagnostic.formatted}`); - else - { - if (diagnostic.fileLine !== undefined) - print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`); - else - print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`); - } + return print.call(context, `${diagnostic.formatted}`); + + if (diagnostic.fileLine !== undefined) + return print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`); + + return print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`); }); }