Automated fix tool for missing sync.Mutex
or sync.RWMutex
unlocks.
# go install github.com/Qs-F/mutexunlock
Run in the target project (if you are not sure, run in the directory which contains go.mod
)
# go vet -vettool=$(which mutexunlock) .
For some reasons go vet
command does not provide to pass flags to external vettool.
Run in the target project (if you are not sure, run in the directory which contains go.mod
)
# mutexunlock -fix .
If target code is like this:
type S struct {
mu sync.Mutex
}
func (s *S) D() {
s.mu.Lock()
// You forgot s.mu.Unlock() here!
}
After Fmt (with automated fix),
type S struct {
mu sync.Mutex
}
func (s *S) D() {
s.mu.Lock()
+ s.mu.Unlock()
// You forgot s.mu.Unlock() here!
}
Qs-F
MIT License