I would like my function prototypes / definitions to always separate out parameters into separate lines, regardless of total length. An otherwise default .clang-format
with options
BasedOnStyle: Chromium
AlignAfterOpenBracket: 'AlwaysBreak'
BinPackArguments: 'false'
BinPackParameters: 'false'
ColumnLimit: '80'
gives the following formatting
void foo(float a, float b);
void foo(float a, float b, float c, float d, float e, float f, float g);
void
foo(float a, float b, float c, float d, float e, float f, float g, float h);
void foo(
float a,
float b,
float c,
float d,
float e,
float f,
float g,
float h,
float i);
I would like for them to all be broken consistently, one parameter per line, like so:
void foo(
float a,
float b);
void foo(
float a,
float b,
float c,
float d,
float e,
float f,
float g);
void foo(
float a,
float b,
float c,
float d,
float e,
float f,
float g,
float h);
void foo(
float a,
float b,
float c,
float d,
float e,
float f,
float g,
float h,
float i);
Is there any mechanism to do this?
Bonus for the bounty: I would additionally like my member function implementations to split on the return type, class name, and function name, so e.g. instead of this:
float A::foo(float a, float b)
{
// ...
}
I'd like this:
float
A::
foo(float a,
float b)
{
// ...
}
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
clang-tidy is a clang-based C++ “linter” tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis.
clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews. It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.
Clang-Format Style Options are flags that are supported by the ClangFormat tool, which became the de-facto standard to format C++ code. Clang offers the option to use one of the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or to create a custom configuration by using the given flags.
It's not possible.
The only what can be tuned is when a return type is split. By setting penalty PenaltyReturnTypeOnItsOwnLine: 1000
, it turns this line
void
foo(float a, float b, ...
into
void foo(
float a, float b, ...
and by AlwaysBreakAfterReturnType: TopLevelDefinitions
format
float A::foo(float a, float b)
{
// ...
}
to
float
A::foo(float a, float b) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With