Skip to content

Add receivernamelen linter #5007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,7 @@ linters:
- promlinter
- protogetter
- reassign
- receivernamelen
- revive
- rowserrcheck
- sloglint
Expand Down Expand Up @@ -2804,6 +2805,7 @@ linters:
- promlinter
- protogetter
- reassign
- receivernamelen
- revive
- rowserrcheck
- sloglint
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ require (
github.com/yagipy/maintidx v1.0.0
github.com/yeya24/promlinter v0.3.0
github.com/ykadowak/zerologlint v0.1.5
github.com/ytnsym/receivernamelen v0.0.0-20240911094623-cb234a87d58c
gitlab.com/bosi/decorder v0.4.2
go-simpler.org/musttag v0.12.2
go-simpler.org/sloglint v0.7.2
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.

1 change: 1 addition & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"promlinter",
"protogetter",
"reassign",
"receivernamelen",
"revive",
"rowserrcheck",
"scopelint",
Expand Down
19 changes: 19 additions & 0 deletions pkg/golinters/receivernamelen/receivernamelen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package receivernamelen

import (
"github.com/ytnsym/receivernamelen"
"golang.org/x/tools/go/analysis"

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

func New() *goanalysis.Linter {
a := receivernamelen.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
11 changes: 11 additions & 0 deletions pkg/golinters/receivernamelen/receivernamelen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package receivernamelen

import (
"testing"

"github.com/golangci/golangci-lint/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
20 changes: 20 additions & 0 deletions pkg/golinters/receivernamelen/testdata/receivernamelen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//golangcitest:args -Ereceivernamelen
package testdata

type Example1 struct{}

func (e *Example1) F() {}

type Example2 struct{}

func (ex *Example2) F() {}

type Example3 struct{}

func (ex3 *Example3) F() {} // want `receiver variable names must be one or two letters in length`

type Example4 struct{}

func (example *Example4) F() {} // want `receiver variable names must be one or two letters in length`

func F() {}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import (
"github.com/golangci/golangci-lint/pkg/golinters/promlinter"
"github.com/golangci/golangci-lint/pkg/golinters/protogetter"
"github.com/golangci/golangci-lint/pkg/golinters/reassign"
"github.com/golangci/golangci-lint/pkg/golinters/receivernamelen"
"github.com/golangci/golangci-lint/pkg/golinters/revive"
"github.com/golangci/golangci-lint/pkg/golinters/rowserrcheck"
"github.com/golangci/golangci-lint/pkg/golinters/sloglint"
Expand Down Expand Up @@ -657,6 +658,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithLoadForGoAnalysis().
WithURL("https://github.com/curioswitch/go-reassign"),

linter.NewConfig(receivernamelen.New()).
WithSince("v1.62.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ytnsym/receivernamelen"),

linter.NewConfig(revive.New(&cfg.LintersSettings.Revive)).
WithSince("v1.37.0").
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
Expand Down