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

feat: imports grouping #1037

Merged
merged 1 commit into from
Jan 3, 2025
Merged

feat: imports grouping #1037

merged 1 commit into from
Jan 3, 2025

Conversation

MilkeeyCat
Copy link
Contributor

This pr changes formatter to keep a new line between imports. For example, if you had such code:

package main

import (
	"fmt"
	"strings"

	"strconv"
)

var _, _ = fmt.Print("")
var _ = strings.Index("", "")
var _ = strconv.Quote("")

It would remove the empty line, but now it doesn't.

closes #939

@a-h
Copy link
Owner

a-h commented Jan 3, 2025

Looks good, could you add a test please?

Should be fairly easy to add something to the txtar files in testdata, as per https://github.com/a-h/templ/blob/main/cmd/templ/imports/testdata/namedimportsadd.txtar

@MilkeeyCat
Copy link
Contributor Author

groups.txtar

-- fmt.templ --
package test

import (
	"strings"
	"fmt"

	"strconv"
)

var _, _ = fmt.Print(strings.Contains(strconv.Quote("Hello"), ""))
-- fmt.templ --
package test

import (
	"fmt"
	"strings"

	"strconv"
)

var _, _ = fmt.Print(strings.Contains(strconv.Quote("Hello"), ""))

Something like this?

@a-h
Copy link
Owner

a-h commented Jan 3, 2025

Yes, but if there's any other behaviour to consider, like what happens if there's two line breaks, something to cover those scenarios would also be helpful.

Thanks!

@MilkeeyCat MilkeeyCat force-pushed the pr_imports_grouping branch from 2fd5972 to 51bc903 Compare January 3, 2025 13:48
@a-h a-h merged commit e47f4c5 into a-h:main Jan 3, 2025
4 checks passed
@a-h
Copy link
Owner

a-h commented Jan 3, 2025

Thanks for that, much appreciated!

@MilkeeyCat MilkeeyCat deleted the pr_imports_grouping branch January 3, 2025 16:07
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.

Allow import grouping
2 participants