From f9cd9177ac2f4c08cd5a57b13dc3754d0d47efea Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 15:22:41 -0700 Subject: [PATCH 01/31] Sort primary keys of ClangFormat configuration The output from the `clang-format --dump-config` command is compared against Arduino's configuration file to check for additions, removals, or type changes resulting from updating to a new version of ClangFormat. The expectation is that any diff represents a change in the tool which must be evaluated before updating the configuration file contents to match the new output. Although it seems some attempt was made at sorting the output in alphabetical order, it is not completely consistent. It turns out that arbitrary changes to the order of the keys may occur from one version to another, resulting in spurious diffs or difficult to read valid diffs. The solution is to sort the keys from the dumped output in a consistent order. This is done using the excellent yq tool. In addition to avoiding problematic diffs, this will make the configuration file easier to use. --- .github/workflows/check-clang-format.yml | 21 ++++- Taskfile.yml | 16 +++- .../clang-format-configuration/.clang-format | 92 +++++++++---------- 3 files changed, 79 insertions(+), 50 deletions(-) diff --git a/.github/workflows/check-clang-format.yml b/.github/workflows/check-clang-format.yml index d1c0b7cb..c51d2738 100644 --- a/.github/workflows/check-clang-format.yml +++ b/.github/workflows/check-clang-format.yml @@ -80,10 +80,11 @@ jobs: echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV" fi echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" + echo "YQ_INSTALL_PATH=${{ runner.temp }}/yq" >> "$GITHUB_ENV" echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV" - name: Download ClangFormat - id: download + id: download-clang-format uses: MrOctopus/download-asset-action@1.0 with: repository: arduino/clang-static-binaries @@ -94,11 +95,27 @@ jobs: - name: Install ClangFormat run: | cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" - tar --extract --file="${{ steps.download.outputs.name }}" + tar --extract --file="${{ steps.download-clang-format.outputs.name }}" # Add installation to PATH: # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" + - name: Download yq + id: download-yq + uses: MrOctopus/download-asset-action@1.0 + with: + repository: mikefarah/yq + asset: yq_linux_amd64.tar.gz + target: ${{ env.YQ_INSTALL_PATH }} + + - name: Install yq + run: | + cd "${{ env.YQ_INSTALL_PATH }}" + tar --extract --file="${{ steps.download-yq.outputs.name }}" + # Add installation to PATH: + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path + echo "${{ env.YQ_INSTALL_PATH }}/yq" >> "$GITHUB_PATH" + - name: Check ClangFormat configuration file id: check run: | diff --git a/Taskfile.yml b/Taskfile.yml index 1879c2f6..2d26d464 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -230,6 +230,12 @@ tasks: deps: - task: clang-format:check-installed cmds: + - | + if ! which yq &>/dev/null; then + echo "ec not found or not in PATH. Please install: https://github.com/mikefarah/yq/#install" + exit 1 + fi + - | # Add source comment echo \ @@ -242,6 +248,10 @@ tasks: --style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" >> \ "{{.TARGET_PATH}}" + - | + # Fix the inconsistent key order + yq --inplace 'sort_keys(.)' "{{.TARGET_PATH}}" + # Use ClangFormat to format the files under the path specified by TARGET_FOLDER recursively clang-format:format: cmds: @@ -272,10 +282,14 @@ tasks: clang-format:update-config: desc: Update ClangFormat configuration file to match effective tool configuration + vars: + WORKING_PATH: + sh: task utility:mktemp-file TEMPLATE="clang-format-update-config-XXXXXXXXXX.json" cmds: - task: clang-format:dump-config vars: - TARGET_PATH: "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" + TARGET_PATH: "{{.WORKING_PATH}}" + - mv --force "{{.WORKING_PATH}}" "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" clang-format:update-golden: desc: Update golden master test data for current configuration diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index efbc0c0b..1a2ff03b 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -1,24 +1,23 @@ # Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration --- -Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false AlignConsecutiveAssignments: false AlignConsecutiveBitFields: false AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: false AlignEscapedNewlines: DontAlign -AlignOperands: Align +AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: true AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: Empty -AllowShortLambdasOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: Empty AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -27,35 +26,35 @@ AlwaysBreakTemplateDeclarations: No BinPackArguments: true BinPackParameters: true BraceWrapping: - AfterCaseLabel: false - AfterClass: false + AfterCaseLabel: false + AfterClass: false AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false + AfterStruct: false + AfterUnion: false AfterExternBlock: false - BeforeCatch: false - BeforeElse: false + BeforeCatch: false + BeforeElse: false BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false + BeforeWhile: false + IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakAfterJavaFieldAnnotations: false BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false +BreakConstructorInitializersBeforeComma: false +BreakInheritanceList: BeforeColon BreakStringLiterals: false -ColumnLimit: 0 -CommentPragmas: '' +ColumnLimit: 0 +CommentPragmas: '' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 2 @@ -63,39 +62,40 @@ ContinuationIndentWidth: 2 Cpp11BracedListStyle: false DeriveLineEnding: true DerivePointerAlignment: true -DisableFormat: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false FixNamespaceComments: false ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH -IncludeBlocks: Preserve +IncludeBlocks: Preserve IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - - Regex: '.*' - Priority: 1 - SortPriority: 0 + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 IncludeIsMainRegex: '' IncludeIsMainSourceRegex: '' -IndentCaseLabels: true IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: Indent IndentGotoLabels: false IndentPPDirectives: None -IndentExternBlock: Indent -IndentWidth: 2 +IndentWidth: 2 IndentWrappedFunctionNames: false InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true +Language: Cpp MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 100000 NamespaceIndentation: None ObjCBinPackProtocolList: Auto @@ -112,8 +112,8 @@ PenaltyBreakTemplateDeclaration: 1 PenaltyExcessCharacter: 1 PenaltyReturnTypeOnItsOwnLine: 1 PointerAlignment: Right -ReflowComments: false -SortIncludes: false +ReflowComments: false +SortIncludes: false SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false @@ -124,26 +124,24 @@ SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: false +SpacesInCStyleCastParentheses: false SpacesInConditionalStatement: false SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -Standard: Auto +Standard: Auto StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION -TabWidth: 2 -UseCRLF: false -UseTab: Never +TabWidth: 2 +UseCRLF: false +UseTab: Never WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE - BOOST_PP_STRINGIZE -... - From bde5c77f82704c2a0884594b800f8621e7f6dbe8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 21:06:32 -0700 Subject: [PATCH 02/31] Increase coverage of ClangFormat test data During development of the ClangFormat configuration file some areas of the targeted test data C++ files where coverage could be increased were identified. --- .../AllowShortIfStatementsOnASingleLine.cpp | 46 ++++++++++++++++++- .../targeted/PackConstructorInitializers.cpp | 31 +++++++++---- .../AllowShortIfStatementsOnASingleLine.cpp | 44 +++++++++++++++++- .../targeted/PackConstructorInitializers.cpp | 32 +++++++++---- 4 files changed, 130 insertions(+), 23 deletions(-) diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp index a4e3f7a5..5c2b5a5f 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp @@ -3,16 +3,58 @@ void foo() { if (a) return; - else { + if (a) + return; + else if (a) + return; + else + return; + if (a) + return; + else if (a) { + return; + } else { + return; + } + + if (a) return; + if (a) + return; + else if (a) + return; + else + return; + if (a) + return; + else if (a) { + return; + } else { return; } if (a) return; + if (a) return; + else if (a) + return; else return; + if (a) return; + else if (a) { + return; + } else { + return; + } if (a) return; - else { + if (a) return; + else if (a) + return; + else + return; + if (a) return; + else if (a) { + return; + } else { return; } } diff --git a/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp index c86b3848..de08301f 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp @@ -3,25 +3,38 @@ class Foo { Foo(int); Foo(int, int); Foo(int, int, int); - int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; - int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - int cccccccccccccccccccccccccccccccccccccccccccccccccc; + Foo(int, int, int, int); + int a; + int b; + int c; + int dddddddddddddddddddddddddddddddddddddddddddddddddd; + int eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee; + int ffffffffffffffffffffffffffffffffffffffffffffffffff; int d; int e; int f; - int ddddddddddddddddddddddddd; int ggggggggggggggggggggggggg; int hhhhhhhhhhhhhhhhhhhhhhhhh; int iiiiiiiiiiiiiiiiiiiiiiiii; }; Foo::Foo() - : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), - cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + : a(42), + b(1234), + c(11) {} Foo::Foo(int bar) - : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(1234), ffffffffffffffffffffffffffffffffffffffffffffffffff(11) {} + +Foo::Foo(int bar, int baz) + : a(bar), b(baz), c(11) {} Foo::Foo(int bar, int baz, int qux) - : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) {} + : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), + eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(baz), + ffffffffffffffffffffffffffffffffffffffffffffffffff(qux) {} + +Foo::Foo(int bar, int baz, int qux, int pippo) + : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) { + (void)pippo; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp index a4e3f7a5..77e587d4 100644 --- a/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp @@ -3,16 +3,56 @@ void foo() { if (a) return; - else { + if (a) + return; + else if (a) + return; + else + return; + if (a) + return; + else if (a) { + return; + } else { return; } if (a) return; + if (a) + return; + else if (a) + return; else return; + if (a) + return; + else if (a) { + return; + } else { + return; + } + + if (a) return; + if (a) return; + else if (a) + return; + else + return; + if (a) return; + else if (a) { + return; + } else { + return; + } if (a) return; - else { + if (a) return; + else if (a) return; + else return; + if (a) return; + else if (a) { + return; + } else { return; } } diff --git a/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp b/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp index 5a098682..8bdf8c6d 100644 --- a/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp +++ b/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp @@ -3,26 +3,38 @@ class Foo { Foo(int); Foo(int, int); Foo(int, int, int); - int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; - int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - int cccccccccccccccccccccccccccccccccccccccccccccccccc; + Foo(int, int, int, int); + int a; + int b; + int c; + int dddddddddddddddddddddddddddddddddddddddddddddddddd; + int eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee; + int ffffffffffffffffffffffffffffffffffffffffffffffffff; int d; int e; int f; - int ddddddddddddddddddddddddd; int ggggggggggggggggggggggggg; int hhhhhhhhhhhhhhhhhhhhhhhhh; int iiiiiiiiiiiiiiiiiiiiiiiii; }; Foo::Foo() - : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), - cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + : a(42), + b(1234), + c(11) {} Foo::Foo(int bar) - : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), - cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(1234), + ffffffffffffffffffffffffffffffffffffffffffffffffff(11) {} + +Foo::Foo(int bar, int baz) : a(bar), b(baz), c(11) {} Foo::Foo(int bar, int baz, int qux) - : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) {} + : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), + eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(baz), + ffffffffffffffffffffffffffffffffffffffffffffffffff(qux) {} + +Foo::Foo(int bar, int baz, int qux, int pippo) + : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) { + (void)pippo; +} From 8797fa6f0151fa228e96e196c7d67d7970d9091a Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 21:11:53 -0700 Subject: [PATCH 03/31] Adjust test data for ClangFormat friendliness The test data that targets specific ClangFormat configuration keys was designed to provide coverage with the minimum amount of extraneous code required to make it valid C++. While experimenting with the IndentRequires configuration key introduced in ClangFormat 13, I discovered that, although valid code, ClangFormat does not correctly format the targeted test data for this key when the value is set to `true`. This could be considered a sign of quality of the test data having caught unwanted output that would result from a specific ClangFormat configuration. However, the problematic form of code, although it is appropriate for this unusual use case of test data, is unlikely to ever occur in a real program. For this reason, I think it is best to adjust the code slightly to a more realistic form that is also correctly handled by ClangFormat. --- .../testdata/golden/targeted/IndentRequires.cpp | 6 ++++-- .../testdata/input/targeted/IndentRequires.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp index 951d2da9..ec49e508 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp @@ -1,5 +1,7 @@ template -requires true T foo() {} +requires(true) + T foo() {} template -requires true T bar() {} +requires(true) + T bar() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp index a7159d8d..f2bb2a4b 100644 --- a/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp +++ b/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp @@ -1,5 +1,7 @@ template - requires true T foo() {} + requires(true) +T foo() {} template -requires true T bar() {} +requires(true) +T bar() {} From f91735e9572958d9ba66db3c58438fd1670837e9 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 21:31:18 -0700 Subject: [PATCH 04/31] Update ClangFormat configuration values to 14.0.0 equivalents The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. Some of the configuration key type have been changed in the interim. These keys changed from a Boolean to an object data type, but an equivalent object value is available, which allows the value to be updated without any functional change to the output from the configuration. --- other/clang-format-configuration/.clang-format | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 1a2ff03b..35c10d51 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -2,10 +2,11 @@ --- AccessModifierOffset: -2 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveBitFields: false -AlignConsecutiveDeclarations: false -AlignConsecutiveMacros: false +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None AlignEscapedNewlines: DontAlign AlignOperands: Align AlignTrailingComments: true @@ -113,7 +114,7 @@ PenaltyExcessCharacter: 1 PenaltyReturnTypeOnItsOwnLine: 1 PointerAlignment: Right ReflowComments: false -SortIncludes: false +SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false From 9a707276d721e7cff8740ab0818a295cde00b284 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 22:59:08 -0700 Subject: [PATCH 05/31] Add and update unused keys in ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. Configuration keys were added or expanded in the interim. Some of the keys allows defining patterns used for matching. Arduino's configuration does not have any need to define custom patterns. A base set of values is hard coded into ClangFormat, without any possibility of being overwritten. For the sake of transparency, these values are written into Arduino's configuration file --- other/clang-format-configuration/.clang-format | 11 +++++++++++ other/clang-format-configuration/notes.md | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 35c10d51..31b75e87 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -24,6 +24,8 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: No +AttributeMacros: + - __capability BinPackArguments: true BinPackParameters: true BraceWrapping: @@ -70,17 +72,22 @@ ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE IncludeBlocks: Preserve IncludeCategories: - Regex: '^"(llvm|llvm-c|clang|clang-c)/' Priority: 2 SortPriority: 0 + CaseSensitive: false - Regex: '^(<|"(gtest|gmock|isl|json)/)' Priority: 3 SortPriority: 0 + CaseSensitive: false - Regex: '.*' Priority: 1 SortPriority: 0 + CaseSensitive: false IncludeIsMainRegex: '' IncludeIsMainSourceRegex: '' IndentCaseBlocks: true @@ -136,6 +143,8 @@ SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION @@ -146,3 +155,5 @@ WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index b6e34b0c..2ea90447 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -6,6 +6,10 @@ This is the additional indent beyond the standard code indentation level. The Arduino IDE 1.x formatting style indented access modifiers (equivalent to `AccessModifierOffset: 0`), but also added an extra indent for the members. So non-indented access modifiers (`AccessModifierOffset: -2`) is actually closest to the previous formatting style. +## `AttributeMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `AttributeMacros: []`. + ## `BasedOnStyle` This key is irrelevant because we define all configuration keys. @@ -36,6 +40,10 @@ Setting this to an empty string (e.g., `""`) prevents any comments from being ma The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `ForEachMacros: []`. +## `IfMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `IfMacros: []`. + ## `IncludeCategories` The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `IncludeCategories: []`. @@ -66,6 +74,10 @@ The `DerivePointerAlignment: true` configuration causes whatever pointer alignme This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such formats, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. +## `StatementAttributeLikeMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `StatementAttributeLikeMacros: []`. + ## `StatementMacros` The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `StatementMacros: []`. From 7d29ec94110135f8161af9bb55fd62a234457ffe Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:17:37 -0700 Subject: [PATCH 06/31] Move notes re: "forced base set" ClangFormat keys to dedicated section Some ClangFormat configuration keys have a base set of values which are hard coded into **ClangFormat**. These are appended to any custom values set in the configuration file and thus can not be overridden. Because this behavior of ClangFormat is unintuitive and not mentioned in the ClangFormat's documentation, notes were written for each such key. A significant number of additional keys were added in the interim between 11.0.1 and 14.0.0, which tipped the scales from documenting each key individually being reasonable. They are now listed under a dedicated section of the notes instead to improve the readability and maintainability of that content. --- other/clang-format-configuration/notes.md | 42 ++++++++--------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 2ea90447..43759da5 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -6,10 +6,6 @@ This is the additional indent beyond the standard code indentation level. The Arduino IDE 1.x formatting style indented access modifiers (equivalent to `AccessModifierOffset: 0`), but also added an extra indent for the members. So non-indented access modifiers (`AccessModifierOffset: -2`) is actually closest to the previous formatting style. -## `AttributeMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `AttributeMacros: []`. - ## `BasedOnStyle` This key is irrelevant because we define all configuration keys. @@ -36,18 +32,6 @@ https://releases.llvm.org/3.8.0/tools/clang/docs/ClangFormatStyleOptions.html#co Setting this to an empty string (e.g., `""`) prevents any comments from being matched. -## `ForEachMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `ForEachMacros: []`. - -## `IfMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `IfMacros: []`. - -## `IncludeCategories` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `IncludeCategories: []`. - ## `IncludeIsMainRegex` Setting this to an empty string (e.g., `""`) prevents any `#include` directives from being matched. @@ -74,14 +58,6 @@ The `DerivePointerAlignment: true` configuration causes whatever pointer alignme This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such formats, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. -## `StatementAttributeLikeMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `StatementAttributeLikeMacros: []`. - -## `StatementMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `StatementMacros: []`. - ## `TabWidth` During the formatting process, **ClangFormat** always uses spaces initially for indentation and alignment, according to the `IndentWidth` configuration setting value. @@ -100,10 +76,6 @@ This key is omitted from the `clang-format --dump-config` output when it is set The `DeriveLineEnding: true` configuration causes whatever line endings are predominant in the code to be used by **ClangFormat**. In the event no prevailing style can be can't be detected from code, this value is used as a fallback. -## `WhitespaceSensitiveMacros` - -The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `WhitespaceSensitiveMacros: []`. - ## "Penalty" keys These keys (e.g., `PenaltyBreakAssignment`) are not applicable when wrapping is disabled by setting `ColumnLimit` to `0`, as is done in Arduino's configuration. They are all arbitrarily set to `1`. @@ -133,3 +105,17 @@ They should be set to **ClangFormat**'s default values. - `ObjCBreakBeforeNestedBlockParam` - `ObjCSpaceAfterProperty` - `ObjCSpaceBeforeProtocolList` + +## Keys with a forced base value set + +Some [sequence type](https://www.yaml.info/learn/index.html#:~:text=A%20sequence%20is%20a%20list) keys have a base set of values which are hard coded into **ClangFormat**. These are appended to any custom values set in the configuration file and thus can not be overridden, even by setting the key to an empty array (e.g., `AttributeMacros: []`). + +Arduino's configuration file sets these base set values explicitly even when they are not relevant to the Arduino code style. This provides transparency of the effective configuration and facilitates the maintenance of the configuration file + +- `AttributeMacros` +- `ForEachMacros` +- `IfMacros` +- `IncludeCategories` +- `StatementAttributeLikeMacros` +- `StatementMacros` +- `WhitespaceSensitiveMacros` From fe2672f5dd2fe6edda8bc96bd50442ada9899467 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:27:02 -0700 Subject: [PATCH 07/31] Update value of `AllowShortIfStatementsOnASingleLine` configuration key for ClangFormat 14.0.0 The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. The values supported for the `AllowShortIfStatementsOnASingleLine` configuration key have changed in the interim, with the previous `Always` value no longer available. The equivalent value for ClangFormat 14.0.0 is `AllIfsAndElse`. Since the behavior resulting from this new value is not immediately apparent from the name or the official ClangFormat documentation, a note was added to document this. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. This was not possible to achieve using the configuration capabilities of ClangFormat 11.0.1, so the diff in the "golden master" test data is actually a reversion of unwanted formatting changes unavoidably produced by the previous version. --- other/clang-format-configuration/.clang-format | 2 +- other/clang-format-configuration/notes.md | 4 ++++ .../examples/SPIFFSDirectories/SPIFFSDirectories.ino | 3 +-- .../examples/Block2-Sports/Projects/Pong/Pong.ino | 5 ++--- .../Projects/CameraRobot/CameraRobot.ino | 6 ++---- .../SBU/examples/SBU_LoadLZSS/lzssEncode.cpp | 12 ++++-------- .../libraries/USBHost/examples/USB_desc/USB_desc.ino | 9 +++------ .../targeted/AllowShortIfStatementsOnASingleLine.cpp | 6 ++---- 8 files changed, 19 insertions(+), 28 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 31b75e87..86424ab4 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -17,7 +17,7 @@ AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: true AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: Empty -AllowShortIfStatementsOnASingleLine: Always +AllowShortIfStatementsOnASingleLine: AllIfsAndElse AllowShortLambdasOnASingleLine: Empty AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 43759da5..6b8ad5f0 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -6,6 +6,10 @@ This is the additional indent beyond the standard code indentation level. The Arduino IDE 1.x formatting style indented access modifiers (equivalent to `AccessModifierOffset: 0`), but also added an extra indent for the members. So non-indented access modifiers (`AccessModifierOffset: -2`) is actually closest to the previous formatting style. +## `AllowShortIfStatementsOnASingleLine` + +It is not clear from the documentation, but this truly is an "allow" setting, rather than ClangFormat's usual approach of forcing a specific formatting style. So the value `AllIfsAndElse` allows the user to break `if` statements according to their whims, in alignment with the Arduino IDE 1.x formatter behavior, while the `Never` is completely restrictive, not allowing short `if`, `else if`, or `else` statements under any conditions. + ## `BasedOnStyle` This key is irrelevant because we define all configuration keys. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino index 3ce22b3b..d2f9d0af 100644 --- a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino @@ -41,8 +41,7 @@ void setup() { DirEntry entry; while (dir.readdir(entry)) { if (entry.isFile()) Serial.print(" F "); - else if (entry.isDirectory()) - Serial.print(" D "); + else if (entry.isDirectory()) Serial.print(" D "); Serial.print(entry.name()); Serial.println(); } diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino index 1202da9a..f5700c2f 100644 --- a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino @@ -75,7 +75,6 @@ void loop() { void gameOver() { vuMeter.blinkAll(100, 10); - if (buttonNotPressed == 1) vuMeter.scrollRight(ledTime, 1); //if button1 was not pressed, scroll LEDs to the right to start over - else if (buttonNotPressed == 2) - vuMeter.scrollLeft(ledTime, 1); //if button2 was not pressed, scroll LEDs to the left to start over + if (buttonNotPressed == 1) vuMeter.scrollRight(ledTime, 1); //if button1 was not pressed, scroll LEDs to the right to start over + else if (buttonNotPressed == 2) vuMeter.scrollLeft(ledTime, 1); //if button2 was not pressed, scroll LEDs to the left to start over } diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino index dd1f32a7..7798d0f2 100644 --- a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino @@ -41,8 +41,7 @@ void loop() { if (panJoystick == 1 && panAngle < 180) panAngle++; //If the X value from the joystick equals -1 and //panAngle is more than 0 degrees, decrease panAngle with 1 - else if (panJoystick == -1 && panAngle > 0) - panAngle--; + else if (panJoystick == -1 && panAngle > 0) panAngle--; } //If the joysYicks Y value is 0 we will tilt if (tiltJoystick != 0) { @@ -51,8 +50,7 @@ void loop() { if (tiltJoystick == 1 && tiltAngle < 180) tiltAngle++; //If the Y value from the joystick equals -1 and //tiltAngle is more than 0 degrees, decrease tiltAngle with 1 - else if (tiltJoystick == -1 && tiltAngle > 0) - tiltAngle--; + else if (tiltJoystick == -1 && tiltAngle > 0) tiltAngle--; } pan.write(panAngle); //Set position of the pan servo tilt.write(tiltAngle); //Set position of the tilt servo diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp index 6d08a492..0d300d98 100644 --- a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp @@ -108,8 +108,7 @@ void output1(int c) { mask = 256; while (mask >>= 1) { if (c & mask) putbit1(); - else - putbit0(); + else putbit0(); } } @@ -120,14 +119,12 @@ void output2(int x, int y) { mask = N; while (mask >>= 1) { if (x & mask) putbit1(); - else - putbit0(); + else putbit0(); } mask = (1 << EJ); while (mask >>= 1) { if (y & mask) putbit1(); - else - putbit0(); + else putbit0(); } } @@ -164,8 +161,7 @@ int lzss_encode(const char buf_in[], uint32_t size) { if (y <= P) { y = 1; output1(c); - } else - output2(x & (N - 1), y - 2); + } else output2(x & (N - 1), y - 2); r += y; s += y; if (r >= N * 2 - F) { diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino index 817dd429..cf797ec4 100644 --- a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -328,16 +328,13 @@ void printepdescr(uint8_t* descr_ptr) { printProgStr(End_Header_str); printProgStr(End_Address_str); if (0x80 & ep_ptr->bEndpointAddress) printProgStr(PSTR("IN\t\t")); - else - printProgStr(PSTR("OUT\t\t")); + else printProgStr(PSTR("OUT\t\t")); print_hex((ep_ptr->bEndpointAddress & 0xF), 8); printProgStr(End_Attr_str); transfer_type = ep_ptr->bmAttributes & bmUSB_TRANSFER_TYPE; if (transfer_type == USB_TRANSFER_TYPE_INTERRUPT) printProgStr(PSTR("INTERRUPT\t")); - else if (transfer_type == USB_TRANSFER_TYPE_BULK) - printProgStr(PSTR("BULK\t")); - else if (transfer_type == USB_TRANSFER_TYPE_ISOCHRONOUS) - printProgStr(PSTR("ISO\t")); + else if (transfer_type == USB_TRANSFER_TYPE_BULK) printProgStr(PSTR("BULK\t")); + else if (transfer_type == USB_TRANSFER_TYPE_ISOCHRONOUS) printProgStr(PSTR("ISO\t")); print_hex(ep_ptr->bmAttributes, 8); printProgStr(End_Pktsize_str); print_hex(ep_ptr->wMaxPacketSize, 16); diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp index 5c2b5a5f..77e587d4 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp @@ -47,10 +47,8 @@ void foo() { if (a) return; if (a) return; - else if (a) - return; - else - return; + else if (a) return; + else return; if (a) return; else if (a) { return; From 7bc1babcb28e949c6fd95a0eb023665fcb0d9567 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:40:49 -0700 Subject: [PATCH 08/31] Add `BitFieldColonSpacing` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 86424ab4..2322d358 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -28,6 +28,7 @@ AttributeMacros: - __capability BinPackArguments: true BinPackParameters: true +BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false From 1946df23c076c9d34c2c32cdf577b65b6ce20250 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:46:09 -0700 Subject: [PATCH 09/31] Add `BreakBeforeConceptDeclarations` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. The `false` value is the most permissive, allowing the user to break or not break at their whim. Since the concepts feature was added to C++ relatively recently, there is not any established style in official Arduino code. --- other/clang-format-configuration/.clang-format | 1 + other/clang-format-configuration/notes.md | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 2322d358..e80e6ce6 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -51,6 +51,7 @@ BraceWrapping: BreakAfterJavaFieldAnnotations: false BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Attach +BreakBeforeConceptDeclarations: false BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 6b8ad5f0..9a53104b 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -20,6 +20,12 @@ This key is irrelevant because we define all configuration keys. This key is ignored when `BreakBeforeBraces` is set to anything other than `Custom`. +## `BreakBeforeConceptDeclarations` + +`true` forces the break. + +`false` allows the user to break or not break at their whim, in alignment with the Arduino IDE 1.x formatter behavior and Arduino's `AlwaysBreakTemplateDeclarations: No` configuration. + ## `BreakBeforeInheritanceComma` Seems to be a backwards compatibility name for `BreakInheritanceList: BeforeComma`: From cd2f59249116f5d7ce8878e2c19f6ccba85079d0 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:50:04 -0700 Subject: [PATCH 10/31] Add `EmptyLineAfterAccessModifier` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. This was not possible to achieve using the configuration capabilities of ClangFormat 11.0.1, so the diff in the "golden master" test data is actually a reversion of unwanted formatting changes unavoidably produced by the previous version. --- other/clang-format-configuration/.clang-format | 1 + .../testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index e80e6ce6..a3210f66 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -68,6 +68,7 @@ Cpp11BracedListStyle: false DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false +EmptyLineAfterAccessModifier: Leave ExperimentalAutoDetectBinPacking: false FixNamespaceComments: false ForEachMacros: diff --git a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp index aa0fbc85..a2262eac 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp @@ -8,10 +8,12 @@ class Bar { int foo; private: + int bar; }; class Baz { public: + int foo; }; From ce42bd9b23459527cd7421e5e075a5507e746a0f Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 28 Jul 2022 23:54:29 -0700 Subject: [PATCH 11/31] Add `EmptyLineBeforeAccessModifier` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. This was not possible to achieve using the configuration capabilities of ClangFormat 11.0.1, so the diff in the "golden master" test data is actually a reversion of unwanted formatting changes unavoidably produced by the previous version. --- other/clang-format-configuration/.clang-format | 1 + .../golden/targeted/EmptyLineBeforeAccessModifier.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index a3210f66..202c52a3 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -69,6 +69,7 @@ DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false EmptyLineAfterAccessModifier: Leave +EmptyLineBeforeAccessModifier: Leave ExperimentalAutoDetectBinPacking: false FixNamespaceComments: false ForEachMacros: diff --git a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp index 84f20ce1..48f8a664 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp @@ -2,15 +2,14 @@ class Foo { public: private: int foo; - protected: }; class Bar { public: + private: int foo; - protected: }; @@ -24,6 +23,7 @@ class Baz { class Qux { public: + private: int foo; From bef117851463ef7213c9a9880aae7201a697f313 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 00:29:18 -0700 Subject: [PATCH 12/31] Add `IndentAccessModifiers` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The hope was that this new support for access modifier indentation would allow Arduino's ClangFormat configuration to achieve code formatting of classes matching the Arduino code style, and aligned with the behavior of the Arduino IDE 1.x "Auto Format" feature (which does indent them). Unfortunately, it turns out that the setting has as an undesirable side effect on struct formatting, which renders the indentation produced by setting it to `true` incompatible with the Arduino code style. For this reason, it was set to `false`, which results in no functional change to the existing configuration. A note has been added about this finding. --- other/clang-format-configuration/.clang-format | 1 + other/clang-format-configuration/notes.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 202c52a3..fe87ca76 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -94,6 +94,7 @@ IncludeCategories: CaseSensitive: false IncludeIsMainRegex: '' IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false IndentCaseBlocks: true IndentCaseLabels: true IndentExternBlock: Indent diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 9a53104b..c88ad748 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -46,6 +46,10 @@ Setting this to an empty string (e.g., `""`) prevents any comments from being ma Setting this to an empty string (e.g., `""`) prevents any `#include` directives from being matched. +## `IndentAccessModifiers` + +The Arduino IDE 1.x formatting style for classes is equivalent to `IndentAccessModifiers: true`. Unfortunately, this key also controls the indentation of `struct` members, the Arduino IDE 1.x formatting style of which is equivalent to `IndentAccessModifiers: false`. For this reason, the key must be set to `false` and the previous approach of aligning the class formatting style as closely as possible via the `AccessModifierOffset` configuration continued. + ## `KeepEmptyLinesAtTheStartOfBlocks` Note that empty lines at the ends of blocks are always removed. From 598dcd3fab04f996e1f180edb7f57b93ae540c59 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 00:35:52 -0700 Subject: [PATCH 13/31] Add `IndentRequires` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. Since the requires clauses feature was added to C++ relatively recently, there is not any established style in official Arduino code. The key setting was chosen based on a survey of the style in use in prominent reference code. --- other/clang-format-configuration/.clang-format | 1 + .../testdata/golden/targeted/IndentRequires.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index fe87ca76..11437aa0 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -100,6 +100,7 @@ IndentCaseLabels: true IndentExternBlock: Indent IndentGotoLabels: false IndentPPDirectives: None +IndentRequires: true IndentWidth: 2 IndentWrappedFunctionNames: false InsertTrailingCommas: None diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp index ec49e508..4a8cee01 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp @@ -1,7 +1,7 @@ template -requires(true) - T foo() {} + requires(true) +T foo() {} template -requires(true) - T bar() {} + requires(true) +T bar() {} From c43ca1eb2c0087a585608d31ff205dbd422f46f1 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 00:40:23 -0700 Subject: [PATCH 14/31] Add `LambdaBodyIndentation` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 11437aa0..5a412118 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -107,6 +107,7 @@ InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature Language: Cpp MacroBlockBegin: '' MacroBlockEnd: '' From ee4ae637929cbcaa8f6242fafa4c5096650ace85 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 00:43:10 -0700 Subject: [PATCH 15/31] Add `PPIndentWidth` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. Since we have `IndentPPDirectives` set to `None`, this option has no effect. It is set to `-1` to cause preprocessor directive indentation to be done according to `IndentWidth` for consistency in the case of custom user configurations which do enable `IndentPPDirectives`. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 5a412118..09e08baa 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -118,6 +118,7 @@ ObjCBlockIndentWidth: 2 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true +PPIndentWidth: -1 PenaltyBreakAssignment: 1 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 1 From b9c00571a01f45e97ad086b2e733c32aafa1fa11 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 00:55:55 -0700 Subject: [PATCH 16/31] Add `PackConstructorInitializers` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. This was not possible to achieve using the configuration capabilities of ClangFormat 11.0.1, so the diff in the "golden master" test data is actually a reversion of unwanted formatting changes unavoidably produced by the previous version. --- other/clang-format-configuration/.clang-format | 3 ++- other/clang-format-configuration/notes.md | 10 ++++++++++ .../golden/targeted/PackConstructorInitializers.cpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 09e08baa..b841972b 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -61,7 +61,7 @@ BreakStringLiterals: false ColumnLimit: 0 CommentPragmas: '' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 2 ContinuationIndentWidth: 2 Cpp11BracedListStyle: false @@ -119,6 +119,7 @@ ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true PPIndentWidth: -1 +PackConstructorInitializers: BinPack PenaltyBreakAssignment: 1 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 1 diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index c88ad748..8fc4967b 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -42,6 +42,12 @@ https://releases.llvm.org/3.8.0/tools/clang/docs/ClangFormatStyleOptions.html#co Setting this to an empty string (e.g., `""`) prevents any comments from being matched. +## `ConstructorInitializerAllOnOneLineOrOnePerLine` + +`ConstructorInitializerAllOnOneLineOrOnePerLine: true` forces `PackConstructorInitializers: NextLine` in the effective configuration even if `PackConstructorInitializers` is set to the desired `BinPack` in the configuration file. + +Since `ConstructorInitializerAllOnOneLineOrOnePerLine` is deprecated, superseded by `PackConstructorInitializers`, `ConstructorInitializerAllOnOneLineOrOnePerLine` is set to the default `false` value that allows the desired setting for `PackConstructorInitializers` to be attained. + ## `IncludeIsMainRegex` Setting this to an empty string (e.g., `""`) prevents any `#include` directives from being matched. @@ -64,6 +70,10 @@ Note that empty lines at the ends of blocks are always removed. This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such macros, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. +## `PackConstructorInitializers` + +With Arduino's `ColumnLimit` setting of `0` (no limit), `PackConstructorInitializers: BinPack` is the most permissive setting, + ## `PointerAlignment` The `DerivePointerAlignment: true` configuration causes whatever pointer alignment style is predominant in the code to be used by **ClangFormat**. In the event no prevailing style can be can't be detected from code, this value is used as a fallback. diff --git a/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp index de08301f..b1765c91 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp @@ -24,7 +24,8 @@ Foo::Foo() c(11) {} Foo::Foo(int bar) - : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(1234), ffffffffffffffffffffffffffffffffffffffffffffffffff(11) {} + : dddddddddddddddddddddddddddddddddddddddddddddddddd(bar), eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(1234), + ffffffffffffffffffffffffffffffffffffffffffffffffff(11) {} Foo::Foo(int bar, int baz) : a(bar), b(baz), c(11) {} From d93cbed69edce66022f8f1b00ac00230c6a855b0 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:27:02 -0700 Subject: [PATCH 17/31] Add `PenaltyBreakOpenParenthesis` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. Since the `Penalty*` keys are not applicable when wrapping is disabled by setting `ColumnLimit: 0`, as is done in Arduino's configuration. These keys are all set to an arbitrary value of `1`. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index b841972b..af59f7b8 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -124,6 +124,7 @@ PenaltyBreakAssignment: 1 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 1 PenaltyBreakFirstLessLess: 1 +PenaltyBreakOpenParenthesis: 1 PenaltyBreakString: 1 PenaltyBreakTemplateDeclaration: 1 PenaltyExcessCharacter: 1 From 064d808c57f4055409f9394f75cf0f2c3e73bfc1 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:28:27 -0700 Subject: [PATCH 18/31] Add `PenaltyIndentedWhitespace` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. Since the `Penalty*` keys are not applicable when wrapping is disabled by setting `ColumnLimit: 0`, as is done in Arduino's configuration. They are all set to an arbitrary value of `1`. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index af59f7b8..a5e5e7cb 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -128,6 +128,7 @@ PenaltyBreakOpenParenthesis: 1 PenaltyBreakString: 1 PenaltyBreakTemplateDeclaration: 1 PenaltyExcessCharacter: 1 +PenaltyIndentedWhitespace: 1 PenaltyReturnTypeOnItsOwnLine: 1 PointerAlignment: Right ReflowComments: false From 8ac0b33711d11bb3a7c5579b094cc5ee96e8b5f4 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:29:16 -0700 Subject: [PATCH 19/31] Add `QualifierAlignment` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. The `Leave` value is the most permissive. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index a5e5e7cb..88810f71 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -131,6 +131,7 @@ PenaltyExcessCharacter: 1 PenaltyIndentedWhitespace: 1 PenaltyReturnTypeOnItsOwnLine: 1 PointerAlignment: Right +QualifierAlignment: Leave ReflowComments: false SortIncludes: Never SortUsingDeclarations: false From 002a4a6b6dadc39f2f35de7eff9376cd17cd4f5a Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:30:44 -0700 Subject: [PATCH 20/31] Add `ReferenceAlignment` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Comply with the established Arduino code style The chosen `Pointer` value provides consistency with the pointer alignment style. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 88810f71..0fe12a19 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -132,6 +132,7 @@ PenaltyIndentedWhitespace: 1 PenaltyReturnTypeOnItsOwnLine: 1 PointerAlignment: Right QualifierAlignment: Leave +ReferenceAlignment: Pointer ReflowComments: false SortIncludes: Never SortUsingDeclarations: false From b8df25d78d01a925a4666929333870cc35467a83 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:40:41 -0700 Subject: [PATCH 21/31] Add `RemoveBracesLLVM` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. - Comply with the established Arduino code style --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 0fe12a19..d3c7d111 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -134,6 +134,7 @@ PointerAlignment: Right QualifierAlignment: Leave ReferenceAlignment: Pointer ReflowComments: false +RemoveBracesLLVM: false SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: false From 07c91d7c1ec0295adf0b37ae51f9509e3a3bf63c Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:44:39 -0700 Subject: [PATCH 22/31] Add `SeparateDefinitionBlocks` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. The `Leave` value the most permissive. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index d3c7d111..2abb71e6 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -135,6 +135,7 @@ QualifierAlignment: Leave ReferenceAlignment: Pointer ReflowComments: false RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: false From 3f95ead0e820baf4f4b72ee596fbeafd08b26779 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:47:49 -0700 Subject: [PATCH 23/31] Add `ShortNamespaceLines` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. This key is only used when `FixNamespaceComments` is set to `true`. Since Arduino's configuration sets `FixNamespaceComments: false`, the value of `ShortNamespaceLines` doesn't have any direct effect, but the chosen value of `0` will provide the maximum possible level of consistency in custom user configurations that set `FixNamespaceComments: true` --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 2abb71e6..b026c009 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -136,6 +136,7 @@ ReferenceAlignment: Pointer ReflowComments: false RemoveBracesLLVM: false SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 0 SortIncludes: Never SortUsingDeclarations: false SpaceAfterCStyleCast: false From b9bf88b2125d670b36aa706c26261f62855d67e8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 01:53:50 -0700 Subject: [PATCH 24/31] Add `SortJavaStaticImport` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. Since this key is specific to the Java language, while Arduino's configuration is intended for use with Arduino language/C++/C, the value of this key is irrelevant so the default value is used. This fact was documented in the notes. --- other/clang-format-configuration/.clang-format | 1 + other/clang-format-configuration/notes.md | 1 + 2 files changed, 2 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index b026c009..dec29eca 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -138,6 +138,7 @@ RemoveBracesLLVM: false SeparateDefinitionBlocks: Leave ShortNamespaceLines: 0 SortIncludes: Never +SortJavaStaticImport: Before SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 8fc4967b..58c50347 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -114,6 +114,7 @@ They should be set to **ClangFormat**'s default values. - `BreakAfterJavaFieldAnnotations` - `JavaImportGroups` +- `SortJavaStaticImport` ### JavaScript From e121f502f1ac39bc51d4510a11cbeec2c92a441c Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:06:30 -0700 Subject: [PATCH 25/31] Add `SpaceAroundPointerQualifiers` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. - Comply with the established Arduino code style The key is set to `Default` in order to preserve the behavior of emulating the Arduino IDE 1.x "Auto Format" feature's permissive behavior by using whichever style is established in the code base (`DerivePointerAlignment: true`), or using the Arduino code style of right alignment (`PointerAlignment: Right`) when ClangFormat can not determine an alignment style from the code. --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index dec29eca..b40dd75e 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -143,6 +143,7 @@ SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true From 0b1f75421b739510083b5a2b1e885ddaa17b6491 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:12:58 -0700 Subject: [PATCH 26/31] Add `SpaceBeforeCaseColon` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Comply with the established Arduino code style --- other/clang-format-configuration/.clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index b40dd75e..50d3f311 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -145,6 +145,7 @@ SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: false SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true From e90c79d93a0bde7c78015ac5a30952809ade0def Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:16:43 -0700 Subject: [PATCH 27/31] Add `SpaceBeforeParensOptions` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. - Comply with the established Arduino code style --- other/clang-format-configuration/.clang-format | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 50d3f311..0b376a15 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -150,6 +150,14 @@ SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false From 8d4f771ffe6846b3fef049fe2bfe93c3f16a51a1 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:25:40 -0700 Subject: [PATCH 28/31] Add `SpacesInAngles` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with behavior of the Arduino IDE 1.x "Auto Format" feature. This was not possible to achieve using the configuration capabilities of ClangFormat 11.0.1, so the diff in the "golden master" test data is actually a reversion of unwanted formatting changes unavoidably produced by the previous version. --- other/clang-format-configuration/.clang-format | 2 +- .../testdata/golden/targeted/SpacesInAngles.cpp | 2 +- .../testdata/golden/targeted/Standard.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 0b376a15..53597562 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -163,7 +163,7 @@ SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: Leave SpacesInCStyleCastParentheses: false SpacesInConditionalStatement: false SpacesInContainerLiterals: false diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp index 292ce32d..c5c51e7e 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp @@ -1,6 +1,6 @@ template void bar() {} void baz() { - bar<42>(); + bar< 42 >(); bar<42>(); } diff --git a/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp b/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp index 05d153df..9a81f34f 100644 --- a/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp +++ b/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp @@ -1,6 +1,6 @@ #include #include -std::vector> foo; +std::vector > foo; std::vector> bar; From b35f9d9820a23b2c81df7fe9aba95c3640db2f37 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:35:05 -0700 Subject: [PATCH 29/31] Add `SpacesInLineCommentPrefix` key to ClangFormat configuration The previous ClangFormat configuration was developed for use with ClangFormat 11.0.1. The version of ClangFormat now in use by Arduino tools is 14.0.0. This configuration key was added in the interim. The key value set here was chosen in order to: - Align with the permissive behavior of the Arduino IDE 1.x "Auto Format" feature. --- other/clang-format-configuration/.clang-format | 3 +++ 1 file changed, 3 insertions(+) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 53597562..923c5ab7 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -167,6 +167,9 @@ SpacesInAngles: Leave SpacesInCStyleCastParentheses: false SpacesInConditionalStatement: false SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Minimum: 0 + Maximum: -1 SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto From f7cf21dd741c38fea99659dd4638504dcc174115 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:41:48 -0700 Subject: [PATCH 30/31] Add `BasedOnStyle` key to ClangFormat configuration The ClangFormat configuration file was previously generated using ClangFormat 11.0.1. The output produced by that version did not contain a `BasedOnStyle` key, which is why it was not present in the configuration despite being supported by 11.0.1. Since Arduino's configuration sets all configuration keys, the `BasedOnStyle` key has no effect anyway. The configuration file generated using ClangFormat 14.0.0 does contain a `BasedOnStyle` key. Unfortunately, regardless of what was set in the configuration, the tool always outputs a key set to an empty string. Even though it is likely not an issue, this is concerning because it is not documented as a supported value. --- other/clang-format-configuration/.clang-format | 1 + other/clang-format-configuration/notes.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index 923c5ab7..bde94017 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -26,6 +26,7 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: No AttributeMacros: - __capability +BasedOnStyle: '' BinPackArguments: true BinPackParameters: true BitFieldColonSpacing: Both diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 58c50347..9ba935f8 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -14,7 +14,7 @@ It is not clear from the documentation, but this truly is an "allow" setting, ra This key is irrelevant because we define all configuration keys. -**ClangFormat** uses the `LLVM` style as a base by default. +Even though it is not one of the documented possible values, `clang-format --dump-config` outputs `BasedOnStyle: ''`, so we use that. ## `BraceWrapping` From 23b40b1f01be0adbe58e0bc0bfe72a3ef15a2c3c Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 29 Jul 2022 02:52:46 -0700 Subject: [PATCH 31/31] 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`. --- Taskfile.yml | 7 +++++++ other/clang-format-configuration/.clang-format | 2 +- other/clang-format-configuration/notes.md | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 2d26d464..be860107 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -248,6 +248,13 @@ tasks: --style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" >> \ "{{.TARGET_PATH}}" + - | + # Correct invalid `BasedOnStyle` key value + # The existing key is deleted before assigning it to a valid value in order to achieve consistent quoting style + # (updating the empty string value in place causes the assigned value to be wrapped in quotes) + yq --inplace 'del(.BasedOnStyle)' "{{.TARGET_PATH}}" + yq --inplace '.BasedOnStyle = "LLVM"' "{{.TARGET_PATH}}" + - | # Fix the inconsistent key order yq --inplace 'sort_keys(.)' "{{.TARGET_PATH}}" diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format index bde94017..e608f4ed 100644 --- a/other/clang-format-configuration/.clang-format +++ b/other/clang-format-configuration/.clang-format @@ -26,7 +26,7 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: No AttributeMacros: - __capability -BasedOnStyle: '' +BasedOnStyle: LLVM BinPackArguments: true BinPackParameters: true BitFieldColonSpacing: Both diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md index 9ba935f8..b378790c 100644 --- a/other/clang-format-configuration/notes.md +++ b/other/clang-format-configuration/notes.md @@ -14,7 +14,7 @@ It is not clear from the documentation, but this truly is an "allow" setting, ra This key is irrelevant because we define all configuration keys. -Even though it is not one of the documented possible values, `clang-format --dump-config` outputs `BasedOnStyle: ''`, so we use that. +Even though it is not one of the documented possible values, `clang-format --dump-config` outputs `BasedOnStyle: ''`. ## `BraceWrapping`