-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rename logrlint to loggercheck
Signed-off-by: Timon Wong <[email protected]>
- Loading branch information
Showing
16 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package golinters | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/timonwong/loggercheck" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewLoggerCheck(settings *config.LoggerCheckSettings) *goanalysis.Linter { | ||
analyzer := loggercheck.NewAnalyzer() | ||
cfg := map[string]map[string]interface{}{} | ||
if settings != nil { | ||
var disabled []string | ||
if !settings.Logr { | ||
disabled = append(disabled, "logr") | ||
} | ||
if !settings.Klog { | ||
disabled = append(disabled, "klog") | ||
} | ||
if !settings.Logr { | ||
disabled = append(disabled, "zap") | ||
} | ||
linterCfg := map[string]interface{}{ | ||
"disable": strings.Join(disabled, ","), | ||
} | ||
cfg[analyzer.Name] = linterCfg | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
analyzer.Name, | ||
analyzer.Doc, | ||
[]*analysis.Analyzer{analyzer}, | ||
cfg, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
loggercheck: | ||
logr: true | ||
klog: false | ||
zap: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
loggercheck: | ||
logr: false | ||
klog: false | ||
zap: zap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module loggercheck | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/go-logr/logr v1.2.3 | ||
go.uber.org/atomic v1.10.0 // indirect | ||
go.uber.org/multierr v1.8.0 // indirect | ||
go.uber.org/zap v1.23.0 | ||
k8s.io/klog/v2 v2.70.1 | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//golangcitest:args -Eloggercheck | ||
package loggercheck | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
"go.uber.org/zap" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
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` | ||
|
||
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` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//golangcitest:args -Eloggercheck | ||
//golangcitest:config_path configs/loggercheck_logronly.yml | ||
package loggercheck | ||
|
||
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//golangcitest:args -Eloggercheck | ||
//golangcitest:config_path configs/loggercheck_zaponly.yml | ||
package loggercheck | ||
|
||
import "go.uber.org/zap" | ||
|
||
func ExampleZapOnly() { | ||
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.Errorw("error message", "key1") // want `odd number of arguments passed as key-value pairs for logging` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//golangcitest:args -Elogrlint | ||
package logrlint | ||
package loggercheck | ||
|
||
import ( | ||
"fmt" | ||
|