Skip to content
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

Open
pierrre opened this issue Sep 18, 2024 · 6 comments
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@pierrre
Copy link

pierrre commented Sep 18, 2024

Go version

1.23.1

Output of go env in your module/workspace:

no relevant

What did you do?

Run the "printf" pass with go vet or golangci-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.

@seankhliao seankhliao changed the title golang.org/x/tools/go/analysis/passes/printf: suggest change to Print x/tools/go/analysis/passes/printf: suggest Printf calls without args to use Print Sep 18, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 18, 2024
@gopherbot gopherbot added this to the Unreleased milestone Sep 18, 2024
@hyangah
Copy link
Contributor

hyangah commented Sep 18, 2024

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

@timothy-king
Copy link
Contributor

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

Vet's checks are about correctness, not style. A vet check must identify real or
potential bugs that could cause incorrect compilation or execution. A check that
only identifies stylistic points or alternative correct approaches to a situation
is not acceptable.

@pierrre
Copy link
Author

pierrre commented Sep 19, 2024

OK, I understand, thank you 😄

@pierrre pierrre closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
@timothy-king
Copy link
Contributor

timothy-king commented Sep 19, 2024

I am modestly in favor of making suggestions like this in gopls (just not vet). Not sure if it should live in the printf package or not. @findleyr

@timothy-king timothy-king reopened this Sep 19, 2024
@adonovan
Copy link
Member

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants