Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls/internal/analysis/modernize: add modernizer for WaitGroup.Go #73059

Closed
adonovan opened this issue Mar 26, 2025 · 1 comment
Closed
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Mar 26, 2025

The existing waitgroup analyzer reports misuses of wg.Add/Done. Now that WaitGroup.Go (#63796) is on course to be approved for go1.25, we should extend the analyzer to also report opportunities to use the new method instead of the old more complex code.

That is, it would report a diagnostic for:

wg.Add(1)
go func() { // "Go statement can be simplified using WaitGroup.Go"
        defer wg.Done()
         ...
}()

and offer a fix that changes it to:

wg.Go(func() {
         ...
})

The criteria should be:

  • wg refers to a WaitGroup;
  • a call to wg.Add directly precedes a go statement with a func literal.
  • the sole use of wg beneath the go statement is a call to wg.Done, either deferred on the first line, or called directly on the last line.

However, modernize is only part of gopls, whereas waitgroup is (soon to be) part of the cmd/vet suite, so some care is required to ensure that only gopls gets the proposed new behavior.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 26, 2025
@gopherbot gopherbot added this to the Unreleased milestone Mar 26, 2025
@adonovan adonovan changed the title x/tools/go/analysis/passes/waitgroup: add modernizer for WaitGroup.Go x/tools/gopls/internal/analysis/modernize: add modernizer for WaitGroup.Go Mar 26, 2025
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Mar 26, 2025
@gabyhelp gabyhelp added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Mar 26, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/661775 mentions this issue: gopls/internal/analysis/modernize: add modernizer for WaitGroup.Go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants