Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent clang-format from collapsing multi-line if statements into a single line

Tags:

Using clang-format with default settings, the following:

if ((exprA) && 
    (exprB))

turns into:

if ((exprA) && (exprB))

I'm trying to prevent the collapsing the conditions into a single line, with no success.
Is there currently a way to achieve this?

In clang-format documentation, the BreakBeforeBinaryOperators parameter seems the closest to what I'm after:

BreakBeforeBinaryOperators (BinaryOperatorStyle)
The way to wrap binary operators.

  • BOS_None (in configuration: None) Break after operators.

But it seems to kick in only when wrapping is required (column limit is exceeded), which isn't the usual case.

like image 854
valiano Avatar asked Jan 14 '18 07:01

valiano


1 Answers

According to Clang 10 document, your request can be done. You have to do these two changes into your clang file

  1. In BraceWrapping: set AfterControlStatement: true.
  2. After than set ColumnLimit: 1
output -: if ((exprA) &&
              (exprB))

You can try this at Here If you have any doubt. but problem is your other codes will also be formatted.

There is no way to split only if ((exprA) && (exprB)). It can be done if anyone can create a patch for that but creating a patch for this is not so much easy. It takes a lot of time and energy.

like image 182
Kalana Avatar answered Oct 04 '22 14:10

Kalana