如何防止 clang-format 在注释字符后添加 space?

How to prevent clang-format to add space after comment char?

我的代码中有一些注释:

//asdf

当我在其上使用 clang-format 时,它会在 // 字符之后添加一个 space:

// asdf

如何防止在 clang-format 配置中发生这种情况?

谢谢

结合这两个问题的答案应该可以解决问题:

  • clang-format breaks lint annotations
  • What regex will match every character except comma ',' or semi-colon ';'?

所以您的 .clang-format 文件中的以下行应该可以解决问题(我没有测试):

CommentPragmas:  '^[^ ]'

这告诉 clang-format 不要混淆以 space 以外的其他内容开头的注释。

For completeness, clang-format documentation here.