Skip to content

Formatting #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
BasedOnStyle: Google
IndentWidth: '4'
ColumnLimit: '120'

IncludeCategories:
# main include automatically assigned to Priority 0
- Regex: '^".*_(conf|config)\.(hpp|h)"$' # config headers
Priority: 3
- Regex: '^".*"$' # sibling & project headers
Priority: 1
- Regex: '^<.*>$' # system & library headers
Priority: 2

# Format function arguments and parameters
BinPackArguments: 'false'
BinPackParameters: 'false'
AllowAllArgumentsOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlignAfterOpenBracket: BlockIndent
SpaceBeforeParens: ControlStatements

# Constructor Formatting
PackConstructorInitializers: CurrentLine
IndentAccessModifiers: 'false'
AccessModifierOffset: '-4'
SpaceBeforeCtorInitializerColon: 'true'
BreakConstructorInitializers: BeforeColon
LambdaBodyIndentation: OuterScope

AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: 'false'
AllowShortEnumsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'Inline'
AllowShortLambdasOnASingleLine: 'All'

# Switch / Case
IndentCaseLabels: 'true'
IndentCaseBlocks: 'false'

# Preprocessor stuff
AlignConsecutiveMacros: 'false'
AlignEscapedNewlines: DontAlign
AlignTrailingComments: 'false'
SpacesBeforeTrailingComments: 1

# Alignment of procedural code
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignConsecutiveBitFields: Consecutive

AlignOperands: AlignAfterOperator
# BreakBeforeTernaryOperators: 'false'
BreakBeforeBinaryOperators: 'true'

# Pointers and East/West Const
DerivePointerAlignment: 'false'
PointerAlignment: Left
QualifierAlignment: Leave
# QualifierOrder: ['volatile', 'constexpr', 'static', 'inline', 'type', 'const']

Cpp11BracedListStyle: 'true'

# Vertical Whitespace
SeparateDefinitionBlocks: Leave
EmptyLineBeforeAccessModifier: Always
EmptyLineAfterAccessModifier: Never

# AlignArrayOfStructures: Right
# InsertTrailingCommas: 'Wrapped'


AlwaysBreakAfterReturnType: None
PenaltyReturnTypeOnItsOwnLine: 9999 # We really hate breaking after return types
PenaltyBreakAssignment: 999 # Prefer not to break around =

SpaceAfterTemplateKeyword: 'false'

MaxEmptyLinesToKeep: 2

FixNamespaceComments: 'true'
#IndentPPDirectives: BeforeHash
# NamespaceIndentation: All
...
36 changes: 36 additions & 0 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Clang-Format Check

on:
push:
branches: [master]
pull_request:
paths:
- '**/*.cpp'
- '**/*.h'
- '**/*.hpp'

jobs:
clang-format-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Clang-Format
run: sudo apt-get install -y clang-format

- name: Run Clang-Format Check
run: |
files=$(find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h")
check_ignore=$(git -c core.excludesFile="format-ignore.txt" check-ignore --stdin --no-index --non-matching --verbose <<< "$files")
files=$(awk '/^::/ {print $2}' <<< "$check_ignore")

echo "Checking $(echo "$files" | wc -l) files"

if [ -n "$files" ]; then
clang-format -style=file -i $files
git diff --exit-code || (echo "Clang-Format check failed!" && exit 1)
else
echo "No files to check."
fi
3 changes: 3 additions & 0 deletions format-ignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# autogenerated files
/src/can_simple_messages.hpp
/src/ODriveEnums.h
3 changes: 1 addition & 2 deletions src/ODriveCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ bool ODriveCAN::getPower(Get_Powers_msg_t& msg, uint16_t timeout_ms) {
return request(msg, timeout_ms);
}

bool ODriveCAN::reset(ResetAction action)
{
bool ODriveCAN::reset(ResetAction action) {
Reboot_msg_t msg;
msg.Action = action;

Expand Down
Loading