Search code examples
code-formattinguncrustify

What does "Force" do in Uncrustify?


Many of the options include the Force value option:

Add or remove space between nested parens

sp_paren_paren { Ignore, Add, Remove, Force }

What does it mean? How is it different than Add?


Solution

  • Add means "add if not already present", meaning that if something's already there, leave it (and the formatting alone). Force means add if not present, and reformat if it is present:

    // Original
    if (cond)         {
        func();
    }
    
    // Add curly braces (already present, leaves formatting alone)
    if (cond)         {
        func();
    }
    
    // Force curly braces
    if (cond) {
        func();
    }
    

    Or another example:

    // Original
    if (cond)
        func();
    
    // Add curly braces
    if (cond) {
        func();
    }
    
    // Force curly braces (behaves just like add in this case)
    if (cond) {
        func();
    }