Skip to content

Commit

Permalink
ci: Add clang-format lint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
wdoekes committed Jan 5, 2025
1 parent 79b520a commit 83bb1c8
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .github/workflows/clang-format-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: clang-format-lint
on: [push, pull_request]

jobs:
clang-format-lint-job:
name: clang-format lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# You may pin to the exact commit or the version.
# uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31
- uses: DoozyX/[email protected]
with:
# 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: file
# Just fix files (`clang-format -i`) instead of returning a diff
inplace: false

0 comments on commit 83bb1c8

Please sign in to comment.