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

Groups with comments below single var declaration are unexpectedly formatted #256

Closed
ndrpnt opened this issue Jan 5, 2023 · 1 comment
Closed

Comments

@ndrpnt
Copy link

ndrpnt commented Jan 5, 2023

This is more of a question. The current behavior:

var (
	foo = "foo"
	// bar = "bar"
	// baz = "baz"
)
var foo = "foo" // bar = "bar"
// baz = "baz"

Is it desired ? I would expect gofumpt to either keep the parentheses and comments untouched, or to format this way:

var foo = "foo"
// bar = "bar"
// baz = "baz"

This is also consistent with the behavior when adding an inline comment:

var (
	foo = "foo" // foo
	// bar = "bar"
	// baz = "baz"
)
var foo = "foo" // foo
// bar = "bar"
// baz = "baz"

I have no strong opinion on the matter, I just found it surprising. Feel free to close if this is intended

@mvdan
Copy link
Owner

mvdan commented Jan 5, 2023

The grouping seems right, even if it looks off - the commens are just comments, so they aren't considered as declarations. And a lone grouped declaration loses the grouping as it's overkill.

In your first example, // bar = "bar" should not become an inline comment, though. That's a bug.

@mvdan mvdan closed this as completed in 05ac8b3 Apr 8, 2023
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