dgryski/semgrep-go

Accidental nanoseconds

ainar-g opened this issue · 3 comments

The classic:

c := &Config{
        // …

        // Whoops!  TTL has the type time.Duration.
        // Wanted sixty seconds, got sixty nanoseconds!
        TTL: 60,
}

I'm pretty sure that 95 % of such raw time.Duration assignments are errors, since not a lot of people actually deal with nanosecond precision in Go.

I thought staticcheck caught these?

Not yet, although there is an issue about it. See dominikh/go-tools#222.

Staticcheck currently only catches time.Sleep calls: https://staticcheck.io/docs/checks/#SA1004