blob: 41969eca4b74597f08863cc44b8311593d42c3bf [file] [log] [blame]
Stephan Beyer1bf02592017-10-02 08:37:14 +09001# This file is an example configuration for clang-format 5.0.
2#
3# Note that this style definition should only be understood as a hint
4# for writing new code. The rules are still work-in-progress and does
5# not yet exactly match the style we have in the existing code.
Brandon Williams6134de62017-08-14 14:30:45 -07006
7# Use tabs whenever we need to fill whitespace that spans at least from one tab
8# stop to the next one.
brian m. carlsonb548d692018-10-08 22:03:53 +00009#
10# These settings are mirrored in .editorconfig. Keep them in sync.
Brandon Williams6134de62017-08-14 14:30:45 -070011UseTab: Always
12TabWidth: 8
13IndentWidth: 8
14ContinuationIndentWidth: 8
15ColumnLimit: 80
16
17# C Language specifics
18Language: Cpp
19
20# Align parameters on the open bracket
21# someLongFunction(argument1,
22# argument2);
23AlignAfterOpenBracket: Align
24
25# Don't align consecutive assignments
26# int aaaa = 12;
27# int b = 14;
28AlignConsecutiveAssignments: false
29
30# Don't align consecutive declarations
31# int aaaa = 12;
32# double b = 3.14;
33AlignConsecutiveDeclarations: false
34
35# Align escaped newlines as far left as possible
36# #define A \
37# int aaaa; \
38# int b; \
39# int cccccccc;
40AlignEscapedNewlines: Left
41
42# Align operands of binary and ternary expressions
43# int aaa = bbbbbbbbbbb +
44# cccccc;
45AlignOperands: true
46
47# Don't align trailing comments
48# int a; // Comment a
49# int b = 2; // Comment b
50AlignTrailingComments: false
51
52# By default don't allow putting parameters onto the next line
53# myFunction(foo, bar, baz);
54AllowAllParametersOfDeclarationOnNextLine: false
55
56# Don't allow short braced statements to be on a single line
57# if (a) not if (a) return;
58# return;
59AllowShortBlocksOnASingleLine: false
60AllowShortCaseLabelsOnASingleLine: false
61AllowShortFunctionsOnASingleLine: false
62AllowShortIfStatementsOnASingleLine: false
63AllowShortLoopsOnASingleLine: false
64
65# By default don't add a line break after the return type of top-level functions
66# int foo();
67AlwaysBreakAfterReturnType: None
68
69# Pack as many parameters or arguments onto the same line as possible
70# int myFunction(int aaaaaaaaaaaa, int bbbbbbbb,
71# int cccc);
72BinPackArguments: true
73BinPackParameters: true
74
Karthik Nayak5e7eee42024-07-23 10:21:07 +020075# Add no space around the bit field
76# unsigned bf:2;
77BitFieldColonSpacing: None
78
Brandon Williams6134de62017-08-14 14:30:45 -070079# Attach braces to surrounding context except break before braces on function
80# definitions.
81# void foo()
82# {
83# if (true) {
84# } else {
85# }
86# };
87BreakBeforeBraces: Linux
88
89# Break after operators
Aditya Neelamraju8f815322023-10-31 13:40:28 +000090# int value = aaaaaaaaaaaaa +
91# bbbbbb -
92# ccccccccccc;
Brandon Williams6134de62017-08-14 14:30:45 -070093BreakBeforeBinaryOperators: None
94BreakBeforeTernaryOperators: false
95
96# Don't break string literals
97BreakStringLiterals: false
98
99# Use the same indentation level as for the switch statement.
100# Switch statement body is always indented one level more than case labels.
101IndentCaseLabels: false
102
Patrick Steinhardt39572672024-07-30 09:24:33 +0200103# Indents directives before the hash. Each level uses a single space for
104# indentation.
Karthik Nayake3ea4322024-07-23 10:21:06 +0200105# #if FOO
Patrick Steinhardt39572672024-07-30 09:24:33 +0200106# # include <foo>
Karthik Nayake3ea4322024-07-23 10:21:06 +0200107# #endif
108IndentPPDirectives: AfterHash
Patrick Steinhardt39572672024-07-30 09:24:33 +0200109PPIndentWidth: 1
Karthik Nayake3ea4322024-07-23 10:21:06 +0200110
Brandon Williams6134de62017-08-14 14:30:45 -0700111# Don't indent a function definition or declaration if it is wrapped after the
112# type
113IndentWrappedFunctionNames: false
114
115# Align pointer to the right
116# int *a;
117PointerAlignment: Right
118
119# Don't insert a space after a cast
120# x = (int32)y; not x = (int32) y;
121SpaceAfterCStyleCast: false
122
Karthik Nayak19939182024-07-23 10:21:08 +0200123# No space is inserted after the logical not operator
124SpaceAfterLogicalNot: false
125
Brandon Williams6134de62017-08-14 14:30:45 -0700126# Insert spaces before and after assignment operators
127# int a = 5; not int a=5;
128# a += 42; a+=42;
129SpaceBeforeAssignmentOperators: true
130
Karthik Nayak19939182024-07-23 10:21:08 +0200131# Spaces will be removed before case colon.
132# case 1: break; not case 1 : break;
133SpaceBeforeCaseColon: false
134
Brandon Williams6134de62017-08-14 14:30:45 -0700135# Put a space before opening parentheses only after control statement keywords.
136# void f() {
137# if (true) {
138# f();
139# }
140# }
141SpaceBeforeParens: ControlStatements
142
143# Don't insert spaces inside empty '()'
144SpaceInEmptyParentheses: false
145
Karthik Nayak19939182024-07-23 10:21:08 +0200146# No space before first '[' in arrays
147# int a[5][5]; not int a [5][5];
148SpaceBeforeSquareBrackets: false
149
150# No space will be inserted into {}
151# while (true) {} not while (true) { }
152SpaceInEmptyBlock: false
153
Brandon Williams6134de62017-08-14 14:30:45 -0700154# The number of spaces before trailing line comments (// - comments).
155# This does not affect trailing block comments (/* - comments).
156SpacesBeforeTrailingComments: 1
157
158# Don't insert spaces in casts
159# x = (int32) y; not x = ( int32 ) y;
160SpacesInCStyleCastParentheses: false
161
162# Don't insert spaces inside container literals
163# var arr = [1, 2, 3]; not var arr = [ 1, 2, 3 ];
164SpacesInContainerLiterals: false
165
166# Don't insert spaces after '(' or before ')'
167# f(arg); not f( arg );
168SpacesInParentheses: false
169
170# Don't insert spaces after '[' or before ']'
171# int a[5]; not int a[ 5 ];
172SpacesInSquareBrackets: false
173
174# Insert a space after '{' and before '}' in struct initializers
175Cpp11BracedListStyle: false
176
177# A list of macros that should be interpreted as foreach loops instead of as
Miguel Ojedafc7e03a2019-06-04 00:48:14 +0200178# function calls. Taken from:
René Scharfe1457dff2024-07-05 21:25:43 +0200179# git grep -h '^#define [^[:space:]]*for_\?each[^[:space:]]*(' |
180# sed "s/^#define / - '/; s/(.*$/'/" | sort | uniq
Miguel Ojedafc7e03a2019-06-04 00:48:14 +0200181ForEachMacros:
Miguel Ojedafc7e03a2019-06-04 00:48:14 +0200182 - 'for_each_builtin'
183 - 'for_each_string_list_item'
184 - 'for_each_ut'
185 - 'for_each_wanted_builtin'
René Scharfe1457dff2024-07-05 21:25:43 +0200186 - 'hashmap_for_each_entry'
187 - 'hashmap_for_each_entry_from'
188 - 'kh_foreach'
189 - 'kh_foreach_value'
Miguel Ojedafc7e03a2019-06-04 00:48:14 +0200190 - 'list_for_each'
191 - 'list_for_each_dir'
192 - 'list_for_each_prev'
193 - 'list_for_each_prev_safe'
194 - 'list_for_each_safe'
René Scharfe1457dff2024-07-05 21:25:43 +0200195 - 'strintmap_for_each_entry'
196 - 'strmap_for_each_entry'
197 - 'strset_for_each_entry'
Brandon Williams6134de62017-08-14 14:30:45 -0700198
René Scharfe96c63042024-07-30 16:08:19 +0200199# A list of macros that should be interpreted as conditionals instead of as
200# function calls.
201IfMacros:
202 - 'if_test'
203
Brandon Williams6134de62017-08-14 14:30:45 -0700204# The maximum number of consecutive empty lines to keep.
205MaxEmptyLinesToKeep: 1
206
207# No empty line at the start of a block.
208KeepEmptyLinesAtTheStartOfBlocks: false
209
210# Penalties
211# This decides what order things should be done if a line is too long
Johannes Schindelin42efde42017-09-29 20:26:44 +0200212PenaltyBreakAssignment: 10
213PenaltyBreakBeforeFirstCallParameter: 30
214PenaltyBreakComment: 10
Brandon Williams6134de62017-08-14 14:30:45 -0700215PenaltyBreakFirstLessLess: 0
Johannes Schindelin42efde42017-09-29 20:26:44 +0200216PenaltyBreakString: 10
217PenaltyExcessCharacter: 100
Patryk Obaraa3715d42018-01-24 12:11:54 +0100218PenaltyReturnTypeOnItsOwnLine: 60
Brandon Williams6134de62017-08-14 14:30:45 -0700219
220# Don't sort #include's
221SortIncludes: false