Detecting identifiers in struct declarations and/or arguments to anonymous functions.
- Dominant language
- Go
- Stars
- 1
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
The findings in [this issue](https://github.com/github-vet/rangeclosure-findings/issues/127) can be avoided by better static analysis.
Consider the below code.
```go
for _, port := range ports {
wg.Add(1)
go func(p int, wg *sync.WaitGroup) {
done := make(chan struct{})
s.jobChan <- portJob{
open: openChan,
closed: closedChan,
filtered: filteredChan,
ip: host,
port: p,
done: done,
ctx: ctx,
}
<-done
wg.Done()
}(port, wg)
}
```
The static analysis is triggering for one of two reasons:
1) either 'port' is mentioned as the label in a struct
2) or it's finding the use of `port` as an argument to the function in the goroutine ~(I think it's probably this one)~.
Both are false-positives for our purposes so it'd be preferred if the analysis ignored these sorts of examples automatically.
Contributor guide
Assessment
This issue has not been assessed yet.