Skip to content

Commit 5e8ecf7

Browse files
authored
Merge pull request #19 from odriverobotics/formatting
Formatting
2 parents 53e8525 + edbdcee commit 5e8ecf7

File tree

10 files changed

+228
-94
lines changed

10 files changed

+228
-94
lines changed

.clang-format

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: '4'
4+
ColumnLimit: '120'
5+
6+
IncludeCategories:
7+
# main include automatically assigned to Priority 0
8+
- Regex: '^".*_(conf|config)\.(hpp|h)"$' # config headers
9+
Priority: 3
10+
- Regex: '^".*"$' # sibling & project headers
11+
Priority: 1
12+
- Regex: '^<.*>$' # system & library headers
13+
Priority: 2
14+
15+
# Format function arguments and parameters
16+
BinPackArguments: 'false'
17+
BinPackParameters: 'false'
18+
AllowAllArgumentsOnNextLine: 'false'
19+
AllowAllParametersOfDeclarationOnNextLine: 'false'
20+
AlignAfterOpenBracket: BlockIndent
21+
SpaceBeforeParens: ControlStatements
22+
23+
# Constructor Formatting
24+
PackConstructorInitializers: CurrentLine
25+
IndentAccessModifiers: 'false'
26+
AccessModifierOffset: '-4'
27+
SpaceBeforeCtorInitializerColon: 'true'
28+
BreakConstructorInitializers: BeforeColon
29+
LambdaBodyIndentation: OuterScope
30+
31+
AllowShortCaseLabelsOnASingleLine: 'true'
32+
AllowShortBlocksOnASingleLine: 'false'
33+
AllowShortIfStatementsOnASingleLine: Never
34+
AllowShortLoopsOnASingleLine: 'false'
35+
AllowShortEnumsOnASingleLine: 'true'
36+
AllowShortFunctionsOnASingleLine: 'Inline'
37+
AllowShortLambdasOnASingleLine: 'All'
38+
39+
# Switch / Case
40+
IndentCaseLabels: 'true'
41+
IndentCaseBlocks: 'false'
42+
43+
# Preprocessor stuff
44+
AlignConsecutiveMacros: 'false'
45+
AlignEscapedNewlines: DontAlign
46+
AlignTrailingComments: 'false'
47+
SpacesBeforeTrailingComments: 1
48+
49+
# Alignment of procedural code
50+
AlignConsecutiveAssignments: 'false'
51+
AlignConsecutiveDeclarations: 'false'
52+
AlignConsecutiveBitFields: Consecutive
53+
54+
AlignOperands: AlignAfterOperator
55+
# BreakBeforeTernaryOperators: 'false'
56+
BreakBeforeBinaryOperators: 'true'
57+
58+
# Pointers and East/West Const
59+
DerivePointerAlignment: 'false'
60+
PointerAlignment: Left
61+
QualifierAlignment: Leave
62+
# QualifierOrder: ['volatile', 'constexpr', 'static', 'inline', 'type', 'const']
63+
64+
Cpp11BracedListStyle: 'true'
65+
66+
# Vertical Whitespace
67+
SeparateDefinitionBlocks: Leave
68+
EmptyLineBeforeAccessModifier: Always
69+
EmptyLineAfterAccessModifier: Never
70+
71+
# AlignArrayOfStructures: Right
72+
# InsertTrailingCommas: 'Wrapped'
73+
74+
75+
AlwaysBreakAfterReturnType: None
76+
PenaltyReturnTypeOnItsOwnLine: 9999 # We really hate breaking after return types
77+
PenaltyBreakAssignment: 999 # Prefer not to break around =
78+
79+
SpaceAfterTemplateKeyword: 'false'
80+
81+
MaxEmptyLinesToKeep: 2
82+
83+
FixNamespaceComments: 'true'
84+
#IndentPPDirectives: BeforeHash
85+
# NamespaceIndentation: All
86+
...

.github/workflows/formatting.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Clang-Format Check
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
paths:
8+
- '**/*.cpp'
9+
- '**/*.h'
10+
- '**/*.hpp'
11+
12+
jobs:
13+
clang-format-check:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install Clang-Format
21+
run: sudo apt-get install -y clang-format
22+
23+
- name: Run Clang-Format Check
24+
run: |
25+
files=$(find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h")
26+
check_ignore=$(git -c core.excludesFile="format-ignore.txt" check-ignore --stdin --no-index --non-matching --verbose <<< "$files")
27+
files=$(awk '/^::/ {print $2}' <<< "$check_ignore")
28+
29+
echo "Checking $(echo "$files" | wc -l) files"
30+
31+
if [ -n "$files" ]; then
32+
clang-format -style=file -i $files
33+
git diff --exit-code || (echo "Clang-Format check failed!" && exit 1)
34+
else
35+
echo "No files to check."
36+
fi

format-ignore.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# autogenerated files
2+
/src/can_simple_messages.hpp
3+
/src/ODriveEnums.h

src/ODriveCAN.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ bool ODriveCAN::getPower(Get_Powers_msg_t& msg, uint16_t timeout_ms) {
134134
return request(msg, timeout_ms);
135135
}
136136

137-
bool ODriveCAN::reset(ResetAction action)
138-
{
137+
bool ODriveCAN::reset(ResetAction action) {
139138
Reboot_msg_t msg;
140139
msg.Action = action;
141140

0 commit comments

Comments
 (0)