How can I tell clang-format to follow this convention?

1.7k views Asked by At

I would like to have this:

if (!enabled)
{
    return;
}

turned to this:

if (!enabled) { return; }

(In other words, I want short if-statements on a single line but keep the {} around them)

Currently I'm using the following configuration:

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

However, the output I'm getting is:

if (!enabled) 
{
    return;
}

Is the above formatting possible to accomplish with clang-format?

1

There are 1 answers

0
silverclaw On BEST ANSWER

Removing

BreakBeforeBraces: Allman

Seems to do what you want (for me). I'm using SVN clang though. Although you probably wanted it there for a reason.

According to the clang-format docs, the AllowShortBlocksOnASingleLine should do exactly what you want (regardless of brace style). This might be a bug in clang-format.