-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Comments
This is a known issue, but I couldn't find an existing bug report for it. |
This looks like #9460. |
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, SomeFunc(/*name:*/ n /*debug:*/, true) The |
Is there any update on this? The problem exists in go 1.64.4 |
No update. Nobody is working on this. |
But is this something where external contribution would be welcomed? Convention in some places (including Google) is that literals in function calls should be tagged with a comment like so:
Also, if the AST does not store the comma's position (seems to be the case for #9460, dunno here), would it be terrible to reverse the decision and put the comment always after the comma? That might generate some large diffs... |
@ncruces |
I'm having this problem with SQL requests. My IDE colorizes and autocomplete SQL requests.... Example: err = db.Select(&someSlice, /*language=sql*/ `
SELECT something
FROM somewhere
`) My problem is that gofmt moves the comment to the end of the previous argument, which breaks the syntax highlighting err = db.Select(&someSlice /*language=sql*/, `
SELECT something
FROM somewhere
`) |
FWIW, to avoid this issue it is possible to wrap the arguments (and comments) in parens, - fmt.Println(/* before first */ "first", /* before second */ "second")
+ fmt.Println(( /* before first */ "first"), ( /* before second */ "second")) |
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
demo
Newline Distributed Post-Gofmt
demo
For the pre cases, be sure to click
Format
in the Go Playground demo to see the post-state.The text was updated successfully, but these errors were encountered: