Skip to content

Commit 4f21370

Browse files
committed
feat: fatcontext settings
1 parent c668d95 commit 4f21370

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

Diff for: .golangci.next.reference.yml

+6
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ linters-settings:
548548
exclude:
549549
- '.+/cobra\.Command$'
550550

551+
fatcontext:
552+
# Check for potential fat contexts in struct pointers.
553+
# May generate false positives.
554+
# Default: false
555+
check-struct-pointers: true
556+
551557
forbidigo:
552558
# Forbid the following identifiers (list of regexp).
553559
# Default: ["^(fmt\\.Print(|f|ln)|print|println)$"]

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/Antonboom/nilnil v1.0.1
1212
github.com/Antonboom/testifylint v1.5.2
1313
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
14-
github.com/Crocmagnon/fatcontext v0.5.3
14+
github.com/Crocmagnon/fatcontext v0.7.0
1515
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
1616
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0
1717
github.com/OpenPeeDeeP/depguard/v2 v2.2.0

Diff for: go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/config/linters_settings.go

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var defaultLintersSettings = LintersSettings{
4040
ExplicitExhaustiveMap: false,
4141
ExplicitExhaustiveSwitch: false,
4242
},
43+
Fatcontext: FatcontextSettings{
44+
CheckStructPointers: false,
45+
},
4346
Forbidigo: ForbidigoSettings{
4447
ExcludeGodocExamples: true,
4548
},
@@ -223,6 +226,7 @@ type LintersSettings struct {
223226
ErrorLint ErrorLintSettings
224227
Exhaustive ExhaustiveSettings
225228
Exhaustruct ExhaustructSettings
229+
Fatcontext FatcontextSettings
226230
Forbidigo ForbidigoSettings
227231
Funlen FunlenSettings
228232
Gci GciSettings
@@ -430,6 +434,10 @@ type ExhaustructSettings struct {
430434
Exclude []string `mapstructure:"exclude"`
431435
}
432436

437+
type FatcontextSettings struct {
438+
CheckStructPointers bool `mapstructure:"check-struct-pointers"`
439+
}
440+
433441
type ForbidigoSettings struct {
434442
Forbid []ForbidigoPattern `mapstructure:"forbid"`
435443
ExcludeGodocExamples bool `mapstructure:"exclude-godoc-examples"`

Diff for: pkg/golinters/fatcontext/fatcontext.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ import (
44
"github.com/Crocmagnon/fatcontext/pkg/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/goanalysis"
89
)
910

10-
func New() *goanalysis.Linter {
11-
a := analyzer.Analyzer
11+
func New(settings *config.FatcontextSettings) *goanalysis.Linter {
12+
a := analyzer.NewAnalyzer()
13+
14+
cfg := map[string]map[string]any{}
15+
16+
if settings != nil {
17+
cfg[a.Name] = map[string]any{
18+
analyzer.FlagCheckStructPointers: settings.CheckStructPointers,
19+
}
20+
}
1221

1322
return goanalysis.NewLinter(
1423
a.Name,
1524
a.Doc,
1625
[]*analysis.Analyzer{a},
17-
nil,
26+
cfg,
1827
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1928
}

Diff for: pkg/lint/lintersdb/builder_linter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
307307
WithPresets(linter.PresetStyle).
308308
WithURL("https://github.com/gostaticanalysis/forcetypeassert"),
309309

310-
linter.NewConfig(fatcontext.New()).
310+
linter.NewConfig(fatcontext.New(&cfg.LintersSettings.Fatcontext)).
311311
WithSince("v1.58.0").
312312
WithPresets(linter.PresetPerformance).
313313
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)