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

vars and consts grouped #33

Closed
domgreen opened this issue Jul 31, 2019 · 3 comments
Closed

vars and consts grouped #33

domgreen opened this issue Jul 31, 2019 · 3 comments

Comments

@domgreen
Copy link

Ideally, it would be best to group all vars/consts that are defined close to each other.

Example:

bad:

var a = "a"
var b = "b"

good:

var (
	a = "a"
	b = "b"
)
@mvdan
Copy link
Owner

mvdan commented Aug 4, 2019

Thanks! I wonder if this would be too noisy to do for two lines, as we double the amount of source lines. But I'd definitely agree that this should happen for three or more contiguous lines.

@andrewrynhard
Copy link

I think I'd still prefer it with only 2 or more. Maybe that could be configurable?

@mvdan
Copy link
Owner

mvdan commented Aug 17, 2019

I'm afraid configuration is near impossible; if we added any flags, config files, or env vars, then this tool would no longer be a drop-in replacement for gofmt.

I also want this tool to be a "gofmt with some extras", so it should work out of the box without any extra configuration needed. If anything requires the user to make a decision, it's not worth doing in a formatting tool that's opinionated.

Having said this, we could make different decisions based on the context. For example, I think globals should be grouped if there are at least 2. Local variables could have a higher threshold (like 3) if 2 is too noisy.

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

3 participants