From 6f626651468dd4a18ff5ddefaa5cd77c51f8703c Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 29 Jul 2022 12:57:11 -0400 Subject: [PATCH] refactor(diagnostics): simplify some conditionals - 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 ad319aea..ef49895f 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)}`); }); }