Skip to content

Commit 0d2539b

Browse files
committed
feat: Add logrlint
Signed-off-by: Timon Wong <[email protected]>
1 parent 235df6e commit 0d2539b

File tree

8 files changed

+55
-0
lines changed

8 files changed

+55
-0
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ require (
9393
github.com/tdakkota/asciicheck v0.1.1
9494
github.com/tetafro/godot v1.4.11
9595
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
96+
github.com/timonwong/logrlint v0.0.0-20220809041504-d0f840667f4f
9697
github.com/tomarrell/wrapcheck/v2 v2.6.2
9798
github.com/tommy-muehle/go-mnd/v2 v2.5.0
9899
github.com/ultraware/funlen v0.0.3

go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/logrlint.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/timonwong/logrlint"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
const LogrLintName = "logrlint"
11+
12+
func NewLogrLint() *goanalysis.Linter {
13+
return goanalysis.NewLinter(
14+
LogrLintName,
15+
logrlint.Doc,
16+
[]*analysis.Analyzer{logrlint.Analyzer},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
}

pkg/lint/lintersdb/manager.go

+6
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
574574
WithSince("v1.8.0").
575575
WithPresets(linter.PresetStyle),
576576

577+
linter.NewConfig(golinters.NewLogrLint()).
578+
WithSince("v1.49.0").
579+
WithLoadForGoAnalysis().
580+
WithPresets(linter.PresetBugs).
581+
WithURL("https://github.com/timonwong/logrlint"),
582+
577583
linter.NewConfig(golinters.NewMaintIdx(maintIdxCfg)).
578584
WithSince("v1.44.0").
579585
WithPresets(linter.PresetComplexity).

test/linters_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func TestGoimportsLocal(t *testing.T) {
8989
ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed")
9090
}
9191

92+
func TestLogrLint(t *testing.T) {
93+
testSourcesFromDir(t, filepath.Join(testdataDir, "logrlint"))
94+
}
95+
9296
func TestGciLocal(t *testing.T) {
9397
sourcePath := filepath.Join(testdataDir, "gci", "gci.go")
9498
args := []string{

test/testdata/logrlint/example.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//golangcitest:args -Elogrlint
2+
package logrlint
3+
4+
import (
5+
"fmt"
6+
7+
"github.com/go-logr/logr"
8+
)
9+
10+
func Example() {
11+
log := logr.Discard()
12+
log = log.WithValues("key") // Error `odd number of arguments passed as key-value pairs for logging`
13+
log.Info("message", "key1", "value1", "key2", "value2", "key3") // Error `odd number of arguments passed as key-value pairs for logging`
14+
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2") // Error `odd number of arguments passed as key-value pairs for logging`
15+
log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2", "value2")
16+
}

test/testdata/logrlint/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module logrlint
2+
3+
go 1.16
4+
5+
require github.com/go-logr/logr v1.2.3

test/testdata/logrlint/go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)