Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does gofmt remove indented TODO formatting?

Tags:

comments

go

todo

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.

like image 631
Noel Moldvai Avatar asked May 28 '26 21:05

Noel Moldvai


2 Answers

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.
like image 198
zangw Avatar answered May 31 '26 15:05

zangw


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

like image 30
Yak2p Avatar answered May 31 '26 15:05

Yak2p



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!