是否有办法配置clang-format使嵌套的命名空间声明保持在同一行

Is there a way to configure clang-format to keep nested namespace declarations on the same line?

本文关键字:一行 声明 命名空间 配置 clang-format 嵌套 是否      更新时间:2023-10-16

在我工作的代码库中,我们总是这样声明嵌套的命名空间:

namespace foo { namespace detail {
// stuff
} }  // foo::detail namespace

我还没有找到一种方法来配置clang-format not将其分解成多行:

namespace foo {
namespace detail {
// stuff
}
}  // foo::detail namespace

我尝试了BreakBeforeBraces配置,并研究了clang 3.8中的新BraceWrapping配置,但都没有成功。

是否可以这样做,而不注释代码与// clang-format [on/off] ?

原来这是clang-format团队考虑过的特性,但被拒绝了。更多详细信息,请参见https://llvm.org/bugs/show_bug.cgi?id=17928。

clang-format 6.0有"CompactNamespaces: true"选项,这正是您所要求的。见http://clang.llvm.org/docs/ClangFormatStyleOptions.html