From: Alan Donovan Date: Fri, 28 Mar 2025 22:04:16 +0000 (-0400) Subject: cmd/vet: add waitgroup analyzer X-Git-Tag: go1.25rc1~566 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dceb77a33676c8a4efb9c63267c351268848de6f;p=gostls13.git cmd/vet: add waitgroup analyzer + relnote Fixes #18022 Change-Id: I92d1939e9d9f16824655c6c909a5f58ed9500014 Reviewed-on: https://go-review.googlesource.com/c/go/+/661519 Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Commit-Queue: Alan Donovan Reviewed-by: Dmitri Shuralyov Auto-Submit: Alan Donovan --- diff --git a/doc/next/3-tools.md b/doc/next/3-tools.md index 977c89670c..886852b784 100644 --- a/doc/next/3-tools.md +++ b/doc/next/3-tools.md @@ -24,3 +24,12 @@ specifying the command's current version. ### Cgo {#cgo} +### Vet {#vet} + + + +The `go vet` command now includes the +[waitgroup](https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/waitgroup) +analyzer, which reports misplaced calls to [sync.WaitGroup.Add]. + + diff --git a/src/cmd/go/internal/test/flagdefs.go b/src/cmd/go/internal/test/flagdefs.go index 0292c19d82..372142467b 100644 --- a/src/cmd/go/internal/test/flagdefs.go +++ b/src/cmd/go/internal/test/flagdefs.go @@ -77,4 +77,5 @@ var passAnalyzersToVet = map[string]bool{ "unreachable": true, "unsafeptr": true, "unusedresult": true, + "waitgroup": true, } diff --git a/src/cmd/vet/doc.go b/src/cmd/vet/doc.go index 5b2fa3d72f..8e72c252ed 100644 --- a/src/cmd/vet/doc.go +++ b/src/cmd/vet/doc.go @@ -59,6 +59,7 @@ To list the available checks, run "go tool vet help": unreachable check for unreachable code unsafeptr check for invalid conversions of uintptr to unsafe.Pointer unusedresult check for unused results of calls to some functions + waitgroup check for misuses of sync.WaitGroup For details and flags of a particular check, such as printf, run "go tool vet help printf". diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index efb6916015..c9d611f927 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -44,7 +44,7 @@ import ( "golang.org/x/tools/go/analysis/passes/unreachable" "golang.org/x/tools/go/analysis/passes/unsafeptr" "golang.org/x/tools/go/analysis/passes/unusedresult" - _ "golang.org/x/tools/go/analysis/passes/waitgroup" // vendoring placeholder + "golang.org/x/tools/go/analysis/passes/waitgroup" ) func main() { @@ -86,6 +86,7 @@ func main() { unreachable.Analyzer, unsafeptr.Analyzer, unusedresult.Analyzer, + waitgroup.Analyzer, ) // It's possible that unitchecker will exit early. In diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index 3860895a0a..2f89784dfc 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -70,8 +70,8 @@ func TestVet(t *testing.T) { "unmarshal", "unsafeptr", "unused", + "waitgroup", } { - pkg := pkg t.Run(pkg, func(t *testing.T) { t.Parallel()