Skip to content

Commit

Permalink
disable zap by default timonwong/loggercheck#27
Browse files Browse the repository at this point in the history
Signed-off-by: Timon Wong <[email protected]>
  • Loading branch information
timonwong committed Aug 29, 2022
1 parent 6cc490f commit bc4699e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ linters-settings:
# Default: true
logr: false
# Allow check for the "sugar logger" from go.uber.org/zap library.
# Default: true
zap: false
# Default: false
zap: true
# List of rules to check against, where each rule is a single logger pattern.
rules:
- k8s.io/klog/v2.InfoS # package level exported functions
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var defaultLintersSettings = LintersSettings{
LoggerCheck: LoggerCheckSettings{
Logr: true,
Klog: true,
Zap: true,
Zap: false,
},
MaintIdx: MaintIdxSettings{
Under: 20,
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/loggercheck/configs/loggercheck_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
loggercheck:
zap: true
7 changes: 4 additions & 3 deletions test/testdata/loggercheck/loggercheck_all.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//golangcitest:args -Eloggercheck
//golangcitest:config_path configs/loggercheck_all.yml
package loggercheck

import (
Expand All @@ -9,19 +10,19 @@ import (
"k8s.io/klog/v2"
)

func ExampleLogr() {
func ExampleAllLogr() {
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")
}

func ExampleKlog() {
func ExampleAllKlog() {
klog.InfoS("message", "key1") // want `odd number of arguments passed as key-value pairs for logging`
}

func ExampleZapSugar() {
func ExampleAllZapSugar() {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
sugar.Infow("message", "key1", "value1", "key2") // want `odd number of arguments passed as key-value pairs for logging`
Expand Down
28 changes: 28 additions & 0 deletions test/testdata/loggercheck/loggercheck_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//golangcitest:args -Eloggercheck
package loggercheck

import (
"fmt"

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

func ExampleDefaultLogr() {
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")
}

func ExampleDefaultKlog() {
klog.InfoS("message", "key1") // want `odd number of arguments passed as key-value pairs for logging`
}

func ExampleZapSugarNotChecked() {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
sugar.Infow("message", "key1", "value1", "key2")
}
2 changes: 1 addition & 1 deletion test/testdata/loggercheck/logrlint_compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ func ExampleLogrlintKlog() {
func ExampleLogrlintZapSugar() {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
sugar.Infow("message", "key1", "value1", "key2") // want `odd number of arguments passed as key-value pairs for logging`
sugar.Infow("message", "key1", "value1", "key2")
}

0 comments on commit bc4699e

Please sign in to comment.