Another false positive case
gitalek opened this issue · comments
gitalek commented
func Run(tasks []Task, n, m int) error {
chTasks := make(chan Task)
chErrSignal := make(chan struct{}, len(tasks))
done := make(chan struct{})
careAboutErrors := m > 0
var errCounter int
go func() {
defer close(chTasks)
for _, task := range tasks {
select {
case <-chErrSignal:
if careAboutErrors {
errCounter++
}
default:
}
if careAboutErrors && errCounter >= m {
close(done)
return
}
chTasks <- task
}
}()
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
go worker(done, chTasks, chErrSignal, &wg)
}
wg.Wait()
close(chErrSignal)
if careAboutErrors && errCounter >= m {
return ErrErrorsLimitExceeded
}
return nil
}
check output:
variable 'careAboutErrors' is only used in the if-statement (run.go:48:2); consider using short syntax (ifshort)
careAboutErrors := m > 0
Adam Snyder commented
I don't see where careAboutErrors
is used except for in your if statement. Isn't this a true positive?
gitalek commented
I don't see where
careAboutErrors
is used except for in your if statement. Isn't this a true positive?
Hello! Thanks for your attention, I have fixed the sample code