Skip to content

Commit 74919d7

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 fdee49b commit 74919d7

File tree

5 files changed

+64
-31
lines changed

5 files changed

+64
-31
lines changed

.golangci.next.reference.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,45 @@ linters:
502502
default-case-required: true
503503

504504
exhaustruct:
505-
# List of regular expressions to match struct packages and their names.
506-
# Regular expressions must match complete canonical struct package/name/structname.
507-
# If this list is empty, all structs are tested.
505+
# List of regular expressions to match type names that should be
506+
# processed. Anonymous structs can be matched by '<anonymous>' alias.
507+
#
508+
# Each regular expression must match the full type name, including package path.
509+
# For example, to match type `net/http.Cookie` regular expression should be
510+
# `.*/http\.Cookie`, but not `http\.Cookie`.
511+
#
508512
# Default: []
509513
include:
510514
- '.+\.Test'
511515
- 'example\.com/package\.ExampleStruct[\d]{1,2}'
512-
# List of regular expressions to exclude struct packages and their names from checks.
513-
# Regular expressions must match complete canonical struct package/name/structname.
516+
# List of regular expressions to match type names that should be
517+
# excluded from processing. Anonymous structs can be matched by '<anonymous>'
518+
# alias.
519+
# Has precedence over IncludeRx.
520+
# Each regular expression must match the full type name, including package path.
521+
# For example, to match type `net/http.Cookie` regular expression should be
522+
# `.*/http\.Cookie`, but not `http\.Cookie`.
514523
# Default: []
515524
exclude:
516525
- '.+/cobra\.Command$'
526+
# AllowEmpty allows empty structures, effectively excluding them from the check.
527+
# Default: false
528+
allow-empty: false
529+
# List of regular expressions to match type names that should be
530+
# allowed to be empty. Anonymous structs can be matched by '<anonymous>'
531+
# alias.
532+
# Each regular expression must match the full type name, including package path.
533+
# For example, to match type `net/http.Cookie` regular expression should be
534+
# `.*/http\.Cookie`, but not `http\.Cookie`.
535+
# Default: []
536+
allow-empty-rx:
537+
- '.*/http\.Cookie'
538+
# Allows empty structures in return statements.
539+
# Default: false
540+
allow-empty-returns: false
541+
# Allows empty structures in variable declarations.
542+
# Default: false
543+
allow-empty-declarations: false
517544

518545
fatcontext:
519546
# Check for potential fat contexts in struct pointers.

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module github.com/golangci/golangci-lint/v2
22

3-
go 1.23.0
3+
go 1.24
4+
5+
toolchain go1.24.5
46

57
require (
68
4d63.com/gocheckcompilerdirectives v1.3.0
79
4d63.com/gochecknoglobals v0.2.2
10+
dev.gaijin.team/go/exhaustruct/v4 v4.0.0
811
github.com/4meepo/tagalign v1.4.3
912
github.com/Abirdcfly/dupword v0.1.6
1013
github.com/AlwxSin/noinlineerr v1.0.5
@@ -13,7 +16,6 @@ require (
1316
github.com/Antonboom/testifylint v1.6.1
1417
github.com/BurntSushi/toml v1.5.0
1518
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
16-
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1
1719
github.com/OpenPeeDeeP/depguard/v2 v2.2.1
1820
github.com/alecthomas/chroma/v2 v2.20.0
1921
github.com/alecthomas/go-check-sumtype v0.3.1
@@ -145,6 +147,7 @@ require (
145147

146148
require (
147149
codeberg.org/chavacava/garif v0.2.0 // indirect
150+
dev.gaijin.team/go/golib v0.6.0 // indirect
148151
github.com/Masterminds/semver/v3 v3.3.1 // indirect
149152
github.com/alfatraining/structtag v1.0.0 // indirect
150153
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
@@ -210,9 +213,8 @@ require (
210213
github.com/valyala/bytebufferpool v1.0.0 // indirect
211214
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
212215
github.com/yusufpapurcu/wmi v1.2.4 // indirect
213-
go.uber.org/atomic v1.7.0 // indirect
214-
go.uber.org/multierr v1.6.0 // indirect
215-
go.uber.org/zap v1.24.0 // indirect
216+
go.uber.org/multierr v1.10.0 // indirect
217+
go.uber.org/zap v1.27.0 // indirect
216218
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
217219
golang.org/x/exp/typeparams v0.0.0-20250620022241-b7579e27df2b // indirect
218220
golang.org/x/text v0.27.0 // indirect

go.sum

Lines changed: 10 additions & 13 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
@@ -421,8 +421,12 @@ type ExhaustiveSettings struct {
421421
}
422422

423423
type ExhaustructSettings struct {
424-
Include []string `mapstructure:"include"`
425-
Exclude []string `mapstructure:"exclude"`
424+
Include []string `mapstructure:"include"`
425+
Exclude []string `mapstructure:"exclude"`
426+
AllowEmpty bool `mapstructure:"allow-empty"`
427+
AllowEmptyRx []string `mapstructure:"allow-empty-rx"`
428+
AllowEmptyReturns bool `mapstructure:"allow-empty-returns"`
429+
AllowEmptyDeclarations bool `mapstructure:"allow-empty-declarations"`
426430
}
427431

428432
type FatcontextSettings struct {

pkg/golinters/exhaustruct/exhaustruct.go

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

33
import (
4-
exhaustruct "github.com/GaijinEntertainment/go-exhaustruct/v3/analyzer"
4+
exhaustruct "dev.gaijin.team/go/exhaustruct/v4/analyzer"
55

66
"github.com/golangci/golangci-lint/v2/pkg/config"
77
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
88
"github.com/golangci/golangci-lint/v2/pkg/golinters/internal"
99
)
1010

1111
func New(settings *config.ExhaustructSettings) *goanalysis.Linter {
12-
var include, exclude []string
13-
12+
cfg := exhaustruct.Config{}
1413
if settings != nil {
15-
include = settings.Include
16-
exclude = settings.Exclude
14+
cfg.IncludeRx = settings.Include
15+
cfg.ExcludeRx = settings.Exclude
16+
cfg.AllowEmpty = settings.AllowEmpty
17+
cfg.AllowEmptyRx = settings.AllowEmptyRx
18+
cfg.AllowEmptyReturns = settings.AllowEmptyReturns
19+
cfg.AllowEmptyDeclarations = settings.AllowEmptyDeclarations
1720
}
1821

19-
analyzer, err := exhaustruct.NewAnalyzer(include, exclude)
22+
analyzer, err := exhaustruct.NewAnalyzer(cfg)
2023
if err != nil {
2124
internal.LinterLogger.Fatalf("exhaustruct configuration: %v", err)
2225
}

0 commit comments

Comments
 (0)