False positive when variable is used in select statement
armsnyder opened this issue · comments
Adam Snyder commented
False positive:
package main
import (
"flag"
"fmt"
"time"
)
func main() {
delayPtr := flag.Duration("delay", 0, "")
flag.Parse()
delay := *delayPtr
if delay == 0 {
delay = time.Second
}
select {
case <-time.After(delay):
fmt.Println("hello")
}
}
Linter error:
example/main.go:12:2: variable 'delay' is only used in the if-statement (example/main.go:13:2); consider using short syntax (ifshort)
delay := *delayPtr
^
In a larger example, you can imaging a for-select loop where there is another case like checking if a context is cancelled.
This is possibly related to #17 except instead of assigning to the variable in the select statement, it is read.