|
| 1 | +/* |
| 2 | +Copyright 2023 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package testdata |
| 18 | + |
| 19 | +import ( |
| 20 | + "k8s.io/klog/v2" |
| 21 | +) |
| 22 | + |
| 23 | +func calls() { |
| 24 | + klog.Infof("%s") // want `k8s.io/klog/v2.Infof format %s reads arg #1, but call has 0 args` |
| 25 | + klog.Infof("%s", "world") |
| 26 | + klog.Info("%s", "world") // want `k8s.io/klog/v2.Info call has possible formatting directive %s` |
| 27 | + klog.Info("world") |
| 28 | + klog.Infoln("%s", "world") // want `k8s.io/klog/v2.Infoln call has possible formatting directive %s` |
| 29 | + klog.Infoln("world") |
| 30 | + |
| 31 | + klog.InfofDepth(1, "%s") // want `k8s.io/klog/v2.InfofDepth format %s reads arg #1, but call has 0 args` |
| 32 | + klog.InfofDepth(1, "%s", "world") |
| 33 | + klog.InfoDepth(1, "%s", "world") // want `k8s.io/klog/v2.InfoDepth call has possible formatting directive %s` |
| 34 | + klog.InfoDepth(1, "world") |
| 35 | + klog.InfolnDepth(1, "%s", "world") // want `k8s.io/klog/v2.InfolnDepth call has possible formatting directive %s` |
| 36 | + klog.InfolnDepth(1, "world") |
| 37 | + |
| 38 | + klog.Warningf("%s") // want `k8s.io/klog/v2.Warningf format %s reads arg #1, but call has 0 args` |
| 39 | + klog.Warningf("%s", "world") |
| 40 | + klog.Warning("%s", "world") // want `k8s.io/klog/v2.Warning call has possible formatting directive %s` |
| 41 | + klog.Warning("world") |
| 42 | + klog.Warningln("%s", "world") // want `k8s.io/klog/v2.Warningln call has possible formatting directive %s` |
| 43 | + klog.Warningln("world") |
| 44 | + |
| 45 | + klog.WarningfDepth(1, "%s") // want `k8s.io/klog/v2.WarningfDepth format %s reads arg #1, but call has 0 args` |
| 46 | + klog.WarningfDepth(1, "%s", "world") |
| 47 | + klog.WarningDepth(1, "%s", "world") // want `k8s.io/klog/v2.WarningDepth call has possible formatting directive %s` |
| 48 | + klog.WarningDepth(1, "world") |
| 49 | + klog.WarninglnDepth(1, "%s", "world") // want `k8s.io/klog/v2.WarninglnDepth call has possible formatting directive %s` |
| 50 | + klog.WarninglnDepth(1, "world") |
| 51 | + |
| 52 | + klog.Errorf("%s") // want `k8s.io/klog/v2.Errorf format %s reads arg #1, but call has 0 args` |
| 53 | + klog.Errorf("%s", "world") |
| 54 | + klog.Error("%s", "world") // want `k8s.io/klog/v2.Error call has possible formatting directive %s` |
| 55 | + klog.Error("world") |
| 56 | + klog.Errorln("%s", "world") // want `k8s.io/klog/v2.Errorln call has possible formatting directive %s` |
| 57 | + klog.Errorln("world") |
| 58 | + |
| 59 | + klog.ErrorfDepth(1, "%s") // want `k8s.io/klog/v2.ErrorfDepth format %s reads arg #1, but call has 0 args` |
| 60 | + klog.ErrorfDepth(1, "%s", "world") |
| 61 | + klog.ErrorDepth(1, "%s", "world") // want `k8s.io/klog/v2.ErrorDepth call has possible formatting directive %s` |
| 62 | + klog.ErrorDepth(1, "world") |
| 63 | + klog.ErrorlnDepth(1, "%s", "world") // want `k8s.io/klog/v2.ErrorlnDepth call has possible formatting directive %s` |
| 64 | + klog.ErrorlnDepth(1, "world") |
| 65 | + |
| 66 | + klog.Fatalf("%s") // want `k8s.io/klog/v2.Fatalf format %s reads arg #1, but call has 0 args` |
| 67 | + klog.Fatalf("%s", "world") |
| 68 | + klog.Fatal("%s", "world") // want `k8s.io/klog/v2.Fatal call has possible formatting directive %s` |
| 69 | + klog.Fatal("world") |
| 70 | + klog.Fatalln("%s", "world") // want `k8s.io/klog/v2.Fatalln call has possible formatting directive %s` |
| 71 | + klog.Fatalln("world") |
| 72 | + |
| 73 | + klog.FatalfDepth(1, "%s") // want `k8s.io/klog/v2.FatalfDepth format %s reads arg #1, but call has 0 args` |
| 74 | + klog.FatalfDepth(1, "%s", "world") |
| 75 | + klog.FatalDepth(1, "%s", "world") // want `k8s.io/klog/v2.FatalDepth call has possible formatting directive %s` |
| 76 | + klog.FatalDepth(1, "world") |
| 77 | + klog.FatallnDepth(1, "%s", "world") // want `k8s.io/klog/v2.FatallnDepth call has possible formatting directive %s` |
| 78 | + klog.FatallnDepth(1, "world") |
| 79 | + |
| 80 | + klog.V(1).Infof("%s") // want `\(k8s.io/klog/v2.Verbose\).Infof format %s reads arg #1, but call has 0 args` |
| 81 | + klog.V(1).Infof("%s", "world") |
| 82 | + klog.V(1).Info("%s", "world") // want `\(k8s.io/klog/v2.Verbose\).Info call has possible formatting directive %s` |
| 83 | + klog.V(1).Info("world") |
| 84 | + klog.V(1).Infoln("%s", "world") // want `\(k8s.io/klog/v2.Verbose\).Infoln call has possible formatting directive %s` |
| 85 | + klog.V(1).Infoln("world") |
| 86 | + |
| 87 | + klog.V(1).InfofDepth(1, "%s") // want `\(k8s.io/klog/v2.Verbose\).InfofDepth format %s reads arg #1, but call has 0 args` |
| 88 | + klog.V(1).InfofDepth(1, "%s", "world") |
| 89 | + klog.V(1).InfoDepth(1, "%s", "world") // want `\(k8s.io/klog/v2.Verbose\).InfoDepth call has possible formatting directive %s` |
| 90 | + klog.V(1).InfoDepth(1, "world") |
| 91 | + klog.V(1).InfolnDepth(1, "%s", "world") // want `\(k8s.io/klog/v2.Verbose\).InfolnDepth call has possible formatting directive %s` |
| 92 | + klog.V(1).InfolnDepth(1, "world") |
| 93 | + |
| 94 | + // Detecting format specifiers for klog.InfoS and other structured logging calls would be nice, |
| 95 | + // but doesn't work the same way because of the extra "msg" string parameter. logcheck |
| 96 | + // can be used instead of "go vet". |
| 97 | + klog.InfoS("%s", "world") |
| 98 | +} |
0 commit comments