copywaitgroup

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 6 Imported by: 0

README

copywaitgroup

test_and_lint

copywaitgroup finds a func that passes sync.WaitGroup as a value instead of a pointer

Instruction

go install github.com/sivchari/copywaitgroup/cmd/copywaitgroup

Usage

package main

import (
	"sync"
)

var globalWait sync.WaitGroup

func g(wg sync.WaitGroup) {
	wg.Done()
}

func pg(wg *sync.WaitGroup) {
	wg.Done()
}

func main() {
	{
		var wg sync.WaitGroup
		a := 1

		wg.Add(1)
		go func(a int, wg sync.WaitGroup) { // want "`wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!"
			println(a)
			wg.Done()
		}(a, wg)
		wg.Wait()

		wg.Add(1)
		go func(a int, wg *sync.WaitGroup) { // ok
			println(a)
			wg.Done()
		}(a, &wg)
		wg.Wait()

		wg.Add(1)
		go func() { // ok
			wg.Done()
		}()
		wg.Wait()
	}

	{
		var wg sync.WaitGroup
		wg.Add(2)
		go g(wg)   // want "`wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!"
		go pg(&wg) // ok
		wg.Wait()
	}

	{
		go g(globalWait) // ok
	}
}
fish
go vet -vettool=(which copywaitgroup) ./...

./main.go:23:3: `wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
./main.go:40:3: `wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
bash
$ go vet -vettool=`which copywaitgroup` ./...

./main.go:23:3: `wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
./main.go:40:3: `wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!

CI

CircleCI
- run:
    name: Install copywaitgroup
    command: go get github.com/sivchari/copywaitgroup

- run:
    name: Run copywaitgroup
    command: go vet -vettool=`which copywaitgroup` ./...
GitHub Actions
- name: Install copywaitgroup
  run: go get github.com/sivchari/copywaitgroup

- name: Run copywaitgroup
  run: go vet -vettool=`which copywaitgroup` ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "copywaitgroup",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is the copywaitgroup analyzer.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL