为什么 gofmt 会删除缩进的 TODO 格式化?

huangapple go评论72阅读模式
英文:

Why does gofmt remove indented TODO formatting?

问题

在go1.19中,似乎gofmt改变了其行为,不再允许根据一些启发式规则进行缩进(来自go文档:https://tip.golang.org/doc/comment)。但这破坏了TODO注释的格式。

这是我以前在我的代码中使用的,gofmt接受了。

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

运行gofmt给我这个结果:

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

我可以将其更改为以下内容,但是GoLand无法正确显示TODO。

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

为什么 gofmt 会删除缩进的 TODO 格式化?

对于如何解决这些问题有什么想法吗?我不明白为什么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.

为什么 gofmt 会删除缩进的 TODO 格式化?

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

答案1

得分: 1

只需在你的TODO前面加一个制表符,就像这样:
为什么 gofmt 会删除缩进的 TODO 格式化?

英文:

Just put a tab in front of your TODO, like this:
为什么 gofmt 会删除缩进的 TODO 格式化?

答案2

得分: 0

我使用的自定义模式来识别TODO是:

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

以下是在Goland中设置它的步骤:

  • 在设置/首选项对话框中,选择编辑器| TODO。
  • 使用正则表达式来指定自定义模式。

为什么 gofmt 会删除缩进的 TODO 格式化?


英文:

The custom pattern I used to recognize TODO is

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

为什么 gofmt 会删除缩进的 TODO 格式化?


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.

huangapple
  • 本文由 发表于 2022年10月7日 18:38:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/73985895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定