-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(45713) Improve error report summaries #45742
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
Changes from 1 commit
0638417
08906dd
1af84d2
f543c40
b2988e7
db56f9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,26 +148,31 @@ namespace ts { | |
| distinctFileNamesWithLines[0]) : | ||
| createCompilerDiagnostic( | ||
| distinctFileNamesWithLines.length === 0 ? | ||
| Diagnostics.Found_0_errors : | ||
| Diagnostics.Found_0_errors : | ||
| distinctFileNamesWithLines.length === 1 ? | ||
| Diagnostics.Found_0_errors_in_1_file : | ||
| Diagnostics.Found_0_errors_in_1_files, | ||
| errorCount, | ||
| distinctFileNamesWithLines.length); | ||
| return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : ''}`; | ||
| return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : ""}`; | ||
| } | ||
|
|
||
| function createTabularErrorsDisplay(filesInError: (ReportFileInError | undefined)[]) { | ||
| const BASE_LEFT_PADDING = 6; | ||
| let tabularData = ""; | ||
| const distinctFiles = filesInError.filter((value, index, self) => index === self.findIndex(file => file!.fileName === value!.fileName)); | ||
| if(distinctFiles.length === 0) return tabularData; | ||
|
|
||
| const headerRow = "Errors Files\n"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs to be a localized message~
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, (which I think we probably do need to do) then the numbers about length etc will need to not be hardcoded anymore. For example the Chinese version of "errors" might be 1-2 characters characters wide.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't think of that, yes this should probably be localised.
May I ask how you mean by "hardcoded" here? Do you mean we don't need to bother so much about left padding?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By hardcoding, I mean Armed with google translate, perhaps this is a reasonable design answer: Where tsc pulls out the longest length of a value from either the highest number of errors in a file or the translated word for "errors", allowing people to have a Does that feel reasonable to you?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will work for me too. I'll work on it and see what I can come up with. Thank you for the explanation. |
||
| tabularData += headerRow; | ||
| distinctFiles.forEach(file => { | ||
| const errorCountForFile = countWhere(filesInError, fileInError => fileInError!.fileName === file!.fileName); | ||
| tabularData += ` ${errorCountForFile} ${file!.fileName}:${file!.line}\n`; | ||
| }) | ||
| const errorCountDigitsLength = Math.log(errorCountForFile) * Math.LOG10E + 1 | 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a less abstract alternative could be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @orta I agree that could also work. I'm happy to update it, it's probably easier to read. I just felt it was a little strange to convert to a string to get the length and nothing else. |
||
| const leftPadding = errorCountDigitsLength < BASE_LEFT_PADDING ? | ||
| " ".repeat(BASE_LEFT_PADDING - errorCountDigitsLength) | ||
| : ""; | ||
| tabularData += `${leftPadding}${errorCountForFile} ${file!.fileName}:${file!.line}\n`; | ||
| }); | ||
|
|
||
| return tabularData; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a dense statement, not sure I have any good ideas off the top off my head on how to improve it though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look back at it and see what I could do. I also try to avoid double ternaries if I can avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me, wes also said this is pretty common in the codebase, so the original is also fine 👍🏻