Skip to content

Commit

Permalink
fix(diagnostics): pretty defaults to true in TS 2.9+ (#372)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Jul 6, 2022
1 parent 8334c9b commit f048e77
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const typescript: PluginImpl<RPT2Options> = (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;
Expand Down Expand Up @@ -131,7 +131,7 @@ const typescript: PluginImpl<RPT2Options> = (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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/print-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down

0 comments on commit f048e77

Please sign in to comment.