From cbe623fc09c7a2f6480f57de5fab05f4d8e89c0b Mon Sep 17 00:00:00 2001 From: Erik Funder Carstensen Date: Thu, 14 Dec 2023 10:58:36 +0100 Subject: [PATCH] Add .clang-format After a bunch of testing, this Clang Format configuration is quite close to what is done _most of the time_ in this repository. The only thing I've found which it breaks consistently is when an UDT is instanciated inline, the braces are split: ``` struct bar {} foo; ``` becomes ``` struct bar { } foo; ``` and (maybe worse cause that's how it's often written in this project) ``` struct bar {} // comment foo; ``` becomes ``` struct bar { } // comment foo; ``` . This along with disallowing the rest of multiple operator seperated items in argument position to flow to the last line if they are neccesary to split giving: ``` throw invalid_argument("Adiar requires at least " + std::to_string(minimum_memory / 1024 / 1024) + " MiB of memory"); ``` instead of ``` throw invalid_argument("Adiar requires at least " + std::to_string(minimum_memory / 1024 / 1024) + " MiB of memory"); ``` Except for that, all changes I've observed it making is within "normal" for the codebase. --- .clang-format | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..49ebda2e5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,55 @@ +BasedOnStyle: LLVM +Language: Cpp + +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true +AlignOperands: AlignAfterOperator +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: All +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Never + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +ColumnLimit: 100 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +Cpp11BracedListStyle: true +FixNamespaceComments: false +IndentWidth: 2 +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +PointerAlignment: Left +SpaceAfterTemplateKeyword: false +# type above function name +# short if on same line