-
Notifications
You must be signed in to change notification settings - Fork 42
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
Truncate too long output instead of using key #71
base: master
Are you sure you want to change the base?
Conversation
When outputing results the current behavior is to use the key in the output if the identifier would be too long for example: "$f != nil" This instead truncates the value and adds elisis as follows: "ThisIsAReallyLongIdentifierThatWillBeTruncatedInsteadOfReje... != nil" This output is more friendly. Addresses quasilyte#70
@cristaloleg what's your opinion on this? |
I also believe some tools truncate statements in a smart way, so you get |
@@ -189,7 +189,7 @@ func (rr *rulesRunner) renderMessage(msg string, n ast.Node, nodes map[string]as | |||
// Don't interpolate strings that are too long. | |||
var replacement string | |||
if truncate && buf.Len() > 60 { | |||
replacement = key | |||
replacement = string([]rune(buf.String())[:60]) + "..." |
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.
Since we're using the value of 60 here twice, maybe make it a local const? It would be easier to find the connection between these two later.
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.
Another thing is that we're checking for 60 bytes length but then we truncate it to the 60 runes.
We either need to check for the "width" (or runes count) in the first condition or slice the string itself instead of doing string->[]rune->string
.
This example demonstrates that the current solution might panic:
https://play.golang.org/p/8WCl054GxLP
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'm not comfortable with string->[]rune->string that can panic. We should fix that prior to merging this.
When outputing results the current behavior is to use the key in the
output if the identifier would be too long for example:
"$f != nil"
This instead truncates the value and adds elisis as follows:
"ThisIsAReallyLongIdentifierThatWillBeTruncatedInsteadOfReje... != nil"
This output is more friendly.
Addresses #70