-
Notifications
You must be signed in to change notification settings - Fork 81
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: Key construction in ExtractGoComments
#112
base: main
Are you sure you want to change the base?
Conversation
@samlown I think this actually fixes the intended use of See cloudquery/cloudquery#14647 for usage example with both vendored code & path that includes |
Hi @samlown! Is there a chance to get this PR (and the other PRs I opened t this repo) reviewed & merged? |
"go/doc" | ||
"go/parser" | ||
"go/token" | ||
"golang.org/x/exp/maps" |
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.
I'm not sure that we want to be using experimental stuff...
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.
I can copy the implementation as it's just a straightforward map[key]value -> []value
func.
LMK if you think this is the way.
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 I understand correctly, this proposal will break previous implementations, certainly the tests have changed suggesting old code would need to be modified. I do not think thats a good idea unless absolutely necessary.
In this case it is just fixing the bug that exists in the mainline version. @samlown as the test update suggests, the only issue seen here is adding the full pkg path for the import (or adding a root of vendored pkg to traverse correctly). Could you please reassess this? |
@samlown any updates? |
The intended (from README.md) usage of
ExtractGoComments(base, path string, commentMap map[string]string) error
treats the params as following:base
– package import pathpath
– package location on the filesystemcommentMap
outputIf we pass
"../"
aspath
param the code will fail to load comments properly because of thepath.Join
used on the unverified input. Moreover, if thepath
is the absolute path, the code will join it withbase
so we end up with keysbase + "/" + absPath
(cleaned in thepath.Clean
func, but still).This PR fixes the behavior in the following way:
path
torootPath
for better understanding the semantics & not allowing name clashes in the funcroot
variable equal to the absolute path of therootPath
locationroot
pathroot
prefix of the path prior to joining with thebase
value