mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
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.
47 lines
1.2 KiB
TypeScript
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)}`);
|
|
}
|
|
});
|
|
}
|