Skip to content

Commit 84739fb

Browse files
Add .clang-format file, add GitHub actions code style check
- Change workflows so that they run on all PRs, not just targeted at develop - Update README.md for code style
1 parent 844044d commit 84739fb

File tree

8 files changed

+212
-4
lines changed

8 files changed

+212
-4
lines changed

.clang-format

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveMacros: true
6+
AlignConsecutiveAssignments: true
7+
AlignConsecutiveBitFields: true
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: Align
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortEnumsOnASingleLine: false
16+
AllowShortBlocksOnASingleLine: Never
17+
AllowShortCaseLabelsOnASingleLine: false
18+
AllowShortFunctionsOnASingleLine: None
19+
AllowShortLambdasOnASingleLine: All
20+
AllowShortIfStatementsOnASingleLine: Never
21+
AllowShortLoopsOnASingleLine: false
22+
AlwaysBreakAfterDefinitionReturnType: None
23+
AlwaysBreakAfterReturnType: None
24+
AlwaysBreakBeforeMultilineStrings: false
25+
AlwaysBreakTemplateDeclarations: MultiLine
26+
BinPackArguments: false
27+
BinPackParameters: false
28+
BraceWrapping:
29+
AfterCaseLabel: true
30+
AfterClass: true
31+
AfterControlStatement: Always
32+
AfterEnum: false
33+
AfterFunction: true
34+
AfterNamespace: true
35+
AfterObjCDeclaration: true
36+
AfterStruct: false
37+
AfterUnion: false
38+
AfterExternBlock: true
39+
BeforeCatch: true
40+
BeforeElse: true
41+
BeforeLambdaBody: false
42+
BeforeWhile: false
43+
IndentBraces: false
44+
SplitEmptyFunction: true
45+
SplitEmptyRecord: true
46+
SplitEmptyNamespace: true
47+
BreakBeforeBinaryOperators: All
48+
BreakBeforeBraces: Custom
49+
BreakBeforeInheritanceComma: false
50+
BreakInheritanceList: BeforeColon
51+
BreakBeforeTernaryOperators: true
52+
BreakConstructorInitializersBeforeComma: false
53+
BreakConstructorInitializers: BeforeColon
54+
BreakAfterJavaFieldAnnotations: false
55+
BreakStringLiterals: true
56+
ColumnLimit: 140
57+
CommentPragmas: '^ IWYU pragma:'
58+
CompactNamespaces: false
59+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
60+
ConstructorInitializerIndentWidth: 4
61+
ContinuationIndentWidth: 4
62+
Cpp11BracedListStyle: true
63+
DeriveLineEnding: true
64+
DerivePointerAlignment: false
65+
DisableFormat: false
66+
ExperimentalAutoDetectBinPacking: false
67+
FixNamespaceComments: true
68+
ForEachMacros:
69+
- foreach
70+
- Q_FOREACH
71+
- BOOST_FOREACH
72+
IncludeBlocks: Preserve
73+
IncludeCategories:
74+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
75+
Priority: 2
76+
SortPriority: 0
77+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
78+
Priority: 3
79+
SortPriority: 0
80+
- Regex: '.*'
81+
Priority: 1
82+
SortPriority: 0
83+
IncludeIsMainRegex: '(Test)?$'
84+
IncludeIsMainSourceRegex: ''
85+
IndentCaseLabels: true
86+
IndentCaseBlocks: true
87+
IndentGotoLabels: true
88+
IndentPPDirectives: BeforeHash
89+
IndentExternBlock: AfterExternBlock
90+
IndentWidth: 4
91+
IndentWrappedFunctionNames: false
92+
InsertTrailingCommas: Wrapped
93+
JavaScriptQuotes: Leave
94+
JavaScriptWrapImports: true
95+
KeepEmptyLinesAtTheStartOfBlocks: false
96+
MacroBlockBegin: ''
97+
MacroBlockEnd: ''
98+
MaxEmptyLinesToKeep: 1
99+
NamespaceIndentation: None
100+
ObjCBinPackProtocolList: Auto
101+
ObjCBlockIndentWidth: 2
102+
ObjCBreakBeforeNestedBlockParam: true
103+
ObjCSpaceAfterProperty: false
104+
ObjCSpaceBeforeProtocolList: true
105+
PenaltyBreakAssignment: 2
106+
PenaltyBreakBeforeFirstCallParameter: 19
107+
PenaltyBreakComment: 300
108+
PenaltyBreakFirstLessLess: 120
109+
PenaltyBreakString: 1000
110+
PenaltyBreakTemplateDeclaration: 10
111+
PenaltyExcessCharacter: 1000000
112+
PenaltyReturnTypeOnItsOwnLine: 1000
113+
PointerAlignment: Right
114+
ReflowComments: false
115+
SortIncludes: false
116+
SortUsingDeclarations: true
117+
SpaceAfterCStyleCast: true
118+
SpaceAfterLogicalNot: false
119+
SpaceAfterTemplateKeyword: true
120+
SpaceBeforeAssignmentOperators: true
121+
SpaceBeforeCpp11BracedList: true
122+
SpaceBeforeCtorInitializerColon: true
123+
SpaceBeforeInheritanceColon: true
124+
SpaceBeforeParens: ControlStatementsExceptForEachMacros
125+
SpaceBeforeRangeBasedForLoopColon: true
126+
SpaceInEmptyBlock: false
127+
SpaceInEmptyParentheses: false
128+
SpacesBeforeTrailingComments: 2
129+
SpacesInAngles: false
130+
SpacesInConditionalStatement: false
131+
SpacesInContainerLiterals: false
132+
SpacesInCStyleCastParentheses: false
133+
SpacesInParentheses: false
134+
SpacesInSquareBrackets: false
135+
SpaceBeforeSquareBrackets: false
136+
Standard: Latest
137+
StatementMacros:
138+
- Q_UNUSED
139+
- QT_REQUIRE_VERSION
140+
TabWidth: 4
141+
UseCRLF: false
142+
UseTab: Never
143+
WhitespaceSensitiveMacros:
144+
- STRINGIZE
145+
- PP_STRINGIZE
146+
- BOOST_PP_STRINGIZE
147+
...
148+

.github/workflows/changelog.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Check changelog and version are matching
22

33
on:
44
pull_request:
5-
branches: [ develop ]
5+
branches:
6+
- '*'
67

78
jobs:
89
check:

.github/workflows/code_format.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Run clang-format
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
status: ${{ steps.early.conclusion }}
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
ref: ${{github.event.pull_request.head.ref}}
17+
repository: ${{github.event.pull_request.head.repo.full_name}}
18+
- uses: DoozyX/[email protected]
19+
with:
20+
source: '. ./src'
21+
exclude: './src/libs ./test ./scripts'
22+
extensions: 'c,cpp,h,hpp'
23+
clangFormatVersion: 12
24+
inplace: True
25+
- name: Check if diff
26+
id: needs_work
27+
run: if git diff --quiet --exit-code; then exit 0; else exit 1; fi
28+
continue-on-error: true
29+
- name: Create patch
30+
if: steps.needs_work.outputs.status != 'success'
31+
run: git diff > ./clang-format-diff.patch
32+
- uses: actions/upload-artifact@v2
33+
if: steps.needs_work.outputs.status != 'success'
34+
with:
35+
name: clang-format-diff.patch
36+
path: ./clang-format-diff.patch
37+
- uses: mshick/add-pr-comment@v1
38+
with:
39+
message: |
40+
Looks like your PR has code that needs to be changed in order to meet our coding standards!
41+
Here are your options:
42+
1. Apply the patch that was generated by the job
43+
1. Click `details` under the failing clang-format check
44+
1. Click the `Artifacts` dropdown in the top right
45+
1. Download + unzip the `clang-format-diff.patch` file into the `OpenAstroTracker-Firmware` repo
46+
1. Run `git apply clang-format-diff.patch` to make the changes
47+
1. Commit and push up the formatted code
48+
1. Run `clang-format` locally
49+
1. Run the command `bash -c 'shopt -s nullglob; for i in ./{.,src,src/inc,boards/*}/*.{c,cpp,h,hpp}; do clang-format -i $i; done'`
50+
1. Commit and push up the formatted code
51+
repo-token: ${{secrets.BOT_ACCESS_TOKEN}}
52+
repo-token-user-login: 'openastrotech-bot'
53+
allow-repeats: false
54+
- name: Fail if needs formatting
55+
if: steps.needs_work.outputs.status != 'success'
56+
run: git diff --quiet --exit-code || exit 1

.github/workflows/platformio.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- develop
77
pull_request:
88
branches:
9-
- develop
9+
- '*'
1010

1111
jobs:
1212
build:

.github/workflows/version.yml

Whitespace-only changes.

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**V1.9.25 - Updates**
2+
- clang-format codebase
3+
14
**V1.9.24 - Updates**
25
- Fix hold currents of AZ/ALT/Focuser drivers.
36

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ See the [Changelog](Changelog.md) for details about what versions made what chan
66

77
## Coding guidelines
88

9-
TBD
9+
See `.clang-format` file. A GitHub action is run on every PR to make sure that the code complies with the formatting guidelines. The action will automatically commit any changes, so you may have to `git pull` after opening a PR.
1010

1111
## Contribution
1212

Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// So 1.8.99 is ok, but 1.8.234 is not. Neither is 1.123.22
33
// Also, numbers are interpreted as simple numbers. _ __ _
44
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/
5-
#define VERSION "V1.9.24"
5+
#define VERSION "V1.9.25"

0 commit comments

Comments
 (0)