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

proposal: cmd/vet: warn on unused AppendFormat return value #63689

Open
1f604 opened this issue Oct 23, 2023 · 2 comments
Open

proposal: cmd/vet: warn on unused AppendFormat return value #63689

1f604 opened this issue Oct 23, 2023 · 2 comments
Labels
Milestone

Comments

@1f604
Copy link

1f604 commented Oct 23, 2023

Currently the compiler will throw an error if the return value of append is not used, but it does not error or even warn if the return value of time.AppendFormat is not used, even though AppendFormat has the same semantics as append.

https://go.dev/play/p/IpxJrcX3FkT

If someone calls AppendFormat without using the return value, that is always an error, because it does nothing.

I looked for linters that would catch this issue and could not find any.

EDIT: I tried to add it to go vet unusedresult but I couldn't get it to work...is it that unusedresult still only works for pure functions as stated in #14972 ?

@1f604 1f604 added the Proposal label Oct 23, 2023
@gopherbot gopherbot added this to the Proposal milestone Oct 23, 2023
@bcmills
Copy link
Contributor

bcmills commented Oct 23, 2023

(See also #20803.)

@timothy-king
Copy link
Contributor

It seems reasonable to me to include time.AppendFormat in unusedresult's list of functions to warn on: funcs. The function does seem directly analogous to append. This function could be called just for a side-effect to write into a slice with sufficient capacity (just like append), in which case we are requesting users write _ = time.AppendFormat(b, ...) (again just like append).

I think it is unlikely adding time.AppendFormat to the list would cause a noticeable performance problem. This covers most of the frequency concern (README).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants