feat: add logrlint (#3093)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
320a18eb37
commit
f48530e25e
@ -1932,6 +1932,7 @@ linters:
|
||||
- interfacer
|
||||
- ireturn
|
||||
- lll
|
||||
- logrlint
|
||||
- maintidx
|
||||
- makezero
|
||||
- maligned
|
||||
@ -2035,6 +2036,7 @@ linters:
|
||||
- interfacer
|
||||
- ireturn
|
||||
- lll
|
||||
- logrlint
|
||||
- maintidx
|
||||
- makezero
|
||||
- maligned
|
||||
|
4
Makefile
4
Makefile
@ -43,6 +43,10 @@ test_linters:
|
||||
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdata/$T
|
||||
.PHONY: test_linters
|
||||
|
||||
test_linters_sub:
|
||||
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataSubDir/$T
|
||||
.PHONY: test_linters_sub
|
||||
|
||||
# Maintenance
|
||||
|
||||
fast_generate: assets/github-action-config.json
|
||||
|
1
go.mod
1
go.mod
@ -94,6 +94,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.1.0
|
||||
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
|
||||
|
2
go.sum
generated
2
go.sum
generated
@ -530,6 +530,8 @@ github.com/tetafro/godot v1.4.11 h1:BVoBIqAf/2QdbFmSwAWnaIqDivZdOV0ZRwEm6jivLKw=
|
||||
github.com/tetafro/godot v1.4.11/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
|
||||
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=
|
||||
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
github.com/timonwong/logrlint v0.1.0 h1:phZCcypL/vtx6cGxObJgWZ5wexZF5SXFPLOM+ru0e/M=
|
||||
github.com/timonwong/logrlint v0.1.0/go.mod h1:Zleg4Gw+kRxNej+Ra7o+tEaW5k1qthTaYKU7rSD39LU=
|
||||
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
|
||||
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
|
||||
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
|
||||
|
19
pkg/golinters/logrlint.go
Normal file
19
pkg/golinters/logrlint.go
Normal file
@ -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"
|
||||
)
|
||||
|
||||
func NewLogrLint() *goanalysis.Linter {
|
||||
a := logrlint.Analyzer
|
||||
|
||||
return goanalysis.NewLinter(
|
||||
a.Name,
|
||||
a.Doc,
|
||||
[]*analysis.Analyzer{a},
|
||||
nil,
|
||||
).WithLoadMode(goanalysis.LoadModeTypesInfo)
|
||||
}
|
@ -582,6 +582,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).
|
||||
|
@ -25,6 +25,18 @@ func TestTypecheck(t *testing.T) {
|
||||
testSourcesFromDir(t, filepath.Join(testdataDir, "notcompiles"))
|
||||
}
|
||||
|
||||
func TestSourcesFromTestdataSubDir(t *testing.T) {
|
||||
subDirs := []string{
|
||||
"logrlint",
|
||||
}
|
||||
|
||||
for _, dir := range subDirs {
|
||||
t.Run(dir, func(t *testing.T) {
|
||||
testSourcesFromDir(t, filepath.Join(testdataDir, dir))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testSourcesFromDir(t *testing.T, dir string) {
|
||||
t.Helper()
|
||||
|
||||
|
5
test/testdata/logrlint/go.mod
vendored
Normal file
5
test/testdata/logrlint/go.mod
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module logrlint
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/go-logr/logr v1.2.3
|
2
test/testdata/logrlint/go.sum
generated
vendored
Normal file
2
test/testdata/logrlint/go.sum
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
16
test/testdata/logrlint/logrlint.go
vendored
Normal file
16
test/testdata/logrlint/logrlint.go
vendored
Normal file
@ -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") // 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")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user