如何防止 clang-format 在新行中添加单个分号?
我在C ++中有这条代码行,
while (fread(pixel_array++, sizeof(byte), 3, fp));
新系列中
while (fread(pixel_array++, sizeof(byte), 3, fp))
;
但是当我使用Clang-Format时,它会将半隆分开,并将其添加到我不喜欢这种样式的
,我只想保留原始的样式。我应该如何修改我的clang-Format配置?谢谢。
I have this line of code in C++
while (fread(pixel_array++, sizeof(byte), 3, fp));
but when I use clang-format, it splits the semicolon and add it into a new line
while (fread(pixel_array++, sizeof(byte), 3, fp))
;
I don't like this kind of style, and I just prefer to keep the original one.
How should I modify my clang-format configuration? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
clang-format 5.0 目前无法识别这种类型的循环。不幸的是,从 clang-format 版本 5 开始,您将无法获得满足您需要的设置。
查找 Clang 格式样式选项,最接近的我发现是
AllowShortLoopsOnASingleLine: true
,但该设置无法将循环条件识别为循环体。只要 clang-format 无法识别这些类型的循环,我要做的就是使用
// clang-format off
标记您的代码,然后使用// clang-format位于代码块周围的
上。clang-format 5.0 currently doesn't recognize that type of loop. Unfortunately as of clang-format version 5, you won't get a setting that does what you need.
Looking up the Clang Format Style Options, the closest that I've found is
AllowShortLoopsOnASingleLine: true
, but that setting doesn't recognize the loop condition as being the body of the loop.As long as clang-format doesn't recognize those kinds of loops, what I'd do is to mark it your code with
// clang-format off
and then// clang-format on
around your block of code.显然这是不可能的,但解决方法可能是用空块替换分号。如果同时设置了
AllowShortLoopsOnASingleLine
和AllowShortBlocksOnASingleLine
,那么它将被格式化为Apparently this is not possible, but a workaround could be to replace the semicolon with an empty block. If both
AllowShortLoopsOnASingleLine
andAllowShortBlocksOnASingleLine
are set, than it will be formatted as当循环没有道理时,架子不会返回布尔和空的。因此,最好将代码重写为
fread does not return bool and empty while loop makes no sense. So it would be better to rewrite your code as