Set AllowAllConstructorInitializersOnNextLine to false. This prevents
formatting problem when initializer list is long enough to be wrapped
once, but all initializers fitted into the next line.
Turn on AlignConsecutiveMacros option.
Rules are defined for all C/C++ code, except src/libs.
These rules are designed to emulate kernel coding convention with some
adaptations for C++11. Configuration file uses options available in
clang-format 8.0 (the newest version in 10.0) to provide compatibility
with older environments and operating systems. Some options are
commented out and marked with TODOs - those need to be investigated and
enabled/disabled during upgrade to clang-format 9.0.
DOSBox codebase is a mix of various styles with only few consistent
rules seen throughout the codebase, these clang-format rules preserve
some of existing conventions and conciously break with others.
Some unwritten upstream rules, that are now encoded in clang-format:
- Using tab for indentation.
- K&R-like indentation for control statements.
- Indentation rules for structs, classes, and non-anonymous enums.
- Case labels in switch statements are aligned the same way goto
statements would be (also K&R rule).
Some formatting aspects that were not followed consistently throughout
old DOSBox code, but are now encoded in clang-format:
- Space placing in control statements and function calls (makes the code
much more readable).
- Control statements (if-else, while) must be broken into multiple lines
(makes the code more readable, helps with debugging, reading compiler
logs and static analysis reports).
Some unwritten upstream rules, that are now changed by these rules:
- Placing opening function bracket in the same line as function
declaration (not in line with K&R). This rule makes it hard to make
constructor formatting consistent - old code dealt with it by not
formatting initializer lists at all. Unformatted initializer list can
result in lines hundreds of lines long and make it hard to add/remove
class fields while assuring correct initialization order.
In new clang-format rules K&R indentation is followed, allowing
initalizer lists to be formatted one initializer per line (which makes
it much easier to read and edit.