mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
fix #982
This commit is contained in:
@@ -138,16 +138,32 @@ func getStructName(r *ast.FieldList) string {
|
|||||||
|
|
||||||
switch v := t.(type) {
|
switch v := t.(type) {
|
||||||
case *ast.StarExpr:
|
case *ast.StarExpr:
|
||||||
t = v.X
|
return extractFromStarExpr(v)
|
||||||
case *ast.IndexExpr:
|
case *ast.IndexExpr:
|
||||||
t = v.X
|
return extractFromIndexExpr(v)
|
||||||
|
case *ast.Ident:
|
||||||
|
return v.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if p, _ := t.(*ast.Ident); p != nil {
|
return defaultStructName
|
||||||
result = p.Name
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
func extractFromStarExpr(expr *ast.StarExpr) string {
|
||||||
|
switch v := expr.X.(type) {
|
||||||
|
case *ast.IndexExpr:
|
||||||
|
return extractFromIndexExpr(v)
|
||||||
|
case *ast.Ident:
|
||||||
|
return v.Name
|
||||||
|
}
|
||||||
|
return defaultStructName
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractFromIndexExpr(expr *ast.IndexExpr) string {
|
||||||
|
switch v := expr.X.(type) {
|
||||||
|
case *ast.Ident:
|
||||||
|
return v.Name
|
||||||
|
}
|
||||||
|
return defaultStructName
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkStructFields(fields *ast.FieldList, structName string, w *lintConfusingNames) {
|
func checkStructFields(fields *ast.FieldList, structName string, w *lintConfusingNames) {
|
||||||
|
|||||||
11
testdata/confusing-naming1.go
vendored
11
testdata/confusing-naming1.go
vendored
@@ -70,3 +70,14 @@ type y[T any] struct{}
|
|||||||
|
|
||||||
func (y[T]) method() {
|
func (y[T]) method() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue #982
|
||||||
|
type a[T any] struct{}
|
||||||
|
|
||||||
|
func (x *a[T]) method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
type b[T any] struct{}
|
||||||
|
|
||||||
|
func (x *b[T]) method() {
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user