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: align function parameter types on subsequent lines #33507

Closed
D1CED opened this issue Aug 6, 2019 · 2 comments
Closed

cmd/gofmt: align function parameter types on subsequent lines #33507

D1CED opened this issue Aug 6, 2019 · 2 comments

Comments

@D1CED
Copy link

@D1CED D1CED commented Aug 6, 2019

Signatures of functions taking a lot of parameters are quickly exceeding a readable line length (80-120 characters).

func httpHandlerFunc(logger *log.Logger, db *sql.DB, imgCache map[string]io.Reader, w http.ResponseWriter, r *http.Request)

To make this more readable one can put each parameter on an individual line like so:

func httpHandlerFunc(
	logger *log.Logger,
	db *sql.DB,
	imgCache map[string]io.Reader,
	w http.ResponseWriter,
	r *http.Request,
)

In contrast to most other forms e.g. imports, structs, variable and constant declarations gofmt does not align this form. I propose that this form should be recognised by gofmt and parameter names and parameter types be appropriately aligned.

func httpHandlerFunc(
	logger   *log.Logger,
	db       *sql.DB,
	imgCache map[string]io.Reader,
	w        http.ResponseWriter,
	r        *http.Request,
)

The objective of this proposal is to increase readability and make formatting rules more consistent.

@jgoc
Copy link

@jgoc jgoc commented Aug 8, 2019

Also for type parameters and multiple returns

func httpHandlerFunc(
	type T constraints.Comparable,
	     U constraints.Ordered,
) (
	logger   *log.Logger,
	db       *sql.DB,
	imgCache map[string]io.Reader,
	w        http.ResponseWriter,
	r        *http.Request,
) (
	f   func(w http.ResponseWriter, r *http.Request),
	err error,
)
@andybons
Copy link
Member

@andybons andybons commented Aug 12, 2019

Sorry, but gofmt is pretty much frozen at this point. Thanks for the issue.

As the syntax for contracts evolves and becomes more concrete, I would reopen a proposal specific to that, but we're still too early to be talking about code formatting since we don't know what the final syntax is.

@andybons andybons closed this Aug 12, 2019
@golang golang locked and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.