Skip to content

Commit

Permalink
feat: Add logrlint
Browse files Browse the repository at this point in the history
Signed-off-by: Timon Wong <timon86.wang@gmail.com>
  • Loading branch information
timonwong committed Aug 12, 2022
1 parent 235df6e commit a06609c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions .golangci.reference.yml
Expand Up @@ -1927,6 +1927,7 @@ linters:
- interfacer
- ireturn
- lll
- logrlint
- maintidx
- makezero
- maligned
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -93,6 +93,7 @@ require (
github.com/tdakkota/asciicheck v0.1.1
github.com/tetafro/godot v1.4.11
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
github.com/timonwong/logrlint v0.0.0-20220809041504-d0f840667f4f
github.com/tomarrell/wrapcheck/v2 v2.6.2
github.com/tommy-muehle/go-mnd/v2 v2.5.0
github.com/ultraware/funlen v0.0.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/golinters/logrlint.go
@@ -0,0 +1,19 @@
package golinters

import (
"github.com/timonwong/logrlint"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

const LogrLintName = "logrlint"

func NewLogrLint() *goanalysis.Linter {
return goanalysis.NewLinter(
LogrLintName,
logrlint.Doc,
[]*analysis.Analyzer{logrlint.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -574,6 +574,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.8.0").
WithPresets(linter.PresetStyle),

linter.NewConfig(golinters.NewLogrLint()).
WithSince("v1.49.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetBugs).
WithURL("https://github.com/timonwong/logrlint"),

linter.NewConfig(golinters.NewMaintIdx(maintIdxCfg)).
WithSince("v1.44.0").
WithPresets(linter.PresetComplexity).
Expand Down
4 changes: 4 additions & 0 deletions test/linters_test.go
Expand Up @@ -89,6 +89,10 @@ func TestGoimportsLocal(t *testing.T) {
ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed")
}

func TestLogrLint(t *testing.T) {
testSourcesFromDir(t, filepath.Join(testdataDir, "logrlint"))
}

func TestGciLocal(t *testing.T) {
sourcePath := filepath.Join(testdataDir, "gci", "gci.go")
args := []string{
Expand Down
16 changes: 16 additions & 0 deletions test/testdata/logrlint/example.go
@@ -0,0 +1,16 @@
//golangcitest:args -Elogrlint
package logrlint

import (
"fmt"

"github.com/go-logr/logr"
)

func Example() {
log := logr.Discard()
log = log.WithValues("key") // Error `odd number of arguments passed as key-value pairs for logging`
log.Info("message", "key1", "value1", "key2", "value2", "key3") // Error `odd number of arguments passed as key-value pairs for logging`
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2") // Error `odd number of arguments passed as key-value pairs for logging`
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2", "value2")
}
5 changes: 5 additions & 0 deletions test/testdata/logrlint/go.mod
@@ -0,0 +1,5 @@
module logrlint

go 1.16

require github.com/go-logr/logr v1.2.3
2 changes: 2 additions & 0 deletions test/testdata/logrlint/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a06609c

Please sign in to comment.