Skip to content

Commit

Permalink
review: fix dependencies and cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 31, 2023
1 parent 04b16cf commit f507714
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
31 changes: 14 additions & 17 deletions pkg/config/linters_settings.go
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"runtime"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var defaultLintersSettings = LintersSettings{
Expand Down Expand Up @@ -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"`
Expand All @@ -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
Expand Down

0 comments on commit f507714

Please sign in to comment.