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

go/format: align top-of-case comments with case statement #9910

Closed
josharian opened this issue Feb 17, 2015 · 1 comment
Closed

go/format: align top-of-case comments with case statement #9910

josharian opened this issue Feb 17, 2015 · 1 comment

Comments

@josharian
Copy link
Contributor

Consider this code

func sign(i int) int {
    switch i {
    default:
        return 0

    // negative
    case i < 0:
        return -1

        // positive
    case i > 0:
        return 1
    }
}

go/format leaves the "negative" and the "positive" comments untouched. This is presumably because it is ambiguous whether the comment is associated with the code above or the case statement below.

I'd suggest as a heuristic that if there is a blank line before the comment (or a run of comments with no blank lines) and no blank line afterwards, then it should be aligned with the case statement.

This would fix many misaligned comments in CL 4851.

@griesemer griesemer self-assigned this Feb 17, 2015
@rsc
Copy link
Contributor

rsc commented Apr 10, 2015

Sometimes you want one or the other. Gofmt preserves what you've done.
The bad comments in the compiler are my fault and should be fixed separately.

@rsc rsc closed this as completed Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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