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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

Lines changed: 1 addition & 0 deletions
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

Lines changed: 19 additions & 0 deletions
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+
}
Lines changed: 11 additions & 0 deletions
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+
}
Lines changed: 14 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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)