登录
首页 >  Golang >  Go问答

为何gofmt删除缩进内的TODO注释格式?

来源:stackoverflow

时间:2024-03-14 13:48:27 432浏览 收藏

在IT行业这个发展更新速度很快的行业,只有不停止的学习,才不会被行业所淘汰。如果你是Golang学习者,那么本文《为何gofmt删除缩进内的TODO注释格式?》就很适合你!本篇内容主要包括##content_title##,希望对大家的知识积累有所帮助,助力实战开发!

问题内容

似乎 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.

关于如何解决这些问题有什么想法吗?我不明白为什么 todo 的接受样式发生了变化。


正确答案


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

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

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

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

今天关于《为何gofmt删除缩进内的TODO注释格式?》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>