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

new check: time.Add with unused return value #1353

Closed
tux21b opened this issue Jan 18, 2023 · 1 comment
Closed

new check: time.Add with unused return value #1353

tux21b opened this issue Jan 18, 2023 · 1 comment

Comments

@tux21b
Copy link

tux21b commented Jan 18, 2023

Hi, thanks for your great work. A common error in our code base that happens over and over again is something like that:

t := time.Now()
t.Add(1 * time.Hour)
fmt.Println(t)

Since time.Time is a "value type", Add() does not modify the current value and returns a new time object, which is unused in the code above. Calling time.Add() without using the return value is always an error.

There are probably lots of similar functions in the standard library. The same check might be used to for time.In, strings.ToLower and strings.ToUpper as well.

Are you interested in a check like that, how should it be called and should I try to prepare a MR for it?

@tux21b tux21b added the needs-triage Newly filed issue that needs triage label Jan 18, 2023
@dominikh
Copy link
Owner

We already have SA4017 for flagging calls like that. It should be a simple matter of extending the list of functions it looks for.

I'll put it on my todo list. To be very frank, a PR would probably be more work for me than just making the change.

@dominikh dominikh added enhancement and removed needs-triage Newly filed issue that needs triage labels Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants