From ff7ea753d4069f125953d690df066c5b8c83e4c2 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 26 Jan 2022 22:02:37 -0500 Subject: [PATCH] .clang-format: update for clang-format 13 This patch adds missing clang-format options for clang-format 11 to 13, as the project now requires clang-format 13. Notable changes: * The `AttributeMacros` and `ForEachMacros` lists make clang-format aware of those identifiers as attributes and for-each macros so that its formatting is more consistent. For example, bt_list_for_each(pos, head) { // ... } becomes bt_list_for_each (pos, head) { // ... } * `EmptyLineBeforeAccessModifier` set to `Always` makes sure there's always an empty line before an access modifier line (`public`/`protected`/`private`). * `SpaceAroundPointerQualifiers` set to `Both` makes qualifiers such as `const` get spaces at their left and right, for example `const Hello * const *hello`. * `SpaceInEmptyBlock` set to `true` makes empty blocks contain a single space instead of none (`{ }` instead of `{}`). * `ReferenceAlignment` set to `Left` makes the `&` of references on the left side: `const Hello& hello`. Having this makes it possible to set `PointerAlignment` to `Right` so that pointers look like they always looked in Babeltrace: `const Hello *hello`. `AlignArrayOfStructures` set to `Left` would be nice but I'm getting bugs (crashes and wrong formatting) with it as of clang-format 13.0.0 (see and ), therefore I'm leaving it to `None` until it's fixed. Signed-off-by: Philippe Proulx Change-Id: I743d630242de0cd222df3ac8a932f8b48ff61125 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7150 Reviewed-by: Simon Marchi Tested-by: jenkins --- .clang-format | 63 ++++++++++++++++++++++++++++++++++++++--------- CONTRIBUTING.adoc | 3 +-- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.clang-format b/.clang-format index 51f4ffa2..300e046c 100644 --- a/.clang-format +++ b/.clang-format @@ -1,17 +1,19 @@ -# for clang-format ≥ 10 +# For clang-format 13 AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: true -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive AlignEscapedNewlines: Right -AlignOperands: true +AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: false AllowAllConstructorInitializersOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: None @@ -19,10 +21,22 @@ AllowShortLoopsOnASingleLine: false AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: [ + '_BT_LOG_PRINTFLIKE', + 'ARGPAR_HIDDEN', + 'BT_ASSERT_COND_DEV_FUNC', + 'BT_ASSERT_DBG_FUNC', + 'BT_CTF_ASSERT_PRE_FUNC', + 'BT_EXTERN_C', + 'BT_HIDDEN', + 'SWIGEXPORT', + 'SWIGUNUSED', + 'YY_ATTRIBUTE_PURE', + 'YY_ATTRIBUTE_UNUSED', + 'yynoreturn', +] BinPackArguments: true BinPackParameters: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom BraceWrapping: AfterCaseLabel: true AfterClass: true @@ -40,6 +54,8 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom BreakBeforeTernaryOperators: false BreakConstructorInitializers: AfterColon BreakInheritanceList: AfterColon @@ -50,38 +66,61 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true +DeriveLineEnding: false DerivePointerAlignment: false DisableFormat: false -ExperimentalAutoDetectBinPacking: false +EmptyLineBeforeAccessModifier: Always FixNamespaceComments: true +ForEachMacros: [ + 'bt_list_for_each', + 'bt_list_for_each_entry', + 'bt_list_for_each_entry_reverse', + 'bt_list_for_each_entry_safe', + 'bt_list_for_each_prev', + 'bt_list_for_each_prev_safe', +] IncludeBlocks: Preserve +IndentAccessModifiers: false +IndentCaseBlocks: false IndentCaseLabels: false +IndentExternBlock: NoIndent +IndentGotoLabels: false IndentPPDirectives: AfterHash IndentWidth: 4 IndentWrappedFunctionNames: false +InsertTrailingCommas: None KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature Language: Cpp MaxEmptyLinesToKeep: 1 NamespaceIndentation: None -PointerAlignment: Left +PPIndentWidth: 4 +PointerAlignment: Right +ReferenceAlignment: Left ReflowComments: false SortIncludes: false SortUsingDeclarations: false SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Both SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: true SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false +SpacesInAngles: Never +SpacesInConditionalStatement: false SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 +UseCRLF: false UseTab: Never diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc index 945f3984..32f53634 100644 --- a/CONTRIBUTING.adoc +++ b/CONTRIBUTING.adoc @@ -1680,8 +1680,7 @@ https://clang.llvm.org/docs/ClangFormatStyleOptions.html[style] of the You _must_ format modified and new {cpp} files with clang-format before you create a contribution patch. -You need clang-format{nbsp}≥{nbsp}10 to use the project's `.clang-format` -file. +You need clang-format{nbsp}13 to use the project's `.clang-format` file. To automatically format all the project's {cpp} files, run: -- 2.34.1