Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create custom rules for clang-format?

There a some external libraries that use a unique coding style. One example would be Qt's signal/slot-connect syntax.

connect(sender.data(), &Sender::valueChanged,
        receiver,      &Receiver::updateValue);

clang-format using a slightly modified llvm formatting reorders this statement to

connect(sender.dataa(), &Sender::valueChanged, receiver, &Receiver::updateValue);

or

connect(sender.dataa(),
        &Sender::valueChanged,
        receiver,
        &Receiver::updateValue);

if it exceeds the 80-character limit.

Is there a possibility to create custom rules for special commands like this, so that it gets formatted as in the first example?

like image 270
Tim Oesterreich Avatar asked Dec 11 '25 04:12

Tim Oesterreich


1 Answers

I don't know of a way to create custom rules, but a workaround could be to tell clang-format to skip the relevant sections with // clang-format off and // clang-format on. (See How to make clang-format skip sections of c++ code)

like image 82
hrantzsch Avatar answered Dec 13 '25 19:12

hrantzsch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!