From f507714f401037f5a2471a5d96c38a0e3c086405 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 31 May 2023 15:33:59 +0200 Subject: [PATCH] review: fix dependencies and cosmetic changes --- go.mod | 4 ++-- pkg/config/linters_settings.go | 31 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index bc13160ddb50..005e266af53b 100644 --- a/go.mod +++ b/go.mod @@ -71,6 +71,7 @@ require ( github.com/mgechev/revive v1.3.2 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-ps v1.0.0 + github.com/mitchellh/mapstructure v1.5.0 github.com/moricho/tparallel v0.3.1 github.com/nakabonne/nestif v0.3.1 github.com/nishanths/exhaustive v0.10.0 @@ -153,7 +154,6 @@ require ( github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mitchellh/mapstructure v1.5.0 github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect @@ -190,6 +190,6 @@ require ( golang.org/x/text v0.9.0 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v2 v2.4.0 // indirect mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect ) diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index ce8496f5f8dc..b520ea4c6eeb 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -5,7 +5,7 @@ import ( "errors" "runtime" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) var defaultLintersSettings = LintersSettings{ @@ -338,17 +338,16 @@ type ForbidigoSettings struct { AnalyzeTypes bool `mapstructure:"analyze-types"` } -// ForbidigoPattern corresponds to forbidigo.pattern and adds -// mapstructure support. The YAML field names must match what -// forbidigo expects. +var _ encoding.TextUnmarshaler = &ForbidigoPattern{} + +// ForbidigoPattern corresponds to forbidigo.pattern and adds mapstructure support. +// The YAML field names must match what forbidigo expects. type ForbidigoPattern struct { - // patternString gets populated when the config contains a string as - // entry in ForbidigoSettings.Forbid[] because ForbidigoPattern - // implements encoding.TextUnmarshaler and the reader uses the - // mapstructure.TextUnmarshallerHookFunc as decoder hook. + // patternString gets populated when the config contains a string as entry in ForbidigoSettings.Forbid[] + // because ForbidigoPattern implements encoding.TextUnmarshaler + // and the reader uses the mapstructure.TextUnmarshallerHookFunc as decoder hook. // - // If the entry is a map, then the other fields are set as usual - // by mapstructure. + // If the entry is a map, then the other fields are set as usual by mapstructure. patternString string Pattern string `yaml:"p" mapstructure:"p"` @@ -362,21 +361,19 @@ func (p *ForbidigoPattern) UnmarshalText(text []byte) error { return nil } -// MarshalString converts the pattern into a string as needed by -// forbidigo.NewLinter. +// MarshalString converts the pattern into a string as needed by forbidigo.NewLinter. // -// MarshalString is intentionally not called MarshalText although it has the -// same signature because implementing encoding.TextMarshaler led to infinite -// recursion when yaml.Marshal called MarshalText. +// MarshalString is intentionally not called MarshalText, +// although it has the same signature +// because implementing encoding.TextMarshaler led to infinite recursion when yaml.Marshal called MarshalText. func (p *ForbidigoPattern) MarshalString() ([]byte, error) { if p.patternString != "" { return []byte(p.patternString), nil } + return yaml.Marshal(p) } -var _ encoding.TextUnmarshaler = &ForbidigoPattern{} - type FunlenSettings struct { Lines int Statements int