Skip to content

build(deps): bump github.com/timonwong/logrlint from 0.1.0 to 0.4.0 #3140

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

Closed
wants to merge 1 commit into from
Closed
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.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,12 @@ linters-settings:
# Default: 1
tab-width: 1

logrlint:
disable-all: false
# By default, both logr and klog will be checked.
enable: []
disable: []

maintidx:
# Show functions with maintainability index lower than N.
# A high index indicates better maintainability (it's kind of the opposite of complexity).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ require (
github.com/tdakkota/asciicheck v0.1.1
github.com/tetafro/godot v1.4.11
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
github.com/timonwong/logrlint v0.1.0
github.com/timonwong/logrlint v0.3.0
github.com/tomarrell/wrapcheck/v2 v2.6.2
github.com/tommy-muehle/go-mnd/v2 v2.5.0
github.com/ultraware/funlen v0.0.3
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.

12 changes: 12 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ var defaultLintersSettings = LintersSettings{
LineLength: 120,
TabWidth: 1,
},
LogrLint: LogrLintSettings{
DisableAll: false,
Enable: nil,
Disable: nil,
},
MaintIdx: MaintIdxSettings{
Under: 20,
},
Expand Down Expand Up @@ -154,6 +159,7 @@ type LintersSettings struct {
InterfaceBloat InterfaceBloatSettings
Ireturn IreturnSettings
Lll LllSettings
LogrLint LogrLintSettings
MaintIdx MaintIdxSettings
Makezero MakezeroSettings
Maligned MalignedSettings
Expand Down Expand Up @@ -470,6 +476,12 @@ type LllSettings struct {
TabWidth int `mapstructure:"tab-width"`
}

type LogrLintSettings struct {
DisableAll bool `mapstructure:"disable-all"`
Enable []string `mapstructure:"enable"`
Disable []string `mapstructure:"disable"`
}

type MaintIdxSettings struct {
Under int `mapstructure:"under"`
}
Expand Down
25 changes: 19 additions & 6 deletions pkg/golinters/logrlint.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package golinters

import (
"strconv"
"strings"

"github.com/timonwong/logrlint"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewLogrLint() *goanalysis.Linter {
a := logrlint.Analyzer
func NewLogrLint(settings *config.LogrLintSettings) *goanalysis.Linter {
analyzer := logrlint.NewAnalyzer()
cfg := map[string]map[string]interface{}{}
if settings != nil {
linterCfg := map[string]interface{}{
"disableall": strconv.FormatBool(settings.DisableAll),
"enable": strings.Join(settings.Enable, ","),
"disable": strings.Join(settings.Disable, ","),
}
cfg[analyzer.Name] = linterCfg
}

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
analyzer.Name,
analyzer.Doc,
[]*analysis.Analyzer{analyzer},
cfg,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
4 changes: 3 additions & 1 deletion pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
interfaceBloatCfg *config.InterfaceBloatSettings
ireturnCfg *config.IreturnSettings
lllCfg *config.LllSettings
logrlintCfg *config.LogrLintSettings
maintIdxCfg *config.MaintIdxSettings
makezeroCfg *config.MakezeroSettings
malignedCfg *config.MalignedSettings
Expand Down Expand Up @@ -214,6 +215,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
interfaceBloatCfg = &m.cfg.LintersSettings.InterfaceBloat
ireturnCfg = &m.cfg.LintersSettings.Ireturn
lllCfg = &m.cfg.LintersSettings.Lll
logrlintCfg = &m.cfg.LintersSettings.LogrLint
maintIdxCfg = &m.cfg.LintersSettings.MaintIdx
makezeroCfg = &m.cfg.LintersSettings.Makezero
malignedCfg = &m.cfg.LintersSettings.Maligned
Expand Down Expand Up @@ -583,7 +585,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.8.0").
WithPresets(linter.PresetStyle),

linter.NewConfig(golinters.NewLogrLint()).
linter.NewConfig(golinters.NewLogrLint(logrlintCfg)).
WithSince("v1.49.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetBugs).
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/logrlint/configs/logrlint_check_logronly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
logrlint:
disable-all: true
enable: [logr]
5 changes: 4 additions & 1 deletion test/testdata/logrlint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module logrlint

go 1.16

require github.com/go-logr/logr v1.2.3
require (
github.com/go-logr/logr v1.2.3
k8s.io/klog/v2 v2.70.1
)
3 changes: 3 additions & 0 deletions test/testdata/logrlint/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"fmt"

"github.com/go-logr/logr"
"k8s.io/klog/v2"
)

func Example() {
func ExampleAll() {
log := logr.Discard()
log = log.WithValues("key") // want `odd number of arguments passed as key-value pairs for logging`
log.Info("message", "key1", "value1", "key2", "value2", "key3") // want `odd number of arguments passed as key-value pairs for logging`
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2") // want `odd number of arguments passed as key-value pairs for logging`
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2", "value2")

klog.InfoS("message", "key1") // want `odd number of arguments passed as key-value pairs for logging`
}
15 changes: 15 additions & 0 deletions test/testdata/logrlint/logrlint_logronly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Elogrlint
//golangcitest:config_path configs/logrlint_check_logronly.yml
package logrlint

import (
"github.com/go-logr/logr"
"k8s.io/klog/v2"
)

func ExampleLogrOnly() {
log := logr.Discard()
log.Info("message", "key1", "value1", "key2", "value2", "key3") // want `odd number of arguments passed as key-value pairs for logging`

klog.InfoS("message", "key1")
}