Skip to content

Update ClangFormat configuration file for ClangFormat 14.0.0 #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f9cd917
Sort primary keys of ClangFormat configuration
per1234 Jul 28, 2022
bde5c77
Increase coverage of ClangFormat test data
per1234 Jul 29, 2022
8797fa6
Adjust test data for ClangFormat friendliness
per1234 Jul 29, 2022
f91735e
Update ClangFormat configuration values to 14.0.0 equivalents
per1234 Jul 29, 2022
9a70727
Add and update unused keys in ClangFormat configuration
per1234 Jul 29, 2022
7d29ec9
Move notes re: "forced base set" ClangFormat keys to dedicated section
per1234 Jul 29, 2022
fe2672f
Update value of `AllowShortIfStatementsOnASingleLine` configuration k…
per1234 Jul 29, 2022
7bc1bab
Add `BitFieldColonSpacing` key to ClangFormat configuration
per1234 Jul 29, 2022
1946df2
Add `BreakBeforeConceptDeclarations` key to ClangFormat configuration
per1234 Jul 29, 2022
cd2f592
Add `EmptyLineAfterAccessModifier` key to ClangFormat configuration
per1234 Jul 29, 2022
ce42bd9
Add `EmptyLineBeforeAccessModifier` key to ClangFormat configuration
per1234 Jul 29, 2022
bef1178
Add `IndentAccessModifiers` key to ClangFormat configuration
per1234 Jul 29, 2022
598dcd3
Add `IndentRequires` key to ClangFormat configuration
per1234 Jul 29, 2022
c43ca1e
Add `LambdaBodyIndentation` key to ClangFormat configuration
per1234 Jul 29, 2022
ee4ae63
Add `PPIndentWidth` key to ClangFormat configuration
per1234 Jul 29, 2022
b9c0057
Add `PackConstructorInitializers` key to ClangFormat configuration
per1234 Jul 29, 2022
d93cbed
Add `PenaltyBreakOpenParenthesis` key to ClangFormat configuration
per1234 Jul 29, 2022
064d808
Add `PenaltyIndentedWhitespace` key to ClangFormat configuration
per1234 Jul 29, 2022
8ac0b33
Add `QualifierAlignment` key to ClangFormat configuration
per1234 Jul 29, 2022
002a4a6
Add `ReferenceAlignment` key to ClangFormat configuration
per1234 Jul 29, 2022
b8df25d
Add `RemoveBracesLLVM` key to ClangFormat configuration
per1234 Jul 29, 2022
07c91d7
Add `SeparateDefinitionBlocks` key to ClangFormat configuration
per1234 Jul 29, 2022
3f95ead
Add `ShortNamespaceLines` key to ClangFormat configuration
per1234 Jul 29, 2022
b9bf88b
Add `SortJavaStaticImport` key to ClangFormat configuration
per1234 Jul 29, 2022
e121f50
Add `SpaceAroundPointerQualifiers` key to ClangFormat configuration
per1234 Jul 29, 2022
0b1f754
Add `SpaceBeforeCaseColon` key to ClangFormat configuration
per1234 Jul 29, 2022
e90c79d
Add `SpaceBeforeParensOptions` key to ClangFormat configuration
per1234 Jul 29, 2022
8d4f771
Add `SpacesInAngles` key to ClangFormat configuration
per1234 Jul 29, 2022
b35f9d9
Add `SpacesInLineCommentPrefix` key to ClangFormat configuration
per1234 Jul 29, 2022
f7cf21d
Add `BasedOnStyle` key to ClangFormat configuration
per1234 Jul 29, 2022
23b40b1
Force valid ClangFormat `BasedOnStyle` configuration key value
per1234 Jul 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/check-clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
repository: arduino/clang-static-binaries
Expand All @@ -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/[email protected]
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: |
Expand Down
23 changes: 22 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -242,6 +248,17 @@ 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}}"

# Use ClangFormat to format the files under the path specified by TARGET_FOLDER recursively
clang-format:format:
cmds:
Expand Down Expand Up @@ -272,10 +289,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
Expand Down
143 changes: 92 additions & 51 deletions other/clang-format-configuration/.clang-format
Original file line number Diff line number Diff line change
@@ -1,149 +1,190 @@
# 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
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
AttributeMacros:
- __capability
BasedOnStyle: LLVM
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
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
BreakBeforeConceptDeclarations: false
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
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
DisableFormat: false
EmptyLineAfterAccessModifier: Leave
EmptyLineBeforeAccessModifier: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IfMacros:
- KJ_IF_MAYBE
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
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: ''
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: None
IndentExternBlock: Indent
IndentWidth: 2
IndentRequires: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 100000
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: -1
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 1
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 1
PenaltyBreakFirstLessLess: 1
PenaltyBreakOpenParenthesis: 1
PenaltyBreakString: 1
PenaltyBreakTemplateDeclaration: 1
PenaltyExcessCharacter: 1
PenaltyIndentedWhitespace: 1
PenaltyReturnTypeOnItsOwnLine: 1
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: false
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 0
SortIncludes: Never
SortJavaStaticImport: Before
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
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
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInAngles: Leave
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Auto
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
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
...

- NS_SWIFT_NAME
- CF_SWIFT_NAME
Loading