Tamás Szelei
Tamás Szelei

Reputation: 23971

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

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?

Upvotes: 8

Views: 1930

Answers (1)

silverclaw
silverclaw

Reputation: 178

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.

Upvotes: 6

Related Questions