-
Notifications
You must be signed in to change notification settings - Fork 95
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
Refactor imports #109
Refactor imports #109
Conversation
Index imports so that any duplicate aliase can be detected immediately before they are added. Instead of hiding the types.TypeString call, implement a types.Qualifier which can be used to return the package alias.
55e6de7
to
43c541f
Compare
} | ||
|
||
// AddImport creates an import with the given alias and path, and adds it to | ||
// Fake.Imports. | ||
func (f *Fake) AddImport(alias string, path string) Import { | ||
func (i *Imports) Add(alias string, path string) Import { | ||
// TODO: why is there extra whitespace on these args? |
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.
Not sure I understand; which white space / args are you referring to?
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.
path
and alias
are both passed to strings.TrimSpace
so I assume there is either leading or trailing whitespace on those strings, but it is not clear to me where that would come from. It seems like this is called with values from inspecting go/types
, which I would assume do not contain extra whitespace.
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 guess I am just always defensive with function arguments (particularly when exported).
unvendor was a copy of this function. x/tools/imports is already a dependency of this package.
I believe in order to implement #103 properly 2 changes must be made:
types.TypeString
needs to be called withtypes.RelativeTo
to remove the package selector when the package matches the target packagetypes.TypeString
for the line withvar _ {{.TargetAlias}}.{{.TargetName}} =
This refactor should make it easier to implement both of these changes. It reduces the code required to handle imports, and I believe makes it easier to follow by doing de-duplication immediately, instead of a post-processing step, which required changing aliases and logic related to imports to
Index imports so that any duplicate aliase can be detected immediately before they are added.
Instead of hiding the types.TypeString call, implement a
types.Qualifier
which can be used to return the package alias. In a follow up PR this can be updated to make the call totypes.RelativeTo
.