clang-format and fluent setters

Viewed 65

I'm using fluent style for my setters and as soon as the line length has been exceeded, clang format is formating my code as requested.

But if the line is shorter, it aligns the setters in one line.

Is it possible to configure clang to allways format connected function calls?

Example:

no formating, if line is to short

add(ModelField(key_T::id).dataType(model::DataType::id).isMandatory(true).isVisible(false));

But if the code exeeds the columnLimit it formats properly

add(ModelField(key_T::name)
        .dataType(model::DataType::text)
        .isMandatory(true)
        .minLength(1)
        .isEditable(true)
        .isSortable(true)
        .isSearchable(true)
        .description("a name"));
1 Answers

Is it possible to configure clang to allways format connected function calls?

Unfortunately, no, alignment will not happen unless you break the column limit.

add(ModelField(key_T::id).dataType(model::DataType::id).isMandatory(true).isVisible(false));
auto a = ModelField(key_T::id).dataType(model::DataType::id).isMandatory(true).isVisible(false);

A poor man's solution is to add a dummy comment after where you'd expect the break, after which clang-format will align subsequent member function calls accordingly (given the appropriate

add(ModelField(key_T::id) //
        .dataType(model::DataType::id)
        .isMandatory(true)
        .isVisible(false));
auto a = ModelField(key_T::id) //
             .dataType(model::DataType::id)
             .isMandatory(true)
             .isVisible(false);
Related