From 04c6af99fc0d0f8b56f1cc703119080cfab2b5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFse=20Brosseau?= <54746458+eloisebrosseau@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:42:13 -0500 Subject: [PATCH] Update ClangFormat (#645) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Update ClangFormat ### Summarize your change. The .clang-format was updated to the latest version and added to the .pre-commit-config.yaml. I also modernized the formatting style based on LLVM. Every options related to the include statements formatting was removed since it might have some side effects on some legacy parts of the codebase if they were to be reorder. Once this PR is merged, the same formatting should be applied to the commercial RV repository for consistency. Moreover, I suggest to make another PR to format all the files afterwards and to add a `.git-blame-ignore-revs` to avoid having the formatting commit show up when using `git blame`. Ideally, once this is done, we should add a formatting validation in our CI pipeline to avoid relying only on users installing the pre-commit hook to follow the formatting convention. ### Describe the reason for the change. The .clang-format had a lot of deprecated options and not all the files were formatted the same way. ### If possible, provide screenshots. Here's an example of what a formatted file would look like with the new .clang-format. Please let me know if you don't agree with any of the chosen options. ![Screenshot 2024-12-02 at 11 47 35 AM](https://github.com/user-attachments/assets/03ff4cd5-ba5a-4244-a078-0a1ffc50cbc7) ![Screenshot 2024-12-02 at 11 47 59 AM](https://github.com/user-attachments/assets/5f77e65d-57ba-4974-b8c5-c6a3f523dfe6) ![Screenshot 2024-12-02 at 11 48 22 AM](https://github.com/user-attachments/assets/4531a430-6f56-4190-8d03-c54c11e8fe11) ![Screenshot 2024-12-02 at 11 48 33 AM](https://github.com/user-attachments/assets/faa38b99-7d1d-4fe1-be41-abaa183ba19e) --------- Signed-off-by: Éloïse Brosseau --- .clang-format | 179 ++++++++++++++++++++++++++-------------- .pre-commit-config.yaml | 5 ++ 2 files changed, 124 insertions(+), 60 deletions(-) diff --git a/.clang-format b/.clang-format index 769cb635b..1ecd79864 100644 --- a/.clang-format +++ b/.clang-format @@ -1,94 +1,153 @@ --- Language: Cpp -AccessModifierOffset: -1 +AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: true -AlignOperands: true -AlignTrailingComments: true +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignConsecutiveShortCaseStatements: + Enabled: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: Always +AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakBeforeMultilineStrings: false BinPackArguments: true BinPackParameters: true -BraceWrapping: - AfterClass: true - AfterControlStatement: true - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: false - BeforeCatch: true - BeforeElse: true - IndentBraces: false -BreakBeforeBinaryOperators: None +BitFieldColonSpacing: Both +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: Automatic +BreakArrays: true +BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Allman +BreakBeforeConceptDeclarations: Always +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakAfterJavaFieldAnnotations: false +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerAllOnOneLineOrOnePerLine: true +CompactNamespaces: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true +DerivePointerAlignment: false DisableFormat: false -ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^<.*\.h>' - Priority: 1 - - Regex: '^<.*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IncludeIsMainRegex: '([-_](test|unittest))?$' -IndentCaseLabels: true -IndentWidth: 2 +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +FixNamespaceComments: true +ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH] +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: Indent +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 IndentWrappedFunctionNames: false +InsertBraces: true +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: All -ObjCBlockIndentWidth: 2 +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: false -PenaltyBreakBeforeFirstCallParameter: 1 +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: Never +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left -ReflowComments: true -SortIncludes: false +PPIndentWidth: -1 +QualifierAlignment: Left +ReferenceAlignment: Pointer +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: Never -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never SpacesInSquareBrackets: false -Standard: Auto -TabWidth: 2 +Standard: Latest +TabWidth: 8 UseTab: Never ---- -Language: JavaScript -DisableFormat: true \ No newline at end of file +... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 30b6ae860..7af06bf06 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,3 +8,8 @@ repos: rev: 24.8.0 hooks: - id: black + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'v19.1.4' + hooks: + - id: clang-format