-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78a738f
commit ed149aa
Showing
12 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package errgroupcheck | ||
|
||
import ( | ||
"github.com/alexbagnolini/errgroupcheck" | ||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/goanalysis" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func New(cfg *config.ErrGroupCheckSettings) *goanalysis.Linter { | ||
var setts = errgroupcheck.DefaultSettings() | ||
|
||
if cfg != nil { | ||
setts.RequireWait = cfg.RequireWait | ||
} | ||
|
||
cfgMap := map[string]map[string]any{} | ||
|
||
analyzer := errgroupcheck.NewAnalyzer(setts) | ||
|
||
if cfg != nil { | ||
cfgMap[analyzer.Name] = map[string]any{ | ||
"require-wait": cfg.RequireWait, | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
analyzer.Name, | ||
analyzer.Doc, | ||
[]*analysis.Analyzer{analyzer}, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package errgroupcheck | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golangci/golangci-lint/test/testshared/integration" | ||
) | ||
|
||
func TestFromTestdata(t *testing.T) { | ||
integration.RunTestdata(t) | ||
} |
101 changes: 101 additions & 0 deletions
101
pkg/golinters/errgroupcheck/testdata/errgroupcheck_wait.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//golangcitest:args -Eerrgroupcheck | ||
//golangcitest:config_path testdata/errgroupcheck_wait.yml | ||
package testdata | ||
|
||
import ( | ||
"context" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
func ErrgroupWithWait() { | ||
eg := errgroup.Group{} | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
_ = eg.Wait() | ||
} | ||
|
||
func ErrgroupMissingWait() { | ||
eg := errgroup.Group{} // want "errgroup 'eg' does not have Wait called" | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
} | ||
|
||
func ErrgroupContextWithWait() { | ||
eg, _ := errgroup.WithContext(context.Background()) | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
_ = eg.Wait() | ||
} | ||
|
||
func ErrgroupContextMissingWait() { | ||
eg, _ := errgroup.WithContext(context.Background()) // want "errgroup 'eg' does not have Wait called" | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
} | ||
|
||
func ErrgroupMultipleScopesWithWait() { | ||
eg := errgroup.Group{} | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
eg2 := errgroup.Group{} | ||
|
||
eg2.Go(func() error { | ||
return nil | ||
}) | ||
|
||
return eg2.Wait() | ||
}) | ||
|
||
_ = eg.Wait() | ||
} | ||
|
||
func ErrgroupMultipleScopesMissingWait() { | ||
eg := errgroup.Group{} | ||
|
||
eg.Go(func() error { | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
eg2 := errgroup.Group{} // want "errgroup 'eg2' does not have Wait called" | ||
|
||
eg2.Go(func() error { | ||
return nil | ||
}) | ||
|
||
return nil | ||
}) | ||
|
||
_ = eg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters-settings: | ||
errgroupcheck: | ||
require-wait: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module wait | ||
|
||
go 1.19 | ||
|
||
require golang.org/x/sync v0.7.0 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters