From 30ebf9eaec0f4a14b1827f08f3b6a9b0c3f5c0fe Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Thu, 22 Oct 2020 22:19:17 +0200 Subject: [PATCH 1/8] finally introduce .clang-format; request for comments and changes --- .clang-format | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..cc0698d887 --- /dev/null +++ b/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + #AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + #SplitEmptyFunction: true + #SplitEmptyRecord: true + #SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +RawStringFormats: + - Language: TextProto + BasedOnStyle: Google + Delimiters: [pb] +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp17 +TabWidth: 4 +UseTab: Never +... + From 786cf4978dd76dcd945428b27014a8edc2dfb958 Mon Sep 17 00:00:00 2001 From: psi29a Date: Fri, 23 Oct 2020 09:21:48 +0000 Subject: [PATCH 2/8] Fix clang12 issue; remove javascript/objc --- .clang-format | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index cc0698d887..ec2bd1bc4b 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,5 @@ --- Language: Cpp -# BasedOnStyle: WebKit AccessModifierOffset: -4 AlignAfterOpenBracket: DontAlign AlignConsecutiveAssignments: false @@ -72,16 +71,11 @@ IndentCaseLabels: false IndentPPDirectives: None IndentWidth: 4 IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: Inner -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 @@ -108,7 +102,7 @@ SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp17 +Standard: cpp17 TabWidth: 4 UseTab: Never ... From c28ae25512eb2ab1e54006e8c597ba55d0b5b776 Mon Sep 17 00:00:00 2001 From: psi29a Date: Fri, 23 Oct 2020 09:22:26 +0000 Subject: [PATCH 3/8] Go Allman all the way. --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index ec2bd1bc4b..b53148694d 100644 --- a/.clang-format +++ b/.clang-format @@ -36,7 +36,7 @@ BraceWrapping: #SplitEmptyRecord: true #SplitEmptyNamespace: true BreakBeforeBinaryOperators: All -BreakBeforeBraces: WebKit +BreakBeforeBraces: Allman BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false From c99807acbc0b92743145be752445c17c9adcf849 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 10 Nov 2020 20:04:43 +0000 Subject: [PATCH 4/8] Fix error: unknown enumerated scalar --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index b53148694d..51f687e418 100644 --- a/.clang-format +++ b/.clang-format @@ -102,7 +102,7 @@ SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: cpp17 +Standard: c++17 TabWidth: 4 UseTab: Never ... From d4a8fdb9b3bca59eae2f6f07b56c14a957468cb6 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 26 Apr 2021 12:20:37 +0000 Subject: [PATCH 5/8] Remove some useless directives --- .clang-format | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.clang-format b/.clang-format index 51f687e418..553eddf798 100644 --- a/.clang-format +++ b/.clang-format @@ -40,11 +40,9 @@ BreakBeforeBraces: Allman BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 0 -CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 @@ -84,10 +82,6 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left -RawStringFormats: - - Language: TextProto - BasedOnStyle: Google - Delimiters: [pb] ReflowComments: true SortIncludes: true SortUsingDeclarations: true @@ -105,5 +99,3 @@ SpacesInSquareBrackets: false Standard: c++17 TabWidth: 4 UseTab: Never -... - From 7af5b3acd2ef5834b707c3feec1773ec0611699d Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 11 Oct 2021 19:58:45 +0000 Subject: [PATCH 6/8] Remove Java option --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index 553eddf798..1723415127 100644 --- a/.clang-format +++ b/.clang-format @@ -40,7 +40,6 @@ BreakBeforeBraces: Allman BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 0 CompactNamespaces: false From ebe42a6c7dcee0b971fd9d54fc19e40f8d1fb222 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 11 Oct 2021 20:10:39 +0000 Subject: [PATCH 7/8] Apply elsid's switch suggestions --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 1723415127..695c3b53e0 100644 --- a/.clang-format +++ b/.clang-format @@ -9,7 +9,7 @@ AlignOperands: false AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false @@ -64,7 +64,7 @@ IncludeCategories: - Regex: '.*' Priority: 1 IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: false +IndentCaseLabels: true IndentPPDirectives: None IndentWidth: 4 IndentWrappedFunctionNames: false From 11d44fda8f08faf576e44e0bdc31cdc4031b8d00 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 16 Aug 2022 16:09:08 +0000 Subject: [PATCH 8/8] Pull in Allman's rules so modifications to BraceWrapping actually do something instead of being ignored because BreakBeforeBraces isn't set to Custom --- .clang-format | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.clang-format b/.clang-format index 695c3b53e0..c272ac1220 100644 --- a/.clang-format +++ b/.clang-format @@ -12,6 +12,7 @@ AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -19,24 +20,22 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - #AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - #SplitEmptyFunction: true - #SplitEmptyRecord: true - #SplitEmptyNamespace: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true BreakBeforeBinaryOperators: All -BreakBeforeBraces: Allman +BreakBeforeBraces: Custom BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false @@ -65,6 +64,7 @@ IncludeCategories: Priority: 1 IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: true +IndentExternBlock: AfterExternBlock IndentPPDirectives: None IndentWidth: 4 IndentWrappedFunctionNames: false @@ -95,6 +95,6 @@ SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: c++17 +Standard: c++20 TabWidth: 4 UseTab: Never