问题描述
在C/C ++的工作中,我们在代码库中使用了lint,我也在尝试将clang格式集成到我的工作流中.
We use lint in our codebase at work for C/C++, I'm trying to start integrating clang-format in my workflow as well.
不幸的是,皮棉偶尔需要使用注释来忽略特定的检查,格式如下:
Unfortunately, lint occasionally requires annotations to ignore a specific check, either of the format:
/*lint -[annotation] */
或
//lint -[annotation]
具体来说,如果注释的开始标记和'lint'之间有空格,则不会将其识别为注释指令.不幸的是,我为clang-format设置的默认设置将其视为错误并有益地插入了空格.
Specifically, if there's a space between the opening token for the comment and 'lint', it doesn't recognize it as an annotation directive. Unfortunately, the default settings I have for clang-format see that as an error and helpfully insert the space.
是否有任何方法可以让clang格式识别与该模式匹配的注释并将其保留?现在我正在使用3.4,但可以根据需要进行升级.
Is there any way to get clang-format to recognize comments matching that pattern and leave them alone? Right now I'm using 3.4, but could upgrade if needed.
推荐答案
Clang格式的"CommentPragmas"选项为
Clang-format has a `CommentPragmas' option that is
当我在.clang格式的文件中添加以下行时,我的Lint注释保持不变.
When I put the following line in my .clang-format file, my Lint comments remain untouched.
CommentPragmas: '^lint'
其他注释中仍然包含"lint"但不是Lint的注释仍会被格式化.
Other comments that still have "lint" in them, but are not Lint comments still get formatted.
这篇关于clang-format破坏了lint注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!