Skip to content

Commit ba9d42c

Browse files
milindledenhill
authored andcommitted
Add more explicit .clang-format files and warn if clang-format version != 10
Using the --dump-files option on clang-format-10, this guards against any changes to the defaults, or changes to the 'BasedOnStyle' styles. For .clang-format-cpp, because of the way we are using it in the script by converting it to the key/value format, a number of options from the --dump-files option has to be omitted, hence why we need to retain the BasedOnStyle. For .clang-format, we no longer need this. Additionally, style-format.sh warns in case clang-format version is not 10 or 11.
1 parent 3b50e1e commit ba9d42c

File tree

3 files changed

+221
-81
lines changed

3 files changed

+221
-81
lines changed

.clang-format

+124-41
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,136 @@
11
---
2-
BasedOnStyle: LLVM
2+
Language: Cpp
3+
AccessModifierOffset: -2
34
AlignAfterOpenBracket: Align
4-
AlignConsecutiveMacros: 'true'
5-
AlignConsecutiveAssignments: 'true'
6-
AlignConsecutiveDeclarations: 'false'
5+
AlignConsecutiveMacros: true
6+
AlignConsecutiveAssignments: true
7+
AlignConsecutiveDeclarations: false
78
AlignEscapedNewlines: Right
8-
AlignOperands: 'true'
9-
AlignTrailingComments: 'true'
10-
AllowAllArgumentsOnNextLine: 'true'
11-
AllowAllConstructorInitializersOnNextLine: 'true'
12-
AllowAllParametersOfDeclarationOnNextLine: 'false'
13-
AllowShortBlocksOnASingleLine: 'false'
14-
AllowShortCaseLabelsOnASingleLine: 'false'
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllArgumentsOnNextLine: true
12+
AllowAllConstructorInitializersOnNextLine: true
13+
AllowAllParametersOfDeclarationOnNextLine: false
14+
AllowShortBlocksOnASingleLine: Never
15+
AllowShortCaseLabelsOnASingleLine: false
1516
AllowShortFunctionsOnASingleLine: None
17+
AllowShortLambdasOnASingleLine: All
1618
AllowShortIfStatementsOnASingleLine: Never
17-
AllowShortLoopsOnASingleLine: 'false'
19+
AllowShortLoopsOnASingleLine: false
20+
AlwaysBreakAfterDefinitionReturnType: None
1821
AlwaysBreakAfterReturnType: None
19-
AlwaysBreakBeforeMultilineStrings: 'true'
20-
BinPackArguments: 'true'
21-
BinPackParameters: 'false'
22+
AlwaysBreakBeforeMultilineStrings: true
23+
AlwaysBreakTemplateDeclarations: MultiLine
24+
BinPackArguments: true
25+
BinPackParameters: false
26+
BraceWrapping:
27+
AfterCaseLabel: false
28+
AfterClass: false
29+
AfterControlStatement: false
30+
AfterEnum: false
31+
AfterFunction: false
32+
AfterNamespace: false
33+
AfterObjCDeclaration: false
34+
AfterStruct: false
35+
AfterUnion: false
36+
AfterExternBlock: false
37+
BeforeCatch: false
38+
BeforeElse: false
39+
IndentBraces: false
40+
SplitEmptyFunction: true
41+
SplitEmptyRecord: true
42+
SplitEmptyNamespace: true
43+
BreakBeforeBinaryOperators: None
2244
BreakBeforeBraces: Custom
23-
BreakBeforeTernaryOperators: 'true'
45+
BreakBeforeInheritanceComma: false
46+
BreakInheritanceList: BeforeColon
47+
BreakBeforeTernaryOperators: true
48+
BreakConstructorInitializersBeforeComma: false
2449
BreakConstructorInitializers: AfterColon
25-
BreakStringLiterals: 'true'
26-
ColumnLimit: '80'
27-
DerivePointerAlignment: 'false'
28-
SortIncludes: 'false'
29-
IncludeBlocks: Preserve
30-
IndentCaseLabels: 'false'
50+
BreakAfterJavaFieldAnnotations: false
51+
BreakStringLiterals: true
52+
ColumnLimit: 80
53+
CommentPragmas: '^ IWYU pragma:'
54+
CompactNamespaces: false
55+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
56+
ConstructorInitializerIndentWidth: 4
57+
ContinuationIndentWidth: 4
58+
Cpp11BracedListStyle: true
59+
DeriveLineEnding: true
60+
DerivePointerAlignment: false
61+
DisableFormat: false
62+
ExperimentalAutoDetectBinPacking: false
63+
FixNamespaceComments: true
64+
ForEachMacros:
65+
- foreach
66+
- Q_FOREACH
67+
- BOOST_FOREACH
68+
IncludeBlocks: Preserve
69+
IncludeCategories:
70+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
71+
Priority: 2
72+
SortPriority: 0
73+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
74+
Priority: 3
75+
SortPriority: 0
76+
- Regex: '.*'
77+
Priority: 1
78+
SortPriority: 0
79+
IncludeIsMainRegex: '(Test)?$'
80+
IncludeIsMainSourceRegex: ''
81+
IndentCaseLabels: false
82+
IndentGotoLabels: true
3183
IndentPPDirectives: None
32-
IndentWidth: '8'
33-
Language: Cpp
34-
MaxEmptyLinesToKeep: '3'
84+
IndentWidth: 8
85+
IndentWrappedFunctionNames: false
86+
JavaScriptQuotes: Leave
87+
JavaScriptWrapImports: true
88+
KeepEmptyLinesAtTheStartOfBlocks: true
89+
MacroBlockBegin: ''
90+
MacroBlockEnd: ''
91+
MaxEmptyLinesToKeep: 3
92+
NamespaceIndentation: None
93+
ObjCBinPackProtocolList: Auto
94+
ObjCBlockIndentWidth: 2
95+
ObjCSpaceAfterProperty: false
96+
ObjCSpaceBeforeProtocolList: true
97+
PenaltyBreakAssignment: 2
98+
PenaltyBreakBeforeFirstCallParameter: 19
99+
PenaltyBreakComment: 300
100+
PenaltyBreakFirstLessLess: 120
101+
PenaltyBreakString: 1000
102+
PenaltyBreakTemplateDeclaration: 10
103+
PenaltyExcessCharacter: 1000000
104+
PenaltyReturnTypeOnItsOwnLine: 60
35105
PointerAlignment: Right
36-
ReflowComments: 'true'
37-
SpaceAfterCStyleCast: 'false'
38-
SpaceAfterLogicalNot: 'false'
39-
SpaceBeforeAssignmentOperators: 'true'
40-
SpaceBeforeCpp11BracedList: 'true'
106+
ReflowComments: true
107+
SortIncludes: false
108+
SortUsingDeclarations: true
109+
SpaceAfterCStyleCast: false
110+
SpaceAfterLogicalNot: false
111+
SpaceAfterTemplateKeyword: true
112+
SpaceBeforeAssignmentOperators: true
113+
SpaceBeforeCpp11BracedList: true
114+
SpaceBeforeCtorInitializerColon: true
115+
SpaceBeforeInheritanceColon: true
41116
SpaceBeforeParens: ControlStatements
42-
SpaceBeforeRangeBasedForLoopColon: 'true'
43-
SpaceInEmptyParentheses: 'false'
44-
SpacesBeforeTrailingComments: '2'
45-
SpacesInAngles: 'false'
46-
SpacesInCStyleCastParentheses: 'false'
47-
SpacesInContainerLiterals: 'false'
48-
SpacesInParentheses: 'false'
49-
SpacesInSquareBrackets: 'false'
50-
TabWidth: '8'
51-
UseTab: Never
52-
117+
SpaceBeforeRangeBasedForLoopColon: true
118+
SpaceInEmptyBlock: false
119+
SpaceInEmptyParentheses: false
120+
SpacesBeforeTrailingComments: 2
121+
SpacesInAngles: false
122+
SpacesInConditionalStatement: false
123+
SpacesInContainerLiterals: false
124+
SpacesInCStyleCastParentheses: false
125+
SpacesInParentheses: false
126+
SpacesInSquareBrackets: false
127+
SpaceBeforeSquareBrackets: false
128+
Standard: Latest
129+
StatementMacros:
130+
- Q_UNUSED
131+
- QT_REQUIRE_VERSION
132+
TabWidth: 8
133+
UseCRLF: false
134+
UseTab: Never
53135
...
136+

.clang-format-cpp

+91-40
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,103 @@
11
---
22
BasedOnStyle: Google
3-
AlignConsecutiveMacros: 'true'
4-
AlignConsecutiveAssignments: 'true'
5-
AlignConsecutiveDeclarations: 'false'
3+
Language: Cpp
4+
AccessModifierOffset: -1
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: true
7+
AlignConsecutiveAssignments: true
8+
AlignConsecutiveDeclarations: false
69
AlignEscapedNewlines: Right
7-
AlignOperands: 'true'
8-
AlignTrailingComments: 'true'
9-
AllowAllArgumentsOnNextLine: 'true'
10-
AllowAllConstructorInitializersOnNextLine: 'true'
11-
AllowAllParametersOfDeclarationOnNextLine: 'false'
12-
AllowShortBlocksOnASingleLine: 'false'
13-
AllowShortCaseLabelsOnASingleLine: 'false'
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: false
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
1417
AllowShortFunctionsOnASingleLine: None
18+
AllowShortLambdasOnASingleLine: All
1519
AllowShortIfStatementsOnASingleLine: Never
16-
AllowShortLoopsOnASingleLine: 'false'
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: None
1722
AlwaysBreakAfterReturnType: None
18-
AlwaysBreakBeforeMultilineStrings: 'true'
19-
BinPackArguments: 'true'
20-
BinPackParameters: 'false'
23+
AlwaysBreakBeforeMultilineStrings: true
24+
AlwaysBreakTemplateDeclarations: Yes
25+
BinPackArguments: true
26+
BinPackParameters: false
27+
BreakBeforeBinaryOperators: None
2128
BreakBeforeBraces: Custom
22-
BreakBeforeTernaryOperators: 'true'
29+
BreakBeforeInheritanceComma: false
30+
BreakInheritanceList: BeforeColon
31+
BreakBeforeTernaryOperators: true
32+
BreakConstructorInitializersBeforeComma: false
2333
BreakConstructorInitializers: AfterColon
24-
BreakStringLiterals: 'true'
25-
ColumnLimit: '80'
26-
DerivePointerAlignment: 'false'
27-
SortIncludes: 'false'
28-
IncludeBlocks: Preserve
29-
IndentCaseLabels: 'false'
34+
BreakAfterJavaFieldAnnotations: false
35+
BreakStringLiterals: true
36+
ColumnLimit: 80
37+
CommentPragmas: '^ IWYU pragma:'
38+
CompactNamespaces: false
39+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
40+
ConstructorInitializerIndentWidth: 4
41+
ContinuationIndentWidth: 4
42+
Cpp11BracedListStyle: true
43+
DeriveLineEnding: true
44+
DerivePointerAlignment: false
45+
DisableFormat: false
46+
ExperimentalAutoDetectBinPacking: false
47+
FixNamespaceComments: true
48+
IncludeBlocks: Preserve
49+
IncludeIsMainRegex: '([-_](test|unittest))?$'
50+
IncludeIsMainSourceRegex: ''
51+
IndentCaseLabels: false
52+
IndentGotoLabels: true
3053
IndentPPDirectives: None
31-
IndentWidth: '2'
32-
Language: Cpp
33-
MaxEmptyLinesToKeep: '3'
54+
IndentWidth: 2
55+
IndentWrappedFunctionNames: false
56+
JavaScriptQuotes: Leave
57+
JavaScriptWrapImports: true
58+
KeepEmptyLinesAtTheStartOfBlocks: false
59+
MacroBlockBegin: ''
60+
MacroBlockEnd: ''
61+
MaxEmptyLinesToKeep: 3
62+
NamespaceIndentation: None
63+
ObjCBinPackProtocolList: Never
64+
ObjCBlockIndentWidth: 2
65+
ObjCSpaceAfterProperty: false
66+
ObjCSpaceBeforeProtocolList: true
67+
PenaltyBreakAssignment: 2
68+
PenaltyBreakBeforeFirstCallParameter: 1
69+
PenaltyBreakComment: 300
70+
PenaltyBreakFirstLessLess: 120
71+
PenaltyBreakString: 1000
72+
PenaltyBreakTemplateDeclaration: 10
73+
PenaltyExcessCharacter: 1000000
74+
PenaltyReturnTypeOnItsOwnLine: 200
3475
PointerAlignment: Right
35-
ReflowComments: 'true'
36-
SpaceAfterCStyleCast: 'false'
37-
SpaceAfterLogicalNot: 'false'
38-
SpaceBeforeAssignmentOperators: 'true'
39-
SpaceBeforeCpp11BracedList: 'true'
76+
ReflowComments: true
77+
SortIncludes: false
78+
SortUsingDeclarations: true
79+
SpaceAfterCStyleCast: false
80+
SpaceAfterLogicalNot: false
81+
SpaceAfterTemplateKeyword: true
82+
SpaceBeforeAssignmentOperators: true
83+
SpaceBeforeCpp11BracedList: true
84+
SpaceBeforeCtorInitializerColon: true
85+
SpaceBeforeInheritanceColon: true
4086
SpaceBeforeParens: ControlStatements
41-
SpaceBeforeRangeBasedForLoopColon: 'true'
42-
SpaceInEmptyParentheses: 'false'
43-
SpacesBeforeTrailingComments: '2'
44-
SpacesInAngles: 'false'
45-
SpacesInCStyleCastParentheses: 'false'
46-
SpacesInContainerLiterals: 'false'
47-
SpacesInParentheses: 'false'
48-
SpacesInSquareBrackets: 'false'
49-
TabWidth: '8'
50-
UseTab: Never
51-
87+
SpaceBeforeRangeBasedForLoopColon: true
88+
SpaceInEmptyBlock: false
89+
SpaceInEmptyParentheses: false
90+
SpacesBeforeTrailingComments: 2
91+
SpacesInAngles: false
92+
SpacesInConditionalStatement: false
93+
SpacesInContainerLiterals: false
94+
SpacesInCStyleCastParentheses: false
95+
SpacesInParentheses: false
96+
SpacesInSquareBrackets: false
97+
SpaceBeforeSquareBrackets: false
98+
Standard: Auto
99+
TabWidth: 8
100+
UseCRLF: false
101+
UseTab: Never
52102
...
103+

packaging/tools/style-format.sh

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ else
2121
fix=0
2222
fi
2323

24+
clang_format_version=$(clang-format --version | sed -Ee 's/.*version ([[:digit:]]+)\.[[:digit:]]+\.[[:digit:]]+.*/\1/')
25+
if ! [[ $clang_format_version == "10" || $clang_format_version == "11" ]]; then
26+
echo "$0: clang-format version 10 or 11 required"
27+
exit 1
28+
fi
29+
2430
# Get list of files from .formatignore to ignore formatting for.
2531
ignore_files=( $(grep '^[^#]..' .formatignore) )
2632

0 commit comments

Comments
 (0)