Skip to content

Commit 1870d9d

Browse files
committed
feat: upgrade exhaustruct to v4
- analyzer package is now distributed via vanity import as `dev.gaijin.team/go/exhaustruct/v4`. - version introduced new features which, in turn, required usage of structure as configuration causing major version bump.
1 parent 2691aac commit 1870d9d

File tree

5 files changed

+81
-43
lines changed

5 files changed

+81
-43
lines changed

.golangci.next.reference.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,18 +532,45 @@ linters-settings:
532532
default-case-required: true
533533

534534
exhaustruct:
535-
# List of regular expressions to match struct packages and their names.
536-
# Regular expressions must match complete canonical struct package/name/structname.
537-
# If this list is empty, all structs are tested.
535+
# List of regular expressions to match type names that should be
536+
# processed. Anonymous structs can be matched by '<anonymous>' alias.
537+
#
538+
# Each regular expression must match the full type name, including package path.
539+
# For example, to match type `net/http.Cookie` regular expression should be
540+
# `.*/http\.Cookie`, but not `http\.Cookie`.
541+
#
538542
# Default: []
539543
include:
540544
- '.+\.Test'
541545
- 'example\.com/package\.ExampleStruct[\d]{1,2}'
542-
# List of regular expressions to exclude struct packages and their names from checks.
543-
# Regular expressions must match complete canonical struct package/name/structname.
546+
# List of regular expressions to match type names that should be
547+
# excluded from processing. Anonymous structs can be matched by '<anonymous>'
548+
# alias.
549+
# Has precedence over IncludeRx.
550+
# Each regular expression must match the full type name, including package path.
551+
# For example, to match type `net/http.Cookie` regular expression should be
552+
# `.*/http\.Cookie`, but not `http\.Cookie`.
544553
# Default: []
545554
exclude:
546555
- '.+/cobra\.Command$'
556+
# AllowEmpty allows empty structures, effectively excluding them from the check.
557+
# Default: false
558+
allow-empty: false
559+
# List of regular expressions to match type names that should be
560+
# allowed to be empty. Anonymous structs can be matched by '<anonymous>'
561+
# alias.
562+
# Each regular expression must match the full type name, including package path.
563+
# For example, to match type `net/http.Cookie` regular expression should be
564+
# `.*/http\.Cookie`, but not `http\.Cookie`.
565+
# Default: []
566+
allow-empty-rx:
567+
- '.*/http\.Cookie'
568+
# Allows empty structures in return statements.
569+
# Default: false
570+
allow-empty-returns: false
571+
# Allows empty structures in variable declarations.
572+
# Default: false
573+
allow-empty-declarations: false
547574

548575
fatcontext:
549576
# Check for potential fat contexts in struct pointers.

go.mod

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23.0
55
require (
66
4d63.com/gocheckcompilerdirectives v1.3.0
77
4d63.com/gochecknoglobals v0.2.2
8+
dev.gaijin.team/go/exhaustruct/v4 v4.0.0
89
github.com/4meepo/tagalign v1.4.2
910
github.com/Abirdcfly/dupword v0.1.3
1011
github.com/Antonboom/errname v1.0.0
@@ -13,7 +14,6 @@ require (
1314
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
1415
github.com/Crocmagnon/fatcontext v0.7.1
1516
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
16-
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1
1717
github.com/OpenPeeDeeP/depguard/v2 v2.2.1
1818
github.com/alecthomas/go-check-sumtype v0.3.1
1919
github.com/alexkohler/nakedret/v2 v2.0.5
@@ -125,16 +125,17 @@ require (
125125
go-simpler.org/musttag v0.13.0
126126
go-simpler.org/sloglint v0.9.0
127127
go.uber.org/automaxprocs v1.6.0
128-
golang.org/x/mod v0.24.0
129-
golang.org/x/sys v0.31.0
130-
golang.org/x/tools v0.31.0
128+
golang.org/x/mod v0.27.0
129+
golang.org/x/sys v0.34.0
130+
golang.org/x/tools v0.35.0
131131
gopkg.in/yaml.v3 v3.0.1
132132
honnef.co/go/tools v0.6.1
133133
mvdan.cc/gofumpt v0.7.0
134134
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f
135135
)
136136

137137
require (
138+
dev.gaijin.team/go/golib v0.6.0 // indirect
138139
github.com/Masterminds/semver/v3 v3.3.0 // indirect
139140
github.com/beorn7/perks v1.0.1 // indirect
140141
github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
@@ -191,13 +192,14 @@ require (
191192
github.com/tklauser/numcpus v0.6.1 // indirect
192193
github.com/valyala/bytebufferpool v1.0.0 // indirect
193194
github.com/yusufpapurcu/wmi v1.2.4 // indirect
194-
go.uber.org/atomic v1.7.0 // indirect
195-
go.uber.org/multierr v1.6.0 // indirect
196-
go.uber.org/zap v1.24.0 // indirect
195+
go.uber.org/multierr v1.10.0 // indirect
196+
go.uber.org/zap v1.27.0 // indirect
197197
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
198198
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
199-
golang.org/x/sync v0.12.0 // indirect
199+
golang.org/x/sync v0.16.0 // indirect
200200
golang.org/x/text v0.22.0 // indirect
201+
golang.org/x/tools/go/expect v0.1.1-deprecated // indirect
202+
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated // indirect
201203
google.golang.org/protobuf v1.36.5 // indirect
202204
gopkg.in/ini.v1 v1.67.0 // indirect
203205
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,12 @@ type ExhaustiveSettings struct {
432432
}
433433

434434
type ExhaustructSettings struct {
435-
Include []string `mapstructure:"include"`
436-
Exclude []string `mapstructure:"exclude"`
435+
Include []string `mapstructure:"include"`
436+
Exclude []string `mapstructure:"exclude"`
437+
AllowEmpty bool `mapstructure:"allow-empty"`
438+
AllowEmptyRx []string `mapstructure:"allow-empty-rx"`
439+
AllowEmptyReturns bool `mapstructure:"allow-empty-returns"`
440+
AllowEmptyDeclarations bool `mapstructure:"allow-empty-declarations"`
437441
}
438442

439443
type FatcontextSettings struct {

pkg/golinters/exhaustruct/exhaustruct.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package exhaustruct
22

33
import (
4-
"github.com/GaijinEntertainment/go-exhaustruct/v3/analyzer"
4+
"dev.gaijin.team/go/exhaustruct/v4/analyzer"
55
"golang.org/x/tools/go/analysis"
66

77
"github.com/golangci/golangci-lint/pkg/config"
@@ -10,13 +10,17 @@ import (
1010
)
1111

1212
func New(settings *config.ExhaustructSettings) *goanalysis.Linter {
13-
var include, exclude []string
13+
cfg := analyzer.Config{}
1414
if settings != nil {
15-
include = settings.Include
16-
exclude = settings.Exclude
15+
cfg.IncludeRx = settings.Include
16+
cfg.ExcludeRx = settings.Exclude
17+
cfg.AllowEmpty = settings.AllowEmpty
18+
cfg.AllowEmptyRx = settings.AllowEmptyRx
19+
cfg.AllowEmptyReturns = settings.AllowEmptyReturns
20+
cfg.AllowEmptyDeclarations = settings.AllowEmptyDeclarations
1721
}
1822

19-
a, err := analyzer.NewAnalyzer(include, exclude)
23+
a, err := analyzer.NewAnalyzer(cfg)
2024
if err != nil {
2125
internal.LinterLogger.Fatalf("exhaustruct configuration: %v", err)
2226
}

0 commit comments

Comments
 (0)