Skip to content

Commit 58c0567

Browse files
authored
Merge pull request #254 from per1234/update-clang-format
Update ClangFormat configuration file for ClangFormat 14.0.0
2 parents e5e0d84 + 23b40b1 commit 58c0567

File tree

19 files changed

+325
-122
lines changed

19 files changed

+325
-122
lines changed

.github/workflows/check-clang-format.yml

+19-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ jobs:
8080
echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV"
8181
fi
8282
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
83+
echo "YQ_INSTALL_PATH=${{ runner.temp }}/yq" >> "$GITHUB_ENV"
8384
echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV"
8485
8586
- name: Download ClangFormat
86-
id: download
87+
id: download-clang-format
8788
uses: MrOctopus/[email protected]
8889
with:
8990
repository: arduino/clang-static-binaries
@@ -94,11 +95,27 @@ jobs:
9495
- name: Install ClangFormat
9596
run: |
9697
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
97-
tar --extract --file="${{ steps.download.outputs.name }}"
98+
tar --extract --file="${{ steps.download-clang-format.outputs.name }}"
9899
# Add installation to PATH:
99100
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
100101
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
101102
103+
- name: Download yq
104+
id: download-yq
105+
uses: MrOctopus/[email protected]
106+
with:
107+
repository: mikefarah/yq
108+
asset: yq_linux_amd64.tar.gz
109+
target: ${{ env.YQ_INSTALL_PATH }}
110+
111+
- name: Install yq
112+
run: |
113+
cd "${{ env.YQ_INSTALL_PATH }}"
114+
tar --extract --file="${{ steps.download-yq.outputs.name }}"
115+
# Add installation to PATH:
116+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
117+
echo "${{ env.YQ_INSTALL_PATH }}/yq" >> "$GITHUB_PATH"
118+
102119
- name: Check ClangFormat configuration file
103120
id: check
104121
run: |

Taskfile.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ tasks:
230230
deps:
231231
- task: clang-format:check-installed
232232
cmds:
233+
- |
234+
if ! which yq &>/dev/null; then
235+
echo "ec not found or not in PATH. Please install: https://github.com/mikefarah/yq/#install"
236+
exit 1
237+
fi
238+
233239
- |
234240
# Add source comment
235241
echo \
@@ -242,6 +248,17 @@ tasks:
242248
--style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" >> \
243249
"{{.TARGET_PATH}}"
244250
251+
- |
252+
# Correct invalid `BasedOnStyle` key value
253+
# The existing key is deleted before assigning it to a valid value in order to achieve consistent quoting style
254+
# (updating the empty string value in place causes the assigned value to be wrapped in quotes)
255+
yq --inplace 'del(.BasedOnStyle)' "{{.TARGET_PATH}}"
256+
yq --inplace '.BasedOnStyle = "LLVM"' "{{.TARGET_PATH}}"
257+
258+
- |
259+
# Fix the inconsistent key order
260+
yq --inplace 'sort_keys(.)' "{{.TARGET_PATH}}"
261+
245262
# Use ClangFormat to format the files under the path specified by TARGET_FOLDER recursively
246263
clang-format:format:
247264
cmds:
@@ -272,10 +289,14 @@ tasks:
272289

273290
clang-format:update-config:
274291
desc: Update ClangFormat configuration file to match effective tool configuration
292+
vars:
293+
WORKING_PATH:
294+
sh: task utility:mktemp-file TEMPLATE="clang-format-update-config-XXXXXXXXXX.json"
275295
cmds:
276296
- task: clang-format:dump-config
277297
vars:
278-
TARGET_PATH: "{{.CLANG_FORMAT_CONFIGURATION_PATH}}"
298+
TARGET_PATH: "{{.WORKING_PATH}}"
299+
- mv --force "{{.WORKING_PATH}}" "{{.CLANG_FORMAT_CONFIGURATION_PATH}}"
279300

280301
clang-format:update-golden:
281302
desc: Update golden master test data for current configuration
+92-51
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,190 @@
11
# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
22
---
3-
Language: Cpp
43
AccessModifierOffset: -2
54
AlignAfterOpenBracket: Align
6-
AlignConsecutiveMacros: false
7-
AlignConsecutiveAssignments: false
8-
AlignConsecutiveBitFields: false
9-
AlignConsecutiveDeclarations: false
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveAssignments: None
7+
AlignConsecutiveBitFields: None
8+
AlignConsecutiveDeclarations: None
9+
AlignConsecutiveMacros: None
1010
AlignEscapedNewlines: DontAlign
11-
AlignOperands: Align
11+
AlignOperands: Align
1212
AlignTrailingComments: true
1313
AllowAllArgumentsOnNextLine: true
1414
AllowAllConstructorInitializersOnNextLine: true
1515
AllowAllParametersOfDeclarationOnNextLine: true
16-
AllowShortEnumsOnASingleLine: true
1716
AllowShortBlocksOnASingleLine: Always
1817
AllowShortCaseLabelsOnASingleLine: true
18+
AllowShortEnumsOnASingleLine: true
1919
AllowShortFunctionsOnASingleLine: Empty
20+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
2021
AllowShortLambdasOnASingleLine: Empty
21-
AllowShortIfStatementsOnASingleLine: Always
2222
AllowShortLoopsOnASingleLine: true
2323
AlwaysBreakAfterDefinitionReturnType: None
2424
AlwaysBreakAfterReturnType: None
2525
AlwaysBreakBeforeMultilineStrings: false
2626
AlwaysBreakTemplateDeclarations: No
27+
AttributeMacros:
28+
- __capability
29+
BasedOnStyle: LLVM
2730
BinPackArguments: true
2831
BinPackParameters: true
32+
BitFieldColonSpacing: Both
2933
BraceWrapping:
30-
AfterCaseLabel: false
31-
AfterClass: false
34+
AfterCaseLabel: false
35+
AfterClass: false
3236
AfterControlStatement: Never
33-
AfterEnum: false
34-
AfterFunction: false
35-
AfterNamespace: false
37+
AfterEnum: false
38+
AfterFunction: false
39+
AfterNamespace: false
3640
AfterObjCDeclaration: false
37-
AfterStruct: false
38-
AfterUnion: false
41+
AfterStruct: false
42+
AfterUnion: false
3943
AfterExternBlock: false
40-
BeforeCatch: false
41-
BeforeElse: false
44+
BeforeCatch: false
45+
BeforeElse: false
4246
BeforeLambdaBody: false
43-
BeforeWhile: false
44-
IndentBraces: false
47+
BeforeWhile: false
48+
IndentBraces: false
4549
SplitEmptyFunction: true
4650
SplitEmptyRecord: true
4751
SplitEmptyNamespace: true
52+
BreakAfterJavaFieldAnnotations: false
4853
BreakBeforeBinaryOperators: NonAssignment
4954
BreakBeforeBraces: Attach
55+
BreakBeforeConceptDeclarations: false
5056
BreakBeforeInheritanceComma: false
51-
BreakInheritanceList: BeforeColon
5257
BreakBeforeTernaryOperators: true
53-
BreakConstructorInitializersBeforeComma: false
5458
BreakConstructorInitializers: BeforeColon
55-
BreakAfterJavaFieldAnnotations: false
59+
BreakConstructorInitializersBeforeComma: false
60+
BreakInheritanceList: BeforeColon
5661
BreakStringLiterals: false
57-
ColumnLimit: 0
58-
CommentPragmas: ''
62+
ColumnLimit: 0
63+
CommentPragmas: ''
5964
CompactNamespaces: false
60-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
65+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
6166
ConstructorInitializerIndentWidth: 2
6267
ContinuationIndentWidth: 2
6368
Cpp11BracedListStyle: false
6469
DeriveLineEnding: true
6570
DerivePointerAlignment: true
66-
DisableFormat: false
71+
DisableFormat: false
72+
EmptyLineAfterAccessModifier: Leave
73+
EmptyLineBeforeAccessModifier: Leave
6774
ExperimentalAutoDetectBinPacking: false
6875
FixNamespaceComments: false
6976
ForEachMacros:
7077
- foreach
7178
- Q_FOREACH
7279
- BOOST_FOREACH
73-
IncludeBlocks: Preserve
80+
IfMacros:
81+
- KJ_IF_MAYBE
82+
IncludeBlocks: Preserve
7483
IncludeCategories:
75-
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
76-
Priority: 2
77-
SortPriority: 0
78-
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
79-
Priority: 3
80-
SortPriority: 0
81-
- Regex: '.*'
82-
Priority: 1
83-
SortPriority: 0
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
8496
IncludeIsMainRegex: ''
8597
IncludeIsMainSourceRegex: ''
86-
IndentCaseLabels: true
98+
IndentAccessModifiers: false
8799
IndentCaseBlocks: true
100+
IndentCaseLabels: true
101+
IndentExternBlock: Indent
88102
IndentGotoLabels: false
89103
IndentPPDirectives: None
90-
IndentExternBlock: Indent
91-
IndentWidth: 2
104+
IndentRequires: true
105+
IndentWidth: 2
92106
IndentWrappedFunctionNames: false
93107
InsertTrailingCommas: None
94108
JavaScriptQuotes: Leave
95109
JavaScriptWrapImports: true
96110
KeepEmptyLinesAtTheStartOfBlocks: true
111+
LambdaBodyIndentation: Signature
112+
Language: Cpp
97113
MacroBlockBegin: ''
98-
MacroBlockEnd: ''
114+
MacroBlockEnd: ''
99115
MaxEmptyLinesToKeep: 100000
100116
NamespaceIndentation: None
101117
ObjCBinPackProtocolList: Auto
102118
ObjCBlockIndentWidth: 2
103119
ObjCBreakBeforeNestedBlockParam: true
104120
ObjCSpaceAfterProperty: false
105121
ObjCSpaceBeforeProtocolList: true
122+
PPIndentWidth: -1
123+
PackConstructorInitializers: BinPack
106124
PenaltyBreakAssignment: 1
107125
PenaltyBreakBeforeFirstCallParameter: 1
108126
PenaltyBreakComment: 1
109127
PenaltyBreakFirstLessLess: 1
128+
PenaltyBreakOpenParenthesis: 1
110129
PenaltyBreakString: 1
111130
PenaltyBreakTemplateDeclaration: 1
112131
PenaltyExcessCharacter: 1
132+
PenaltyIndentedWhitespace: 1
113133
PenaltyReturnTypeOnItsOwnLine: 1
114134
PointerAlignment: Right
115-
ReflowComments: false
116-
SortIncludes: false
135+
QualifierAlignment: Leave
136+
ReferenceAlignment: Pointer
137+
ReflowComments: false
138+
RemoveBracesLLVM: false
139+
SeparateDefinitionBlocks: Leave
140+
ShortNamespaceLines: 0
141+
SortIncludes: Never
142+
SortJavaStaticImport: Before
117143
SortUsingDeclarations: false
118144
SpaceAfterCStyleCast: false
119145
SpaceAfterLogicalNot: false
120146
SpaceAfterTemplateKeyword: false
147+
SpaceAroundPointerQualifiers: Default
121148
SpaceBeforeAssignmentOperators: true
149+
SpaceBeforeCaseColon: false
122150
SpaceBeforeCpp11BracedList: false
123151
SpaceBeforeCtorInitializerColon: true
124152
SpaceBeforeInheritanceColon: true
125153
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
126162
SpaceBeforeRangeBasedForLoopColon: true
163+
SpaceBeforeSquareBrackets: false
127164
SpaceInEmptyBlock: false
128165
SpaceInEmptyParentheses: false
129166
SpacesBeforeTrailingComments: 2
130-
SpacesInAngles: false
167+
SpacesInAngles: Leave
168+
SpacesInCStyleCastParentheses: false
131169
SpacesInConditionalStatement: false
132170
SpacesInContainerLiterals: false
133-
SpacesInCStyleCastParentheses: false
171+
SpacesInLineCommentPrefix:
172+
Minimum: 0
173+
Maximum: -1
134174
SpacesInParentheses: false
135175
SpacesInSquareBrackets: false
136-
SpaceBeforeSquareBrackets: false
137-
Standard: Auto
176+
Standard: Auto
177+
StatementAttributeLikeMacros:
178+
- Q_EMIT
138179
StatementMacros:
139180
- Q_UNUSED
140181
- QT_REQUIRE_VERSION
141-
TabWidth: 2
142-
UseCRLF: false
143-
UseTab: Never
182+
TabWidth: 2
183+
UseCRLF: false
184+
UseTab: Never
144185
WhitespaceSensitiveMacros:
145186
- STRINGIZE
146187
- PP_STRINGIZE
147188
- BOOST_PP_STRINGIZE
148-
...
149-
189+
- NS_SWIFT_NAME
190+
- CF_SWIFT_NAME

0 commit comments

Comments
 (0)