Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10f0ab8

Browse files
committed
added errgroupcheck linter
1 parent90664f6 commit10f0ab8

File tree

12 files changed

+187
-0
lines changed

12 files changed

+187
-0
lines changed

‎.golangci.next.reference.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ linters-settings:
324324
# Default: false
325325
report-no-exported:false
326326

327+
errgroupcheck:
328+
# Check if any sync.errgroup.Group instance is missing a call to the Wait() func.
329+
# Default: true
330+
require-wait:true
331+
327332
errorlint:
328333
# Check whether fmt.Errorf uses the %w verb for formatting errors.
329334
# See the https://github.com/polyfloyd/go-errorlint for caveats.

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/GaijinEntertainment/go-exhaustruct/v3v3.3.0
1717
github.com/OpenPeeDeeP/depguard/v2v2.2.0
1818
github.com/alecthomas/go-check-sumtypev0.1.4
19+
github.com/alexbagnolini/errgroupcheckv0.1.2
1920
github.com/alexkohler/nakedret/v2v2.0.4
2021
github.com/alexkohler/preallocv1.0.0
2122
github.com/alingse/asasalintv0.0.11

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎jsonschema/golangci.next.jsonschema.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@
312312
"durationcheck",
313313
"errcheck",
314314
"errchkjson",
315+
"errgroupcheck",
315316
"errname",
316317
"errorlint",
317318
"execinquery",
@@ -865,6 +866,17 @@
865866
}
866867
}
867868
},
869+
"errgroupcheck": {
870+
"type":"object",
871+
"additionalProperties":false,
872+
"properties": {
873+
"require-wait": {
874+
"description":"Check if any sync.errgroup.Group instance is missing a call to the Wait() func.",
875+
"type":"boolean",
876+
"default":true
877+
}
878+
}
879+
},
868880
"errorlint": {
869881
"type":"object",
870882
"additionalProperties":false,

‎pkg/config/linters_settings.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ type LintersSettings struct {
208208
DupWordDupWordSettings
209209
ErrcheckErrcheckSettings
210210
ErrChkJSONErrChkJSONSettings
211+
ErrGroupCheckErrGroupCheckSettings
211212
ErrorLintErrorLintSettings
212213
ExhaustiveExhaustiveSettings
213214
ExhaustructExhaustructSettings
@@ -382,6 +383,10 @@ type ErrChkJSONSettings struct {
382383
ReportNoExportedbool`mapstructure:"report-no-exported"`
383384
}
384385

386+
typeErrGroupCheckSettingsstruct {
387+
RequireWaitbool`mapstructure:"require-wait"`
388+
}
389+
385390
typeErrorLintSettingsstruct {
386391
Errorfbool`mapstructure:"errorf"`
387392
ErrorfMultibool`mapstructure:"errorf-multi"`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package errgroupcheck
2+
3+
import (
4+
"github.com/alexbagnolini/errgroupcheck"
5+
"github.com/golangci/golangci-lint/pkg/config"
6+
"github.com/golangci/golangci-lint/pkg/goanalysis"
7+
"golang.org/x/tools/go/analysis"
8+
)
9+
10+
funcNew(cfg*config.ErrGroupCheckSettings)*goanalysis.Linter {
11+
varsetts=errgroupcheck.DefaultSettings()
12+
13+
ifcfg!=nil {
14+
setts.RequireWait=cfg.RequireWait
15+
}
16+
17+
cfgMap:=map[string]map[string]any{}
18+
19+
analyzer:=errgroupcheck.NewAnalyzer(setts)
20+
21+
ifcfg!=nil {
22+
cfgMap[analyzer.Name]=map[string]any{
23+
"require-wait":cfg.RequireWait,
24+
}
25+
}
26+
27+
returngoanalysis.NewLinter(
28+
analyzer.Name,
29+
analyzer.Doc,
30+
[]*analysis.Analyzer{analyzer},
31+
nil,
32+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
33+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package errgroupcheck
2+
3+
import (
4+
"testing"
5+
6+
"github.com/golangci/golangci-lint/test/testshared/integration"
7+
)
8+
9+
funcTestFromTestdata(t*testing.T) {
10+
integration.RunTestdata(t)
11+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//golangcitest:args -Eerrgroupcheck
2+
//golangcitest:config_path testdata/errgroupcheck_wait.yml
3+
package testdata
4+
5+
import (
6+
"context"
7+
8+
"golang.org/x/sync/errgroup"
9+
)
10+
11+
funcErrgroupWithWait() {
12+
eg:= errgroup.Group{}
13+
14+
eg.Go(func()error {
15+
returnnil
16+
})
17+
18+
eg.Go(func()error {
19+
returnnil
20+
})
21+
22+
_=eg.Wait()
23+
}
24+
25+
funcErrgroupMissingWait() {
26+
eg:= errgroup.Group{}// want "errgroup 'eg' does not have Wait called"
27+
28+
eg.Go(func()error {
29+
returnnil
30+
})
31+
32+
eg.Go(func()error {
33+
returnnil
34+
})
35+
}
36+
37+
funcErrgroupContextWithWait() {
38+
eg,_:=errgroup.WithContext(context.Background())
39+
40+
eg.Go(func()error {
41+
returnnil
42+
})
43+
44+
eg.Go(func()error {
45+
returnnil
46+
})
47+
48+
_=eg.Wait()
49+
}
50+
51+
funcErrgroupContextMissingWait() {
52+
eg,_:=errgroup.WithContext(context.Background())// want "errgroup 'eg' does not have Wait called"
53+
54+
eg.Go(func()error {
55+
returnnil
56+
})
57+
58+
eg.Go(func()error {
59+
returnnil
60+
})
61+
}
62+
63+
funcErrgroupMultipleScopesWithWait() {
64+
eg:= errgroup.Group{}
65+
66+
eg.Go(func()error {
67+
returnnil
68+
})
69+
70+
eg.Go(func()error {
71+
eg2:= errgroup.Group{}
72+
73+
eg2.Go(func()error {
74+
returnnil
75+
})
76+
77+
returneg2.Wait()
78+
})
79+
80+
_=eg.Wait()
81+
}
82+
83+
funcErrgroupMultipleScopesMissingWait() {
84+
eg:= errgroup.Group{}
85+
86+
eg.Go(func()error {
87+
returnnil
88+
})
89+
90+
eg.Go(func()error {
91+
eg2:= errgroup.Group{}// want "errgroup 'eg2' does not have Wait called"
92+
93+
eg2.Go(func()error {
94+
returnnil
95+
})
96+
97+
returnnil
98+
})
99+
100+
_=eg.Wait()
101+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
errgroupcheck:
3+
require-wait:true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
modulewait
2+
3+
go1.19
4+
5+
requiregolang.org/x/syncv0.7.0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp