From 9cc4fab93897cf8e4aef7cc60773726da5cc0298 Mon Sep 17 00:00:00 2001 From: Sergei Shirokov Date: Mon, 6 May 2024 15:43:50 +0300 Subject: [PATCH] try fix clang format/tidy issues --- .github/workflows/main.yml | 4 +- socketcan/libcanard/.clang-format | 68 +++++++++++++------------------ stm32/libcanard/.clang-format | 68 +++++++++++++------------------ stm32/libcanard/.clang-tidy | 5 ++- 4 files changed, 63 insertions(+), 82 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41dcff1..58fb66b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: run: | sudo apt update wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 18 - sudo apt install clang-tidy-18 clang-format-12 + sudo apt install clang-tidy-18 clang-format-18 - name: Static analysis working-directory: ${{github.workspace}}/stm32/libcanard/bxcan/ @@ -61,6 +61,6 @@ jobs: - name: Format check working-directory: ${{github.workspace}}/stm32/libcanard/bxcan/ run: | - clang-format-12 -i -fallback-style=none -style=file --verbose src/*.[ch] + clang-format-18 -i -fallback-style=none -style=file --verbose src/*.[ch] modified="$(git status --porcelain --untracked-files=no)" if [ -n "$modified" ]; then echo "Please format code properly."; exit 1; fi diff --git a/socketcan/libcanard/.clang-format b/socketcan/libcanard/.clang-format index d6b6f78..b2e1534 100644 --- a/socketcan/libcanard/.clang-format +++ b/socketcan/libcanard/.clang-format @@ -1,18 +1,18 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM +--- +Language: Cpp +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: Left -AlignOperands: true +AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: Never +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -20,48 +20,42 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom BraceWrapping: - AfterCaseLabel: true + SplitEmptyRecord: false + AfterEnum: true + AfterStruct: true AfterClass: true AfterControlStatement: true - AfterEnum: true AfterFunction: true - AfterNamespace: true - AfterStruct: true AfterUnion: true - BeforeCatch: true + AfterNamespace: true + AfterExternBlock: true BeforeElse: true - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false - AfterExternBlock: false # Keeps the contents un-indented. -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom + BreakBeforeTernaryOperators: true -BreakConstructorInitializers: AfterColon -# BreakInheritanceList: AfterColon +BreakConstructorInitializers: BeforeComma BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ (coverity|pragma:)' +ColumnLimit: 120 +CommentPragmas: '^ (coverity|pragma:)' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false +DisableFormat: false FixNamespaceComments: true -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeBlocks: Preserve IndentCaseLabels: false IndentPPDirectives: AfterHash -IndentWidth: 4 +IndentWidth: 4 IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None PenaltyBreakAssignment: 2 @@ -72,25 +66,21 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 10000 # Raised intentionally because it hurts readability PointerAlignment: Left -ReflowComments: true -SortIncludes: false +ReflowComments: true +SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: true SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements -SpaceBeforeCtorInitializerColon: true -SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: false SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 -UseTab: Never +Standard: c++14 +TabWidth: 8 +UseTab: Never ... diff --git a/stm32/libcanard/.clang-format b/stm32/libcanard/.clang-format index d6b6f78..b2e1534 100644 --- a/stm32/libcanard/.clang-format +++ b/stm32/libcanard/.clang-format @@ -1,18 +1,18 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM +--- +Language: Cpp +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: Left -AlignOperands: true +AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: Never +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -20,48 +20,42 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom BraceWrapping: - AfterCaseLabel: true + SplitEmptyRecord: false + AfterEnum: true + AfterStruct: true AfterClass: true AfterControlStatement: true - AfterEnum: true AfterFunction: true - AfterNamespace: true - AfterStruct: true AfterUnion: true - BeforeCatch: true + AfterNamespace: true + AfterExternBlock: true BeforeElse: true - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false - AfterExternBlock: false # Keeps the contents un-indented. -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom + BreakBeforeTernaryOperators: true -BreakConstructorInitializers: AfterColon -# BreakInheritanceList: AfterColon +BreakConstructorInitializers: BeforeComma BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ (coverity|pragma:)' +ColumnLimit: 120 +CommentPragmas: '^ (coverity|pragma:)' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false +DisableFormat: false FixNamespaceComments: true -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeBlocks: Preserve IndentCaseLabels: false IndentPPDirectives: AfterHash -IndentWidth: 4 +IndentWidth: 4 IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None PenaltyBreakAssignment: 2 @@ -72,25 +66,21 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 10000 # Raised intentionally because it hurts readability PointerAlignment: Left -ReflowComments: true -SortIncludes: false +ReflowComments: true +SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: true SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements -SpaceBeforeCtorInitializerColon: true -SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: false SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 -UseTab: Never +Standard: c++14 +TabWidth: 8 +UseTab: Never ... diff --git a/stm32/libcanard/.clang-tidy b/stm32/libcanard/.clang-tidy index ed0c2de..6cdf0a7 100644 --- a/stm32/libcanard/.clang-tidy +++ b/stm32/libcanard/.clang-tidy @@ -13,10 +13,11 @@ Checks: >- performance-*, portability-*, readability-*, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-macro-to-enum,modernize-macro-to-enum, -google-readability-todo, - -readability-avoid-const-params-in-decls, -llvm-header-guard, - -cppcoreguidelines-avoid-magic-numbers, + -readability-avoid-const-params-in-decls, -readability-magic-numbers, CheckOptions: - key: readability-function-cognitive-complexity.Threshold