Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump github.com/Crocmagnon/fatcontext from 0.6.0 to 0.7.1 #5335

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
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.6.0
github.com/Crocmagnon/fatcontext v0.7.1
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.

11 changes: 11 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,17 @@
}
}
},
"fatcontext": {
"type": "object",
"additionalProperties": false,
"properties": {
"check-struct-pointers": {
"description": "Check for potential fat contexts in struct pointers.",
"type": "boolean",
"default": false
}
}
},
"forbidigo": {
"type": "object",
"additionalProperties": false,
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ type LintersSettings struct {
ErrorLint ErrorLintSettings
Exhaustive ExhaustiveSettings
Exhaustruct ExhaustructSettings
Fatcontext FatcontextSettings
Forbidigo ForbidigoSettings
Funlen FunlenSettings
Gci GciSettings
Expand Down Expand Up @@ -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"`
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)
}
25 changes: 25 additions & 0 deletions pkg/golinters/fatcontext/testdata/fatcontext_structpointer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//golangcitest:args -Efatcontext
//golangcitest:config_path testdata/fatcontext_structpointer.yml
package testdata

import (
"context"
)

type Container struct {
Ctx context.Context
}

func something() func(*Container) {
return func(r *Container) {
ctx := r.Ctx
ctx = context.WithValue(ctx, "key", "val")
r.Ctx = ctx // want "potential nested context in struct pointer"
}
}

func blah(r *Container) {
ctx := r.Ctx
ctx = context.WithValue(ctx, "key", "val")
r.Ctx = ctx // want "potential nested context in struct pointer"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
fatcontext:
check-struct-pointers: true

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
Loading