Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Entuazism committed May 10, 2024
1 parent 582822e commit 6a2eb55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
26 changes: 21 additions & 5 deletions rule/confusing-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,32 @@ func getStructName(r *ast.FieldList) string {

switch v := t.(type) {
case *ast.StarExpr:
t = v.X
return extractFromStarExpr(v)
case *ast.IndexExpr:
t = v.X
return extractFromIndexExpr(v)
case *ast.Ident:
return v.Name
}

if p, _ := t.(*ast.Ident); p != nil {
result = p.Name
return defaultStructName
}

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
}

return result
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) {
Expand Down
11 changes: 11 additions & 0 deletions testdata/confusing-naming1.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ type y[T any] struct{}

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() {
}

0 comments on commit 6a2eb55

Please sign in to comment.