我怎样才能告诉 clang-format 遵循这个约定?
How can I tell clang-format to follow this convention?
我想要这个:
if (!enabled)
{
return;
}
转向这个:
if (!enabled) { return; }
(换句话说,我想在一行中使用简短的 if 语句,但要在它们周围保留 {}
)
目前我正在使用以下配置:
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
BreakBeforeBraces: Allman
但是,我得到的输出是:
if (!enabled)
{
return;
}
是否可以使用 clang-format 完成上述格式设置?
删除
BreakBeforeBraces: Allman
似乎做你想做的事(对我来说)。我正在使用 SVN clang。
尽管您可能出于某种原因想要它。
根据 clang-format 文档,AllowShortBlocksOnASingleLine
应该完全符合您的要求(无论括号样式如何)。这可能是 clang-format 中的错误。
我想要这个:
if (!enabled)
{
return;
}
转向这个:
if (!enabled) { return; }
(换句话说,我想在一行中使用简短的 if 语句,但要在它们周围保留 {}
)
目前我正在使用以下配置:
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
BreakBeforeBraces: Allman
但是,我得到的输出是:
if (!enabled)
{
return;
}
是否可以使用 clang-format 完成上述格式设置?
删除
BreakBeforeBraces: Allman
似乎做你想做的事(对我来说)。我正在使用 SVN clang。 尽管您可能出于某种原因想要它。
根据 clang-format 文档,AllowShortBlocksOnASingleLine
应该完全符合您的要求(无论括号样式如何)。这可能是 clang-format 中的错误。