time.Sleep is given a small number without a unit, which counts nanoseconds
What it finds
time.Sleep(5): a time.Duration counts nanoseconds, so a plain number sleeps that many nanoseconds, which is next to nothing. A unit was meant, as in time.Sleep(5 * time.Second).
The argument must be an integer literal from 1 to 999, a sleep shorter than a microsecond that no one writes on purpose, and the function Sleep of the package time, resolved through the imports of the file. time.Sleep(0), which only yields, is left alone.
From the rule's source, sleep_without_unit.rs.
package p import ( "time" t "time") const delay = 5 func f(d time.Duration) { time.Sleep(5)tx0 reports: time.Sleep(5) sleeps 5 nanoseconds t.Sleep((100))tx0 reports: sleeps 100 nanoseconds time.Sleep(999)tx0 reports: sleeps 999 nanoseconds time.Sleep(0) time.Sleep(1000) time.Sleep(5 * time.Second) time.Sleep(time.Millisecond) time.Sleep(d) time.Sleep(delay) time.Sleep(0x10)} func g() { time := clock{} time.Sleep(5)} type clock struct{} func (clock) Sleep(int) {} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:sleep-without-unit" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:sleep-without-unit] reason="..."tx0 explain tx0/go:sleep-without-unit shows the same in the terminal. Found a false positive? Report it.