Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang-format breaks lint annotations

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.

like image 998
Joe Sunday Avatar asked Sep 17 '14 01:09

Joe Sunday


People also ask

Is clang-format a Linter?

[clang-format](http://clang.llvm.org/docs/ClangTools.html#clang-format) is a helpful linting tool for C/C++/Objective-C.

Is clang-format good?

clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews. It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.

What is Clang_format?

Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.

What is penalty in clang-format?

When you have a line that's over the line length limit, clang-format will need to insert one or more breaks somewhere. You can think of penalties as a way of discouraging certain line-breaking behavior.


1 Answers

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.

like image 127
John Avatar answered Sep 17 '22 15:09

John