Skip to content
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: "Redeclared as the imported package name" error #91

Closed
wants to merge 4 commits into from

Conversation

zcolleen
Copy link
Collaborator

Fix on issue #87

}

options.Imports = append(options.Imports, `"`+srcPackage.PkgPath+`"`)
options.Imports = append(options.Imports, srcPackageAlias+` "`+srcPackage.PkgPath+`"`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the best way is to always use srcPackageAST.Name for package alias. But im afraid we would break backwards compatibility because e.g. minimock has already such import that was added manually https://github.com/gojuno/minimock/blob/master/template.go#L22 . So if we add here import with srcPackageAST.Name alias we would break existing templates because we would have the same import duplicated

lastSrcPackagePart := getLastImportPart(srcPackageImport)
lastImpPart := getLastImportPart(imp.Path.Value)
if lastImpPart == lastSrcPackagePart {
srcPackageImportAlias = "__" + lastSrcPackagePart
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here ideally is to recursively check if there is no such import alias in project already, but i think its to much overheaded

@zcolleen zcolleen closed this Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant