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: Faulty Comment Re-Arrangement in Argument Lists #13113

Open
matttproud opened this issue Oct 30, 2015 · 3 comments
Open

cmd/gofmt: Faulty Comment Re-Arrangement in Argument Lists #13113

matttproud opened this issue Oct 30, 2015 · 3 comments
Assignees
Milestone

Comments

@matttproud
Copy link
Contributor

@matttproud matttproud commented Oct 30, 2015

Hi,

I noticed today that gofmt (on the Playground at least) reformats /* */ comments that are inlined in argument lists inconsistently and in a non-faithful manner to their original ordering in the list:

Pre-Gofmt

fmt.Println(/* before first */ "first", /* before second */ "second")
demo

Post-Gofmt

fmt.Println( /* before first */ "first" /* before second */, "second")
demo

Notice how in the Post-Gofmt case it moves the comment that occurred after the comma to before.

This behavior is incongruent to what happens when the argument lists are spread across multiple lines:

Newline Distributed Pre-Gofmt

package main

import "fmt"

func main() {
    fmt.Println(
    /* before first */ "first")
    fmt.Println(
    /* before first */ "first",
    /* before second */ "second")   
}

demo

Newline Distributed Post-Gofmt

package main

import "fmt"

func main() {
    fmt.Println(
        /* before first */ "first")
    fmt.Println(
        /* before first */ "first",
        /* before second */ "second")
}

demo

For the pre cases, be sure to click Format in the Go Playground demo to see the post-state.

@ianlancetaylor ianlancetaylor changed the title gofmt: Faulty Comment Re-Arrangement in Argument Lists cmd/gofmt: Faulty Comment Re-Arrangement in Argument Lists Oct 30, 2015
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 30, 2015

This is a known issue, but I couldn't find an existing bug report for it.

@dominikh
Copy link
Member

@dominikh dominikh commented Oct 31, 2015

This looks like #9460.

@rhysd
Copy link

@rhysd rhysd commented Jul 2, 2017

I ran into this issue (I'm not sure this is a real issue, tho).

Go does not support named argument. So I wrote parameter names as prefixed comment in function call as below.

SomeFunc(/*name:*/ n, /*debug:*/ true)

However, gofmt formats it as following.

SomeFunc(/*name:*/ n /*debug:*/, true)

The /*debug:*/ comment is placed in the first argument though it's for the second argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.