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

cmd/gofmt: indenting of multi-line argument list is confusing #48064

Closed
ghost opened this issue Aug 30, 2021 · 5 comments
Closed

cmd/gofmt: indenting of multi-line argument list is confusing #48064

ghost opened this issue Aug 30, 2021 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 30, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17 linux/amd64

What did you do?

I pass this file to gofmt:

func f(first int,
second string) {
fmt.Println(first, second, third)
fmt.Println("That's all folks")
}

What did you see?

func f(first int,
	second string) {
	fmt.Println(first, second, third)
	fmt.Println("That's all folks")
}

Notice how the argument list blends into the function's code.

What did you expect?

I can think of two options:

  • Add two indentation levels when starting the second line of the multi-line argument list, and remove one indentation level when entering the function
func f(first int,
		second string) {
	fmt.Println(first, second, third)
	fmt.Println("That's all folks")
}
  • Align with the first argument of the argument list
func f(first int,
       second string) {
    fmt.Println(first, second, third)
    fmt.Println("That's all folks")
}
@ghost
Copy link
Author

ghost commented Aug 30, 2021

I don't know the logic of gofmt. This might be the same issue as #48065. Sorry to double submit if this is the case.

@cherrymui
Copy link
Member

I think we always indent a tab if the second line is the same statement following the first line. So this is working as intended.

cc @griesemer to confirm. Thanks.

@griesemer
Copy link
Contributor

What @cherrymui said.

@ghost
Copy link
Author

ghost commented Sep 2, 2021

I would think the goal of gofmt is to produce easily readable code. As shown by my example "always indent a tab if the second line is the same statement following the first line" is clearly not a great rule.

I didn't want to submit this as a bug. I searched for ways to submit improvements, but couldn't find anything. So I submitted it here as an issue. In most other projects, github issues are also used to discuss new feature/improvements. But seeing how quickly this get closed, I must have been wrong.

So how do I submit a request for an improvement to gofmt?

@seankhliao
Copy link
Member

proposals are also filed as issues, but given how large of a change this would be for negligible gain it is unlikely to ever be accepted

@golang golang locked and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants