【问题标题】:Why does gofmt remove indented TODO formatting?为什么 gofmt 删除缩进的 TODO 格式?
【发布时间】:2022-10-08 14:49:14
【问题描述】:

似乎 go1.19 中的 gofmt 将其行为更改为不允许基于一些启发式的缩进(来自 go docs: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.

关于如何调和这些问题的任何想法?我不明白为什么 TODO 的公认风格发生了变化。

【问题讨论】:

  • 从您提供的链接中,“在这两个中,最后一行都是缩进的,使其成为一个代码块。解决方法是取消缩进这些行。”似乎 Go 认为它不应该缩进。也许 GoLand 需要改变?

标签: go comments todo


【解决方案1】:

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

/(/|*)[ ]*todo(.|
)*(*/|)


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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2022-12-23
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多