Skip to content

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

@tux21b

Description

@tux21b

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions