Adding braces for If-else using Uncrustify

if-statement, uncrustify

Solution

My experience with Uncrustify in your example :

Add or remove braces on single - line `if` statement. Will not remove the braces if they contain an `else`.

mod_full_brace_if = add

Make all `if` / `elseif` / `else` statements in a chain be braced or not. Overrides `mod_full_brace_if`.

If any must be braced, they are all braced. If all can be unbraced, then the braces are removed.

mod_full_brace_if_chain = false

And it worked for me.

Problem

I was wondering if there is any way to add braces in nested If-else using Uncrustify. For example: ``` if( stat_error == -1 ){ if ( debug > 0 ) printf( "...ERROR ); //I would like to add braces around here. exit( -1 ); } else { ``` I have seen this: ``` # Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'. mod_full_brace_if = add # ignore/add/remove/force ``` But it doesn't seem to work for nested conditionals. Is there any way to do it?

Original source