Skip to content
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

fix #864: confusing-naming FP on methods of generic types #869

Merged
merged 1 commit into from
Aug 12, 2023
Merged
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
11 changes: 7 additions & 4 deletions rule/confusing-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ type packages struct {

func (ps *packages) methodNames(lp *lint.Package) pkgMethods {
ps.mu.Lock()
defer ps.mu.Unlock()

for _, pkg := range ps.pkgs {
if pkg.pkg == lp {
ps.mu.Unlock()
return pkg
}
}

pkgm := pkgMethods{pkg: lp, methods: make(map[string]map[string]*referenceMethod), mu: &sync.Mutex{}}
ps.pkgs = append(ps.pkgs, pkgm)

ps.mu.Unlock()
return pkgm
}

Expand Down Expand Up @@ -72,6 +71,7 @@ func (*ConfusingNamingRule) Name() string {

// checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file.
func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {

if id.Name == "init" && holder == defaultStructName {
// ignore init functions
return
Expand Down Expand Up @@ -137,8 +137,11 @@ func getStructName(r *ast.FieldList) string {

t := r.List[0].Type

if p, _ := t.(*ast.StarExpr); p != nil { // if a pointer receiver => dereference pointer receiver types
t = p.X
switch v := t.(type) {
case *ast.StarExpr:
t = v.X
case *ast.IndexExpr:
t = v.X
}

if p, _ := t.(*ast.Ident); p != nil {
Expand Down
12 changes: 11 additions & 1 deletion testdata/confusing-naming1.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Test of confusing-naming rule.

// Package pkg ...
package pkg

Expand Down Expand Up @@ -60,3 +59,14 @@ type tBar struct {
qwe bool
zxc float32
}

// issue #864
type x[T any] struct{}

func (x[T]) method() {
}

type y[T any] struct{}

func (y[T]) method() {
}
Loading