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: duplicate import added when import path contains hyphens (#859) #890

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

a-h
Copy link
Owner

@a-h a-h commented Aug 19, 2024

No description provided.

joerdav
joerdav previously approved these changes Aug 19, 2024
Copy link
Collaborator

@joerdav joerdav left a comment

Choose a reason for hiding this comment

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

Cool, this looks good to me!

@joerdav joerdav dismissed their stale review August 21, 2024 10:22

Will take a look again once you're ready!

@a-h
Copy link
Owner Author

a-h commented Aug 21, 2024

I think the issue was actually in the underlying imports repo. Now, duplicate imports aren't being added by the tooling.

I've added a unit test to capture the expected behaviour:

  • If the import isn't used, it's removed by the go imports.Process package, since the referenced name can't be resolved.
package main

import (
	"context"
	"os"
        // Next line is removed.
	"templ/testproject/css-classes"
)

templ View() {
}

func main() {
	View().Render(context.Background(), os.Stdout)
}
  • If the import is present, it's not removed:
package main

import (
	"context"
	"os"
        // Next line is retained.
	cssclasses "templ/testproject/css-classes"
)

templ View() {
	{ cssclasses.Header }
}

func main() {
	View().Render(context.Background(), os.Stdout)
}
  • If the import is not named, the name is added:

  • If the import isn't used, it's removed by the go imports.Process package, since the referenced name can't be resolved.

package main

import (
	"context"
	"os"
	cssclasses "templ/testproject/css-classes"
)

templ View() {
	{ cssclasses.Header }
}

func main() {
	View().Render(context.Background(), os.Stdout)
}

@joerdav
Copy link
Collaborator

joerdav commented Aug 22, 2024

Okay that makes sense! The fix is the version bump of the experimental modules, great looks good to me then

@a-h a-h merged commit 4b2219c into main Aug 23, 2024
3 checks passed
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.

2 participants