-
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
x/tools/go/analysis/passes/printf: suggest Printf calls without args to use Print #69515
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
If this is about tightening printf check further to flag even when the format string is const and requires no verb, I think this should be in proposals since this will cause churns (with unknown benefit). See the latest proposal & implementation (for 1.24) to tighten the analysis. #60529 |
This is decent style suggestion to give folks, but vet is not the right home for it. https://github.com/golang/go/blob/master/src/cmd/vet/README#L11-L14
|
OK, I understand, thank you 😄 |
I am modestly in favor of making suggestions like this in gopls (just not vet). Not sure if it should live in the |
There's nothing wrong with using printf with literal strings that don't contain formatting operators, and I don't think we should nag users of vet (or even gopls) for doing so. (There isn't even a performance justification: though Print is faster than Printf, the difference only matters for long strings, and it is extremely rare to printf long string literals repeatedly.) |
Go version
1.23.1
Output of
go env
in your module/workspace:What did you do?
Run the "printf" pass with
go vet
orgolangci-lint
What did you see happen?
It doesn't detect anything for
fmt.Printf("some message")
.What did you expect to see?
Maybe it should suggest to rewrite
fmt.Printf("some message")
=>fmt.Print("some message")
, because it doesn't use any argument.The text was updated successfully, but these errors were encountered: