blob: 3611bdd7b00d07faa5d6465eb9052afe77b182fa [file] [log] [blame]
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
Paul Hoadcbb726d2019-03-21 13:09:22 +000010the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
11create a custom style by configuring specific style options.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000012
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
Hans Wennborg9f6581b2013-09-10 15:41:12 +000019use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000021
22When using ``-style=file``, :program:`clang-format` for each input file will
23try to find the ``.clang-format`` file located in the closest parent directory
24of the input file. When the standard input is used, the search is started from
25the current directory.
26
27The ``.clang-format`` file uses YAML format:
28
29.. code-block:: yaml
30
31 key1: value1
32 key2: value2
33 # A comment.
34 ...
35
Alexander Kornienko092cb212014-08-12 13:34:22 +000036The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An example of a configuration file for multiple languages:
51
52.. code-block:: yaml
53
54 ---
55 # We'll use defaults from the LLVM style, but with 4 columns indentation.
56 BasedOnStyle: LLVM
57 IndentWidth: 4
58 ---
59 Language: Cpp
60 # Force pointers to the type for C++.
61 DerivePointerAlignment: false
62 PointerAlignment: Left
63 ---
64 Language: JavaScript
65 # Use 100 columns for JS.
66 ColumnLimit: 100
67 ---
68 Language: Proto
69 # Don't format .proto files.
70 DisableFormat: true
Paul Hoadcbb726d2019-03-21 13:09:22 +000071 ---
72 Language: CSharp
73 # Use 100 columns for C#.
74 ColumnLimit: 100
Alexander Kornienko092cb212014-08-12 13:34:22 +000075 ...
76
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000077An easy way to get a valid ``.clang-format`` file containing all configuration
78options of a certain predefined style is:
79
80.. code-block:: console
81
82 clang-format -style=llvm -dump-config > .clang-format
83
84When specifying configuration in the ``-style=`` option, the same configuration
85is applied for all input files. The format of the configuration is:
86
87.. code-block:: console
88
89 -style='{key1: value1, key2: value2, ...}'
90
91
Daniel Jasperd8b4ec02014-10-07 12:15:15 +000092Disabling Formatting on a Piece of Code
93=======================================
94
95Clang-format understands also special comments that switch formatting in a
96delimited range. The code between a comment ``// clang-format off`` or
97``/* clang-format off */`` up to a comment ``// clang-format on`` or
98``/* clang-format on */`` will not be formatted. The comments themselves
99will be formatted (aligned) normally.
100
101.. code-block:: c++
102
103 int formatted_code;
104 // clang-format off
105 void unformatted_code ;
106 // clang-format on
107 void formatted_code_again;
108
109
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000110Configuring Style in Code
111=========================
112
113When using ``clang::format::reformat(...)`` functions, the format is specified
114by supplying the `clang::format::FormatStyle
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000115<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000116structure.
117
118
119Configurable Format Style Options
120=================================
121
122This section lists the supported style options. Value type is specified for
123each option. For enumeration types possible values are specified both as a C++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000124enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
125the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000126
127
128**BasedOnStyle** (``string``)
129 The style used for all options not specifically set in the configuration.
130
131 This option is supported only in the :program:`clang-format` configuration
132 (both within ``-style='{...}'`` and the ``.clang-format`` file).
133
134 Possible values:
135
136 * ``LLVM``
137 A style complying with the `LLVM coding standards
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000138 <https://llvm.org/docs/CodingStandards.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000139 * ``Google``
140 A style complying with `Google's C++ style guide
141 <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
142 * ``Chromium``
143 A style complying with `Chromium's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000144 <https://www.chromium.org/developers/coding-style>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000145 * ``Mozilla``
146 A style complying with `Mozilla's style guide
147 <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
148 * ``WebKit``
149 A style complying with `WebKit's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000150 <https://www.webkit.org/coding/coding-style.html>`_
Paul Hoadcbb726d2019-03-21 13:09:22 +0000151 * ``Microsoft``
152 A style complying with `Microsoft's style guide
153 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000154
155.. START_FORMAT_STYLE_OPTIONS
156
157**AccessModifierOffset** (``int``)
Alexander Kornienkoe99a3a32016-02-23 16:12:08 +0000158 The extra indent or outdent of access modifiers, e.g. ``public:``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000159
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000160**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
Daniel Jasper3219e432014-12-02 13:24:51 +0000161 If ``true``, horizontally aligns arguments after an open bracket.
162
163 This applies to round brackets (parentheses), angle brackets and square
Alexander Kornienko1e048232016-02-23 16:11:51 +0000164 brackets.
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000165
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000166 Possible values:
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000167
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000168 * ``BAS_Align`` (in configuration: ``Align``)
169 Align parameters on the open bracket, e.g.:
170
171 .. code-block:: c++
172
173 someLongFunction(argument1,
174 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000175
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000176 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
177 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
178
179 .. code-block:: c++
180
181 someLongFunction(argument1,
182 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000183
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000184 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
185 Always break after an open bracket, if the parameters don't fit
186 on a single line, e.g.:
187
188 .. code-block:: c++
189
190 someLongFunction(
191 argument1, argument2);
192
Daniel Jasper3219e432014-12-02 13:24:51 +0000193
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000194
Daniel Jaspera44991332015-04-29 13:06:49 +0000195**AlignConsecutiveAssignments** (``bool``)
196 If ``true``, aligns consecutive assignments.
197
198 This will align the assignment operators of consecutive lines. This
199 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000200
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000201 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000202
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000203 int aaaa = 12;
204 int b = 23;
205 int ccc = 23;
206
207**AlignConsecutiveDeclarations** (``bool``)
208 If ``true``, aligns consecutive declarations.
209
210 This will align the declaration names of consecutive lines. This
211 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000212
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000213 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000214
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000215 int aaaa = 12;
216 float b = 23;
217 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000218
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000219**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
220 Options for aligning backslashes in escaped newlines.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000221
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000222 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000223
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000224 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
225 Don't align escaped newlines.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000226
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000227 .. code-block:: c++
228
229 #define A \
230 int aaaa; \
231 int b; \
232 int dddddddddd;
233
234 * ``ENAS_Left`` (in configuration: ``Left``)
235 Align escaped newlines as far left as possible.
236
237 .. code-block:: c++
238
239 true:
240 #define A \
241 int aaaa; \
242 int b; \
243 int dddddddddd;
244
245 false:
246
247 * ``ENAS_Right`` (in configuration: ``Right``)
248 Align escaped newlines in the right-most column.
249
250 .. code-block:: c++
251
252 #define A \
253 int aaaa; \
254 int b; \
255 int dddddddddd;
256
257
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000258
Daniel Jasper3219e432014-12-02 13:24:51 +0000259**AlignOperands** (``bool``)
260 If ``true``, horizontally align operands of binary and ternary
261 expressions.
262
Alexander Kornienko1e048232016-02-23 16:11:51 +0000263 Specifically, this aligns operands of a single expression that needs to be
264 split over multiple lines, e.g.:
265
266 .. code-block:: c++
267
268 int aaa = bbbbbbbbbbbbbbb +
269 ccccccccccccccc;
270
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000271**AlignTrailingComments** (``bool``)
272 If ``true``, aligns trailing comments.
273
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000274 .. code-block:: c++
275
Krasimir Georgiev818da9b2017-11-09 15:41:23 +0000276 true: false:
277 int a; // My comment a vs. int a; // My comment a
278 int b = 2; // comment b int b = 2; // comment about b
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000279
Paul Hoadc6deae42019-03-23 14:37:58 +0000280**AllowAllArgumentsOnNextLine** (``bool``)
281 If a function call or braced initializer list doesn't fit on a
282 line, allow putting all arguments onto the next line, even if
283 ``BinPackArguments`` is ``false``.
284
285 .. code-block:: c++
286
287 true:
288 callFunction(
289 a, b, c, d);
290
291 false:
292 callFunction(a,
293 b,
294 c,
295 d);
296
297**AllowAllConstructorInitializersOnNextLine** (``bool``)
298 If a constructor definition with a member initializer list doesn't
299 fit on a single line, allow putting all member initializers onto the next
300 line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
301 Note that this parameter has no effect if
302 ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
303
304 .. code-block:: c++
305
306 true:
307 MyClass::MyClass() :
308 member0(0), member1(2) {}
309
310 false:
311 MyClass::MyClass() :
312 member0(0),
313 member1(2) {}
314
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000315**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000316 If the function declaration doesn't fit on a line,
317 allow putting all parameters of a function declaration onto
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000318 the next line even if ``BinPackParameters`` is ``false``.
319
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000320 .. code-block:: c++
321
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000322 true:
323 void myFunction(
324 int a, int b, int c, int d, int e);
325
326 false:
327 void myFunction(int a,
328 int b,
329 int c,
330 int d,
331 int e);
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000332
Daniel Jasper17605d32014-05-14 09:33:35 +0000333**AllowShortBlocksOnASingleLine** (``bool``)
334 Allows contracting simple braced statements to a single line.
335
336 E.g., this allows ``if (a) { return; }`` to be put on a single line.
337
Daniel Jasperb87899b2014-09-10 13:11:45 +0000338**AllowShortCaseLabelsOnASingleLine** (``bool``)
339 If ``true``, short case labels will be contracted to a single line.
340
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000341 .. code-block:: c++
342
343 true: false:
344 switch (a) { vs. switch (a) {
345 case 1: x = 1; break; case 1:
346 case 2: return; x = 1;
347 } break;
348 case 2:
349 return;
350 }
351
Daniel Jasperb5524822014-04-09 14:05:49 +0000352**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000353 Dependent on the value, ``int f() { return 0; }`` can be put on a
354 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000355
356 Possible values:
357
358 * ``SFS_None`` (in configuration: ``None``)
359 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000360
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000361 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
362 Only merge functions defined inside a class. Same as "inline",
363 except it does not implies "empty": i.e. top level empty functions
364 are not merged either.
365
366 .. code-block:: c++
367
368 class Foo {
369 void f() { foo(); }
370 };
371 void f() {
372 foo();
373 }
374 void f() {
375 }
376
Daniel Jasper3219e432014-12-02 13:24:51 +0000377 * ``SFS_Empty`` (in configuration: ``Empty``)
378 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000379
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000380 .. code-block:: c++
381
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000382 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000383 void f2() {
384 bar2();
385 }
386
Daniel Jasper20580fd2015-06-11 13:31:45 +0000387 * ``SFS_Inline`` (in configuration: ``Inline``)
388 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000389
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000390 .. code-block:: c++
391
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000392 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000393 void f() { foo(); }
394 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000395 void f() {
396 foo();
397 }
398 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000399
Daniel Jasperb5524822014-04-09 14:05:49 +0000400 * ``SFS_All`` (in configuration: ``All``)
401 Merge all functions fitting on a single line.
402
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000403 .. code-block:: c++
404
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000405 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000406 void f() { foo(); }
407 };
408 void f() { bar(); }
409
Owen Pan806d5742019-04-08 23:36:25 +0000410
411
Paul Hoad15000a12019-03-13 08:26:39 +0000412**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
Owen Pan806d5742019-04-08 23:36:25 +0000413 If ``true``, ``if (a) return;`` can be put on a single line.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000414
Paul Hoad15000a12019-03-13 08:26:39 +0000415 Possible values:
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000416
Paul Hoad15000a12019-03-13 08:26:39 +0000417 * ``SIS_Never`` (in configuration: ``Never``)
Owen Pan806d5742019-04-08 23:36:25 +0000418 Never put short ifs on the same line.
Paul Hoad15000a12019-03-13 08:26:39 +0000419
420 .. code-block:: c++
421
Owen Pan806d5742019-04-08 23:36:25 +0000422 if (a)
423 return ;
424 else {
425 return;
426 }
Paul Hoad15000a12019-03-13 08:26:39 +0000427
428 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
Owen Pan806d5742019-04-08 23:36:25 +0000429 Without else put short ifs on the same line only if
430 the else is not a compound statement.
Paul Hoad15000a12019-03-13 08:26:39 +0000431
432 .. code-block:: c++
433
Owen Pan806d5742019-04-08 23:36:25 +0000434 if (a) return;
435 else
436 return;
Paul Hoad15000a12019-03-13 08:26:39 +0000437
438 * ``SIS_Always`` (in configuration: ``Always``)
Owen Pan806d5742019-04-08 23:36:25 +0000439 Always put short ifs on the same line if
440 the else is not a compound statement or not.
Paul Hoad15000a12019-03-13 08:26:39 +0000441
442 .. code-block:: c++
443
Owen Pan806d5742019-04-08 23:36:25 +0000444 if (a) return;
445 else {
446 return;
447 }
448
449
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000450
Ronald Wamplera83e2db2019-03-26 20:18:14 +0000451**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
452 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
453 single line.
454
455 Possible values:
456
457 * ``SLS_None`` (in configuration: ``None``)
458 Never merge lambdas into a single line.
459
460 * ``SLS_Empty`` (in configuration: ``Empty``)
461 Only merge empty lambdas.
462
463 .. code-block:: c++
464
465 auto lambda = [](int a) {}
466 auto lambda2 = [](int a) {
467 return a;
468 };
469
470 * ``SLS_Inline`` (in configuration: ``Inline``)
471 Merge lambda into a single line if argument of a function.
472
473 .. code-block:: c++
474
475 auto lambda = [](int a) {
476 return a;
477 };
478 sort(a.begin(), a.end(), ()[] { return x < y; })
479
480 * ``SLS_All`` (in configuration: ``All``)
481 Merge all lambdas fitting on a single line.
482
483 .. code-block:: c++
484
485 auto lambda = [](int a) {}
486 auto lambda2 = [](int a) { return a; };
487
488
489
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000490**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000491 If ``true``, ``while (true) continue;`` can be put on a single
492 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000493
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000494**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000495 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000496 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000497
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000498 Possible values:
499
500 * ``DRTBS_None`` (in configuration: ``None``)
501 Break after return type automatically.
502 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000503
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000504 * ``DRTBS_All`` (in configuration: ``All``)
505 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000506
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000507 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000508 Always break after the return types of top-level functions.
509
510
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000511
Zachary Turner448592e2015-12-18 22:20:15 +0000512**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
513 The function declaration return type breaking style to use.
514
515 Possible values:
516
517 * ``RTBS_None`` (in configuration: ``None``)
518 Break after return type automatically.
519 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000520
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000521 .. code-block:: c++
522
523 class A {
524 int f() { return 0; };
525 };
526 int f();
527 int f() { return 1; }
528
Zachary Turner448592e2015-12-18 22:20:15 +0000529 * ``RTBS_All`` (in configuration: ``All``)
530 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000531
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000532 .. code-block:: c++
533
534 class A {
535 int
536 f() {
537 return 0;
538 };
539 };
540 int
541 f();
542 int
543 f() {
544 return 1;
545 }
546
Zachary Turner448592e2015-12-18 22:20:15 +0000547 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
548 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000549
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000550 .. code-block:: c++
551
552 class A {
553 int f() { return 0; };
554 };
555 int
556 f();
557 int
558 f() {
559 return 1;
560 }
561
Zachary Turner448592e2015-12-18 22:20:15 +0000562 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
563 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000564
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000565 .. code-block:: c++
566
567 class A {
568 int
569 f() {
570 return 0;
571 };
572 };
573 int f();
574 int
575 f() {
576 return 1;
577 }
578
Zachary Turner448592e2015-12-18 22:20:15 +0000579 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
580 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000581
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000582 .. code-block:: c++
583
584 class A {
585 int f() { return 0; };
586 };
587 int f();
588 int
589 f() {
590 return 1;
591 }
592
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000593
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000594
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000595**AlwaysBreakBeforeMultilineStrings** (``bool``)
596 If ``true``, always break before multiline string literals.
597
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000598 This flag is mean to make cases where there are multiple multiline strings
599 in a file look more consistent. Thus, it will only take effect if wrapping
600 the string at that point leads to it being indented
601 ``ContinuationIndentWidth`` spaces from the start of the line.
602
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000603 .. code-block:: c++
604
605 true: false:
606 aaaa = vs. aaaa = "bbbb"
607 "bbbb" "cccc";
608 "cccc";
609
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000610**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
611 The template declaration breaking style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000612
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000613 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000614
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000615 * ``BTDS_No`` (in configuration: ``No``)
616 Do not force break before declaration.
617 ``PenaltyBreakTemplateDeclaration`` is taken into account.
618
619 .. code-block:: c++
620
621 template <typename T> T foo() {
622 }
623 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
624 int bbbbbbbbbbbbbbbbbbbbb) {
625 }
626
627 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
628 Force break after template declaration only when the following
629 declaration spans multiple lines.
630
631 .. code-block:: c++
632
633 template <typename T> T foo() {
634 }
635 template <typename T>
636 T foo(int aaaaaaaaaaaaaaaaaaaaa,
637 int bbbbbbbbbbbbbbbbbbbbb) {
638 }
639
640 * ``BTDS_Yes`` (in configuration: ``Yes``)
641 Always break after template declaration.
642
643 .. code-block:: c++
644
645 template <typename T>
646 T foo() {
647 }
648 template <typename T>
649 T foo(int aaaaaaaaaaaaaaaaaaaaa,
650 int bbbbbbbbbbbbbbbbbbbbb) {
651 }
652
653
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000654
Daniel Jasper18210d72014-10-09 09:52:05 +0000655**BinPackArguments** (``bool``)
656 If ``false``, a function call's arguments will either be all on the
657 same line or will have one line each.
658
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000659 .. code-block:: c++
660
661 true:
662 void f() {
663 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
664 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
665 }
666
667 false:
668 void f() {
669 f(aaaaaaaaaaaaaaaaaaaa,
670 aaaaaaaaaaaaaaaaaaaa,
671 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
672 }
673
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000674**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000675 If ``false``, a function declaration's or function definition's
676 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000677
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000678 .. code-block:: c++
679
680 true:
681 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
682 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
683
684 false:
685 void f(int aaaaaaaaaaaaaaaaaaaa,
686 int aaaaaaaaaaaaaaaaaaaa,
687 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
688
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000689**BraceWrapping** (``BraceWrappingFlags``)
690 Control of individual brace wrapping cases.
691
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000692 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
693 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000694
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000695 .. code-block:: yaml
696
697 # Example of usage:
698 BreakBeforeBraces: Custom
699 BraceWrapping:
700 AfterEnum: true
701 AfterStruct: false
702 SplitEmptyFunction: false
703
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000704 Nested configuration flags:
705
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000706
Owen Pan806d5742019-04-08 23:36:25 +0000707 * ``bool AfterCaseLabel`` Wrap case labels.
708
709 .. code-block:: c++
710
711 false: true:
712 switch (foo) { vs. switch (foo) {
713 case 1: { case 1:
714 bar(); {
715 break; bar();
716 } break;
717 default: { }
718 plop(); default:
719 } {
720 } plop();
721 }
722 }
723
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000724 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000725
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000726 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000727
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000728 true:
729 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000730
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000731 false:
732 class foo
733 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000734
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000735 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000736
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000737 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000738
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000739 true:
740 if (foo())
741 {
742 } else
743 {}
744 for (int i = 0; i < 10; ++i)
745 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000746
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000747 false:
748 if (foo()) {
749 } else {
750 }
751 for (int i = 0; i < 10; ++i) {
752 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000753
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000754 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000755
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000756 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000757
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000758 true:
759 enum X : int
760 {
761 B
762 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000763
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000764 false:
765 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000766
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000767 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000768
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000769 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000770
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000771 true:
772 void foo()
773 {
774 bar();
775 bar2();
776 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000777
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000778 false:
779 void foo() {
780 bar();
781 bar2();
782 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000783
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000784 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000785
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000786 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000787
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000788 true:
789 namespace
790 {
791 int foo();
792 int bar();
793 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000794
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000795 false:
796 namespace {
797 int foo();
798 int bar();
799 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000800
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000801 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
802 @autoreleasepool and @synchronized blocks are wrapped
803 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000804
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000805 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000806
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000807 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000808
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000809 true:
810 struct foo
811 {
812 int x;
813 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000814
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000815 false:
816 struct foo {
817 int x;
818 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000819
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000820 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000821
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000822 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000823
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000824 true:
825 union foo
826 {
827 int x;
828 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000829
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000830 false:
831 union foo {
832 int x;
833 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000834
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000835 * ``bool AfterExternBlock`` Wrap extern blocks.
836
837 .. code-block:: c++
838
839 true:
840 extern "C"
841 {
842 int foo();
843 }
844
845 false:
846 extern "C" {
847 int foo();
848 }
849
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000850 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000851
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000852 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000853
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000854 true:
855 try {
856 foo();
857 }
858 catch () {
859 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000860
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000861 false:
862 try {
863 foo();
864 } catch () {
865 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000866
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000867 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000868
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000869 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000870
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000871 true:
872 if (foo()) {
873 }
874 else {
875 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000876
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000877 false:
878 if (foo()) {
879 } else {
880 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000881
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000882 * ``bool IndentBraces`` Indent the wrapped braces themselves.
883
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000884 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000885 This option is used only if the opening brace of the function has
886 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
887 set, and the function could/should not be put on a single line (as per
888 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000889
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000890 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000891
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000892 int f() vs. inf f()
893 {} {
894 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000895
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000896 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
897 can be put on a single line. This option is used only if the opening
898 brace of the record has already been wrapped, i.e. the `AfterClass`
899 (for classes) brace wrapping mode is set.
900
901 .. code-block:: c++
902
903 class Foo vs. class Foo
904 {} {
905 }
906
907 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
908 This option is used only if the opening brace of the namespace has
909 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
910 set.
911
912 .. code-block:: c++
913
914 namespace Foo vs. namespace Foo
915 {} {
916 }
917
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000918
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000919**BreakAfterJavaFieldAnnotations** (``bool``)
920 Break after each annotation on a field in Java files.
921
Sylvestre Ledrude098242017-04-11 07:07:05 +0000922 .. code-block:: java
923
924 true: false:
925 @Partial vs. @Partial @Mock DataLoad loader;
926 @Mock
927 DataLoad loader;
928
Daniel Jasperac043c92014-09-15 11:11:00 +0000929**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
930 The way to wrap binary operators.
931
932 Possible values:
933
934 * ``BOS_None`` (in configuration: ``None``)
935 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000936
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000937 .. code-block:: c++
938
939 LooooooooooongType loooooooooooooooooooooongVariable =
940 someLooooooooooooooooongFunction();
941
942 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
943 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
944 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
945 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
946 ccccccccccccccccccccccccccccccccccccccccc;
947
Daniel Jasperac043c92014-09-15 11:11:00 +0000948 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
949 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000950
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000951 .. code-block:: c++
952
953 LooooooooooongType loooooooooooooooooooooongVariable =
954 someLooooooooooooooooongFunction();
955
956 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
957 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
958 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
959 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
960 > ccccccccccccccccccccccccccccccccccccccccc;
961
Daniel Jasperac043c92014-09-15 11:11:00 +0000962 * ``BOS_All`` (in configuration: ``All``)
963 Break before operators.
964
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000965 .. code-block:: c++
966
967 LooooooooooongType loooooooooooooooooooooongVariable
968 = someLooooooooooooooooongFunction();
969
970 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
971 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
972 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
973 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
974 > ccccccccccccccccccccccccccccccccccccccccc;
975
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000976
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000977
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000978**BreakBeforeBraces** (``BraceBreakingStyle``)
979 The brace breaking style to use.
980
981 Possible values:
982
983 * ``BS_Attach`` (in configuration: ``Attach``)
984 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000985
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000986 .. code-block:: c++
987
988 try {
989 foo();
990 } catch () {
991 }
992 void foo() { bar(); }
993 class foo {};
994 if (foo()) {
995 } else {
996 }
997 enum X : int { A, B };
998
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000999 * ``BS_Linux`` (in configuration: ``Linux``)
1000 Like ``Attach``, but break before braces on function, namespace and
1001 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001002
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001003 .. code-block:: c++
1004
1005 try {
1006 foo();
1007 } catch () {
1008 }
1009 void foo() { bar(); }
1010 class foo
1011 {
1012 };
1013 if (foo()) {
1014 } else {
1015 }
1016 enum X : int { A, B };
1017
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +00001018 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1019 Like ``Attach``, but break before braces on enum, function, and record
1020 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001021
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001022 .. code-block:: c++
1023
1024 try {
1025 foo();
1026 } catch () {
1027 }
1028 void foo() { bar(); }
1029 class foo
1030 {
1031 };
1032 if (foo()) {
1033 } else {
1034 }
1035 enum X : int { A, B };
1036
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001037 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001038 Like ``Attach``, but break before function definitions, ``catch``, and
1039 ``else``.
1040
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001041 .. code-block:: c++
1042
1043 try {
1044 foo();
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001045 }
1046 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001047 }
1048 void foo() { bar(); }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001049 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001050 };
1051 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001052 }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001053 else {
1054 }
1055 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001056
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001057 * ``BS_Allman`` (in configuration: ``Allman``)
1058 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001059
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001060 .. code-block:: c++
1061
Owen Pan806d5742019-04-08 23:36:25 +00001062 try {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001063 foo();
1064 }
Owen Pan806d5742019-04-08 23:36:25 +00001065 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001066 }
1067 void foo() { bar(); }
Owen Pan806d5742019-04-08 23:36:25 +00001068 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001069 };
Owen Pan806d5742019-04-08 23:36:25 +00001070 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001071 }
Owen Pan806d5742019-04-08 23:36:25 +00001072 else {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001073 }
Owen Pan806d5742019-04-08 23:36:25 +00001074 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001075
Daniel Jasperee107ad2014-02-13 12:51:50 +00001076 * ``BS_GNU`` (in configuration: ``GNU``)
1077 Always break before braces and add an extra level of indentation to
1078 braces of control statements, not to those of class, function
1079 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001080
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001081 .. code-block:: c++
1082
1083 try
1084 {
1085 foo();
1086 }
1087 catch ()
1088 {
1089 }
1090 void foo() { bar(); }
1091 class foo
1092 {
1093 };
1094 if (foo())
1095 {
1096 }
1097 else
1098 {
1099 }
1100 enum X : int
1101 {
1102 A,
1103 B
1104 };
1105
Roman Kashitsyn291f64f2015-08-10 13:43:19 +00001106 * ``BS_WebKit`` (in configuration: ``WebKit``)
1107 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001108
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001109 .. code-block:: c++
1110
1111 try {
1112 foo();
1113 } catch () {
1114 }
1115 void foo() { bar(); }
1116 class foo {
1117 };
1118 if (foo()) {
1119 } else {
1120 }
1121 enum X : int { A, B };
1122
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001123 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001124 Configure each individual brace in `BraceWrapping`.
1125
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001126
1127
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001128**BreakBeforeTernaryOperators** (``bool``)
1129 If ``true``, ternary operators will be placed after line breaks.
1130
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001131 .. code-block:: c++
1132
1133 true:
1134 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1135 ? firstValue
1136 : SecondValueVeryVeryVeryVeryLong;
1137
Sylvestre Ledru121224d2017-06-06 07:26:19 +00001138 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001139 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1140 firstValue :
1141 SecondValueVeryVeryVeryVeryLong;
1142
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001143**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1144 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001145
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001146 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001147
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001148 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1149 Break constructor initializers before the colon and after the commas.
1150
1151 .. code-block:: c++
1152
Francois Ferrand767e1522018-06-14 13:32:14 +00001153 Constructor()
1154 : initializer1(),
1155 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001156
1157 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1158 Break constructor initializers before the colon and commas, and align
1159 the commas with the colon.
1160
1161 .. code-block:: c++
1162
Francois Ferrand767e1522018-06-14 13:32:14 +00001163 Constructor()
1164 : initializer1()
1165 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001166
1167 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1168 Break constructor initializers after the colon and commas.
1169
1170 .. code-block:: c++
1171
Francois Ferrand767e1522018-06-14 13:32:14 +00001172 Constructor() :
1173 initializer1(),
1174 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001175
1176
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001177
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001178**BreakInheritanceList** (``BreakInheritanceListStyle``)
1179 The inheritance list style to use.
1180
1181 Possible values:
1182
1183 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1184 Break inheritance list before the colon and after the commas.
1185
1186 .. code-block:: c++
1187
Francois Ferrand767e1522018-06-14 13:32:14 +00001188 class Foo
1189 : Base1,
1190 Base2
1191 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001192
1193 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1194 Break inheritance list before the colon and commas, and align
1195 the commas with the colon.
1196
1197 .. code-block:: c++
1198
Francois Ferrand767e1522018-06-14 13:32:14 +00001199 class Foo
1200 : Base1
1201 , Base2
1202 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001203
1204 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1205 Break inheritance list after the colon and commas.
1206
1207 .. code-block:: c++
1208
Francois Ferrand767e1522018-06-14 13:32:14 +00001209 class Foo :
1210 Base1,
1211 Base2
1212 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001213
1214
1215
Alexander Kornienko1e048232016-02-23 16:11:51 +00001216**BreakStringLiterals** (``bool``)
1217 Allow breaking string literals when formatting.
1218
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001219**ColumnLimit** (``unsigned``)
1220 The column limit.
1221
1222 A column limit of ``0`` means that there is no column limit. In this case,
1223 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001224 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001225
Daniel Jasperee107ad2014-02-13 12:51:50 +00001226**CommentPragmas** (``std::string``)
1227 A regular expression that describes comments with special meaning,
1228 which should not be split into lines or otherwise changed.
1229
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001230 .. code-block:: c++
1231
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001232 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001233 // Will leave the following line unaffected
1234 #include <vector> // FOOBAR pragma: keep
1235
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001236**CompactNamespaces** (``bool``)
1237 If ``true``, consecutive namespace declarations will be on the same
1238 line. If ``false``, each namespace is declared on a new line.
1239
1240 .. code-block:: c++
1241
1242 true:
1243 namespace Foo { namespace Bar {
1244 }}
1245
1246 false:
1247 namespace Foo {
1248 namespace Bar {
1249 }
1250 }
1251
1252 If it does not fit on a single line, the overflowing namespaces get
1253 wrapped:
1254
1255 .. code-block:: c++
1256
1257 namespace Foo { namespace Bar {
1258 namespace Extra {
1259 }}}
1260
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001261**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1262 If the constructor initializers don't fit on a line, put each
1263 initializer on its own line.
1264
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001265 .. code-block:: c++
1266
1267 true:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001268 SomeClass::Constructor()
1269 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1270 return 0;
1271 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001272
1273 false:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001274 SomeClass::Constructor()
1275 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1276 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1277 return 0;
1278 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001279
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001280**ConstructorInitializerIndentWidth** (``unsigned``)
1281 The number of characters to use for indentation of constructor
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001282 initializer lists as well as inheritance lists.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001283
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001284**ContinuationIndentWidth** (``unsigned``)
1285 Indent width for line continuations.
1286
Sylvestre Ledrude098242017-04-11 07:07:05 +00001287 .. code-block:: c++
1288
1289 ContinuationIndentWidth: 2
1290
1291 int i = // VeryVeryVeryVeryVeryLongComment
1292 longFunction( // Again a long comment
1293 arg);
1294
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001295**Cpp11BracedListStyle** (``bool``)
1296 If ``true``, format braced lists as best suited for C++11 braced
1297 lists.
1298
1299 Important differences:
1300 - No spaces inside the braced list.
1301 - No line break before the closing brace.
1302 - Indentation with the continuation indent, not with the block indent.
1303
1304 Fundamentally, C++11 braced lists are formatted exactly like function
1305 calls would be formatted in their place. If the braced list follows a name
1306 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1307 the parentheses of a function call with that name. If there is no name,
1308 a zero-length name is assumed.
1309
Sylvestre Ledrude098242017-04-11 07:07:05 +00001310 .. code-block:: c++
1311
1312 true: false:
1313 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1314 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1315 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1316 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1317
Daniel Jasper553d4872014-06-17 12:40:34 +00001318**DerivePointerAlignment** (``bool``)
1319 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001320 alignment of ``&`` and ``*``.
1321 Pointer and reference alignment styles are going to be updated according
1322 to the preferences found in the file.
1323 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001324
1325**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001326 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001327
1328**ExperimentalAutoDetectBinPacking** (``bool``)
1329 If ``true``, clang-format detects whether function calls and
1330 definitions are formatted with one parameter per line.
1331
1332 Each call can be bin-packed, one-per-line or inconclusive. If it is
1333 inconclusive, e.g. completely on one line, but a decision needs to be
1334 made, clang-format analyzes whether there are other bin-packed cases in
1335 the input file and act accordingly.
1336
1337 NOTE: This is an experimental flag, that might go away or be renamed. Do
1338 not use this in config files, etc. Use at your own risk.
1339
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001340**FixNamespaceComments** (``bool``)
1341 If ``true``, clang-format adds missing namespace end comments and
1342 fixes invalid existing ones.
1343
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001344 .. code-block:: c++
1345
1346 true: false:
1347 namespace a { vs. namespace a {
1348 foo(); foo();
Owen Pand7f287f2019-04-26 07:05:47 +00001349 } // namespace a }
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001350
Daniel Jaspere1e43192014-04-01 12:55:11 +00001351**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001352 A vector of macros that should be interpreted as foreach loops
1353 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001354
Daniel Jasperb5524822014-04-09 14:05:49 +00001355 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001356
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001357 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001358
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001359 FOREACH(<variable-declaration>, ...)
1360 <loop-body>
1361
1362 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001363
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001364 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001365
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001366 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001367
1368 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001369
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001370**IncludeBlocks** (``IncludeBlocksStyle``)
1371 Dependent on the value, multiple ``#include`` blocks can be sorted
1372 as one and divided based on category.
1373
1374 Possible values:
1375
1376 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1377 Sort each ``#include`` block separately.
1378
1379 .. code-block:: c++
1380
1381 #include "b.h" into #include "b.h"
1382
1383 #include <lib/main.h> #include "a.h"
1384 #include "a.h" #include <lib/main.h>
1385
1386 * ``IBS_Merge`` (in configuration: ``Merge``)
1387 Merge multiple ``#include`` blocks together and sort as one.
1388
1389 .. code-block:: c++
1390
1391 #include "b.h" into #include "a.h"
1392 #include "b.h"
1393 #include <lib/main.h> #include <lib/main.h>
1394 #include "a.h"
1395
1396 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1397 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001398 Then split into groups based on category priority. See
1399 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001400
1401 .. code-block:: c++
1402
1403 #include "b.h" into #include "a.h"
1404 #include "b.h"
1405 #include <lib/main.h>
1406 #include "a.h" #include <lib/main.h>
1407
1408
1409
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001410**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001411 Regular expressions denoting the different ``#include`` categories
1412 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001413
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001414 `POSIX extended
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +00001415 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001416 regular expressions are supported.
1417
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001418 These regular expressions are matched against the filename of an include
1419 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001420 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001421 according to increasing category number and then alphabetically within
1422 each category.
1423
Alexander Kornienko1e048232016-02-23 16:11:51 +00001424 If none of the regular expressions match, INT_MAX is assigned as
1425 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001426 so that it is generally kept at the beginning of the ``#includes``
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +00001427 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
Alexander Kornienko1e048232016-02-23 16:11:51 +00001428 can also assign negative priorities if you have certain headers that
1429 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001430
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001431 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001432
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001433 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001434
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001435 IncludeCategories:
1436 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1437 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001438 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001439 Priority: 3
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001440 - Regex: '<[[:alnum:].]+>'
1441 Priority: 4
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001442 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001443 Priority: 1
1444
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001445**IncludeIsMainRegex** (``std::string``)
1446 Specify a regular expression of suffixes that are allowed in the
1447 file-to-main-include mapping.
1448
1449 When guessing whether a #include is the "main" include (to assign
1450 category 0, see above), use this regex of allowed suffixes to the header
1451 stem. A partial match is done, so that:
1452 - "" means "arbitrary suffix"
1453 - "$" means "no suffix"
1454
1455 For example, if configured to "(_test)?$", then a header a.h would be seen
1456 as the "main" include in both a.cc and a_test.cc.
1457
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001458**IndentCaseLabels** (``bool``)
1459 Indent case labels one level from the switch statement.
1460
1461 When ``false``, use the same indentation level as for the switch statement.
1462 Switch statement body is always indented one level more than case labels.
1463
Sylvestre Ledrude098242017-04-11 07:07:05 +00001464 .. code-block:: c++
1465
1466 false: true:
1467 switch (fool) { vs. switch (fool) {
1468 case 1: case 1:
1469 bar(); bar();
1470 break; break;
1471 default: default:
1472 plop(); plop();
1473 } }
1474
Krasimir Georgievad47c902017-08-30 14:34:57 +00001475**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001476 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001477
1478 Possible values:
1479
1480 * ``PPDIS_None`` (in configuration: ``None``)
1481 Does not indent any directives.
1482
1483 .. code-block:: c++
1484
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001485 #if FOO
1486 #if BAR
1487 #include <foo>
1488 #endif
1489 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001490
1491 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1492 Indents directives after the hash.
1493
1494 .. code-block:: c++
1495
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001496 #if FOO
1497 # if BAR
1498 # include <foo>
1499 # endif
1500 #endif
1501
Paul Hoad701a0d72019-03-20 20:49:43 +00001502 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1503 Indents directives before the hash.
1504
1505 .. code-block:: c++
1506
1507 #if FOO
1508 #if BAR
1509 #include <foo>
1510 #endif
1511 #endif
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001512
Krasimir Georgievad47c902017-08-30 14:34:57 +00001513
Owen Pan806d5742019-04-08 23:36:25 +00001514
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001515**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001516 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001517
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001518 .. code-block:: c++
1519
1520 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001521
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001522 void f() {
1523 someFunction();
1524 if (true, false) {
1525 f();
1526 }
1527 }
1528
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001529**IndentWrappedFunctionNames** (``bool``)
1530 Indent if a function definition or declaration is wrapped after the
1531 type.
1532
Sylvestre Ledrude098242017-04-11 07:07:05 +00001533 .. code-block:: c++
1534
1535 true:
1536 LoooooooooooooooooooooooooooooooooooooooongReturnType
1537 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1538
1539 false:
1540 LoooooooooooooooooooooooooooooooooooooooongReturnType
1541 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1542
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001543**JavaImportGroups** (``std::vector<std::string>``)
1544 A vector of prefixes ordered by the desired groups for Java imports.
1545
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001546 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001547 same grouping convention above all non-static imports. One group's prefix
1548 can be a subset of another - the longest prefix is always matched. Within
1549 a group, the imports are ordered lexicographically.
1550
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001551 In the .clang-format configuration file, this can be configured like
1552 in the following yaml example. This will result in imports being
1553 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001554
1555 .. code-block:: yaml
1556
1557 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001558
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001559
1560 .. code-block:: java
1561
1562 import static com.example.function1;
1563
1564 import static com.test.function2;
1565
1566 import static org.example.function3;
1567
1568 import com.example.ClassA;
1569 import com.example.Test;
1570 import com.example.a.ClassB;
1571
1572 import com.test.ClassC;
1573
1574 import org.example.ClassD;
1575
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001576**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1577 The JavaScriptQuoteStyle to use for JavaScript strings.
1578
1579 Possible values:
1580
1581 * ``JSQS_Leave`` (in configuration: ``Leave``)
1582 Leave string quotes as they are.
1583
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001584 .. code-block:: js
1585
1586 string1 = "foo";
1587 string2 = 'bar';
1588
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001589 * ``JSQS_Single`` (in configuration: ``Single``)
1590 Always use single quotes.
1591
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001592 .. code-block:: js
1593
1594 string1 = 'foo';
1595 string2 = 'bar';
1596
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001597 * ``JSQS_Double`` (in configuration: ``Double``)
1598 Always use double quotes.
1599
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001600 .. code-block:: js
1601
1602 string1 = "foo";
1603 string2 = "bar";
1604
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001605
1606
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001607**JavaScriptWrapImports** (``bool``)
1608 Whether to wrap JavaScript import/export statements.
1609
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001610 .. code-block:: js
1611
1612 true:
1613 import {
1614 VeryLongImportsAreAnnoying,
1615 VeryLongImportsAreAnnoying,
1616 VeryLongImportsAreAnnoying,
1617 } from 'some/module.js'
1618
1619 false:
1620 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1621
Daniel Jasperb5524822014-04-09 14:05:49 +00001622**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001623 If true, the empty line at the start of blocks is kept.
1624
1625 .. code-block:: c++
1626
1627 true: false:
1628 if (foo) { vs. if (foo) {
1629 bar();
1630 bar(); }
1631 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001632
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001633**Language** (``LanguageKind``)
1634 Language, this format style is targeted at.
1635
1636 Possible values:
1637
1638 * ``LK_None`` (in configuration: ``None``)
1639 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001640
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001641 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001642 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001643
Paul Hoadcbb726d2019-03-21 13:09:22 +00001644 * ``LK_CSharp`` (in configuration: ``CSharp``)
1645 Should be used for C#.
1646
Daniel Jasper18210d72014-10-09 09:52:05 +00001647 * ``LK_Java`` (in configuration: ``Java``)
1648 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001649
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001650 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1651 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001652
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001653 * ``LK_ObjC`` (in configuration: ``ObjC``)
1654 Should be used for Objective-C, Objective-C++.
1655
Daniel Jasperee107ad2014-02-13 12:51:50 +00001656 * ``LK_Proto`` (in configuration: ``Proto``)
1657 Should be used for Protocol Buffers
1658 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001659
Alexander Kornienko1e048232016-02-23 16:11:51 +00001660 * ``LK_TableGen`` (in configuration: ``TableGen``)
1661 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001662
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001663 * ``LK_TextProto`` (in configuration: ``TextProto``)
1664 Should be used for Protocol Buffer messages in text format
1665 (https://developers.google.com/protocol-buffers/).
1666
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001667
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001668
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001669**MacroBlockBegin** (``std::string``)
1670 A regular expression matching macros that start a block.
1671
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001672 .. code-block:: c++
1673
1674 # With:
1675 MacroBlockBegin: "^NS_MAP_BEGIN|\
1676 NS_TABLE_HEAD$"
1677 MacroBlockEnd: "^\
1678 NS_MAP_END|\
1679 NS_TABLE_.*_END$"
1680
1681 NS_MAP_BEGIN
1682 foo();
1683 NS_MAP_END
1684
1685 NS_TABLE_HEAD
1686 bar();
1687 NS_TABLE_FOO_END
1688
1689 # Without:
1690 NS_MAP_BEGIN
1691 foo();
1692 NS_MAP_END
1693
1694 NS_TABLE_HEAD
1695 bar();
1696 NS_TABLE_FOO_END
1697
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001698**MacroBlockEnd** (``std::string``)
1699 A regular expression matching macros that end a block.
1700
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001701**MaxEmptyLinesToKeep** (``unsigned``)
1702 The maximum number of consecutive empty lines to keep.
1703
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001704 .. code-block:: c++
1705
1706 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1707 int f() { int f() {
1708 int = 1; int i = 1;
1709 i = foo();
1710 i = foo(); return i;
1711 }
1712 return i;
1713 }
1714
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001715**NamespaceIndentation** (``NamespaceIndentationKind``)
1716 The indentation used for namespaces.
1717
1718 Possible values:
1719
1720 * ``NI_None`` (in configuration: ``None``)
1721 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001722
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001723 .. code-block:: c++
1724
1725 namespace out {
1726 int i;
1727 namespace in {
1728 int i;
1729 }
1730 }
1731
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001732 * ``NI_Inner`` (in configuration: ``Inner``)
1733 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001734
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001735 .. code-block:: c++
1736
1737 namespace out {
1738 int i;
1739 namespace in {
1740 int i;
1741 }
1742 }
1743
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001744 * ``NI_All`` (in configuration: ``All``)
1745 Indent in all namespaces.
1746
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001747 .. code-block:: c++
1748
1749 namespace out {
1750 int i;
1751 namespace in {
1752 int i;
1753 }
1754 }
1755
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001756
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001757
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001758**ObjCBinPackProtocolList** (``BinPackStyle``)
1759 Controls bin-packing Objective-C protocol conformance list
1760 items into as few lines as possible when they go over ``ColumnLimit``.
1761
1762 If ``Auto`` (the default), delegates to the value in
1763 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1764 protocol conformance list items into as few lines as possible
1765 whenever they go over ``ColumnLimit``.
1766
1767 If ``Always``, always bin-packs Objective-C protocol conformance
1768 list items into as few lines as possible whenever they go over
1769 ``ColumnLimit``.
1770
1771 If ``Never``, lays out Objective-C protocol conformance list items
1772 onto individual lines whenever they go over ``ColumnLimit``.
1773
1774
Aaron Ballman37485fd2018-06-28 12:02:38 +00001775 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001776
1777 Always (or Auto, if BinPackParameters=true):
1778 @interface ccccccccccccc () <
1779 ccccccccccccc, ccccccccccccc,
1780 ccccccccccccc, ccccccccccccc> {
1781 }
1782
1783 Never (or Auto, if BinPackParameters=false):
1784 @interface ddddddddddddd () <
1785 ddddddddddddd,
1786 ddddddddddddd,
1787 ddddddddddddd,
1788 ddddddddddddd> {
1789 }
1790
1791 Possible values:
1792
1793 * ``BPS_Auto`` (in configuration: ``Auto``)
1794 Automatically determine parameter bin-packing behavior.
1795
1796 * ``BPS_Always`` (in configuration: ``Always``)
1797 Always bin-pack parameters.
1798
1799 * ``BPS_Never`` (in configuration: ``Never``)
1800 Never bin-pack parameters.
1801
1802
1803
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001804**ObjCBlockIndentWidth** (``unsigned``)
1805 The number of characters to use for indentation of ObjC blocks.
1806
Sylvestre Ledrude098242017-04-11 07:07:05 +00001807 .. code-block:: objc
1808
1809 ObjCBlockIndentWidth: 4
1810
1811 [operation setCompletionBlock:^{
1812 [self onOperationDone];
1813 }];
1814
Daniel Jasperee107ad2014-02-13 12:51:50 +00001815**ObjCSpaceAfterProperty** (``bool``)
1816 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001817 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001818
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001819**ObjCSpaceBeforeProtocolList** (``bool``)
1820 Add a space in front of an Objective-C protocol list, i.e. use
1821 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1822
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001823**PenaltyBreakAssignment** (``unsigned``)
1824 The penalty for breaking around an assignment operator.
1825
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001826**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001827 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001828
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001829**PenaltyBreakComment** (``unsigned``)
1830 The penalty for each line break introduced inside a comment.
1831
1832**PenaltyBreakFirstLessLess** (``unsigned``)
1833 The penalty for breaking before the first ``<<``.
1834
1835**PenaltyBreakString** (``unsigned``)
1836 The penalty for each line break introduced inside a string literal.
1837
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001838**PenaltyBreakTemplateDeclaration** (``unsigned``)
1839 The penalty for breaking after template declaration.
1840
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001841**PenaltyExcessCharacter** (``unsigned``)
1842 The penalty for each character outside of the column limit.
1843
1844**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1845 Penalty for putting the return type of a function onto its own
1846 line.
1847
Daniel Jasper553d4872014-06-17 12:40:34 +00001848**PointerAlignment** (``PointerAlignmentStyle``)
1849 Pointer and reference alignment style.
1850
1851 Possible values:
1852
1853 * ``PAS_Left`` (in configuration: ``Left``)
1854 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001855
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001856 .. code-block:: c++
1857
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001858 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001859
Daniel Jasper553d4872014-06-17 12:40:34 +00001860 * ``PAS_Right`` (in configuration: ``Right``)
1861 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001862
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001863 .. code-block:: c++
1864
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001865 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001866
Daniel Jasper553d4872014-06-17 12:40:34 +00001867 * ``PAS_Middle`` (in configuration: ``Middle``)
1868 Align pointer in the middle.
1869
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001870 .. code-block:: c++
1871
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001872 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001873
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001874
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001875
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001876**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001877 Defines hints for detecting supported languages code blocks in raw
1878 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001879
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001880 A raw string with a matching delimiter or a matching enclosing function
1881 name will be reformatted assuming the specified language based on the
1882 style for that language defined in the .clang-format file. If no style has
1883 been defined in the .clang-format file for the specific language, a
1884 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1885 found, the formatting is based on llvm style. A matching delimiter takes
1886 precedence over a matching enclosing function name for determining the
1887 language of the raw string contents.
1888
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001889 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001890 the same language will be updated to the canonical if possible.
1891
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001892 There should be at most one specification per language and each delimiter
1893 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001894
1895 To configure this in the .clang-format file, use:
1896
1897 .. code-block:: yaml
1898
1899 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001900 - Language: TextProto
1901 Delimiters:
1902 - 'pb'
1903 - 'proto'
1904 EnclosingFunctions:
1905 - 'PARSE_TEXT_PROTO'
1906 BasedOnStyle: google
1907 - Language: Cpp
1908 Delimiters:
1909 - 'cc'
1910 - 'cpp'
1911 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001912 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001913
Alexander Kornienko1e048232016-02-23 16:11:51 +00001914**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001915 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001916
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001917 .. code-block:: c++
1918
1919 false:
1920 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1921 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1922
1923 true:
1924 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1925 // information
1926 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1927 * information */
1928
Alexander Kornienko1e048232016-02-23 16:11:51 +00001929**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001930 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001931
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001932 .. code-block:: c++
1933
1934 false: true:
1935 #include "b.h" vs. #include "a.h"
1936 #include "a.h" #include "b.h"
1937
Krasimir Georgievac16a202017-06-23 11:46:03 +00001938**SortUsingDeclarations** (``bool``)
1939 If ``true``, clang-format will sort using declarations.
1940
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001941 The order of using declarations is defined as follows:
1942 Split the strings by "::" and discard any initial empty strings. The last
1943 element of each list is a non-namespace name; all others are namespace
1944 names. Sort the lists of names lexicographically, where the sort order of
1945 individual names is that all non-namespace names come before all namespace
1946 names, and within those groups, names are in case-insensitive
1947 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001948
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001949 .. code-block:: c++
1950
1951 false: true:
1952 using std::cout; vs. using std::cin;
1953 using std::cin; using std::cout;
1954
Daniel Jasperb87899b2014-09-10 13:11:45 +00001955**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001956 If ``true``, a space is inserted after C style casts.
1957
1958 .. code-block:: c++
1959
1960 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001961 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001962
Reuben Thomas91f60b42019-04-08 12:54:48 +00001963**SpaceAfterLogicalNot** (``bool``)
1964 If ``true``, a space is inserted after the logical not operator (``!``).
Owen Pan806d5742019-04-08 23:36:25 +00001965
Reuben Thomas91f60b42019-04-08 12:54:48 +00001966 .. code-block:: c++
1967
1968 true: false:
1969 ! someExpression(); vs. !someExpression();
1970
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001971**SpaceAfterTemplateKeyword** (``bool``)
1972 If ``true``, a space will be inserted after the 'template' keyword.
1973
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001974 .. code-block:: c++
1975
1976 true: false:
1977 template <int> void foo(); vs. template<int> void foo();
1978
Daniel Jasperd94bff32013-09-25 15:15:02 +00001979**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001980 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001981
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001982 .. code-block:: c++
1983
1984 true: false:
1985 int a = 5; vs. int a=5;
1986 a += 42 a+=42;
1987
Hans Wennborgbfc34062018-06-14 08:01:09 +00001988**SpaceBeforeCpp11BracedList** (``bool``)
1989 If ``true``, a space will be inserted before a C++11 braced list
1990 used to initialize an object (after the preceding identifier or type).
1991
1992 .. code-block:: c++
1993
1994 true: false:
1995 Foo foo { bar }; vs. Foo foo{ bar };
1996 Foo {}; Foo{};
1997 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1998 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1999
Francois Ferrand2a9ea782018-03-01 10:09:13 +00002000**SpaceBeforeCtorInitializerColon** (``bool``)
2001 If ``false``, spaces will be removed before constructor initializer
2002 colon.
2003
2004 .. code-block:: c++
2005
2006 true: false:
2007 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
2008
2009**SpaceBeforeInheritanceColon** (``bool``)
2010 If ``false``, spaces will be removed before inheritance colon.
2011
2012 .. code-block:: c++
2013
2014 true: false:
2015 class Foo : Bar {} vs. class Foo: Bar {}
2016
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002017**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
2018 Defines in which cases to put a space before opening parentheses.
2019
2020 Possible values:
2021
2022 * ``SBPO_Never`` (in configuration: ``Never``)
2023 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002024
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002025 .. code-block:: c++
2026
2027 void f() {
2028 if(true) {
2029 f();
2030 }
2031 }
2032
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002033 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
2034 Put a space before opening parentheses only after control statement
2035 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002036
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002037 .. code-block:: c++
2038
2039 void f() {
2040 if (true) {
2041 f();
2042 }
2043 }
2044
Owen Pan806d5742019-04-08 23:36:25 +00002045 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
2046 Put a space before opening parentheses only if the parentheses are not
2047 empty i.e. '()'
2048
2049 .. code-block:: c++
2050
2051 void() {
2052 if (true) {
2053 f();
2054 g (x, y, z);
2055 }
2056 }
2057
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002058 * ``SBPO_Always`` (in configuration: ``Always``)
2059 Always put a space before opening parentheses, except when it's
2060 prohibited by the syntax rules (in function-like macro definitions) or
2061 when determined by other style rules (after unary operators, opening
2062 parentheses, etc.)
2063
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002064 .. code-block:: c++
2065
2066 void f () {
2067 if (true) {
2068 f ();
2069 }
2070 }
2071
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002072
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002073
Francois Ferrand2a9ea782018-03-01 10:09:13 +00002074**SpaceBeforeRangeBasedForLoopColon** (``bool``)
2075 If ``false``, spaces will be removed before range-based for loop
2076 colon.
2077
2078 .. code-block:: c++
2079
2080 true: false:
2081 for (auto v : values) {} vs. for(auto v: values) {}
2082
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002083**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002084 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002085
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002086 .. code-block:: c++
2087
2088 true: false:
2089 void f( ) { vs. void f() {
2090 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
2091 if (true) { if (true) {
2092 f( ); f();
2093 } }
2094 } }
2095
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002096**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00002097 The number of spaces before trailing line comments
2098 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00002099
Alexander Kornienko70f97c92016-02-27 14:02:08 +00002100 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002101 those commonly have different usage patterns and a number of special
2102 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002103
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002104 .. code-block:: c++
2105
2106 SpacesBeforeTrailingComments: 3
2107 void f() {
2108 if (true) { // foo1
2109 f(); // bar
2110 } // foo
2111 }
2112
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002113**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002114 If ``true``, spaces will be inserted after ``<`` and before ``>``
2115 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002116
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002117 .. code-block:: c++
2118
2119 true: false:
2120 static_cast< int >(arg); vs. static_cast<int>(arg);
2121 std::function< void(int) > fct; std::function<void(int)> fct;
2122
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002123**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002124 If ``true``, spaces may be inserted into C style casts.
2125
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002126 .. code-block:: c++
2127
2128 true: false:
2129 x = ( int32 )y vs. x = (int32)y
2130
Daniel Jasperee107ad2014-02-13 12:51:50 +00002131**SpacesInContainerLiterals** (``bool``)
2132 If ``true``, spaces are inserted inside container literals (e.g.
2133 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002134
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002135 .. code-block:: js
2136
2137 true: false:
2138 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2139 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2140
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002141**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002142 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002143
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002144 .. code-block:: c++
2145
2146 true: false:
2147 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2148
Daniel Jasperad981f82014-08-26 11:41:14 +00002149**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002150 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002151 Lambdas or unspecified size array declarations will not be affected.
2152
2153 .. code-block:: c++
2154
2155 true: false:
2156 int a[ 5 ]; vs. int a[5];
2157 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002158
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002159**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002160 Format compatible with this standard, e.g. use ``A<A<int> >``
2161 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002162
2163 Possible values:
2164
2165 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2166 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002167
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002168 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002169 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002170 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002171
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002172 * ``LS_Auto`` (in configuration: ``Auto``)
2173 Automatic detection based on the input.
2174
2175
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002176
Francois Ferrand6f40e212018-10-02 16:37:51 +00002177**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002178 A vector of macros that should be interpreted as complete
2179 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002180
2181 Typical macros are expressions, and require a semi-colon to be
2182 added; sometimes this is not the case, and this allows to make
2183 clang-format aware of such cases.
2184
2185 For example: Q_UNUSED
2186
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002187**TabWidth** (``unsigned``)
2188 The number of columns used for tab stops.
2189
2190**UseTab** (``UseTabStyle``)
2191 The way to use tab characters in the resulting file.
2192
2193 Possible values:
2194
2195 * ``UT_Never`` (in configuration: ``Never``)
2196 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002197
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002198 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2199 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002200
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002201 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2202 Use tabs only for line continuation and indentation.
2203
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002204 * ``UT_Always`` (in configuration: ``Always``)
2205 Use tabs whenever we need to fill whitespace that spans at least from
2206 one tab stop to the next one.
2207
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002208
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002209
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002210.. END_FORMAT_STYLE_OPTIONS
2211
Daniel Jasper49d3d582015-10-05 07:24:55 +00002212Adding additional style options
2213===============================
2214
2215Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002216these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002217sure that any given combination of options work and that new features don't
2218break any of the existing options in any way. There are also costs for end users
2219as options become less discoverable and people have to think about and make a
2220decision on options they don't really care about.
2221
2222The goal of the clang-format project is more on the side of supporting a
2223limited set of styles really well as opposed to supporting every single style
2224used by a codebase somewhere in the wild. Of course, we do want to support all
2225major projects and thus have established the following bar for adding style
2226options. Each new style option must ..
2227
Daniel Jasperfcbea712015-10-05 13:30:42 +00002228 * be used in a project of significant size (have dozens of contributors)
2229 * have a publicly accessible style guide
2230 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002231
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002232Examples
2233========
2234
2235A style similar to the `Linux Kernel style
2236<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2237
2238.. code-block:: yaml
2239
2240 BasedOnStyle: LLVM
2241 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002242 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002243 BreakBeforeBraces: Linux
2244 AllowShortIfStatementsOnASingleLine: false
2245 IndentCaseLabels: false
2246
2247The result is (imagine that tabs are used for indentation here):
2248
2249.. code-block:: c++
2250
2251 void test()
2252 {
2253 switch (x) {
2254 case 0:
2255 case 1:
2256 do_something();
2257 break;
2258 case 2:
2259 do_something_else();
2260 break;
2261 default:
2262 break;
2263 }
2264 if (condition)
2265 do_something_completely_different();
2266
2267 if (x == y) {
2268 q();
2269 } else if (x > y) {
2270 w();
2271 } else {
2272 r();
2273 }
2274 }
2275
2276A style similar to the default Visual Studio formatting style:
2277
2278.. code-block:: yaml
2279
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002280 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002281 IndentWidth: 4
2282 BreakBeforeBraces: Allman
2283 AllowShortIfStatementsOnASingleLine: false
2284 IndentCaseLabels: false
2285 ColumnLimit: 0
2286
2287The result is:
2288
2289.. code-block:: c++
2290
2291 void test()
2292 {
2293 switch (suffix)
2294 {
2295 case 0:
2296 case 1:
2297 do_something();
2298 break;
2299 case 2:
2300 do_something_else();
2301 break;
2302 default:
2303 break;
2304 }
2305 if (condition)
2306 do_somthing_completely_different();
2307
2308 if (x == y)
2309 {
2310 q();
2311 }
2312 else if (x > y)
2313 {
2314 w();
2315 }
2316 else
2317 {
2318 r();
2319 }
2320 }