clang-format breaks lint annotations

蹲街弑〆低调 提交于 2019-12-08 15:07:23

问题


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] */

or

//lint -[annotation]

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.

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.


回答1:


Clang-format has a `CommentPragmas' option that is

A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.

When I put the following line in my .clang-format file, my Lint comments remain untouched.

CommentPragmas:  '^lint'

Other comments that still have "lint" in them, but are not Lint comments still get formatted.




回答2:


You can disable clang-format for that section of your file by using:

int formatted_code;
// clang-format off
    void    unformatted_code  ;
// clang-format on
void formatted_code_again;

See the Disabling formating on a piece of code section.



来源:https://stackoverflow.com/questions/25880990/clang-format-breaks-lint-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!