From 02f8fa6e07f3dff154314dc6b3cb5af9f24a1323 Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Mon, 3 Jun 2024 17:31:24 -0400 Subject: [PATCH 1/5] initial implementation of #150, minus adjustments to `CONTRIBUTING.md` - drop dead code within `CMakeLists.txt` - remove old `.github/workflows/.clang-format` - create new `.clang-format` at the repository root, with settings based on observed patterns & `CONTRIBUTING.md` --- .clang-format | 41 +++++++++++++++++++++++++++++++++ .github/workflows/.clang-format | 9 -------- CMakeLists.txt | 4 ---- 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 .clang-format delete mode 100644 .github/workflows/.clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..bdd151d72 --- /dev/null +++ b/.clang-format @@ -0,0 +1,41 @@ +Language: Cpp +AccessModifierOffset: 0 +AlignConsecutiveMacros: true +BreakBeforeBraces: Linux +IndentWidth: 2 +ConstructorInitializerIndentWidth: 2 +AlignAfterOpenBracket: Align +Standard: c++11 +IndentAccessModifiers: true +IndentCaseBlocks: true +IndentCaseLabels: true +IndentGotoLabels: true +IndentExternBlock: Indent +UseTab: Never +ReflowComments: true +QualifierAlignment: Left +ReferenceAlignment: Pointer +PointerAlignment: Left +InsertBraces: true +NamespaceIndentation: All +LineEnding: LF +IntegerLiteralSeparator: + Binary: 4 + BinaryMinDigits: 8 + Decimal: 3 + DecimalMinDigits: 4 + Hex: 2 + HexMinDigits: 6 +BreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +AllowShortFunctionsOnASingleLine: None +AllowAllArgumentsOnNextLine: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: -1 + - Regex: '.*' + Priority: 0 diff --git a/.github/workflows/.clang-format b/.github/workflows/.clang-format deleted file mode 100644 index b8cef3e95..000000000 --- a/.github/workflows/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -# Documentation about the style options and their meaning -# https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html - -Language: Cpp -AccessModifierOffset: 0 -AlignConsecutiveMacros: true -BreakBeforeBraces: Linux -ColumnLimit: 150 -ConstructorInitializerIndentWidth: 2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4da16fa..21b77e930 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,10 +59,6 @@ set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) # Add CMake sources from `cmake` dir list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -# Including clang-format cmake files to do automatic checking of formating -# TODO: Set up clang-format -#include(./cmake/clang-format) - # This will create target `doxygen` for building documentation locally. # For now, this target is intended only for developers who want to test # different documentation configurations. To have Doxygen configuration From b96114bc02f35ff8aa9f9e6415253f5959838a7b Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Mon, 3 Jun 2024 17:50:38 -0400 Subject: [PATCH 2/5] use deprecated template declaration breaking option to support clang-format 16 minimum --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index bdd151d72..46022e311 100644 --- a/.clang-format +++ b/.clang-format @@ -26,7 +26,7 @@ IntegerLiteralSeparator: DecimalMinDigits: 4 Hex: 2 HexMinDigits: 6 -BreakTemplateDeclarations: Yes +AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false AllowShortFunctionsOnASingleLine: None From a5b3e827402f5f78f5a8ed1cfb17ce3ba4228725 Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Tue, 11 Jun 2024 15:33:52 -0400 Subject: [PATCH 3/5] integrate suggestions + adjustment to include ordering regex --- .clang-format | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 46022e311..ec3791191 100644 --- a/.clang-format +++ b/.clang-format @@ -4,6 +4,7 @@ AlignConsecutiveMacros: true BreakBeforeBraces: Linux IndentWidth: 2 ConstructorInitializerIndentWidth: 2 +ColumnLimit: 0 AlignAfterOpenBracket: Align Standard: c++11 IndentAccessModifiers: true @@ -33,7 +34,7 @@ AllowShortFunctionsOnASingleLine: None AllowAllArgumentsOnNextLine: false IncludeBlocks: Regroup IncludeCategories: - - Regex: '^' Priority: -1 From b1f6fa25e85d6f3f5479e9ea5314f8ebde3ae81a Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Tue, 11 Jun 2024 15:35:06 -0400 Subject: [PATCH 4/5] drop integer literal separators --- .clang-format | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.clang-format b/.clang-format index ec3791191..f4733e1f6 100644 --- a/.clang-format +++ b/.clang-format @@ -20,13 +20,6 @@ PointerAlignment: Left InsertBraces: true NamespaceIndentation: All LineEnding: LF -IntegerLiteralSeparator: - Binary: 4 - BinaryMinDigits: 8 - Decimal: 3 - DecimalMinDigits: 4 - Hex: 2 - HexMinDigits: 6 AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false From de28145428a7815156481544451ae82e8e5df8b4 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Tue, 4 Mar 2025 14:46:28 -0600 Subject: [PATCH 5/5] Synchronize style guidelines with GridKit. --- .clang-format | 134 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 102 insertions(+), 32 deletions(-) diff --git a/.clang-format b/.clang-format index f4733e1f6..65fb6179c 100644 --- a/.clang-format +++ b/.clang-format @@ -1,35 +1,105 @@ -Language: Cpp -AccessModifierOffset: 0 -AlignConsecutiveMacros: true -BreakBeforeBraces: Linux -IndentWidth: 2 +Language: Cpp +BasedOnStyle: Microsoft + +# Indentation +IndentWidth: 2 # 2 spaces per indent +AccessModifierOffset: -2 +IndentAccessModifiers: false # Align access modifiers to braces +NamespaceIndentation: All # Indent namspace contents ConstructorInitializerIndentWidth: 2 -ColumnLimit: 0 -AlignAfterOpenBracket: Align -Standard: c++11 -IndentAccessModifiers: true -IndentCaseBlocks: true -IndentCaseLabels: true -IndentGotoLabels: true -IndentExternBlock: Indent -UseTab: Never -ReflowComments: true -QualifierAlignment: Left -ReferenceAlignment: Pointer -PointerAlignment: Left -InsertBraces: true -NamespaceIndentation: All -LineEnding: LF -AlwaysBreakTemplateDeclarations: true -BinPackArguments: false -BinPackParameters: false + +# Comments which match this regex will be unformatted (and therefore can be longer or have more whitespace than other comments) +CommentPragmas: '^\*\*' + + +# Alignment +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + AlignCompound: true + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true +AlignConsecutiveDeclarations: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + # For future versions of clang-format + # AlignFunctionDeclarations: false + # AlignFunctionPointers: false +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + +# Newlines +ColumnLimit: 0 +BreakBeforeBraces: Allman # Braces on their own lines +SeparateDefinitionBlocks: Always # Separate definitions (functions etc.) with an empty line +AlwaysBreakTemplateDeclarations: true # Put template on their own lines +AllowShortBlocksOnASingleLine: Never +# On a newer version of clang-format, replace with BinPackArguments: OnePerLine +BinPackArguments: false # Don't allow multiple function arguments on the same line unless they all fit +BinPackParameters: false # Same but for parameters +PackConstructorInitializers: NextLine AllowShortFunctionsOnASingleLine: None -AllowAllArgumentsOnNextLine: false -IncludeBlocks: Regroup +BreakBeforeBinaryOperators: NonAssignment # Put binary operators after a line break, rather than before +AllowShortIfStatementsOnASingleLine: Never + +# Spaces +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceAfterCStyleCast: true +PointerAlignment: Left + +# Includes +IncludeBlocks: Regroup # Regroup includes based on config IncludeCategories: - - Regex: '^<(resolve|tests)/' - Priority: 1 - - Regex: '^<[[:alnum:].]+>' - Priority: -1 - - Regex: '.*' - Priority: 0 + - Regex: '(^"|\.hpp)' # 'local' includes + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '\/' # Library includes + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' # Everything else + Priority: 1 + SortPriority: 0 + CaseSensitive: false + +# AccessModifierOffset: 0 +# AlignConsecutiveMacros: true +# IndentWidth: 2 +# ConstructorInitializerIndentWidth: 2 +# ColumnLimit: 0 +# AlignAfterOpenBracket: Align +# Standard: c++11 +# IndentAccessModifiers: true +# IndentCaseBlocks: true +# IndentCaseLabels: true +# IndentGotoLabels: true +# IndentExternBlock: Indent +# UseTab: Never +# ReflowComments: true +# QualifierAlignment: Left +# ReferenceAlignment: Pointer +# PointerAlignment: Left +# InsertBraces: true +# NamespaceIndentation: All +# LineEnding: LF +# AlwaysBreakTemplateDeclarations: true +# BinPackArguments: false +# BinPackParameters: false +# AllowShortFunctionsOnASingleLine: None +# AllowAllArgumentsOnNextLine: false +# IncludeBlocks: Regroup +# IncludeCategories: +# - Regex: '^<(resolve|tests)/' +# Priority: 1 +# - Regex: '^<[[:alnum:].]+>' +# Priority: -1 +# - Regex: '.*' +# Priority: 0