Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--pretty-er output by default #23408

Merged
merged 6 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ namespace ts {
category: Diagnostics.Command_line_Options,
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather we do not add a new flag if we can. i think auto is just pretty === undefined.

if we really need a new value i would make pretty take boolean | "auto"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean | "auto" | "simple" | "styled"? (Where boolean toggles between auto and styled).

name: "diagnosticStyle",
type: createMapFromTemplate({
auto: DiagnosticStyle.Auto,
pretty: DiagnosticStyle.Pretty,
simple: DiagnosticStyle.Simple,
}),
},
{
name: "preserveWatchOutput",
type: "boolean",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ namespace ts {
newLine: string;
useCaseSensitiveFileNames: boolean;
write(s: string): void;
writeOutputIsTty?(): boolean;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a reasonable name @weswigham?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TTY, not Tty.

readFile(path: string, encoding?: string): string | undefined;
getFileSize?(path: string): number;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
Expand Down Expand Up @@ -561,6 +562,9 @@ namespace ts {
write(s: string): void {
process.stdout.write(s);
},
writeOutputIsTty() {
return process.stdout.isTTY;
},
readFile,
writeFile,
watchFile: getWatchFile(),
Expand Down
11 changes: 9 additions & 2 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ namespace ts {

let reportDiagnostic = createDiagnosticReporter(sys);
function updateReportDiagnostic(options: CompilerOptions) {
if (options.pretty) {
if (shouldBePretty(options)) {
reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
}
}

function shouldBePretty(options: CompilerOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now there are two CLI flags that can tell tsc it's pretty. What if the user provides tsc --pretty false --diagnosticStyle pretty or tsc --pretty true --diagnosticStyle simple? Should there be a warning for providing both?

if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) {
return !!sys.writeOutputIsTty && sys.writeOutputIsTty();
}
return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty;
Copy link
Contributor

@mhegazy mhegazy Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! options.pretty

}

function padLeft(s: string, length: number) {
while (s.length < length) {
s = " " + s;
Expand Down Expand Up @@ -159,7 +166,7 @@ namespace ts {
}

function createWatchStatusReporter(options: CompilerOptions) {
return ts.createWatchStatusReporter(sys, !!options.pretty);
return ts.createWatchStatusReporter(sys, shouldBePretty(options));
}

function createWatchOfConfigFile(configParseResult: ParsedCommandLine, optionsToExtend: CompilerOptions) {
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4193,7 +4193,8 @@ namespace ts {
preserveSymlinks?: boolean;
/* @internal */ preserveWatchOutput?: boolean;
project?: string;
/* @internal */ pretty?: DiagnosticStyle;
/* @internal */ pretty?: boolean;
/* @internal */ diagnosticStyle?: DiagnosticStyle;
reactNamespace?: string;
jsxFactory?: string;
removeComments?: boolean;
Expand Down Expand Up @@ -4293,8 +4294,9 @@ namespace ts {

/* @internal */
export const enum DiagnosticStyle {
Simple,
Auto,
Pretty,
Simple,
}

/** Either a parsed command line or a parsed tsconfig.json */
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,7 @@ declare namespace ts {
newLine: string;
useCaseSensitiveFileNames: boolean;
write(s: string): void;
writeOutputIsTty?(): boolean;
readFile(path: string, encoding?: string): string | undefined;
getFileSize?(path: string): number;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,7 @@ declare namespace ts {
newLine: string;
useCaseSensitiveFileNames: boolean;
write(s: string): void;
writeOutputIsTty?(): boolean;
readFile(path: string, encoding?: string): string | undefined;
getFileSize?(path: string): number;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
Expand Down