diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0dee20d --- /dev/null +++ b/.clang-format @@ -0,0 +1,95 @@ +# PEP8: Indentation is 4 spaces +# https://peps.python.org/pep-0008/#tabs-or-spaces +UseTab: Never +TabWidth: 4 +IndentWidth: 4 +#LineEnding: LF +#InsertNewlineAtEOF: true + +# Indentation for preprocessor is 1, after the hash. +PPIndentWidth: 1 +IndentPPDirectives: AfterHash + +# PEP8: Line length is 79 characters +# https://peps.python.org/pep-0008/#maximum-line-length +ColumnLimit: 79 +BreakStringLiterals: true +AlwaysBreakBeforeMultilineStrings: true + +# PEP8: Hanging indentation +# https://peps.python.org/pep-0008/#indentation +AlignAfterOpenBracket: AlwaysBreak + +# PEP8: Break before operators +# https://peps.python.org/pep-0008/#should-a-line-break-before-or-after-a-binary-operator +BreakBeforeBinaryOperators: NonAssignment +# Force function declaration on individual lines, but not function calls. +BinPackArguments: true +BinPackParameters: false + +# No space after cast "(float)4 / 2.0" to signify precedence. +SpaceAfterCStyleCast: false + +# Never any if/for/while body on the same line. +AllowShortBlocksOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false + +# Braces only on a line of their own for functions. +# (Mostly always here. Helps with hanging indent.) +# (The 'extern "C" {' gets to be unindented.) +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + AfterFunction: true + AfterCaseLabel: true + AfterControlStatement: true + AfterEnum: true + AfterExternBlock: false + AfterStruct: true + BeforeElse: true + BeforeWhile: true +IndentExternBlock: NoIndent +IndentCaseLabels: false +IndentGotoLabels: false +# public:/private:/protected: start on the left. +AccessModifierOffset: -4 +IndentAccessModifiers: false + +# Function definition/declarations. +AlwaysBreakAfterReturnType: None + +# Alignment of define-values and declarations. +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignConsecutiveDeclarations: AcrossEmptyLines +# AcrossEmptyLines: true +# AcrossComments: false +# AlignCompound: false +# AlignFunctionDeclarations: false +# AlignFunctionPointers: true +# PadOperators: false + +# Alignment of array of struct (initializations). +# Either "Left" or "None". Left is nice for big structs. +AlignArrayOfStructures: None + +# Pointers as int* a or int *b. +PointerAlignment: Left +ReferenceAlignment: Left + +# Fixes: +# -static char* +# -base64_decode_string(const char* buf, unsigned int len, int* newlen) +# +static char* base64_decode_string( +# + const char* buf, unsigned int len, int* newlen) +PenaltyReturnTypeOnItsOwnLine: 150 + +# Unsure.. +# - bool has_recent_data = ( +# - (millis() - last_update) < updates_at_least_every); +# + bool has_recent_data = +# + ((millis() - last_update) < updates_at_least_every); +# ^- this still needs fixing +#PenaltyBreakOpenParenthesis: 0 +#PenaltyBreakAssignment: 1000 diff --git a/.github/workflows/clang-format-lint.yaml b/.github/workflows/clang-format-lint.yaml new file mode 100644 index 0000000..6ffccbe --- /dev/null +++ b/.github/workflows/clang-format-lint.yaml @@ -0,0 +1,25 @@ +name: clang-format-lint +on: [push, pull_request] + +jobs: + clang-format-lint-job: + # You may pin to the exact commit or the version. + # uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 + uses: DoozyX/clang-format-lint-action@v0.18.2 + with: + source: './include/benchmark ./src ./test' + extensions: 'h,cc' + clangFormatVersion: 12 + style: Google + # Source folder to check formatting + source: . + # Folder to exclude from formatting check + exclude: 'opt usbfs zabbix' + # List of extensions to check + extensions: # optional, default is c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx + # Version of clang-format + clangFormatVersion: # optional, default is 18 + # Formatting style to use + style: # optional, default is file + # Just fix files (`clang-format -i`) instead of returning a diff + inplace: # optional