Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,42 @@ linters:
default-case-required: true

exhaustruct:
# List of regular expressions to match struct packages and their names.
# Regular expressions must match complete canonical struct package/name/structname.
# If this list is empty, all structs are tested.
# List of regular expressions to match type names that should be processed.
# Anonymous structs can be matched by '<anonymous>' alias.
#
# Each regular expression must match the full type name, including package path.
# For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`,
# but not `http\.Cookie`.
# Default: []
include:
- '.+\.Test'
- 'example\.com/package\.ExampleStruct[\d]{1,2}'
# List of regular expressions to exclude struct packages and their names from checks.
# Regular expressions must match complete canonical struct package/name/structname.
# List of regular expressions to match type names that should be excluded from processing.
# Anonymous structs can be matched by '<anonymous>' alias.
# Has precedence over `include`.
# Each regular expression must match the full type name, including package path.
# For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`,
# but not `http\.Cookie`.
# Default: []
exclude:
- '.+/cobra\.Command$'
# Allows empty structures, effectively excluding them from the check.
# Default: false
allow-empty: true
# List of regular expressions to match type names that should be allowed to be empty.
# Anonymous structs can be matched by '<anonymous>' alias.
# Each regular expression must match the full type name, including package path.
# For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`,
# but not `http\.Cookie`.
# Default: []
allow-empty-rx:
- '.*/http\.Cookie'
# Allows empty structures in return statements.
# Default: false
allow-empty-returns: true
# Allows empty structures in variable declarations.
# Default: false
allow-empty-declarations: true

fatcontext:
# Check for potential fat contexts in struct pointers.
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.24.0
require (
4d63.com/gocheckcompilerdirectives v1.3.0
4d63.com/gochecknoglobals v0.2.2
dev.gaijin.team/go/exhaustruct/v4 v4.0.0
github.com/4meepo/tagalign v1.4.3
github.com/Abirdcfly/dupword v0.1.6
github.com/AlwxSin/noinlineerr v1.0.5
Expand All @@ -13,7 +14,6 @@ require (
github.com/Antonboom/testifylint v1.6.1
github.com/BurntSushi/toml v1.5.0
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1
github.com/OpenPeeDeeP/depguard/v2 v2.2.1
github.com/alecthomas/chroma/v2 v2.20.0
github.com/alecthomas/go-check-sumtype v0.3.1
Expand Down Expand Up @@ -145,6 +145,7 @@ require (

require (
codeberg.org/chavacava/garif v0.2.0 // indirect
dev.gaijin.team/go/golib v0.6.0 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/alfatraining/structtag v1.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand Down Expand Up @@ -210,9 +211,8 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/exp/typeparams v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/text v0.27.0 // indirect
Expand Down
23 changes: 10 additions & 13 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,28 @@
"items": {
"type": "string"
}
},
"allow-empty": {
"description": "Allows empty structures, effectively excluding them from the check.",
"type": "boolean",
"default": false
},
"allow-empty-rx": {
"description": "List of regular expressions to match type names that should be allowed to be empty.",
"type": "array",
"items": {
"type": "string"
}
},
"allow-empty-returns": {
"description": "Allows empty structures in return statements.",
"type": "boolean",
"default": false
},
"allow-empty-declarations": {
"description": "Allows empty structures in variable declarations.",
"type": "boolean",
"default": false
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,12 @@ type ExhaustiveSettings struct {
}

type ExhaustructSettings struct {
Include []string `mapstructure:"include"`
Exclude []string `mapstructure:"exclude"`
Include []string `mapstructure:"include"`
Exclude []string `mapstructure:"exclude"`
AllowEmpty bool `mapstructure:"allow-empty"`
AllowEmptyRx []string `mapstructure:"allow-empty-rx"`
AllowEmptyReturns bool `mapstructure:"allow-empty-returns"`
AllowEmptyDeclarations bool `mapstructure:"allow-empty-declarations"`
}

type FatcontextSettings struct {
Expand Down
15 changes: 9 additions & 6 deletions pkg/golinters/exhaustruct/exhaustruct.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package exhaustruct

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

"github.com/golangci/golangci-lint/v2/pkg/config"
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
"github.com/golangci/golangci-lint/v2/pkg/golinters/internal"
)

func New(settings *config.ExhaustructSettings) *goanalysis.Linter {
var include, exclude []string

cfg := exhaustruct.Config{}
if settings != nil {
include = settings.Include
exclude = settings.Exclude
cfg.IncludeRx = settings.Include
cfg.ExcludeRx = settings.Exclude
cfg.AllowEmpty = settings.AllowEmpty
cfg.AllowEmptyRx = settings.AllowEmptyRx
cfg.AllowEmptyReturns = settings.AllowEmptyReturns
cfg.AllowEmptyDeclarations = settings.AllowEmptyDeclarations
}

analyzer, err := exhaustruct.NewAnalyzer(include, exclude)
analyzer, err := exhaustruct.NewAnalyzer(cfg)
if err != nil {
internal.LinterLogger.Fatalf("exhaustruct configuration: %v", err)
}
Expand Down
Loading