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: comments under case statements indented inconsistently #20681

Closed
stjj89 opened this issue Jun 15, 2017 · 5 comments
Closed

cmd/gofmt: comments under case statements indented inconsistently #20681

stjj89 opened this issue Jun 15, 2017 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@stjj89
Copy link
Contributor

stjj89 commented Jun 15, 2017

go version go1.8.1.typealias linux/amd64

gofmt indents comments under case statements differently, depending on whether or not there is a subsequent default case.

https://play.golang.org/p/04RrASTyjn

Press "Format" and notice that "// CommentBar" is properly indented, whereas "// CommentFoo" is missing an indent.

@bradfitz bradfitz changed the title gofmt: comments under case statements indented inconsistently cmd/gofmt: comments under case statements indented inconsistently Jun 15, 2017
@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 15, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Jun 15, 2017
@griesemer
Copy link
Contributor

That's because it's not obvious whether //CommentFoo belongs to the (missing) code for case "a" or whether it's a comment for the next (default) case. There's some heuristics one could employ but there's no clear-cut approach. In fact, if you indent manually, gofmt accepts that as well.

Leaving open for future consideration.

@mattn
Copy link
Member

mattn commented Jun 15, 2017

It works well for me.

package test

func foo(a string) {
	switch {
	// if a is "a"
	case a == "a":
		// then call doSomething()
	// not all
	default:
		// then call doOtherThing()
	}
}

@stjj89
Copy link
Contributor Author

stjj89 commented Jun 15, 2017

That's because it's not obvious whether //CommentFoo belongs to the (missing) code for case "a" or whether it's a comment for the next (default) case. There's some heuristics one could employ but there's no clear-cut approach. In fact, if you indent manually, gofmt accepts that as well.

Thanks for the explanation, that makes sense.

@josharian
Copy link
Contributor

See also #9910, of which this is perhaps a dup.

@griesemer
Copy link
Contributor

@josharian Yes, indeed. Closing as duplicate of #9910.

@golang golang locked and limited conversation to collaborators Jun 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants