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

make breaking long lines manually easier by reading off of trailing commas #279

Open
effinsky opened this issue Aug 7, 2023 · 0 comments

Comments

@effinsky
Copy link

effinsky commented Aug 7, 2023

Hi, I realize there's been some talk of making gofumpt take care of breaking long lines, but that's not gone anywhere, I don't think. I'd like to ask about something related, but a different approach.

Inspired by formatters for Zig and by Black (for Python), I'd like to suggest including some logic that would latch onto a presence/absence of a trailing comma in a param/arg/field list to break a def or decl automatically. I think we have nothing like this on the fmt level now except for Golines which (according to my colleagues, at least) takes away too much control from our code formatting. So here's how that would work:

If you write one of the above, say a func sig, pre-save, this way (mind the trailing comma):

func TooLong(longParamName string, longParamName2 string, longParamName3 string,) string {
}

and then hit save (or just fmt), then if gets broken down into:

func TooLong(
	longParamName string, 
	longParamName2 string, 
	longParamName3 string,
) string {
}

But if you omit the trailing comma to begin with and then save/fmt, it does not get broken down.

Analogously, if you have a def etc that's split into several lines like so (mind the trailing comma now removed, we are pre-save/fmt):

func TooLong(
	longParamName string, 
	longParamName2 string, 
	longParamName3 string
) string {
}

and now you hit save/fmt, the lines get joined into a single-line (notably, trailing comma now missing post-join as well):

func TooLong(longParamName string, longParamName2 string, longParamName3 string) string {
}

Would you consider adding this kind of a feature? I am sold on it, frankly -- it gives you control over the line length, but also lets you easily break lines down and bring them back together quickly with the assistance of the fmtr.

All the best!

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

1 participant