Skip to content

Commit

Permalink
Do not show the additional file/errors table when there's 1 file with…
Browse files Browse the repository at this point in the history
… many errors (#47345)

* Use relative paths for the end of compile report

* Have a tighter suffix for multiple errors in one file

* Review feedback

* Refactors, and adds color

* Update baselinies
  • Loading branch information
Orta Therox committed Jan 19, 2022
1 parent 9f64839 commit 113a681
Show file tree
Hide file tree
Showing 39 changed files with 153 additions and 144 deletions.
3 changes: 1 addition & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4165,7 +4165,6 @@
"category": "Message",
"code": 6041
},

"Generates corresponding '.map' file.": {
"category": "Message",
"code": 6043
Expand Down Expand Up @@ -4949,7 +4948,7 @@
"category": "Message",
"code": 6259
},
"Found {0} errors in 1 file.": {
"Found {0} errors in the same file, starting at: {1}": {
"category": "Message",
"code": 6260
},
Expand Down
26 changes: 20 additions & 6 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ namespace ts {
Diagnostics.Found_0_errors_Watching_for_file_changes;
}

function prettyPathForFileError(error: ReportFileInError, cwd: string) {
const line = formatColorAndReset(":" + error.line, ForegroundColorEscapeSequences.Grey);
if (pathIsAbsolute(error.fileName) && pathIsAbsolute(cwd)) {
return getRelativePathFromDirectory(cwd, error.fileName, /* ignoreCase */ false) + line;
}

return error.fileName + line;
}

export function getErrorSummaryText(
errorCount: number,
filesInError: readonly (ReportFileInError | undefined)[],
Expand All @@ -140,22 +149,27 @@ namespace ts {
const nonNilFiles = filesInError.filter(fileInError => fileInError !== undefined);
const distinctFileNamesWithLines = nonNilFiles.map(fileInError => `${fileInError!.fileName}:${fileInError!.line}`)
.filter((value, index, self) => self.indexOf(value) === index);

const firstFileReference = nonNilFiles[0] && prettyPathForFileError(nonNilFiles[0], host.getCurrentDirectory());

const d = errorCount === 1 ?
createCompilerDiagnostic(
filesInError[0] !== undefined ?
Diagnostics.Found_1_error_in_1 :
Diagnostics.Found_1_error,
errorCount,
distinctFileNamesWithLines[0]) :
firstFileReference) :
createCompilerDiagnostic(
distinctFileNamesWithLines.length === 0 ?
Diagnostics.Found_0_errors :
distinctFileNamesWithLines.length === 1 ?
Diagnostics.Found_0_errors_in_1_file :
Diagnostics.Found_0_errors_in_the_same_file_starting_at_Colon_1 :
Diagnostics.Found_0_errors_in_1_files,
errorCount,
distinctFileNamesWithLines.length);
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : ""}`;
distinctFileNamesWithLines.length === 1 ? firstFileReference : distinctFileNamesWithLines.length);

const suffix = distinctFileNamesWithLines.length > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "";
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${suffix}`;
}

function createTabularErrorsDisplay(filesInError: (ReportFileInError | undefined)[], host: HasCurrentDirectory) {
Expand All @@ -180,8 +194,8 @@ namespace ts {
" ".repeat(leftPaddingGoal - errorCountDigitsLength)
: "";

const relativePath = getRelativePathFromDirectory(host.getCurrentDirectory(), file!.fileName, /* ignoreCase */ false);
tabularData += `${leftPadding}${errorCount} ${relativePath}:${file!.line}\n`;
const fileRef = prettyPathForFileError(file!, host.getCurrentDirectory());
tabularData += `${leftPadding}${errorCount} ${fileRef}\n`;
});

return tabularData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,5 @@
}
}

Found 2 errors in 1 file.
Found 2 errors in the same file, starting at: tests/cases/compiler/deeplyNestedAssignabilityIssue.ts:22

Errors Files
2 tests/cases/compiler/deeplyNestedAssignabilityIssue.ts:22
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@
Found 6 errors in 3 files.

Errors Files
2 tests/cases/compiler/file1.ts:1
2 tests/cases/compiler/file2.ts:1
2 tests/cases/compiler/file3.ts:1
2 tests/cases/compiler/file1.ts:1
2 tests/cases/compiler/file2.ts:1
2 tests/cases/compiler/file3.ts:1
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
Found 2 errors in 2 files.

Errors Files
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:1
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:1
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@
Found 6 errors in 2 files.

Errors Files
3 tests/cases/compiler/file1.ts:2
3 tests/cases/compiler/file2.ts:2
3 tests/cases/compiler/file1.ts:2
3 tests/cases/compiler/file2.ts:2
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
Found 2 errors in 2 files.

Errors Files
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:1
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:1
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@
Found 6 errors in 2 files.

Errors Files
3 tests/cases/compiler/file1.ts:3
3 tests/cases/compiler/file2.ts:4
3 tests/cases/compiler/file1.ts:3
3 tests/cases/compiler/file2.ts:4
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@
Found 6 errors in 2 files.

Errors Files
3 tests/cases/compiler/file1.ts:3
3 tests/cases/compiler/file2.ts:5
3 tests/cases/compiler/file1.ts:3
3 tests/cases/compiler/file2.ts:5
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
Found 2 errors in 2 files.

Errors Files
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:3
1 tests/cases/compiler/file1.ts:1
1 tests/cases/compiler/file2.ts:3
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
!!! error TS2345: Type '{ default: () => void; }' provides no match for the signature '(): void'.
!!! related TS7038 tests/cases/compiler/index.ts:1:1: Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

Found 1 error in tests/cases/compiler/index.ts:3
Found 1 error in tests/cases/compiler/index.ts:3

Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@
Found 21 errors in 2 files.

Errors Files
18 tests/cases/compiler/a.ts:1
3 tests/cases/compiler/b.ts:1
18 tests/cases/compiler/a.ts:1
3 tests/cases/compiler/b.ts:1
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ c: string; }'.
};

Found 1 error in tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts:2
Found 1 error in tests/cases/compiler/multiLineContextDiagnosticWithPretty.ts:2

Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/compiler/index.ts:1:11: The parser expected to find a '}' to match the '{' token here.
Found 1 error in tests/cases/compiler/index.ts:2
Found 1 error in tests/cases/compiler/index.ts:2

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
}
Found 3 errors in 1 file.
Found 3 errors in the same file, starting at: tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:3

Errors Files
3 tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:3
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Output::
   ~~~~~~~~~~~~~~~~~


Found 1 error in src/project/tsconfig.json:6
Found 1 error in src/project/tsconfig.json[90m:6[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pkg3/src/keys.ts
pkg3/src/index.ts
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'

Found 1 error in /user/username/projects/myproject/pkg3/src/keys.ts:2
Found 1 error in pkg3/src/keys.ts[90m:2[0m



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pkg3/src/keys.ts
pkg3/src/index.ts
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'

Found 1 error in /user/username/projects/myproject/pkg3/src/keys.ts:2
Found 1 error in pkg3/src/keys.ts[90m:2[0m



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down Expand Up @@ -313,8 +313,8 @@ Output::
Found 2 errors in 2 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated


Expand Down Expand Up @@ -500,7 +500,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down Expand Up @@ -634,7 +634,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down Expand Up @@ -675,7 +675,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down Expand Up @@ -722,9 +722,9 @@ Output::
Found 3 errors in 3 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/noChangeFileWithEmitSpecificError.ts:1
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
1 src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated


Expand Down Expand Up @@ -939,9 +939,9 @@ Output::
Found 3 errors in 3 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/noChangeFileWithEmitSpecificError.ts:1
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
1 src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated


Expand Down Expand Up @@ -977,8 +977,8 @@ Output::
Found 2 errors in 2 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped


Expand Down Expand Up @@ -1014,8 +1014,8 @@ Output::
Found 2 errors in 2 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped


Expand Down Expand Up @@ -1056,9 +1056,9 @@ Output::
Found 3 errors in 3 files.

Errors Files
1 src/project/src/directUse.ts:2
1 src/project/src/indirectUse.ts:2
1 src/project/src/noChangeFileWithEmitSpecificError.ts:1
1 src/project/src/directUse.ts[90m:2[0m
1 src/project/src/indirectUse.ts[90m:2[0m
1 src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated


Expand Down Expand Up @@ -1217,7 +1217,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down Expand Up @@ -1388,7 +1388,7 @@ Output::
   ~~~~~~~~~~~~~~~~~~


Found 1 error in /src/project/src/noChangeFileWithEmitSpecificError.ts:1
Found 1 error in src/project/src/noChangeFileWithEmitSpecificError.ts[90m:1[0m

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

Expand Down

0 comments on commit 113a681

Please sign in to comment.