Skip to content

Commit

Permalink
bump varnamelen to v0.8.0 (golangci#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzy78 authored and SeigeC committed Apr 4, 2023
1 parent 76d6685 commit 288a599
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
14 changes: 11 additions & 3 deletions .golangci.example.yml
Expand Up @@ -1498,12 +1498,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
Expand All @@ -1518,8 +1521,11 @@ linters-settings:
ignore-names:
- err
# Optional list of variable declarations that should be ignored completely.
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>"
# for variables, or "const <name>" 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:
# <name> <type> (<type> can also be a pointer/slice/map/chan/...)
# - for constants: const <name>
#
# Default: []
ignore-decls:
- c echo.Context
Expand All @@ -1528,6 +1534,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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
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.

1 change: 1 addition & 0 deletions pkg/config/linters_settings.go
Expand Up @@ -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"`
Expand Down
11 changes: 6 additions & 5 deletions pkg/golinters/varnamelen.go
Expand Up @@ -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),
Expand All @@ -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)
}

0 comments on commit 288a599

Please sign in to comment.