Search code examples
c++uncrustify

Format constructor member initialization with Uncrustify


I'm using uncrustify 0.56 and I'd like to know if it's possible to format constructors like that:

MyClass::MyClass(int arg1, int arg2, int arg3) : m_arg1(arg1), m_arg2(arg2), m_arg3(arg3) {}

// shall be formatted to

MyClass::MyClass(int arg1, int arg2, int arg3) : 
   m_arg1(arg1), 
   m_arg2(arg2), 
   m_arg3(arg3)
{
}

I couldn't find any option. Is this possible or is there another code beautifer/tool to achieve this kind of format?

Thanks in advance ...


Solution

  • Uncrustify 0.59:

    # Whether to indent the stuff after a leading class colon.
    # The term "class colon" refers to both 'class Dog: public Animal'
    #                                                 ^
    # and 'Dog::Dog(): Animal(), _fur(BLACK)'.
    #                ^
    indent_class_colon = true
    
    # Add or remove a newline around a class colon.
    # Related to <pos_class_colon>, <nl_class_init_args>, and <pos_comma>.
    nl_class_colon     = force
    
    # Add or remove newline after each ',' in the constructor member initialization.
    nl_class_init_args = force
    

    Currently, Uncrustify is the most flexible and configurable beast that I am aware of. I've tried tones of different code formatters in the past, including non-free ones. However, I found them to be either lacking some vital options or containing nasty bugs, these include: built-in code formatter of Eclipse CDT, AStyle, Jindent, and some others.