diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index f74cf71fe791..0184ca29eb48 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -502,18 +502,45 @@ 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 '' 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 '' + # alias. + # Has precedence over IncludeRx. + # 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$' + # AllowEmpty allows empty structures, effectively excluding them from the check. + # Default: false + allow-empty: false + # List of regular expressions to match type names that should be + # allowed to be empty. Anonymous structs can be matched by '' + # 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: false + # Allows empty structures in variable declarations. + # Default: false + allow-empty-declarations: false fatcontext: # Check for potential fat contexts in struct pointers. diff --git a/go.mod b/go.mod index 55331f20869e..0c7eb1d9a8a7 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,13 @@ module github.com/golangci/golangci-lint/v2 -go 1.23.0 +go 1.24 + +toolchain go1.24.6 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 @@ -13,7 +16,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 @@ -145,6 +147,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 @@ -210,9 +213,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 diff --git a/go.sum b/go.sum index 9fa2c24ab5bb..d4b0a2ac5c40 100644 --- a/go.sum +++ b/go.sum @@ -36,6 +36,10 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= codeberg.org/chavacava/garif v0.2.0 h1:F0tVjhYbuOCnvNcU3YSpO6b3Waw6Bimy4K0mM8y6MfY= codeberg.org/chavacava/garif v0.2.0/go.mod h1:P2BPbVbT4QcvLZrORc2T29szK3xEOlnl0GiPTJmEqBQ= +dev.gaijin.team/go/exhaustruct/v4 v4.0.0 h1:873r7aNneqoBB3IaFIzhvt2RFYTuHgmMjoKfwODoI1Y= +dev.gaijin.team/go/exhaustruct/v4 v4.0.0/go.mod h1:aZ/k2o4Y05aMJtiux15x8iXaumE88YdiB0Ai4fXOzPI= +dev.gaijin.team/go/golib v0.6.0 h1:v6nnznFTs4bppib/NyU1PQxobwDHwCXXl15P7DV5Zgo= +dev.gaijin.team/go/golib v0.6.0/go.mod h1:uY1mShx8Z/aNHWDyAkZTkX+uCi5PdX7KsG1eDQa2AVE= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/4meepo/tagalign v1.4.3 h1:Bnu7jGWwbfpAie2vyl63Zup5KuRv21olsPIha53BJr8= github.com/4meepo/tagalign v1.4.3/go.mod h1:00WwRjiuSbrRJnSVeGWPLp2epS5Q/l4UEy0apLLS37c= @@ -55,8 +59,6 @@ github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= -github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1 h1:Sz1JIXEcSfhz7fUi7xHnhpIE0thVASYjvosApmHuD2k= -github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1/go.mod h1:n/LSCXNuIYqVfBlVXyHfMQkZDdp1/mmxfSjADd3z1Zg= github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4= github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/OpenPeeDeeP/depguard/v2 v2.2.1 h1:vckeWVESWp6Qog7UZSARNqfu/cZqvki8zsuj3piCMx4= @@ -90,8 +92,6 @@ github.com/ashanbrown/makezero/v2 v2.0.1 h1:r8GtKetWOgoJ4sLyUx97UTwyt2dO7WkGFHiz github.com/ashanbrown/makezero/v2 v2.0.1/go.mod h1:kKU4IMxmYW1M4fiEHMb2vc5SFoPzXvgbMR9gIp5pjSw= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -459,7 +459,6 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0 github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -639,16 +638,14 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 35bcfaf03c9d..9394f89ba5f6 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -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 { diff --git a/pkg/golinters/exhaustruct/exhaustruct.go b/pkg/golinters/exhaustruct/exhaustruct.go index 290878e1c404..01136aadc88a 100644 --- a/pkg/golinters/exhaustruct/exhaustruct.go +++ b/pkg/golinters/exhaustruct/exhaustruct.go @@ -1,7 +1,7 @@ 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" @@ -9,14 +9,17 @@ import ( ) 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) }