-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Templ formatting breaks imports at v0.2.747 #859
Comments
Seems like this PR is at fault |
Here is an example.
Output:
As you can see, |
Thanks for the bug report, and sorry for the inconvenience. The tests for templ auto-import adjustments are in the repo at The first section (delineated by the --) is the input, and the second section is the expected output.
This makes it pretty easy to add new test cases, so I dropped your sample input into a file, and ran I didn't see a duplicate
So, I wonder if the test can't reproduce this because of the lack of I'll try that next. |
Yes, I can reproduce with a simpler example.
css-classes/classes.gopackage cssclasses
const Header = "header" main.templpackage main
import (
"context"
"github.com/a-h/templ/cmd/templ/imports/testdata/module/css-classes"
"os"
)
templ View() {
{ cssclasses.Header }
}
func main() {
View().Render(context.Background(), os.Stdout)
} OutputThis is then formatted to: package main
import (
"context"
"github.com/a-h/templ/cmd/templ/imports/testdata/module/css-classes"
cssclasses "github.com/a-h/templ/cmd/templ/imports/testdata/module/css-classes"
"os"
)
templ View() {
{ cssclasses.Header }
}
func main() {
View().Render(context.Background(), os.Stdout)
} |
OK, I have a PR for this at #890 If you have time to build templ from source and test it out, that would be great. |
Actually, might need a bit more thinking as per golang/go#28428 - the expected behaviour is to always add the alias. But it shouldn't add two copies of the import and break stuff. |
Fixed in 4b2219c |
There is a problem we noticed with formatting after upgrading to v0.2.747:
To Reproduce
To reproduce you need multiple lines with hyphen in the folder name but package name without like this
import "someproject/components/standard-metadata"
someproject/components/standard-metadata/some.go
file has astandardmetadata
package name. In go it is ok to import a package with hyphens without an alias.templ fmt .
adds the alias, which isn't a big deal, but breaking imports is.Expected behavior
Either leave imports as is without adding the aliases or add the alias but not remove or duplicate lines
Logs
N/A
templ info
outputRun
templ info
and include the output.Desktop (please complete the following information):
templ version
): v0.2.747go version
): go1.22.5gopls
version (gopls version
): v0.14.2Additional context
Reproducing seems to be deterministic. Same input generates same broken output
The text was updated successfully, but these errors were encountered: