Skip to content

Commit 6a6e65c

Browse files
committed
bump loggercheck; add support to no-printf-like
Signed-off-by: Timon Wong <[email protected]>
1 parent aa4a24b commit 6a6e65c

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

.golangci.reference.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,12 @@ linters-settings:
11241124
# Allow check for the "sugar logger" from go.uber.org/zap library.
11251125
# Default: true
11261126
zap: false
1127-
# Require all logging keys to be inlined constant strings
1127+
# Require all logging keys to be inlined constant strings.
11281128
# Default: false
11291129
require-string-key: true
1130+
# Require printf-like format specifier (%s, %d for example) not present.
1131+
# Default: false
1132+
no-printf-like: true
11301133
# List of custom rules to check against, where each rule is a single logger pattern.
11311134
# Default: empty
11321135
rules:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ require (
9595
github.com/tdakkota/asciicheck v0.1.1
9696
github.com/tetafro/godot v1.4.11
9797
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
98-
github.com/timonwong/loggercheck v0.8.0
98+
github.com/timonwong/loggercheck v0.9.2
9999
github.com/tomarrell/wrapcheck/v2 v2.6.2
100100
github.com/tommy-muehle/go-mnd/v2 v2.5.0
101101
github.com/ultraware/funlen v0.0.3

go.sum

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var defaultLintersSettings = LintersSettings{
7272
Logr: true,
7373
Zap: true,
7474
RequireStringKey: false,
75+
NoPrintfLike: false,
7576
Rules: nil,
7677
},
7778
MaintIdx: MaintIdxSettings{
@@ -485,6 +486,7 @@ type LoggerCheckSettings struct {
485486
Logr bool `mapstructure:"logr"`
486487
Zap bool `mapstructure:"zap"`
487488
RequireStringKey bool `mapstructure:"require-string-key"`
489+
NoPrintfLike bool `mapstructure:"no-printf-like"`
488490
Rules []string `mapstructure:"rules"`
489491
}
490492

pkg/golinters/loggercheck.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func NewLoggerCheck(settings *config.LoggerCheckSettings) *goanalysis.Linter {
3030
loggercheck.WithDisable(disable),
3131
loggercheck.WithRequireStringKey(settings.RequireStringKey),
3232
loggercheck.WithRules(settings.Rules),
33+
loggercheck.WithNoPrintfLike(settings.NoPrintfLike),
3334
}
3435
}
3536

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
loggercheck:
3+
no-printf-like: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//golangcitest:args -Eloggercheck
2+
//golangcitest:config_path configs/loggercheck_noprintflike.yml
3+
package loggercheck
4+
5+
import (
6+
"github.com/go-logr/logr"
7+
)
8+
9+
func ExampleNoPrintfLike() {
10+
log := logr.Discard()
11+
12+
log.Info("This message is ok")
13+
log.Info("Should not contains printf like format specifiers: %s %d %w") // want `logging message should not use format specifier "%s"`
14+
log.Info("It also checks for the key value pairs", "key", "value %.2f") // want `logging message should not use format specifier "%\.2f"`
15+
}

0 commit comments

Comments
 (0)