Skip to content

Check sync.Mutex.Unlock is called before exit from a function

License

Notifications You must be signed in to change notification settings

prg-titech/mutexunlock

Repository files navigation

pkg mutexunlock

test

Automated fix tool for missing sync.Mutex or sync.RWMutex unlocks.

Installation

# go install github.com/Qs-F/mutexunlock

Usgae

Lint (without automated fix)

Run in the target project (if you are not sure, run in the directory which contains go.mod)

# go vet -vettool=$(which mutexunlock) .

Fmt (with automated fix)

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 .

Example Behavior

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!
}

Auhtor

Qs-F

License

MIT License

About

Check sync.Mutex.Unlock is called before exit from a function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •