Skip to content

Commit 23b40b1

Browse files
committed
Force valid ClangFormat BasedOnStyle configuration key value
In order to facilitate maintenance and development, the ClangFormat configuration file is standardized by running a `clang-format --dump-config` command while configured according to the current configuration file, then updating the file according to the dumped effective configuration. The configuration file generated using ClangFormat 14.0.0 contains a `BasedOnStyle` key set to an empty string (`BasedOnStyle: ''`), even when configured via the arbitrary `BasedOnStyle: LLVM` setting previously used by Arduino's configuration. Since Arduino's configuration sets all configuration keys, the `BasedOnStyle` key has no effect, and so this is likely not an issue. However, it is concerning because an empty string is not documented as a supported value. Out of an abundance of caution and to avoid confusion, the value of this key is reset to the documented valid value `LLVM`.
1 parent f7cf21d commit 23b40b1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Taskfile.yml

+7
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ tasks:
248248
--style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" >> \
249249
"{{.TARGET_PATH}}"
250250
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+
251258
- |
252259
# Fix the inconsistent key order
253260
yq --inplace 'sort_keys(.)' "{{.TARGET_PATH}}"

other/clang-format-configuration/.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AlwaysBreakBeforeMultilineStrings: false
2626
AlwaysBreakTemplateDeclarations: No
2727
AttributeMacros:
2828
- __capability
29-
BasedOnStyle: ''
29+
BasedOnStyle: LLVM
3030
BinPackArguments: true
3131
BinPackParameters: true
3232
BitFieldColonSpacing: Both

other/clang-format-configuration/notes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It is not clear from the documentation, but this truly is an "allow" setting, ra
1414

1515
This key is irrelevant because we define all configuration keys.
1616

17-
Even though it is not one of the documented possible values, `clang-format --dump-config` outputs `BasedOnStyle: ''`, so we use that.
17+
Even though it is not one of the documented possible values, `clang-format --dump-config` outputs `BasedOnStyle: ''`.
1818

1919
## `BraceWrapping`
2020

0 commit comments

Comments
 (0)