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

consider breaking lines before ) in multi-line calls #74

Open
kovetskiy opened this issue Jun 12, 2020 · 4 comments
Open

consider breaking lines before ) in multi-line calls #74

kovetskiy opened this issue Jun 12, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@kovetskiy
Copy link

kovetskiy commented Jun 12, 2020

gofumpt doesn't enforce any styles related to closing ) in multi-line calls:

	x := call(
		a,
		b,
		c,
	)

	x := call(
		a,
		b,
		c)

It would be great if gofumpt would format these calls to the first option (or at least one of them, but I personally prefer the first one because it makes it clear that the next line should go on the same indentation level)

@mvdan
Copy link
Owner

mvdan commented Jun 12, 2020

Sounds good. Let's make this rule a bit conservative for now, though; if we make all multi-line argument lists use a separate closing parentheses, we would rewrite

x := call(a, b,
    c, d)

into one of

x := call(
    a, b,
    c, d,
)

x := call(
    a,
    b,
    c,
    d,
)

You could argue we want to do something like that in the long run, but it seems like less of a clear case. For example, we could only apply the rule to place ) at the start of a line when ( is at the end of a line as well.

@mvdan mvdan added the enhancement New feature or request label Nov 23, 2020
@icio
Copy link

icio commented Mar 3, 2021

I'd hope for at least the opening/closing newline behaviour of "Composite literals should use newlines consistently":

// A newline before or after an element requires newlines for the opening and
// closing braces.
var ints = []int{1, 2,
	3, 4}
// ->
var ints = []int{
	1, 2,
	3, 4,
}

@mvdan
Copy link
Owner

mvdan commented Mar 3, 2021

@icio the plan is to only change the code if the opening parentheses is at the end of a line, or if the closing parenthesis is at the start of a line. Those cases are pretty clearly inconsistent.

What you suggest, which is what I mentioned in my last comment, would also trigger the rule if there are any newlines between arguments. I think that makes sense for composite literals, but I'm not convinced it always makes sense for calls. I'm still leaving that idea as a "maybe" for the future, but for now I want to add the more conservative rule that's a clear win.

@kovetskiy
Copy link
Author

There is also https://github.com/segmentio/golines which does exactly one thing — splits long lines. It perfectly fits with gofumpt at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants