Skip to content

Commit

Permalink
feat: fatcontext settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Crocmagnon committed Jan 16, 2025
1 parent c668d95 commit 4f21370
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)$"]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.3
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

8 changes: 8 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ var defaultLintersSettings = LintersSettings{
ExplicitExhaustiveMap: false,
ExplicitExhaustiveSwitch: false,
},
Fatcontext: FatcontextSettings{
CheckStructPointers: false,
},
Forbidigo: ForbidigoSettings{
ExcludeGodocExamples: true,
},
Expand Down Expand Up @@ -223,6 +226,7 @@ type LintersSettings struct {
ErrorLint ErrorLintSettings
Exhaustive ExhaustiveSettings
Exhaustruct ExhaustructSettings
Fatcontext FatcontextSettings
Forbidigo ForbidigoSettings
Funlen FunlenSettings
Gci GciSettings
Expand Down Expand Up @@ -430,6 +434,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"`
Expand Down
15 changes: 12 additions & 3 deletions pkg/golinters/fatcontext/fatcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 4f21370

Please sign in to comment.