Skip to content

Latest commit

 

History

History
68 lines (45 loc) · 1.02 KB

README.md

File metadata and controls

68 lines (45 loc) · 1.02 KB

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