Noel Moldvai
Noel Moldvai

Reputation: 121

Why does gofmt remove indented TODO formatting?

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.

Upvotes: 8

Views: 1295

Answers (2)

Yak2p
Yak2p

Reputation: 31

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

Upvotes: 2

zangw
zangw

Reputation: 48476

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.

Upvotes: 2

Related Questions