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..9085fe5 --- /dev/null +++ b/.github/workflows/clang-format-check.yml @@ -0,0 +1,27 @@ +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 20.0.0 + - name: Install clang-format + run: | + sudo apt-get update + sudo apt-get install -y clang-format + + # Step 3: Run clang-format + - name: Run clang-format check + run: | + FILES_TO_CHECK=$(find . -name "*.c" -o -name "*.h") + clang-format -i $FILES_TO_CHECK --dry-run --Werror