aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/timonwong/loggercheck/staticrules.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/timonwong/loggercheck/staticrules.go
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/timonwong/loggercheck/staticrules.go')
-rw-r--r--vendor/github.com/timonwong/loggercheck/staticrules.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/timonwong/loggercheck/staticrules.go b/vendor/github.com/timonwong/loggercheck/staticrules.go
new file mode 100644
index 000000000..f955b3434
--- /dev/null
+++ b/vendor/github.com/timonwong/loggercheck/staticrules.go
@@ -0,0 +1,68 @@
+package loggercheck
+
+import (
+ "errors"
+ "fmt"
+
+ "github.com/timonwong/loggercheck/internal/checkers"
+ "github.com/timonwong/loggercheck/internal/rules"
+)
+
+var (
+ staticRuleList = []rules.Ruleset{
+ mustNewStaticRuleSet("logr", []string{
+ "(github.com/go-logr/logr.Logger).Error",
+ "(github.com/go-logr/logr.Logger).Info",
+ "(github.com/go-logr/logr.Logger).WithValues",
+ }),
+ mustNewStaticRuleSet("klog", []string{
+ "k8s.io/klog/v2.InfoS",
+ "k8s.io/klog/v2.InfoSDepth",
+ "k8s.io/klog/v2.ErrorS",
+ "(k8s.io/klog/v2.Verbose).InfoS",
+ "(k8s.io/klog/v2.Verbose).InfoSDepth",
+ "(k8s.io/klog/v2.Verbose).ErrorS",
+ }),
+ mustNewStaticRuleSet("zap", []string{
+ "(*go.uber.org/zap.SugaredLogger).With",
+ "(*go.uber.org/zap.SugaredLogger).Debugw",
+ "(*go.uber.org/zap.SugaredLogger).Infow",
+ "(*go.uber.org/zap.SugaredLogger).Warnw",
+ "(*go.uber.org/zap.SugaredLogger).Errorw",
+ "(*go.uber.org/zap.SugaredLogger).DPanicw",
+ "(*go.uber.org/zap.SugaredLogger).Panicw",
+ "(*go.uber.org/zap.SugaredLogger).Fatalw",
+ }),
+ mustNewStaticRuleSet("kitlog", []string{
+ "github.com/go-kit/log.With",
+ "github.com/go-kit/log.WithPrefix",
+ "github.com/go-kit/log.WithSuffix",
+ "(github.com/go-kit/log.Logger).Log",
+ }),
+ }
+ checkerByRulesetName = map[string]checkers.Checker{
+ // by default, checkers.General will be used.
+ "zap": checkers.Zap{},
+ }
+)
+
+// mustNewStaticRuleSet only called at init, catch errors during development.
+// In production it will not panic.
+func mustNewStaticRuleSet(name string, lines []string) rules.Ruleset {
+ if len(lines) == 0 {
+ panic(errors.New("no rules provided"))
+ }
+
+ rulesetList, err := rules.ParseRules(lines)
+ if err != nil {
+ panic(err)
+ }
+
+ if len(rulesetList) != 1 {
+ panic(fmt.Errorf("expected 1 ruleset, got %d", len(rulesetList)))
+ }
+
+ ruleset := rulesetList[0]
+ ruleset.Name = name
+ return ruleset
+}