可以在所有控制语句主体上强制使用clang格式吗? [英] Can clang-format force bracing on all control statement bodies?
问题描述
IE,这是
if (x > 5)
return test;
总是会变成:
if (x > 5)
{
return test;
}
我不是说括号风格(Allman,GNU,Whiteman,
I'm not talking about the brace style (Allman, GNU, Whiteman, etc) I just mean having the braces there at all.
有些东西可以防止/启用单行控制语句,例如:
There is something to prevent/enable single-line control statements like:
if(x> 5)返回测试;
AllowShortBlocksOnASingleLine
,但这不是我在这里寻找的东西。
which is AllowShortBlocksOnASingleLine
, but that's not what I'm looking for here.
如果它适用于clang 7,那是理想的选择,但是如果不这样做的话我知道。
If it works on clang 7 that's ideal, but if not let me know.
推荐答案
您可以坚持使用 clang-format
这是可以理解的我最近的帖子使我失望类似的兔子洞。看来 clang-format
主要用作纯空格格式化程序。要完全准确,我建议使用 Uncrustify 。构建过程非常简单(有关详细信息,请参见github页),适合您的配置如下:
It's understandable you would want to stick with clang-format
however my recent post has led me down a similar rabbit hole you are in. It appears that clang-format
is mostly used as a whitespace-only formatter. To get exactly what you want, I recommend using Uncrustify. The build process is very easy (see the github page for details), and the config for you is as follows:
$ cat .uncrustify
# Uncrustify-0.70.1
nl_if_brace = remove
nl_brace_else = force
nl_elseif_brace = remove
nl_else_brace = remove
nl_else_if = remove
nl_before_if_closing_paren = remove
nl_for_brace = remove
nl_while_brace = remove
nl_do_brace = remove
nl_brace_while = remove
nl_multi_line_sparen_open = remove
nl_multi_line_sparen_close = remove
nl_after_vbrace_close = true
mod_full_brace_do = force
mod_full_brace_for = force
mod_full_brace_function = force
mod_full_brace_if = force
mod_full_brace_while = force
您可以使用以下命令对源文件运行Uncrustify:
You can run Uncrustify against your source file this using the command:
$ uncrustify -c /path/to/.uncrustify --no-backup example.c
是否需要更多格式设置选项,它们的在线配置工具提供了许多可配置项的示例和说明。
Should you require even more formatting options, their online config tool has some examples and descriptions for a plethora of configurables.
您声明:
我不是要安装辅助工具-它必须与未更改的clang格式安装一起使用。 [...]
I'm not looking for a secondary tool to install - it must work with an unaltered install of clang-format. [...]
恐怕从 clang-format
开始6.0(我研究和测试过的东西)和7.0(我研究过的东西)似乎不可能。
I'm afraid as of clang-format
6.0 (what I researched and tested on) and 7.0 (what I researched on) it doesn't seem possible.
这篇关于可以在所有控制语句主体上强制使用clang格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!