-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/vet: suggest fix for "fmt.Println call has possible formatting directive" #47872
Comments
See previous discussion under #46190 |
#46190 (comment) brings up good reasons not to suggest
Is there an alternative wording that you think might be clear? |
Something like |
I agree with this, and would be reluctant to accept the proposal for that reason. However maybe there's a way forward where I would suggest that something like this, where the apparent value to be formatted is an identifier, is likely to be a valid candidate for replacement with v := "value"
fmt.Println("variable=%v", v) Whereas this, where the apparent value to be formatted is a (string) literal, is more likely to be the intended usage: fmt.Println("variable=%v", "value") So maybe |
Branching on cases adds more complexity to the checker and it is not clear that it is a better solution than a single clear message. I will keep this open for a while in hope that we can come up with such a message. |
Okay, just to throw a completely different idea into the mix on the odd chance it's better than I imagine ('cause I don't necessarily think this is a decent idea), why not perform the formatting, appending a new line to the result? Clearly, the caller intends to do formatting. And the issue happens often enough that people seem to expect this behavior. So why not embrace it, while still remaining true to the 'ln' component of the function's name? |
I am somewhat coming around @LexRiver's suggestion in #47872 (comment) . My suggested wording:
It is less likely to be misinterpreted. It is not as pithy though. This is about twice an long as the current message:
@adonovan @zpavlinovic thoughts? |
This would break compatibility promise with existing |
This seems to be suggesting the change of |
Why not just
I get that it indirectly suggests what is wrong, but IMO it is less confusing than the current message. Or something like
if it is not too hard to get the string representation of the offending Println call. |
Summarizing approaches suggested above:
|
I think this wording works. |
Looks good to me as well. |
Change https://go.dev/cl/491075 mentions this issue: |
Change https://go.dev/cl/493617 mentions this issue: |
Originally the message said: Println call has possible formatting directive %v For golang/go#47872 it was extended to: Println call contains %v, possibly intended as Printf formatting directive The only new information content in this message is the mention of Printf. All the rest of the wording is just longer words. This CL preserves the Printf mention but goes back to the more concise text: Println call has possible Printf formatting directive %v Fixes golang/go#47872. Change-Id: Id514644d0cdbb4c983797e756be5e4444230cc1c Reviewed-on: https://go-review.googlesource.com/c/tools/+/493617 TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
I'm about the warning message
In my opinion it's counter-intuitive. "Off course it has, that is what I want!" -)
Seems like I'm not alone:
https://stackoverflow.com/questions/53961617/call-has-possible-formatting-directive
I think error message should be something like this
btw why not add
fmt.Printlnf
also?The text was updated successfully, but these errors were encountered: