1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-17 20:57:58 +02:00

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

This commit is contained in:
chavacava 2023-08-12 10:56:53 +02:00 committed by GitHub
parent 7cb4540a46
commit 16871ed55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -27,10 +27,10 @@ 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
}
}
@ -38,7 +38,6 @@ func (ps *packages) methodNames(lp *lint.Package) pkgMethods {
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
}
@ -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
@ -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 {

View File

@ -1,5 +1,4 @@
// Test of confusing-naming rule.
// Package pkg ...
package pkg
@ -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() {
}