-
Notifications
You must be signed in to change notification settings - Fork 8
Fix message for imported embedded structs #50
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
Conversation
@@ -24,6 +26,8 @@ type CommentStartTestStruct struct { | |||
|
|||
A `json:"a"` // want "field A is missing godoc comment" | |||
|
|||
pkg.Embedded `json:"embedded"` // want "field Embedded is missing godoc comment" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you were to name this as well, ie, if we use a named type from another package, does the name also come up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me. Do you intend fields with names like below?
NoComment pkg.Struct `json:"noComment"`
@@ -51,6 +51,8 @@ func checkField(pass *analysis.Pass, field *ast.Field, tagInfo extractjsontags.F | |||
fieldName = field.Names[0].Name | |||
} else if ident, ok := field.Type.(*ast.Ident); ok { | |||
fieldName = ident.Name | |||
} else if selector, ok := field.Type.(*ast.SelectorExpr); ok { | |||
fieldName = selector.Sel.Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it's going to be useful to many of the analyzers, probably want a helper at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this still can't handle pointer types like *Type
. Let me check it.
If the logic gets complex, it would be good to prepare a helper now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types.ExprString may work for this! Very useful function.
https://pkg.go.dev/go/types#ExprString
8fe1f67
to
240b5cc
Compare
Fixing an issue that golden files don't work in a sub-package |
} else if ident, ok := field.Type.(*ast.Ident); ok { | ||
fieldName = ident.Name | ||
} else { | ||
fieldName = types.ExprString(field.Type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well that's a lot easier!
Using embedded structs from external packages, I got an error as below: