【问题标题】:How can I tell clang-format to follow this convention?我如何告诉 clang-format 遵循这个约定?
【发布时间】:2015-09-07 22:03:02
【问题描述】:

我想要这个:

if (!enabled)
{
    return;
}

转向这个:

if (!enabled) { return; }

(换句话说,我希望在一行中使用简短的 if 语句,但在它们周围保留 {})

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

AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
BreakBeforeBraces: Allman

但是,我得到的输出是:

if (!enabled) 
{
    return;
}

上述格式可以用clang-format完成吗?

【问题讨论】:

    标签: c++ clang-format


    【解决方案1】:

    删除

    BreakBeforeBraces:奥尔曼

    似乎做你想做的事(对我来说)。我正在使用 SVN clang。 尽管您可能出于某种原因想要它。

    根据 clang-format 文档,AllowShortBlocksOnASingleLine 应该完全符合您的要求(无论大括号样式如何)。这可能是 clang 格式的错误。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2015-05-25
      • 2014-05-16
      • 2017-10-30
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 2022-09-27
      • 2018-12-17
      相关资源
      最近更新 更多