Skip to content

Commit c37dbf6

Browse files
authored
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
1 parent bbed47e commit c37dbf6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/print-diagnostics.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[],
3434
const type = diagnostic.type + " ";
3535

3636
if (pretty)
37-
print.call(context, `${diagnostic.formatted}`);
38-
else
39-
{
40-
if (diagnostic.fileLine !== undefined)
41-
print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
42-
else
43-
print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
44-
}
37+
return print.call(context, `${diagnostic.formatted}`);
38+
39+
if (diagnostic.fileLine !== undefined)
40+
return print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
41+
42+
return print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
4543
});
4644
}

0 commit comments

Comments
 (0)