From a9037784f76e45b860f9d1d67a8eb59d45af043c Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Wed, 29 Jun 2022 02:23:56 -0400 Subject: [PATCH] fix(diagnostics): `pretty` defaults to `true` in TS 2.9+ - per https://www.typescriptlang.org/tsconfig#pretty - TS 2.9 changed the default to `true`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#--pretty-output-by-default - so this is a legacy remnant of older versions of TS - this is why `tsc` by default pretty prints, even when `pretty` is unset - only if it is _explicitly_ set to `false` does it not do that - so change rpt2's diagnostic printing to be `pretty` by default as well - I think this is a pretty _big_ DX improvement, to be honest - I always thought something was up with the error reporting, but saw that there was code for `pretty`, so didn't quite connect the dots until now - that while there was code for it, the default was wrong, and so unless I set `pretty: true`, I wasn't getting easier to read printing - and given that `pretty: true` is the default, that's a redundant / unnecessary option to set in `tsconfig` that I normally wouldn't ever re-set --- src/index.ts | 4 ++-- src/parse-tsconfig.ts | 2 +- src/print-diagnostics.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 30352ab7..b0220575 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,7 +57,7 @@ const typescript: PluginImpl = (options) => const typecheckFile = (id: string, snapshot: tsTypes.IScriptSnapshot, tcContext: IContext) => { const diagnostics = getDiagnostics(id, snapshot); - printDiagnostics(tcContext, diagnostics, parsedConfig.options.pretty === true); + printDiagnostics(tcContext, diagnostics, parsedConfig.options.pretty !== false); if (diagnostics.length > 0) noErrors = false; @@ -131,7 +131,7 @@ const typescript: PluginImpl = (options) => // printing compiler option errors if (pluginOptions.check) { const diagnostics = convertDiagnostic("options", service.getCompilerOptionsDiagnostics()); - printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true); + printDiagnostics(context, diagnostics, parsedConfig.options.pretty !== false); if (diagnostics.length > 0) noErrors = false; } diff --git a/src/parse-tsconfig.ts b/src/parse-tsconfig.ts index 8fb39f5c..7686dfc9 100644 --- a/src/parse-tsconfig.ts +++ b/src/parse-tsconfig.ts @@ -20,7 +20,7 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions) let loadedConfig: any = {}; let baseDir = pluginOptions.cwd; let configFileName; - let pretty = false; + let pretty = true; if (fileName) { const text = tsModule.sys.readFile(fileName); diff --git a/src/print-diagnostics.ts b/src/print-diagnostics.ts index 770d140c..ad319aea 100644 --- a/src/print-diagnostics.ts +++ b/src/print-diagnostics.ts @@ -4,7 +4,7 @@ import { tsModule } from "./tsproxy"; import { IContext } from "./context"; import { IDiagnostics } from "./tscache"; -export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void +export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty = true): void { diagnostics.forEach((diagnostic) => {