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

cmd/vet: suggest fix for "fmt.Println call has possible formatting directive" #47872

Open
LexRiver opened this issue Aug 21, 2021 · 5 comments
Open

Comments

@LexRiver
Copy link

@LexRiver LexRiver commented Aug 21, 2021

I'm about the warning message

fmt.Println("variable=%v", v)
fmt.Println call has possible formatting directive %v

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

fmt.Println call has possible formatting directive %v. Did you mean fmt.Printf?

btw why not add fmt.Printlnf also?

@fzipp
Copy link
Contributor

@fzipp fzipp commented Aug 21, 2021

btw why not add fmt.Printlnf also?

See previous discussion under #46190

Loading

@seankhliao seankhliao changed the title More details for warning message "fmt.Println call has possible formatting directive" cmd/vet: suggest fix for "fmt.Println call has possible formatting directive" Aug 23, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Aug 23, 2021

Loading

@timothy-king
Copy link
Contributor

@timothy-king timothy-king commented Aug 24, 2021

#46190 (comment) brings up good reasons not to suggest fmt.Printf when starting from fmt.Println. I am worried folks will accept suggested changes as is. So I am hesitant to suggest fmt.Printf as a replacement.

In my opinion it's counter-intuitive.

Is there an alternative wording that you think might be clear?

Loading

@LexRiver
Copy link
Author

@LexRiver LexRiver commented Aug 25, 2021

Something like
Formatting directive %v found in unformattable method call fmt.Println

Loading

@joe-mann
Copy link

@joe-mann joe-mann commented Aug 25, 2021

#46190 (comment) brings up good reasons not to suggest fmt.Printf when starting from fmt.Println. I am worried folks will accept suggested changes as is. So I am hesitant to suggest fmt.Printf as a replacement.

I agree with this, and would be reluctant to accept the proposal for that reason. However maybe there's a way forward where vet could be a little more selective about when to offer the suggestion, Did you mean fmt.Printf?.

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 fmt.Printf:

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 vet could print fmt.Println call has possible formatting directive %v. Did you mean fmt.Printf? for the former, but the existing fmt.Println call has possible formatting directive %v in the latter scenario, could be a useful enhancement?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants