5

It seems gofmt in go1.19 changed its behavior to not allowing indenting based on some heuristics (from go docs: https://tip.golang.org/doc/comment). But this breaks the TODO comment formatting.

This is what I used to have in my code that gofmt accepted.

// TODO: Do some stuff. And this is a long comment so it'll need to
//       be wrapped. This is the next line.

Running gofmt gives me this:

// TODO: Do some stuff. And this is a long comment so it'll need to
//
//  be wrapped. This is the next line.

I could change it to this but then GoLand doesn't display the TODO properly.

// TODO: Do some stuff. And this is a long comment so it'll need to
// be wrapped. This is the next line.

GoLand view

Any ideas on how to reconcile these problems? I don't understand why the accepted style for TODO has changed.

  • 1
    From that link you provided, "In both of these, the last line is indented, making it a code block. The fix is to unindent the lines." Seems like Go thinks it shouldn't be indented. Maybe GoLand needs to change? – Zach Young Oct 08 '22 at 05:58

2 Answers2

1

Just put a tab in front of your TODO, like this: enter image description here

Yak2p
  • 21
  • 2
0

The custom pattern I used to recognize TODO is

\/(\/|\*)[ ]*\btodo\b(.|\n)*(\*\/|)

enter image description here


Here are steps to set it in Goland

  • In the Settings/Preferences dialog , select Editor | TODO.
  • Use a regular expression to specify a custom pattern.
zangw
  • 43,869
  • 19
  • 177
  • 214