rollup-plugin-typescript2/src/print-diagnostics.ts
Warren Seine 5b629f17e8 Update diagnostic message according to standard tool parsing. (#151)
MSBuild and many other tools / IDEs will correctly parse the message if ":" is added right after the error code.

See https://blogs.msdn.microsoft.com/msbuild/2006/11/02/msbuild-visual-studio-aware-error-messages-and-message-formats/ for reference.
2019-05-17 13:22:53 -06:00

47 lines
1.2 KiB
TypeScript

import { tsModule } from "./tsproxy";
import { red, white, yellow } from "colors/safe";
import { IContext } from "./context";
import { IDiagnostics } from "./tscache";
import * as _ from "lodash";
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void
{
_.each(diagnostics, (diagnostic) =>
{
let print;
let color;
let category;
switch (diagnostic.category)
{
case tsModule.DiagnosticCategory.Message:
print = context.info;
color = white;
category = "";
break;
case tsModule.DiagnosticCategory.Error:
print = context.error;
color = red;
category = "error";
break;
case tsModule.DiagnosticCategory.Warning:
default:
print = context.warn;
color = yellow;
category = "warning";
break;
}
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)}`);
}
});
}