diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index aeda8070e4ae..48b7c1593eda 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -548,6 +548,12 @@ linters-settings: exclude: - '.+/cobra\.Command$' + fatcontext: + # Check for potential fat contexts in struct pointers. + # May generate false positives. + # Default: false + check-struct-pointers: true + forbidigo: # Forbid the following identifiers (list of regexp). # Default: ["^(fmt\\.Print(|f|ln)|print|println)$"] diff --git a/go.mod b/go.mod index 9f91e090929e..e248b82a421f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Antonboom/nilnil v1.0.1 github.com/Antonboom/testifylint v1.5.2 github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c - github.com/Crocmagnon/fatcontext v0.6.0 + github.com/Crocmagnon/fatcontext v0.7.0 github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 github.com/OpenPeeDeeP/depguard/v2 v2.2.0 diff --git a/go.sum b/go.sum index 5f5c064cd02b..22c155931e4f 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Crocmagnon/fatcontext v0.6.0 h1:DxGYfrUrJBOtvldiWpMvntvkTDgj6c1zLCTKelMqAtw= -github.com/Crocmagnon/fatcontext v0.6.0/go.mod h1:1wMvv3NXEBJucFGfwOJBxSVWcoIO6emV215SMkW9MFU= +github.com/Crocmagnon/fatcontext v0.7.0 h1:z0mPJ/MsuhiEq+cj4LwRHv7qo/LQH0mL8rXBDpTDT/s= +github.com/Crocmagnon/fatcontext v0.7.0/go.mod h1:1wMvv3NXEBJucFGfwOJBxSVWcoIO6emV215SMkW9MFU= 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.0 h1:/fTUt5vmbkAcMBt4YQiuC23cV0kEsN1MVMNqeOW43cU= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 8e6c184ca4d3..9968f3a0760b 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -223,6 +223,7 @@ type LintersSettings struct { ErrorLint ErrorLintSettings Exhaustive ExhaustiveSettings Exhaustruct ExhaustructSettings + Fatcontext FatcontextSettings Forbidigo ForbidigoSettings Funlen FunlenSettings Gci GciSettings @@ -430,6 +431,10 @@ type ExhaustructSettings struct { Exclude []string `mapstructure:"exclude"` } +type FatcontextSettings struct { + CheckStructPointers bool `mapstructure:"check-struct-pointers"` +} + type ForbidigoSettings struct { Forbid []ForbidigoPattern `mapstructure:"forbid"` ExcludeGodocExamples bool `mapstructure:"exclude-godoc-examples"` diff --git a/pkg/golinters/fatcontext/fatcontext.go b/pkg/golinters/fatcontext/fatcontext.go index 378025a8cc5e..2ffacacd39a7 100644 --- a/pkg/golinters/fatcontext/fatcontext.go +++ b/pkg/golinters/fatcontext/fatcontext.go @@ -4,16 +4,25 @@ import ( "github.com/Crocmagnon/fatcontext/pkg/analyzer" "golang.org/x/tools/go/analysis" + "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/goanalysis" ) -func New() *goanalysis.Linter { - a := analyzer.Analyzer +func New(settings *config.FatcontextSettings) *goanalysis.Linter { + a := analyzer.NewAnalyzer() + + cfg := map[string]map[string]any{} + + if settings != nil { + cfg[a.Name] = map[string]any{ + analyzer.FlagCheckStructPointers: settings.CheckStructPointers, + } + } return goanalysis.NewLinter( a.Name, a.Doc, []*analysis.Analyzer{a}, - nil, + cfg, ).WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 116e46a9f4ee..beda9e3c76b6 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -307,7 +307,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithPresets(linter.PresetStyle). WithURL("https://github.com/gostaticanalysis/forcetypeassert"), - linter.NewConfig(fatcontext.New()). + linter.NewConfig(fatcontext.New(&cfg.LintersSettings.Fatcontext)). WithSince("v1.58.0"). WithPresets(linter.PresetPerformance). WithLoadForGoAnalysis().