From d2ccc6d2bbbb78494617b9590e6d7f0a5881db9d Mon Sep 17 00:00:00 2001 From: Maik Schreiber Date: Wed, 30 Mar 2022 03:00:13 +0200 Subject: [PATCH] bump varnamelen to v0.8.0 (#2703) --- .golangci.example.yml | 14 +++++++++++--- go.mod | 2 +- go.sum | 4 ++-- pkg/config/linters_settings.go | 1 + pkg/golinters/varnamelen.go | 11 ++++++----- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index 72d5c7acd68f..9edde4f472d9 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -1473,12 +1473,15 @@ linters-settings: # Variable names that are at least this long will be ignored. # Default: 3 min-name-length: 2 - # Check method receiver names. + # Check method receivers. # Default: false check-receiver: true # Check named return values. # Default: false check-return: true + # Check type parameters. + # Default: false + check-type-param: true # Ignore "ok" variables that hold the bool return value of a type assertion. # Default: false ignore-type-assert-ok: true @@ -1493,8 +1496,11 @@ linters-settings: ignore-names: - err # Optional list of variable declarations that should be ignored completely. - # Entries must be in the form of " " or " *" - # for variables, or "const " for constants. + # Entries must be in one of the following forms (see below for examples): + # - for variables, parameters, named return values, method receivers, or type parameters: + # ( can also be a pointer/slice/map/chan/...) + # - for constants: const + # # Default: [] ignore-decls: - c echo.Context @@ -1503,6 +1509,8 @@ linters-settings: - e error - i int - const C + - T any + - m map[string]int whitespace: # Enforces newlines (or comments) after every multi-line if statement. diff --git a/go.mod b/go.mod index 8e1c87e63701..d6771ba1a6e4 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/ashanbrown/forbidigo v1.3.0 github.com/ashanbrown/makezero v1.1.1 github.com/bkielbasa/cyclop v1.2.0 - github.com/blizzy78/varnamelen v0.6.2 + github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v3 v3.3.0 github.com/breml/bidichk v0.2.3 github.com/breml/errchkjson v0.3.0 diff --git a/go.sum b/go.sum index 9ef4cfa52b22..616b33132b62 100644 --- a/go.sum +++ b/go.sum @@ -98,8 +98,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bkielbasa/cyclop v1.2.0 h1:7Jmnh0yL2DjKfw28p86YTd/B4lRGcNuu12sKE35sM7A= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= -github.com/blizzy78/varnamelen v0.6.2 h1:Z857yhnsqKadJo+ALsdpRpN5SCyTTR5rEX+hwVGY4Vk= -github.com/blizzy78/varnamelen v0.6.2/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= +github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= +github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v3 v3.3.0 h1:Mka/+kRLoQJq7g2rggtgQsjuI/K5Efd87WX96EWFxjM= github.com/bombsimon/wsl/v3 v3.3.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc= github.com/breml/bidichk v0.2.3 h1:qe6ggxpTfA8E75hdjWPZ581sY3a2lnl0IRxLQFelECI= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 8f59ca5289dd..97c2065d4bf5 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -579,6 +579,7 @@ type VarnamelenSettings struct { MinNameLength int `mapstructure:"min-name-length"` CheckReceiver bool `mapstructure:"check-receiver"` CheckReturn bool `mapstructure:"check-return"` + CheckTypeParam bool `mapstructure:"check-type-param"` IgnoreNames []string `mapstructure:"ignore-names"` IgnoreTypeAssertOk bool `mapstructure:"ignore-type-assert-ok"` IgnoreMapIndexOk bool `mapstructure:"ignore-map-index-ok"` diff --git a/pkg/golinters/varnamelen.go b/pkg/golinters/varnamelen.go index 6e3176f178c6..d86c04b20a15 100644 --- a/pkg/golinters/varnamelen.go +++ b/pkg/golinters/varnamelen.go @@ -12,13 +12,14 @@ import ( ) func NewVarnamelen(settings *config.VarnamelenSettings) *goanalysis.Linter { - a := varnamelen.NewAnalyzer() - + analyzer := varnamelen.NewAnalyzer() cfg := map[string]map[string]interface{}{} + if settings != nil { vnlCfg := map[string]interface{}{ "checkReceiver": strconv.FormatBool(settings.CheckReceiver), "checkReturn": strconv.FormatBool(settings.CheckReturn), + "checkTypeParam": strconv.FormatBool(settings.CheckTypeParam), "ignoreNames": strings.Join(settings.IgnoreNames, ","), "ignoreTypeAssertOk": strconv.FormatBool(settings.IgnoreTypeAssertOk), "ignoreMapIndexOk": strconv.FormatBool(settings.IgnoreMapIndexOk), @@ -33,13 +34,13 @@ func NewVarnamelen(settings *config.VarnamelenSettings) *goanalysis.Linter { vnlCfg["minNameLength"] = strconv.Itoa(settings.MinNameLength) } - cfg[a.Name] = vnlCfg + cfg[analyzer.Name] = vnlCfg } return goanalysis.NewLinter( - a.Name, + analyzer.Name, "checks that the length of a variable's name matches its scope", - []*analysis.Analyzer{a}, + []*analysis.Analyzer{analyzer}, cfg, ).WithLoadMode(goanalysis.LoadModeTypesInfo) }