From 878a372a097dfe2b050b4906ad9874f58d6f9522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Peixoto?= Date: Thu, 24 Oct 2024 11:52:13 +0100 Subject: [PATCH] ci(clang-format): add clang-format check workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Peixoto --- .clang-format | 119 +++++++++++++++++++++++ .github/workflows/clang-format-check.yml | 38 ++++++++ 2 files changed, 157 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/clang-format-check.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..10d63cb --- /dev/null +++ b/.clang-format @@ -0,0 +1,119 @@ +--- +Language: Cpp +BasedOnStyle: Mozilla +AccessModifierOffset: -2 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Left +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Always + OverEmptyLines: 2 +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterStruct: false + AfterUnion: false + BeforeElse: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: false +BreakBeforeInlineASMColon: Never +BreakStringLiterals: true +ColumnLimit: 100 +ContinuationIndentWidth: 4 +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IncludeBlocks: Preserve +IndentCaseBlocks: false +IndentCaseLabels: true +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: true +InsertNewlineAtEOF: true +InsertTrailingCommas: None +KeepEmptyLinesAtEOF: false +KeepEmptyLinesAtTheStartOfBlocks: false +LineEnding: LF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 10 +PenaltyBreakOpenParenthesis: 100 +PenaltyBreakString: 100 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 50 +PenaltyReturnTypeOnItsOwnLine: 100 +PointerAlignment: Left +# Not using QualigierAlignment as it seems only to affect parameter lists, not +# variable declarations. May enable it if this changes in future clang-format +# versions. +# QualifierAlignment: Custom +# QualifierOrder: ['static', 'inline', 'type', 'const', 'volatile'] +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: MultipleParentheses +RemoveSemicolon: true +SeparateDefinitionBlocks: Leave +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyBlock: true +SpacesInParens: Custom +SpacesInParensOptions: + InConditionalStatements: false + InEmptyParentheses: false + InCStyleCasts: false + Other: false +SpacesBeforeTrailingComments: 1 +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE +ForEachMacros: ['list_foreach'] +# TODO: +# - IncludeCategories +# - IncludeIsMainRegex +# - IncludeIsMainSourceRegex +... diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml new file mode 100644 index 0000000..be273f7 --- /dev/null +++ b/.github/workflows/clang-format-check.yml @@ -0,0 +1,38 @@ +name: Clang Format Check + +on: + pull_request: + push: + branches: + - main + +jobs: + clang-format-check: + runs-on: ubuntu-latest + steps: + # Step 1: Checkout the code from the repository + - name: Checkout the code + uses: actions/checkout@v3 + + # Step 2: Install clang-format + - name: Install clang-format + run: sudo apt-get install -y clang-format + + # Step 3: Find .c and .h files that need formatting + - name: Check if files are properly formatted + run: | + FILES_TO_CHECK=$(find . -name "*.c" -o -name "*.h") + for file in $FILES_TO_CHECK; do + clang-format --style=file -i $file + done + + # Step 4: Check if files match .clang-format style + - name: Validate formatting + run: | + FILES_TO_CHECK=$(find . -name "*.c" -o -name "*.h") + for file in $FILES_TO_CHECK; do + if ! diff -u $file <(clang-format --style=file $file); then + echo "Formatting issues in $file" + exit 1 + fi + done