-
Notifications
You must be signed in to change notification settings - Fork 27
/
.clang-format
167 lines (156 loc) · 4.62 KB
/
.clang-format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
# .clang-format in root of repository. To run on single file:
#
# $ clang-format -style=file -i <file path>
#
# To run on whole repo:
#
# $ scripts/format
# llvm coding standard is used as a starting point
# https://llvm.org/docs/CodingStandards.html
BasedOnStyle: llvm,
# BASICS
Standard: C++11,
IndentWidth: 4,
AccessModifierOffset: -4,
UseTab: Never,
FixNamespaceComments: "true",
IncludeBlocks: Regroup,
MaxEmptyLinesToKeep: 1,
BreakBeforeTernaryOperators: "true",
SpaceBeforeCpp11BracedList: "false",
Cpp11BracedListStyle: "true",
KeepEmptyLinesAtTheStartOfBlocks: "true",
AllowShortIfStatementsOnASingleLine: "false",
SpaceAfterTemplateKeyword: "false",
AlwaysBreakAfterReturnType: None,
PenaltyReturnTypeOnItsOwnLine: 10000000,
SpaceAfterCStyleCast: "false",
SpaceBeforeAssignmentOperators: "true",
# ARGUMENTS AND PARAMETERS PACKING
# Aligning arguments and parameters to brackets is hard to
# maintain. If arguments span multiple lines, more than one
# argument per line is difficult to parse.
#
# GOOD:
# my_function(a, b, c);
# my_function(
# very,
# long,
# multi,
# line,
# parameter,
# list);
# my_function(
# very, long, parameter, list);
#
# BAD:
# // Hard to maintain and generates unnecessary changes as
# // functions are renamed.
# my_function(very,
# long,
# multi,
# line,
# parameter,
# list);
#
# // Difficult to parse arguments
# my_function(
# very, long, multi, line,
# parameter, list);
#
# (NOTE: this seems to cause breaks in very long template
# parameter lists, but that seems like a reasonable price to
# occasionally pay to avoid ambiguity)
AlignAfterOpenBracket: AlwaysBreak,
AllowAllParametersOfDeclarationOnNextLine: "true",
BinPackArguments: "false",
BinPackParameters: "false",
AlwaysBreakTemplateDeclarations: MultiLine,
# BRACE POSITIONING
# Braces at end of line:
#
# if (cond) {
# x = 0;
# } else {
# x = 1;
# }
#
# except for namespaces, functions, classes, (where indentation
# often does not give us good visual cues):
BreakBeforeBraces: Linux,
# CONSTRUCTOR INITIALIZERS
# Constructor initializer packed similarly to function parameters,
# with separators before the member names.
#
# GOOD:
# my_class::my_class()
# : parent()
# , member1(x)
# , member2(y)
# {
# }
#
# BAD:
# // Annoying to reorder and indent
# my_class::my_class()
# : parent(),
# member1(x),
# member2(y)
# {
# }
#
# // Annoying to reorder
# my_class::my_class() :
# parent(),
# member1(x),
# member2(y)
# {
# }
BreakConstructorInitializers: BeforeComma,
BreakInheritanceList: BeforeComma,
ConstructorInitializerAllOnOneLineOrOnePerLine: "true",
# AllowAllConstructorInitializersOnNextLine: "false",
# ADDITIONAL NOTES
#
# - Long comments at the end of lines cause unnecessary line
# breaks. Better to comment above the line (do not add
# add empty line between the comment and the line).
#
# - Multi-line comments should use `//` style (clang-format
# does not cope well with other styles).
# // Your comment here line 1
# // line 2
#
# - Avoid `using namespace`, even in .cpp files.
#
# - Use `auto` only when it is strictly necessary, avoid otherwise.
#
# - Always use braces with control flow statements (if, for, while...),
# event though clang-format does not enforce this for single-line
# statements:
# GOOD:
# if (condition) {
# x = 0;
# } else {
# x = 1;
# }
#
# BAD:
# if (condition)
# x = 0;
# else
# x = 1;
#
# - `//` can be used at the end of a line in an initializer to retain
# formatting:
# libsnark::pb_variable_array<FieldT> value = from_bits(
# {
# 0, 0, 1, 0, 1, 1, 1, 1, // <--- these breaks will remain
# 0, 0, 0, 0, 0, 0, 0, 0, //
# 0, 0, 0, 0, 0, 0, 0, 0, //
# 0, 0, 0, 0, 0, 0, 0, 0, //
# ...
#
# - Do not leave whitespace at the end of lines
}