Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dfedf56

Browse files
authoredOct 3, 2022
Merge pull request #58 from per1234/clang-format
Use ClangFormat as code formatter for examples
2 parents d62f11c + 4bbbf5c commit dfedf56

File tree

75 files changed

+728
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+728
-570
lines changed
 

‎.clang-format

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
2+
---
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveAssignments: None
7+
AlignConsecutiveBitFields: None
8+
AlignConsecutiveDeclarations: None
9+
AlignConsecutiveMacros: None
10+
AlignEscapedNewlines: DontAlign
11+
AlignOperands: Align
12+
AlignTrailingComments: true
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortBlocksOnASingleLine: Always
17+
AllowShortCaseLabelsOnASingleLine: true
18+
AllowShortEnumsOnASingleLine: true
19+
AllowShortFunctionsOnASingleLine: Empty
20+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
21+
AllowShortLambdasOnASingleLine: Empty
22+
AllowShortLoopsOnASingleLine: true
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: No
27+
AttributeMacros:
28+
- __capability
29+
BasedOnStyle: LLVM
30+
BinPackArguments: true
31+
BinPackParameters: true
32+
BitFieldColonSpacing: Both
33+
BraceWrapping:
34+
AfterCaseLabel: false
35+
AfterClass: false
36+
AfterControlStatement: Never
37+
AfterEnum: false
38+
AfterFunction: false
39+
AfterNamespace: false
40+
AfterObjCDeclaration: false
41+
AfterStruct: false
42+
AfterUnion: false
43+
AfterExternBlock: false
44+
BeforeCatch: false
45+
BeforeElse: false
46+
BeforeLambdaBody: false
47+
BeforeWhile: false
48+
IndentBraces: false
49+
SplitEmptyFunction: true
50+
SplitEmptyRecord: true
51+
SplitEmptyNamespace: true
52+
BreakAfterJavaFieldAnnotations: false
53+
BreakBeforeBinaryOperators: NonAssignment
54+
BreakBeforeBraces: Attach
55+
BreakBeforeConceptDeclarations: false
56+
BreakBeforeInheritanceComma: false
57+
BreakBeforeTernaryOperators: true
58+
BreakConstructorInitializers: BeforeColon
59+
BreakConstructorInitializersBeforeComma: false
60+
BreakInheritanceList: BeforeColon
61+
BreakStringLiterals: false
62+
ColumnLimit: 0
63+
CommentPragmas: ''
64+
CompactNamespaces: false
65+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
66+
ConstructorInitializerIndentWidth: 2
67+
ContinuationIndentWidth: 2
68+
Cpp11BracedListStyle: false
69+
DeriveLineEnding: true
70+
DerivePointerAlignment: true
71+
DisableFormat: false
72+
EmptyLineAfterAccessModifier: Leave
73+
EmptyLineBeforeAccessModifier: Leave
74+
ExperimentalAutoDetectBinPacking: false
75+
FixNamespaceComments: false
76+
ForEachMacros:
77+
- foreach
78+
- Q_FOREACH
79+
- BOOST_FOREACH
80+
IfMacros:
81+
- KJ_IF_MAYBE
82+
IncludeBlocks: Preserve
83+
IncludeCategories:
84+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
85+
Priority: 2
86+
SortPriority: 0
87+
CaseSensitive: false
88+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
89+
Priority: 3
90+
SortPriority: 0
91+
CaseSensitive: false
92+
- Regex: '.*'
93+
Priority: 1
94+
SortPriority: 0
95+
CaseSensitive: false
96+
IncludeIsMainRegex: ''
97+
IncludeIsMainSourceRegex: ''
98+
IndentAccessModifiers: false
99+
IndentCaseBlocks: true
100+
IndentCaseLabels: true
101+
IndentExternBlock: Indent
102+
IndentGotoLabels: false
103+
IndentPPDirectives: None
104+
IndentRequires: true
105+
IndentWidth: 2
106+
IndentWrappedFunctionNames: false
107+
InsertTrailingCommas: None
108+
JavaScriptQuotes: Leave
109+
JavaScriptWrapImports: true
110+
KeepEmptyLinesAtTheStartOfBlocks: true
111+
LambdaBodyIndentation: Signature
112+
Language: Cpp
113+
MacroBlockBegin: ''
114+
MacroBlockEnd: ''
115+
MaxEmptyLinesToKeep: 100000
116+
NamespaceIndentation: None
117+
ObjCBinPackProtocolList: Auto
118+
ObjCBlockIndentWidth: 2
119+
ObjCBreakBeforeNestedBlockParam: true
120+
ObjCSpaceAfterProperty: false
121+
ObjCSpaceBeforeProtocolList: true
122+
PPIndentWidth: -1
123+
PackConstructorInitializers: BinPack
124+
PenaltyBreakAssignment: 1
125+
PenaltyBreakBeforeFirstCallParameter: 1
126+
PenaltyBreakComment: 1
127+
PenaltyBreakFirstLessLess: 1
128+
PenaltyBreakOpenParenthesis: 1
129+
PenaltyBreakString: 1
130+
PenaltyBreakTemplateDeclaration: 1
131+
PenaltyExcessCharacter: 1
132+
PenaltyIndentedWhitespace: 1
133+
PenaltyReturnTypeOnItsOwnLine: 1
134+
PointerAlignment: Right
135+
QualifierAlignment: Leave
136+
ReferenceAlignment: Pointer
137+
ReflowComments: false
138+
RemoveBracesLLVM: false
139+
SeparateDefinitionBlocks: Leave
140+
ShortNamespaceLines: 0
141+
SortIncludes: Never
142+
SortJavaStaticImport: Before
143+
SortUsingDeclarations: false
144+
SpaceAfterCStyleCast: false
145+
SpaceAfterLogicalNot: false
146+
SpaceAfterTemplateKeyword: false
147+
SpaceAroundPointerQualifiers: Default
148+
SpaceBeforeAssignmentOperators: true
149+
SpaceBeforeCaseColon: false
150+
SpaceBeforeCpp11BracedList: false
151+
SpaceBeforeCtorInitializerColon: true
152+
SpaceBeforeInheritanceColon: true
153+
SpaceBeforeParens: ControlStatements
154+
SpaceBeforeParensOptions:
155+
AfterControlStatements: true
156+
AfterForeachMacros: true
157+
AfterFunctionDefinitionName: false
158+
AfterFunctionDeclarationName: false
159+
AfterIfMacros: true
160+
AfterOverloadedOperator: false
161+
BeforeNonEmptyParentheses: false
162+
SpaceBeforeRangeBasedForLoopColon: true
163+
SpaceBeforeSquareBrackets: false
164+
SpaceInEmptyBlock: false
165+
SpaceInEmptyParentheses: false
166+
SpacesBeforeTrailingComments: 2
167+
SpacesInAngles: Leave
168+
SpacesInCStyleCastParentheses: false
169+
SpacesInConditionalStatement: false
170+
SpacesInContainerLiterals: false
171+
SpacesInLineCommentPrefix:
172+
Minimum: 0
173+
Maximum: -1
174+
SpacesInParentheses: false
175+
SpacesInSquareBrackets: false
176+
Standard: Auto
177+
StatementAttributeLikeMacros:
178+
- Q_EMIT
179+
StatementMacros:
180+
- Q_UNUSED
181+
- QT_REQUIRE_VERSION
182+
TabWidth: 2
183+
UseCRLF: false
184+
UseTab: Never
185+
WhitespaceSensitiveMacros:
186+
- STRINGIZE
187+
- PP_STRINGIZE
188+
- BOOST_PP_STRINGIZE
189+
- NS_SWIFT_NAME
190+
- CF_SWIFT_NAME

‎.github/workflows/code-formatting-check.yml

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,58 @@ on:
44
pull_request:
55
paths:
66
- ".github/workflows/code-formatting-check.yml"
7+
- ".clang-format"
8+
- "examples_formatter.sh"
79
- "examples/**"
810
push:
911
paths:
1012
- ".github/workflows/code-formatting-check.yml"
13+
- ".clang-format"
14+
- "examples_formatter.sh"
1115
- "examples/**"
1216

1317
jobs:
1418
check-formatting:
1519
runs-on: ubuntu-latest
1620

1721
env:
18-
# See: https://sourceforge.net/projects/astyle/files/astyle/
19-
ASTYLE_VERSION: 3.1
22+
# See: https://github.com/arduino/arduino-ide/blob/main/arduino-ide-extension/package.json
23+
CLANG_FORMAT_VERSION: 14.0.0
2024

2125
steps:
26+
- name: Set environment variables
27+
run: |
28+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
29+
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
30+
2231
- name: Checkout
2332
uses: actions/checkout@v3
2433

25-
# See: http://astyle.sourceforge.net/
26-
- name: Download Artistic Style
27-
uses: carlosperate/download-file-action@v1
34+
- name: Download ClangFormat
35+
id: download
36+
uses: MrOctopus/download-asset-action@1.0
2837
with:
29-
file-url: https://iweb.dl.sourceforge.net/project/astyle/astyle/astyle%20${{ env.ASTYLE_VERSION }}/astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz
30-
location: ${{ runner.temp }}/astyle
38+
repository: arduino/clang-static-binaries
39+
tag: ${{ env.CLANG_FORMAT_VERSION }}
40+
asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2
41+
target: ${{ env.CLANG_FORMAT_INSTALL_PATH }}
3142

32-
# See: http://astyle.sourceforge.net/install.html#_GCC_Makefile
33-
- name: Build Artistic Style
43+
- name: Install ClangFormat
3444
run: |
35-
# Build Artistic Style
36-
cd "${{ runner.temp }}/astyle"
37-
tar --extract --file="astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz"
38-
cd "astyle/build/gcc"
39-
make
40-
41-
# GITHUB_WORKSPACE
42-
- name: Check code formatting
45+
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
46+
tar --extract --file="${{ steps.download.outputs.name }}"
47+
# Add installation to PATH:
48+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
49+
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
50+
51+
- name: Format examples
52+
run: ./examples_formatter.sh
53+
54+
- name: Check formatting
4355
run: |
44-
# Check code formatting of example sketches
45-
# Don't exit on first formatting check fail
46-
set +e
47-
# Set default exit status
48-
EXIT_STATUS=0
49-
while read -r filePath; do
50-
# Check if it's a file (find matches on pruned folders)
51-
if [[ -f "$filePath" ]]; then
52-
if ! diff --strip-trailing-cr "$filePath" <("${{ runner.temp }}/astyle/astyle/build/gcc/bin/astyle" --options="${GITHUB_WORKSPACE}/examples_formatter.conf" --dry-run <"$filePath"); then
53-
echo "ERROR: Non-compliant code formatting in $filePath"
54-
EXIT_STATUS=1
55-
fi
56-
fi
57-
done <<<"$(find "${GITHUB_WORKSPACE}/examples" -regextype posix-extended \( -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and -type f \))"
58-
if [[ "$EXIT_STATUS" != "0" ]]; then
56+
if ! git diff --color --exit-code; then
5957
echo "Please do an Auto Format on the sketches:"
6058
echo "Arduino IDE: Tools > Auto Format"
6159
echo "Arduino Web Editor: Ctrl + B"
60+
exit 1
6261
fi
63-
exit "$EXIT_STATUS"

0 commit comments

Comments
 (0)
Please sign in to comment.