I'm looking for a Clang configuration that will convert code A into code B (see below).
My preference is to "explode" functions with 3 or more arguments for personal readability, and I haven't found a Clang configuration to do this exactly how I want.
I suspect there isn't one, but I wanted to make sure. There does not appear to be a Clang option to put the first parenthesis of a function call on a newline if the number of args is > x or if the line is over a certain char length.
I would certainly be open to another style tool with the suggested flags/options to do what I want.
Desired output
Code A (input)
class X {
public:
int function(Arg arg1, Arg arg2);
private:
int _biggerFunction(Arg1 arg1, Arg2 arg2, bool arg3);
};
int X::function(Arg1 arg1, Arg2 arg2) {
return arg1 + arg2;
}
int X::_biggerFunction(Arg1 arg1, Arg2 arg2, bool arg3) {
if (arg3) {
return arg1 + arg2;
}
else {
return arg1 - arg2;
}
}
Code B (output)
class X
{
public:
int function(Arg arg1, Arg arg2);
private:
int _biggerFunction
(
Arg arg1,
Arg arg2,
bool arg3
);
};
int X::function(Arg1 arg1, Arg2 arg2)
{
return arg1 + arg2;
}
int X::_biggerFunction
(
Arg1 arg1,
Arg2 arg2,
bool arg3
)
{
if (arg3)
{
return arg1 + arg2;
}
else
{
return arg1 - arg2;
}
}
Attempted solution
I've used the Clang Style Detector (in Clang Power Tools for Visual Studio) to try and find a matching configuration, but the result wasn't quite what I wanted. Clang Style Detector recommended the following:
# Format Style Options - Created with Clang Power Tools
---
BasedOnStyle: WebKit
BreakBeforeBraces: Allman
ColumnLimit: 50
ExperimentalAutoDetectBinPacking: true
...
However, the result is not a good style match:
Clang Style Detector test
Code A (input)
class X {
public:
int function(Arg arg1, Arg arg2);
private:
int _biggerFunction(Arg1 arg1, Arg2 arg2, bool arg3);
};
int X::function(Arg1 arg1, Arg2 arg2) {
return arg1 + arg2;
}
int X::_biggerFunction(Arg1 arg1, Arg2 arg2, bool arg3) {
if (arg3) {
return arg1 + arg2;
}
else {
return arg1 - arg2;
}
}
Code B (output)
class X
{
public:
int function(Arg arg1, Arg arg2);
private:
int _biggerFunction(
Arg1 arg1, Arg2 arg2, bool arg3);
};
int X::function(Arg1 arg1, Arg2 arg2)
{
return arg1 + arg2;
}
int X::_biggerFunction(
Arg1 arg1, Arg2 arg2, bool arg3)
{
if (arg3)
{
return arg1 + arg2;
}
else
{
return arg1 - arg2;
}
}
(is signature too long, but splitting signature by other rules removes that reason. There's only one sweet spot where the function name ends exactly at the width limit - longer and you need a newline after type, shorter and you don't need a newline before(.newlines.cpp, functionvoid newline_func_multi_lineand chunknewline_iarf(start,- it only adds newline after and you need to change that into before&after for an extra option.