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: unexpected comment indentation #22408

Closed
rakyll opened this issue Oct 23, 2017 · 5 comments
Closed

cmd/gofmt: unexpected comment indentation #22408

rakyll opened this issue Oct 23, 2017 · 5 comments

Comments

@rakyll
Copy link
Contributor

@rakyll rakyll commented Oct 23, 2017

$ go version
go version devel +fb54abe9ce Wed Sep 20 03:54:16 2017 +0000 darwin/amd64
type Value struct {
	Count           int64   // number of data points aggregated
	Min             float64 // minimum value in the distribution
	Max             float64 // max value in the distribution
	Mean            float64
	SumOfSquaredDev float64   // the sum of the squared deviation from the mean
	CountPerBucket  []int64   // number of occurrences per bucket
	Bounds          []float64 // histogram distribution of the values
}

Although I was expecting it to be:

type Value struct {
	Count           int64     // number of data points aggregated
	Min             float64   // minimum value in the distribution
	Max             float64   // max value in the distribution
	Mean            float64 
	SumOfSquaredDev float64   // the sum of the squared deviation from the mean
	CountPerBucket  []int64   // number of occurrences per bucket
	Bounds          []float64 // histogram distribution of the values
}

/cc @griesemer

@mvdan
Copy link
Member

@mvdan mvdan commented Oct 23, 2017

The alignment is broken if there is a line without a comment, I believe. Are you suggesting that the design should be different? Have you thought of a change to the rule in particular?

@rakyll
Copy link
Contributor Author

@rakyll rakyll commented Oct 23, 2017

I am suggesting that the alignment shouldn't be broken unless there is a new line.

@robpike
Copy link
Contributor

@robpike robpike commented Oct 23, 2017

I see this as working as intended. Each set of end-of-line comments will be aligned as a unit. A missing comment initiates a new unit.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 23, 2017

What @robpike said.

@griesemer griesemer closed this Oct 23, 2017
@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 23, 2017

To clarify: gofmt handled comments like this from day one and it is by design: A "column" of things (comments in this case) ends whenever the thing in question is missing on a new line. There are other mechanisms that end a column (e.g. indentation of a block), but if you want the comment column to continue, you need to add an (empty) comment where there's none in this case.

I can see that aligning all comments in this case looks nicer.

@golang golang locked and limited conversation to collaborators Oct 23, 2018
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
5 participants
You can’t perform that action at this time.