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

feature: Enforce line breaks between multiline function calls with func() argument #290

Open
Limero opened this issue Jan 5, 2024 · 1 comment

Comments

@Limero
Copy link

Limero commented Jan 5, 2024

At work we often use t.Run() inside of test cases to separate parts of it, but there is no consistency to the line breaks separating these, so our tests often end up looking like this:

t.Run("a", func(t *testing.T) {
	//
})
t.Run("b", func(t *testing.T) {
	//
})

t.Run("c", func(t *testing.T) {
	//
})

It would be useful if gofumpt enforced the linebreaks between multiline function calls with func() as argument.

When a function is passed as an argument, it basically becomes a wrapper around a stand-alone function, so rules similar to the existing "Multiline top-level declarations must be separated by empty lines" rule should be applied.

Expected result:

t.Run("a", func(t *testing.T) {
	//
})

t.Run("b", func(t *testing.T) {
	//
})

t.Run("c", func(t *testing.T) {
	//
})
@mvdan
Copy link
Owner

mvdan commented Jan 28, 2024

Thanks for filing this issue. I can see how you might want consistency when empty lines are used between some t.Run calls and not others, but I honestly don't think either approach (all use empty lines in between, versus none use empty lines in between) is clearly the canonical formatting that everyone should use.

For example, https://github.com/cue-labs/oci/blob/14751940d5b22f24e01c024cc61a3138565f8c7e/ociregistry/internal/conformance/conformance_test.go#L131-L139 seems perfectly fine to me, as does https://github.com/go-json-experiment/json/blob/2e55bd4e08b08427ba10066e9617338e1f113c53/jsontext/coder_test.go#L704-L753, which also seems to group subtest functions based on the categories.

All in all, I don't think we can enforce anything like this in general.

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

No branches or pull requests

2 participants