clang format: break before braces, empty line after opening brace and empty line before closing brace

Viewed 619

I'm trying to format classes inside namespaces in the following way (BreakBeforeBraces: Allman):

namespace test_a::test_b
{

struct A
{
    int a;
    int b;
};

}  // namespace test_a::test_b

but clang format keeps changing it to

namespace test_a::test_b
{
struct A
{
    int a;
    int b;
};

}  // namespace test_a::test_b

The workaround in this question works only with configurations like BasedOnStyle: Google no brakes before opening braces for example

namespace test_a::test_b {

struct A {
    int a;
    int b;
};

}  // namespace test_a::test_b

Same for this answer

I want clang-format to always add an empty line after namespace opening brace and before closing brace, is that possible?

For clarity, this is the clang-format I use

---
BasedOnStyle: Google
AccessModifierOffset: -4
AlignConsecutiveDeclarations: 'true'
BinPackArguments: 'false'
BinPackParameters: 'false'
IndentWidth: '4'
AlignConsecutiveAssignments: 'true'
ColumnLimit: 120
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
...
1 Answers

clang format can't do that specifically for namespace for the moment, but you can use KeepEmptyLinesAtTheStartOfBlocks to put empty line for all blocks. what if you use BreakBeforeBraces: Custom ?

Related