Skip to content

Commit 893ff0f

Browse files
raeperduudashr
authored andcommitted
Add recvcheck linter (golangci#5014)
1 parent 388959e commit 893ff0f

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

.golangci.next.reference.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,7 @@ linters:
27012701
- promlinter
27022702
- protogetter
27032703
- reassign
2704+
- recvcheck
27042705
- revive
27052706
- rowserrcheck
27062707
- sloglint
@@ -2817,6 +2818,7 @@ linters:
28172818
- promlinter
28182819
- protogetter
28192820
- reassign
2821+
- recvcheck
28202822
- revive
28212823
- rowserrcheck
28222824
- sloglint

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ require (
8686
github.com/pelletier/go-toml/v2 v2.2.3
8787
github.com/polyfloyd/go-errorlint v1.6.0
8888
github.com/quasilyte/go-ruleguard/dsl v0.3.22
89+
github.com/raeperd/recvcheck v0.1.2
8990
github.com/ryancurrah/gomodguard v1.3.5
9091
github.com/ryanrolds/sqlclosecheck v0.5.1
9192
github.com/sanposhiho/wastedassign/v2 v2.0.7

go.sum

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

jsonschema/golangci.next.jsonschema.json

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@
389389
"promlinter",
390390
"protogetter",
391391
"reassign",
392+
"recvcheck",
392393
"revive",
393394
"rowserrcheck",
394395
"scopelint",

pkg/golinters/recvcheck/recvcheck.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package recvcheck
2+
3+
import (
4+
"github.com/raeperd/recvcheck"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/goanalysis"
8+
)
9+
10+
func New() *goanalysis.Linter {
11+
a := recvcheck.Analyzer
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package recvcheck_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/golangci/golangci-lint/test/testshared/integration"
7+
)
8+
9+
func TestFromTestdata(t *testing.T) {
10+
integration.RunTestdata(t)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//golangcitest:args -Erecvcheck
2+
package testdata
3+
4+
import "fmt"
5+
6+
type Bar struct{} // want `the methods of "Bar" use pointer receiver and non-pointer receiver.`
7+
8+
func (b Bar) A() {
9+
fmt.Println("A")
10+
}
11+
12+
func (b *Bar) B() {
13+
fmt.Println("B")
14+
}

pkg/lint/lintersdb/builder_linter.go

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import (
8686
"github.com/golangci/golangci-lint/pkg/golinters/promlinter"
8787
"github.com/golangci/golangci-lint/pkg/golinters/protogetter"
8888
"github.com/golangci/golangci-lint/pkg/golinters/reassign"
89+
"github.com/golangci/golangci-lint/pkg/golinters/recvcheck"
8990
"github.com/golangci/golangci-lint/pkg/golinters/revive"
9091
"github.com/golangci/golangci-lint/pkg/golinters/rowserrcheck"
9192
"github.com/golangci/golangci-lint/pkg/golinters/sloglint"
@@ -664,6 +665,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
664665
WithLoadForGoAnalysis().
665666
WithURL("https://github.com/curioswitch/go-reassign"),
666667

668+
linter.NewConfig(recvcheck.New()).
669+
WithSince("v1.62.0").
670+
WithPresets(linter.PresetBugs).
671+
WithLoadForGoAnalysis().
672+
WithURL("https://github.com/raeperd/recvcheck"),
673+
667674
linter.NewConfig(revive.New(&cfg.LintersSettings.Revive)).
668675
WithSince("v1.37.0").
669676
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).

0 commit comments

Comments
 (0)