我怎么能告诉clang-format遵循这个约定?

Tam*_*lei 8 c++ clang-format

我想要这个:

if (!enabled)
{
    return;
}
Run Code Online (Sandbox Code Playgroud)

转向这个:

if (!enabled) { return; }
Run Code Online (Sandbox Code Playgroud)

(换句话说,我想在单行上使用简短的if语句但保留{}它们)

目前我正在使用以下配置:

AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
BreakBeforeBraces: Allman
Run Code Online (Sandbox Code Playgroud)

但是,我得到的输出是:

if (!enabled) 
{
    return;
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用clang格式完成上述格式化?

sil*_*law 5

删除

BreakBeforeBraces:奥尔曼

似乎做你想要的(对我来说).我虽然使用SVN铿锵声.虽然你可能想要它有一个原因.

根据clang格式的文档,AllowShortBlocksOnASingleLine应该完全按照你想要的(不管支撑样式).这可能是clang格式的错误.