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: indenting removed from multi-line bullet-lists inside numbered lists #56072

Closed
thaJeztah opened this issue Oct 6, 2022 · 8 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@thaJeztah
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.19.2 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

(probably not relevant)

What did you do?

Given the following file;

/*
Package main is an example.

 1. Item 1.
 2. Item 2.
    - SubItem 1.
    - SubItem 2.
    - SubItem 3 spans two lines. Lorem ipsum dolor sit amet, consectetur
      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
    - Subitem 3 spans three lines. Lorem ipsum dolor sit amet, consectetur
      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
      Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
*/
package main

Running gofmt reformat the bullet-list, removing the indentation for bullets spanning multiple lines;

gofmt -d .
diff main.go.orig main.go
--- main.go.orig
+++ main.go
@@ -6,9 +6,9 @@
     - SubItem 1.
     - SubItem 2.
     - SubItem 3 spans two lines. Lorem ipsum dolor sit amet, consectetur
-      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
+    adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
     - Subitem 3 spans three lines. Lorem ipsum dolor sit amet, consectetur
-      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
-      Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
+    adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
+    Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
 */
 package main

I also tried adding whitespace after the bullet-list (following the example at https://go.dev/doc/comment#mistakes):

/*
Package main is an example.

 1. Item 1.

 2. Item 2.

    - SubItem 1.
    - SubItem 2.
    - SubItem 3 spans two lines. Lorem ipsum dolor sit amet, consectetur
      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
    - Subitem 3 spans three lines. Lorem ipsum dolor sit amet, consectetur
      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
      Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
*/
package main

But this gave the same result;

gofmt -d .
diff main.go.orig main.go
--- main.go.orig
+++ main.go
@@ -8,10 +8,9 @@
     - SubItem 1.
     - SubItem 2.
     - SubItem 3 spans two lines. Lorem ipsum dolor sit amet, consectetur
-      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
+    adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
     - Subitem 3 spans three lines. Lorem ipsum dolor sit amet, consectetur
-      adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
-      Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
+    adipiscing elit. Morbi porta eros nunc, in viverra ex porttitor vitae.
+    Mauris nisi magna, faucibus quis velit vitae, euismod convallis magna.
 */
 package main

What did you expect to see?

The indentation preserved.

What did you see instead?

The indentation removed.

@mvdan
Copy link
Member

mvdan commented Oct 6, 2022

I'm fairly sure that this is a duplicate of #55990. Even if the case is not exactly the same, the two issues seem to be about gofmt and the indentation of bulleted lists, so I think using a single issue will be less confusing.

@thaJeztah
Copy link
Contributor Author

I saw that one, but that one looks like it's trying nested bullet-lists, which are documented as not supported;

Go doc comments do not support nested lists, so gofmt reformats

So the alternative suggested there is to use a numbered list, and embed the bullet list in it.

That said, it could definitely have the same cause. The "interesting" bit is that it does format the first lines of the bullet list correctly, so I wonder if the bug is cause by the formatter taking the indentation level of the outer list, and applying it to those "second" lines.

I must admit that I haven't looked at the formatting code at all though 😅

@mvdan
Copy link
Member

mvdan commented Oct 6, 2022

You're right, that issue was about nested lists, I forgot that.

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 6, 2022
@cagedmantis cagedmantis added this to the Backlog milestone Oct 6, 2022
@cagedmantis
Copy link
Contributor

@griesemer

@gopherbot
Copy link

Change https://go.dev/cl/446775 mentions this issue: go/doc/comment: correct indent format of nested list on Doc comments

@HeCorr
Copy link

HeCorr commented Jun 18, 2023

Hello, I've recently updated Go from 1.18 to 1.20 and noticed most multi-line comments have lost their original formatting:

image

It was previously spaced like that to be more readable:

image

in comparison to:

image

What is the reason for the change? And could it be reverted to allow such formatting again? Thanks!

@ianlancetaylor
Copy link
Contributor

@HeCorr Please paste plain text as plain text, not images. Images are much harder to read. Thanks.

The change you are describing is documented at https://go.dev/doc/go1.19#go-doc. The links there explain how you can get doc comments that format correctly in both text and HTML.

@ianlancetaylor
Copy link
Contributor

I'm closing this issue because the comment is working according to the current doc comment formatting rules.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants