blob: 7cd11c7aa75eac8e7e40b56fbe2da0f892f0d922 [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
10the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
11custom style by configuring specific style options.
12
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
71 ...
72
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000073An easy way to get a valid ``.clang-format`` file containing all configuration
74options of a certain predefined style is:
75
76.. code-block:: console
77
78 clang-format -style=llvm -dump-config > .clang-format
79
80When specifying configuration in the ``-style=`` option, the same configuration
81is applied for all input files. The format of the configuration is:
82
83.. code-block:: console
84
85 -style='{key1: value1, key2: value2, ...}'
86
87
Daniel Jasperd8b4ec02014-10-07 12:15:15 +000088Disabling Formatting on a Piece of Code
89=======================================
90
91Clang-format understands also special comments that switch formatting in a
92delimited range. The code between a comment ``// clang-format off`` or
93``/* clang-format off */`` up to a comment ``// clang-format on`` or
94``/* clang-format on */`` will not be formatted. The comments themselves
95will be formatted (aligned) normally.
96
97.. code-block:: c++
98
99 int formatted_code;
100 // clang-format off
101 void unformatted_code ;
102 // clang-format on
103 void formatted_code_again;
104
105
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000106Configuring Style in Code
107=========================
108
109When using ``clang::format::reformat(...)`` functions, the format is specified
110by supplying the `clang::format::FormatStyle
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000111<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000112structure.
113
114
115Configurable Format Style Options
116=================================
117
118This section lists the supported style options. Value type is specified for
119each option. For enumeration types possible values are specified both as a C++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000120enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
121the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000122
123
124**BasedOnStyle** (``string``)
125 The style used for all options not specifically set in the configuration.
126
127 This option is supported only in the :program:`clang-format` configuration
128 (both within ``-style='{...}'`` and the ``.clang-format`` file).
129
130 Possible values:
131
132 * ``LLVM``
133 A style complying with the `LLVM coding standards
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000134 <https://llvm.org/docs/CodingStandards.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000135 * ``Google``
136 A style complying with `Google's C++ style guide
137 <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
138 * ``Chromium``
139 A style complying with `Chromium's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000140 <https://www.chromium.org/developers/coding-style>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000141 * ``Mozilla``
142 A style complying with `Mozilla's style guide
143 <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
144 * ``WebKit``
145 A style complying with `WebKit's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000146 <https://www.webkit.org/coding/coding-style.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000147
148.. START_FORMAT_STYLE_OPTIONS
149
150**AccessModifierOffset** (``int``)
Alexander Kornienkoe99a3a32016-02-23 16:12:08 +0000151 The extra indent or outdent of access modifiers, e.g. ``public:``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000152
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000153**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
Daniel Jasper3219e432014-12-02 13:24:51 +0000154 If ``true``, horizontally aligns arguments after an open bracket.
155
156 This applies to round brackets (parentheses), angle brackets and square
Alexander Kornienko1e048232016-02-23 16:11:51 +0000157 brackets.
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000158
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000159 Possible values:
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000160
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000161 * ``BAS_Align`` (in configuration: ``Align``)
162 Align parameters on the open bracket, e.g.:
163
164 .. code-block:: c++
165
166 someLongFunction(argument1,
167 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000168
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000169 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
170 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
171
172 .. code-block:: c++
173
174 someLongFunction(argument1,
175 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000176
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000177 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
178 Always break after an open bracket, if the parameters don't fit
179 on a single line, e.g.:
180
181 .. code-block:: c++
182
183 someLongFunction(
184 argument1, argument2);
185
Daniel Jasper3219e432014-12-02 13:24:51 +0000186
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000187
Daniel Jaspera44991332015-04-29 13:06:49 +0000188**AlignConsecutiveAssignments** (``bool``)
189 If ``true``, aligns consecutive assignments.
190
191 This will align the assignment operators of consecutive lines. This
192 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000193
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000194 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000195
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000196 int aaaa = 12;
197 int b = 23;
198 int ccc = 23;
199
200**AlignConsecutiveDeclarations** (``bool``)
201 If ``true``, aligns consecutive declarations.
202
203 This will align the declaration names of consecutive lines. This
204 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000205
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000206 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000207
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000208 int aaaa = 12;
209 float b = 23;
210 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000211
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000212**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
213 Options for aligning backslashes in escaped newlines.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000214
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000215 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000216
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000217 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
218 Don't align escaped newlines.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000219
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000220 .. code-block:: c++
221
222 #define A \
223 int aaaa; \
224 int b; \
225 int dddddddddd;
226
227 * ``ENAS_Left`` (in configuration: ``Left``)
228 Align escaped newlines as far left as possible.
229
230 .. code-block:: c++
231
232 true:
233 #define A \
234 int aaaa; \
235 int b; \
236 int dddddddddd;
237
238 false:
239
240 * ``ENAS_Right`` (in configuration: ``Right``)
241 Align escaped newlines in the right-most column.
242
243 .. code-block:: c++
244
245 #define A \
246 int aaaa; \
247 int b; \
248 int dddddddddd;
249
250
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000251
Daniel Jasper3219e432014-12-02 13:24:51 +0000252**AlignOperands** (``bool``)
253 If ``true``, horizontally align operands of binary and ternary
254 expressions.
255
Alexander Kornienko1e048232016-02-23 16:11:51 +0000256 Specifically, this aligns operands of a single expression that needs to be
257 split over multiple lines, e.g.:
258
259 .. code-block:: c++
260
261 int aaa = bbbbbbbbbbbbbbb +
262 ccccccccccccccc;
263
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000264**AlignTrailingComments** (``bool``)
265 If ``true``, aligns trailing comments.
266
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000267 .. code-block:: c++
268
Krasimir Georgiev818da9b2017-11-09 15:41:23 +0000269 true: false:
270 int a; // My comment a vs. int a; // My comment a
271 int b = 2; // comment b int b = 2; // comment about b
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000272
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000273**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000274 If the function declaration doesn't fit on a line,
275 allow putting all parameters of a function declaration onto
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000276 the next line even if ``BinPackParameters`` is ``false``.
277
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000278 .. code-block:: c++
279
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000280 true:
281 void myFunction(
282 int a, int b, int c, int d, int e);
283
284 false:
285 void myFunction(int a,
286 int b,
287 int c,
288 int d,
289 int e);
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000290
Daniel Jasper17605d32014-05-14 09:33:35 +0000291**AllowShortBlocksOnASingleLine** (``bool``)
292 Allows contracting simple braced statements to a single line.
293
294 E.g., this allows ``if (a) { return; }`` to be put on a single line.
295
Daniel Jasperb87899b2014-09-10 13:11:45 +0000296**AllowShortCaseLabelsOnASingleLine** (``bool``)
297 If ``true``, short case labels will be contracted to a single line.
298
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000299 .. code-block:: c++
300
301 true: false:
302 switch (a) { vs. switch (a) {
303 case 1: x = 1; break; case 1:
304 case 2: return; x = 1;
305 } break;
306 case 2:
307 return;
308 }
309
Daniel Jasperb5524822014-04-09 14:05:49 +0000310**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000311 Dependent on the value, ``int f() { return 0; }`` can be put on a
312 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000313
314 Possible values:
315
316 * ``SFS_None`` (in configuration: ``None``)
317 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000318
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000319 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
320 Only merge functions defined inside a class. Same as "inline",
321 except it does not implies "empty": i.e. top level empty functions
322 are not merged either.
323
324 .. code-block:: c++
325
326 class Foo {
327 void f() { foo(); }
328 };
329 void f() {
330 foo();
331 }
332 void f() {
333 }
334
Daniel Jasper3219e432014-12-02 13:24:51 +0000335 * ``SFS_Empty`` (in configuration: ``Empty``)
336 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000337
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000338 .. code-block:: c++
339
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000340 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000341 void f2() {
342 bar2();
343 }
344
Daniel Jasper20580fd2015-06-11 13:31:45 +0000345 * ``SFS_Inline`` (in configuration: ``Inline``)
346 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000347
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000348 .. code-block:: c++
349
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000350 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000351 void f() { foo(); }
352 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000353 void f() {
354 foo();
355 }
356 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000357
Daniel Jasperb5524822014-04-09 14:05:49 +0000358 * ``SFS_All`` (in configuration: ``All``)
359 Merge all functions fitting on a single line.
360
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000361 .. code-block:: c++
362
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000363 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000364 void f() { foo(); }
365 };
366 void f() { bar(); }
367
Paul Hoad15000a12019-03-13 08:26:39 +0000368**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
369 Dependent on the value, ``if (a) return 0;`` can be put on a
370 single line.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000371
Paul Hoad15000a12019-03-13 08:26:39 +0000372 Possible values:
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000373
Paul Hoad15000a12019-03-13 08:26:39 +0000374 * ``SIS_Never`` (in configuration: ``Never``)
375 Do not allow short if functions.
376
377 .. code-block:: c++
378
379 if (a)
380 return;
381 else
382 return;
383
384 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
385 Allow short if functions on the same line, as long as else
386 is not a compound statement.
387
388 .. code-block:: c++
389
390 if (a) return;
391 else
392 return;
393
394 if (a)
395 return;
396 else {
397 return;
398 }
399
400 * ``SIS_Always`` (in configuration: ``Always``)
401 Allow short if statements even if the else is a compound statement.
402
403 .. code-block:: c++
404
405 if (a) return;
406 else {
407 return;
408 }
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000409
410**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000411 If ``true``, ``while (true) continue;`` can be put on a single
412 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000413
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000414**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000415 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000416 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000417
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000418 Possible values:
419
420 * ``DRTBS_None`` (in configuration: ``None``)
421 Break after return type automatically.
422 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000423
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000424 * ``DRTBS_All`` (in configuration: ``All``)
425 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000426
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000427 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000428 Always break after the return types of top-level functions.
429
430
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000431
Zachary Turner448592e2015-12-18 22:20:15 +0000432**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
433 The function declaration return type breaking style to use.
434
435 Possible values:
436
437 * ``RTBS_None`` (in configuration: ``None``)
438 Break after return type automatically.
439 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000440
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000441 .. code-block:: c++
442
443 class A {
444 int f() { return 0; };
445 };
446 int f();
447 int f() { return 1; }
448
Zachary Turner448592e2015-12-18 22:20:15 +0000449 * ``RTBS_All`` (in configuration: ``All``)
450 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000451
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000452 .. code-block:: c++
453
454 class A {
455 int
456 f() {
457 return 0;
458 };
459 };
460 int
461 f();
462 int
463 f() {
464 return 1;
465 }
466
Zachary Turner448592e2015-12-18 22:20:15 +0000467 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
468 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000469
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000470 .. code-block:: c++
471
472 class A {
473 int f() { return 0; };
474 };
475 int
476 f();
477 int
478 f() {
479 return 1;
480 }
481
Zachary Turner448592e2015-12-18 22:20:15 +0000482 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
483 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000484
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000485 .. code-block:: c++
486
487 class A {
488 int
489 f() {
490 return 0;
491 };
492 };
493 int f();
494 int
495 f() {
496 return 1;
497 }
498
Zachary Turner448592e2015-12-18 22:20:15 +0000499 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
500 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000501
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000502 .. code-block:: c++
503
504 class A {
505 int f() { return 0; };
506 };
507 int f();
508 int
509 f() {
510 return 1;
511 }
512
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000513
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000514
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000515**AlwaysBreakBeforeMultilineStrings** (``bool``)
516 If ``true``, always break before multiline string literals.
517
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000518 This flag is mean to make cases where there are multiple multiline strings
519 in a file look more consistent. Thus, it will only take effect if wrapping
520 the string at that point leads to it being indented
521 ``ContinuationIndentWidth`` spaces from the start of the line.
522
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000523 .. code-block:: c++
524
525 true: false:
526 aaaa = vs. aaaa = "bbbb"
527 "bbbb" "cccc";
528 "cccc";
529
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000530**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
531 The template declaration breaking style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000532
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000533 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000534
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000535 * ``BTDS_No`` (in configuration: ``No``)
536 Do not force break before declaration.
537 ``PenaltyBreakTemplateDeclaration`` is taken into account.
538
539 .. code-block:: c++
540
541 template <typename T> T foo() {
542 }
543 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
544 int bbbbbbbbbbbbbbbbbbbbb) {
545 }
546
547 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
548 Force break after template declaration only when the following
549 declaration spans multiple lines.
550
551 .. code-block:: c++
552
553 template <typename T> T foo() {
554 }
555 template <typename T>
556 T foo(int aaaaaaaaaaaaaaaaaaaaa,
557 int bbbbbbbbbbbbbbbbbbbbb) {
558 }
559
560 * ``BTDS_Yes`` (in configuration: ``Yes``)
561 Always break after template declaration.
562
563 .. code-block:: c++
564
565 template <typename T>
566 T foo() {
567 }
568 template <typename T>
569 T foo(int aaaaaaaaaaaaaaaaaaaaa,
570 int bbbbbbbbbbbbbbbbbbbbb) {
571 }
572
573
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000574
Daniel Jasper18210d72014-10-09 09:52:05 +0000575**BinPackArguments** (``bool``)
576 If ``false``, a function call's arguments will either be all on the
577 same line or will have one line each.
578
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000579 .. code-block:: c++
580
581 true:
582 void f() {
583 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
584 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
585 }
586
587 false:
588 void f() {
589 f(aaaaaaaaaaaaaaaaaaaa,
590 aaaaaaaaaaaaaaaaaaaa,
591 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
592 }
593
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000594**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000595 If ``false``, a function declaration's or function definition's
596 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000597
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000598 .. code-block:: c++
599
600 true:
601 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
602 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
603
604 false:
605 void f(int aaaaaaaaaaaaaaaaaaaa,
606 int aaaaaaaaaaaaaaaaaaaa,
607 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
608
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000609**BraceWrapping** (``BraceWrappingFlags``)
610 Control of individual brace wrapping cases.
611
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000612 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
613 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000614
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000615 .. code-block:: yaml
616
617 # Example of usage:
618 BreakBeforeBraces: Custom
619 BraceWrapping:
620 AfterEnum: true
621 AfterStruct: false
622 SplitEmptyFunction: false
623
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000624 Nested configuration flags:
625
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000626
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000627 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000628
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000629 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000630
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000631 true:
632 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000633
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000634 false:
635 class foo
636 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000637
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000638 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000639
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000640 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000641
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000642 true:
643 if (foo())
644 {
645 } else
646 {}
647 for (int i = 0; i < 10; ++i)
648 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000649
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000650 false:
651 if (foo()) {
652 } else {
653 }
654 for (int i = 0; i < 10; ++i) {
655 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000656
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000657 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000658
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000659 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000660
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000661 true:
662 enum X : int
663 {
664 B
665 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000666
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000667 false:
668 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000669
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000670 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000671
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000672 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000673
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000674 true:
675 void foo()
676 {
677 bar();
678 bar2();
679 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000680
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000681 false:
682 void foo() {
683 bar();
684 bar2();
685 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000686
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000687 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000688
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000689 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000690
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000691 true:
692 namespace
693 {
694 int foo();
695 int bar();
696 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000697
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000698 false:
699 namespace {
700 int foo();
701 int bar();
702 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000703
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000704 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
705 @autoreleasepool and @synchronized blocks are wrapped
706 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000707
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000708 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000709
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000710 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000711
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000712 true:
713 struct foo
714 {
715 int x;
716 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000717
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000718 false:
719 struct foo {
720 int x;
721 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000722
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000723 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000724
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000725 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000726
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000727 true:
728 union foo
729 {
730 int x;
731 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000732
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000733 false:
734 union foo {
735 int x;
736 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000737
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000738 * ``bool AfterExternBlock`` Wrap extern blocks.
739
740 .. code-block:: c++
741
742 true:
743 extern "C"
744 {
745 int foo();
746 }
747
748 false:
749 extern "C" {
750 int foo();
751 }
752
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000753 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000754
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000755 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000756
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000757 true:
758 try {
759 foo();
760 }
761 catch () {
762 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000763
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000764 false:
765 try {
766 foo();
767 } catch () {
768 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000769
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000770 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000771
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000772 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000773
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000774 true:
775 if (foo()) {
776 }
777 else {
778 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000779
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000780 false:
781 if (foo()) {
782 } else {
783 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000784
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000785 * ``bool IndentBraces`` Indent the wrapped braces themselves.
786
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000787 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000788 This option is used only if the opening brace of the function has
789 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
790 set, and the function could/should not be put on a single line (as per
791 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000792
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000793 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000794
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000795 int f() vs. inf f()
796 {} {
797 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000798
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000799 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
800 can be put on a single line. This option is used only if the opening
801 brace of the record has already been wrapped, i.e. the `AfterClass`
802 (for classes) brace wrapping mode is set.
803
804 .. code-block:: c++
805
806 class Foo vs. class Foo
807 {} {
808 }
809
810 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
811 This option is used only if the opening brace of the namespace has
812 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
813 set.
814
815 .. code-block:: c++
816
817 namespace Foo vs. namespace Foo
818 {} {
819 }
820
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000821
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000822**BreakAfterJavaFieldAnnotations** (``bool``)
823 Break after each annotation on a field in Java files.
824
Sylvestre Ledrude098242017-04-11 07:07:05 +0000825 .. code-block:: java
826
827 true: false:
828 @Partial vs. @Partial @Mock DataLoad loader;
829 @Mock
830 DataLoad loader;
831
Daniel Jasperac043c92014-09-15 11:11:00 +0000832**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
833 The way to wrap binary operators.
834
835 Possible values:
836
837 * ``BOS_None`` (in configuration: ``None``)
838 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000839
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000840 .. code-block:: c++
841
842 LooooooooooongType loooooooooooooooooooooongVariable =
843 someLooooooooooooooooongFunction();
844
845 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
846 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
847 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
848 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
849 ccccccccccccccccccccccccccccccccccccccccc;
850
Daniel Jasperac043c92014-09-15 11:11:00 +0000851 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
852 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000853
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000854 .. code-block:: c++
855
856 LooooooooooongType loooooooooooooooooooooongVariable =
857 someLooooooooooooooooongFunction();
858
859 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
860 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
861 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
862 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
863 > ccccccccccccccccccccccccccccccccccccccccc;
864
Daniel Jasperac043c92014-09-15 11:11:00 +0000865 * ``BOS_All`` (in configuration: ``All``)
866 Break before operators.
867
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000868 .. code-block:: c++
869
870 LooooooooooongType loooooooooooooooooooooongVariable
871 = someLooooooooooooooooongFunction();
872
873 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
874 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
875 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
876 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
877 > ccccccccccccccccccccccccccccccccccccccccc;
878
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000879
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000880
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000881**BreakBeforeBraces** (``BraceBreakingStyle``)
882 The brace breaking style to use.
883
884 Possible values:
885
886 * ``BS_Attach`` (in configuration: ``Attach``)
887 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000888
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000889 .. code-block:: c++
890
891 try {
892 foo();
893 } catch () {
894 }
895 void foo() { bar(); }
896 class foo {};
897 if (foo()) {
898 } else {
899 }
900 enum X : int { A, B };
901
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000902 * ``BS_Linux`` (in configuration: ``Linux``)
903 Like ``Attach``, but break before braces on function, namespace and
904 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000905
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000906 .. code-block:: c++
907
908 try {
909 foo();
910 } catch () {
911 }
912 void foo() { bar(); }
913 class foo
914 {
915 };
916 if (foo()) {
917 } else {
918 }
919 enum X : int { A, B };
920
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000921 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
922 Like ``Attach``, but break before braces on enum, function, and record
923 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000924
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000925 .. code-block:: c++
926
927 try {
928 foo();
929 } catch () {
930 }
931 void foo() { bar(); }
932 class foo
933 {
934 };
935 if (foo()) {
936 } else {
937 }
938 enum X : int { A, B };
939
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000940 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000941 Like ``Attach``, but break before function definitions, ``catch``, and
942 ``else``.
943
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000944 .. code-block:: c++
945
946 try {
947 foo();
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000948 }
949 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000950 }
951 void foo() { bar(); }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000952 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000953 };
954 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000955 }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000956 else {
957 }
958 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000959
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000960 * ``BS_Allman`` (in configuration: ``Allman``)
961 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000962
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000963 .. code-block:: c++
964
Jan Korous3fd4a962019-03-05 01:45:31 +0000965 try
966 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000967 foo();
968 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000969 catch ()
970 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000971 }
972 void foo() { bar(); }
Jan Korous3fd4a962019-03-05 01:45:31 +0000973 class foo
974 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000975 };
Jan Korous3fd4a962019-03-05 01:45:31 +0000976 if (foo())
977 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000978 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000979 else
980 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000981 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000982 enum X : int
983 {
984 A,
985 B
986 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000987
Daniel Jasperee107ad2014-02-13 12:51:50 +0000988 * ``BS_GNU`` (in configuration: ``GNU``)
989 Always break before braces and add an extra level of indentation to
990 braces of control statements, not to those of class, function
991 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000992
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000993 .. code-block:: c++
994
995 try
996 {
997 foo();
998 }
999 catch ()
1000 {
1001 }
1002 void foo() { bar(); }
1003 class foo
1004 {
1005 };
1006 if (foo())
1007 {
1008 }
1009 else
1010 {
1011 }
1012 enum X : int
1013 {
1014 A,
1015 B
1016 };
1017
Roman Kashitsyn291f64f2015-08-10 13:43:19 +00001018 * ``BS_WebKit`` (in configuration: ``WebKit``)
1019 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001020
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001021 .. code-block:: c++
1022
1023 try {
1024 foo();
1025 } catch () {
1026 }
1027 void foo() { bar(); }
1028 class foo {
1029 };
1030 if (foo()) {
1031 } else {
1032 }
1033 enum X : int { A, B };
1034
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001035 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001036 Configure each individual brace in `BraceWrapping`.
1037
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001038
1039
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001040**BreakBeforeTernaryOperators** (``bool``)
1041 If ``true``, ternary operators will be placed after line breaks.
1042
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001043 .. code-block:: c++
1044
1045 true:
1046 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1047 ? firstValue
1048 : SecondValueVeryVeryVeryVeryLong;
1049
Sylvestre Ledru121224d2017-06-06 07:26:19 +00001050 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001051 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1052 firstValue :
1053 SecondValueVeryVeryVeryVeryLong;
1054
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001055**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1056 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001057
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001058 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001059
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001060 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1061 Break constructor initializers before the colon and after the commas.
1062
1063 .. code-block:: c++
1064
Francois Ferrand767e1522018-06-14 13:32:14 +00001065 Constructor()
1066 : initializer1(),
1067 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001068
1069 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1070 Break constructor initializers before the colon and commas, and align
1071 the commas with the colon.
1072
1073 .. code-block:: c++
1074
Francois Ferrand767e1522018-06-14 13:32:14 +00001075 Constructor()
1076 : initializer1()
1077 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001078
1079 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1080 Break constructor initializers after the colon and commas.
1081
1082 .. code-block:: c++
1083
Francois Ferrand767e1522018-06-14 13:32:14 +00001084 Constructor() :
1085 initializer1(),
1086 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001087
1088
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001089
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001090**BreakInheritanceList** (``BreakInheritanceListStyle``)
1091 The inheritance list style to use.
1092
1093 Possible values:
1094
1095 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1096 Break inheritance list before the colon and after the commas.
1097
1098 .. code-block:: c++
1099
Francois Ferrand767e1522018-06-14 13:32:14 +00001100 class Foo
1101 : Base1,
1102 Base2
1103 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001104
1105 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1106 Break inheritance list before the colon and commas, and align
1107 the commas with the colon.
1108
1109 .. code-block:: c++
1110
Francois Ferrand767e1522018-06-14 13:32:14 +00001111 class Foo
1112 : Base1
1113 , Base2
1114 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001115
1116 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1117 Break inheritance list after the colon and commas.
1118
1119 .. code-block:: c++
1120
Francois Ferrand767e1522018-06-14 13:32:14 +00001121 class Foo :
1122 Base1,
1123 Base2
1124 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001125
1126
1127
Alexander Kornienko1e048232016-02-23 16:11:51 +00001128**BreakStringLiterals** (``bool``)
1129 Allow breaking string literals when formatting.
1130
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001131**ColumnLimit** (``unsigned``)
1132 The column limit.
1133
1134 A column limit of ``0`` means that there is no column limit. In this case,
1135 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001136 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001137
Daniel Jasperee107ad2014-02-13 12:51:50 +00001138**CommentPragmas** (``std::string``)
1139 A regular expression that describes comments with special meaning,
1140 which should not be split into lines or otherwise changed.
1141
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001142 .. code-block:: c++
1143
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001144 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001145 // Will leave the following line unaffected
1146 #include <vector> // FOOBAR pragma: keep
1147
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001148**CompactNamespaces** (``bool``)
1149 If ``true``, consecutive namespace declarations will be on the same
1150 line. If ``false``, each namespace is declared on a new line.
1151
1152 .. code-block:: c++
1153
1154 true:
1155 namespace Foo { namespace Bar {
1156 }}
1157
1158 false:
1159 namespace Foo {
1160 namespace Bar {
1161 }
1162 }
1163
1164 If it does not fit on a single line, the overflowing namespaces get
1165 wrapped:
1166
1167 .. code-block:: c++
1168
1169 namespace Foo { namespace Bar {
1170 namespace Extra {
1171 }}}
1172
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001173**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1174 If the constructor initializers don't fit on a line, put each
1175 initializer on its own line.
1176
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001177 .. code-block:: c++
1178
1179 true:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001180 SomeClass::Constructor()
1181 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1182 return 0;
1183 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001184
1185 false:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001186 SomeClass::Constructor()
1187 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1188 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1189 return 0;
1190 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001191
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001192**ConstructorInitializerIndentWidth** (``unsigned``)
1193 The number of characters to use for indentation of constructor
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001194 initializer lists as well as inheritance lists.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001195
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001196**ContinuationIndentWidth** (``unsigned``)
1197 Indent width for line continuations.
1198
Sylvestre Ledrude098242017-04-11 07:07:05 +00001199 .. code-block:: c++
1200
1201 ContinuationIndentWidth: 2
1202
1203 int i = // VeryVeryVeryVeryVeryLongComment
1204 longFunction( // Again a long comment
1205 arg);
1206
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001207**Cpp11BracedListStyle** (``bool``)
1208 If ``true``, format braced lists as best suited for C++11 braced
1209 lists.
1210
1211 Important differences:
1212 - No spaces inside the braced list.
1213 - No line break before the closing brace.
1214 - Indentation with the continuation indent, not with the block indent.
1215
1216 Fundamentally, C++11 braced lists are formatted exactly like function
1217 calls would be formatted in their place. If the braced list follows a name
1218 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1219 the parentheses of a function call with that name. If there is no name,
1220 a zero-length name is assumed.
1221
Sylvestre Ledrude098242017-04-11 07:07:05 +00001222 .. code-block:: c++
1223
1224 true: false:
1225 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1226 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1227 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1228 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1229
Daniel Jasper553d4872014-06-17 12:40:34 +00001230**DerivePointerAlignment** (``bool``)
1231 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001232 alignment of ``&`` and ``*``.
1233 Pointer and reference alignment styles are going to be updated according
1234 to the preferences found in the file.
1235 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001236
1237**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001238 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001239
1240**ExperimentalAutoDetectBinPacking** (``bool``)
1241 If ``true``, clang-format detects whether function calls and
1242 definitions are formatted with one parameter per line.
1243
1244 Each call can be bin-packed, one-per-line or inconclusive. If it is
1245 inconclusive, e.g. completely on one line, but a decision needs to be
1246 made, clang-format analyzes whether there are other bin-packed cases in
1247 the input file and act accordingly.
1248
1249 NOTE: This is an experimental flag, that might go away or be renamed. Do
1250 not use this in config files, etc. Use at your own risk.
1251
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001252**FixNamespaceComments** (``bool``)
1253 If ``true``, clang-format adds missing namespace end comments and
1254 fixes invalid existing ones.
1255
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001256 .. code-block:: c++
1257
1258 true: false:
1259 namespace a { vs. namespace a {
1260 foo(); foo();
1261 } // namespace a; }
1262
Daniel Jaspere1e43192014-04-01 12:55:11 +00001263**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001264 A vector of macros that should be interpreted as foreach loops
1265 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001266
Daniel Jasperb5524822014-04-09 14:05:49 +00001267 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001268
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001269 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001270
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001271 FOREACH(<variable-declaration>, ...)
1272 <loop-body>
1273
1274 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001275
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001276 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001277
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001278 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001279
1280 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001281
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001282**IncludeBlocks** (``IncludeBlocksStyle``)
1283 Dependent on the value, multiple ``#include`` blocks can be sorted
1284 as one and divided based on category.
1285
1286 Possible values:
1287
1288 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1289 Sort each ``#include`` block separately.
1290
1291 .. code-block:: c++
1292
1293 #include "b.h" into #include "b.h"
1294
1295 #include <lib/main.h> #include "a.h"
1296 #include "a.h" #include <lib/main.h>
1297
1298 * ``IBS_Merge`` (in configuration: ``Merge``)
1299 Merge multiple ``#include`` blocks together and sort as one.
1300
1301 .. code-block:: c++
1302
1303 #include "b.h" into #include "a.h"
1304 #include "b.h"
1305 #include <lib/main.h> #include <lib/main.h>
1306 #include "a.h"
1307
1308 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1309 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001310 Then split into groups based on category priority. See
1311 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001312
1313 .. code-block:: c++
1314
1315 #include "b.h" into #include "a.h"
1316 #include "b.h"
1317 #include <lib/main.h>
1318 #include "a.h" #include <lib/main.h>
1319
1320
1321
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001322**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001323 Regular expressions denoting the different ``#include`` categories
1324 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001325
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001326 `POSIX extended
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +00001327 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001328 regular expressions are supported.
1329
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001330 These regular expressions are matched against the filename of an include
1331 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001332 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001333 according to increasing category number and then alphabetically within
1334 each category.
1335
Alexander Kornienko1e048232016-02-23 16:11:51 +00001336 If none of the regular expressions match, INT_MAX is assigned as
1337 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001338 so that it is generally kept at the beginning of the ``#includes``
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +00001339 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
Alexander Kornienko1e048232016-02-23 16:11:51 +00001340 can also assign negative priorities if you have certain headers that
1341 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001342
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001343 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001344
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001345 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001346
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001347 IncludeCategories:
1348 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1349 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001350 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001351 Priority: 3
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001352 - Regex: '<[[:alnum:].]+>'
1353 Priority: 4
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001354 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001355 Priority: 1
1356
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001357**IncludeIsMainRegex** (``std::string``)
1358 Specify a regular expression of suffixes that are allowed in the
1359 file-to-main-include mapping.
1360
1361 When guessing whether a #include is the "main" include (to assign
1362 category 0, see above), use this regex of allowed suffixes to the header
1363 stem. A partial match is done, so that:
1364 - "" means "arbitrary suffix"
1365 - "$" means "no suffix"
1366
1367 For example, if configured to "(_test)?$", then a header a.h would be seen
1368 as the "main" include in both a.cc and a_test.cc.
1369
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001370**IndentCaseLabels** (``bool``)
1371 Indent case labels one level from the switch statement.
1372
1373 When ``false``, use the same indentation level as for the switch statement.
1374 Switch statement body is always indented one level more than case labels.
1375
Sylvestre Ledrude098242017-04-11 07:07:05 +00001376 .. code-block:: c++
1377
1378 false: true:
1379 switch (fool) { vs. switch (fool) {
1380 case 1: case 1:
1381 bar(); bar();
1382 break; break;
1383 default: default:
1384 plop(); plop();
1385 } }
1386
Krasimir Georgievad47c902017-08-30 14:34:57 +00001387**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001388 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001389
1390 Possible values:
1391
1392 * ``PPDIS_None`` (in configuration: ``None``)
1393 Does not indent any directives.
1394
1395 .. code-block:: c++
1396
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001397 #if FOO
1398 #if BAR
1399 #include <foo>
1400 #endif
1401 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001402
1403 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1404 Indents directives after the hash.
1405
1406 .. code-block:: c++
1407
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001408 #if FOO
1409 # if BAR
1410 # include <foo>
1411 # endif
1412 #endif
1413
Paul Hoad701a0d72019-03-20 20:49:43 +00001414 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1415 Indents directives before the hash.
1416
1417 .. code-block:: c++
1418
1419 #if FOO
1420 #if BAR
1421 #include <foo>
1422 #endif
1423 #endif
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001424
Krasimir Georgievad47c902017-08-30 14:34:57 +00001425
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001426**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001427 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001428
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001429 .. code-block:: c++
1430
1431 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001432
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001433 void f() {
1434 someFunction();
1435 if (true, false) {
1436 f();
1437 }
1438 }
1439
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001440**IndentWrappedFunctionNames** (``bool``)
1441 Indent if a function definition or declaration is wrapped after the
1442 type.
1443
Sylvestre Ledrude098242017-04-11 07:07:05 +00001444 .. code-block:: c++
1445
1446 true:
1447 LoooooooooooooooooooooooooooooooooooooooongReturnType
1448 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1449
1450 false:
1451 LoooooooooooooooooooooooooooooooooooooooongReturnType
1452 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1453
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001454**JavaImportGroups** (``std::vector<std::string>``)
1455 A vector of prefixes ordered by the desired groups for Java imports.
1456
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001457 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001458 same grouping convention above all non-static imports. One group's prefix
1459 can be a subset of another - the longest prefix is always matched. Within
1460 a group, the imports are ordered lexicographically.
1461
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001462 In the .clang-format configuration file, this can be configured like
1463 in the following yaml example. This will result in imports being
1464 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001465
1466 .. code-block:: yaml
1467
1468 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001469
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001470
1471 .. code-block:: java
1472
1473 import static com.example.function1;
1474
1475 import static com.test.function2;
1476
1477 import static org.example.function3;
1478
1479 import com.example.ClassA;
1480 import com.example.Test;
1481 import com.example.a.ClassB;
1482
1483 import com.test.ClassC;
1484
1485 import org.example.ClassD;
1486
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001487**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1488 The JavaScriptQuoteStyle to use for JavaScript strings.
1489
1490 Possible values:
1491
1492 * ``JSQS_Leave`` (in configuration: ``Leave``)
1493 Leave string quotes as they are.
1494
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001495 .. code-block:: js
1496
1497 string1 = "foo";
1498 string2 = 'bar';
1499
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001500 * ``JSQS_Single`` (in configuration: ``Single``)
1501 Always use single quotes.
1502
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001503 .. code-block:: js
1504
1505 string1 = 'foo';
1506 string2 = 'bar';
1507
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001508 * ``JSQS_Double`` (in configuration: ``Double``)
1509 Always use double quotes.
1510
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001511 .. code-block:: js
1512
1513 string1 = "foo";
1514 string2 = "bar";
1515
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001516
1517
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001518**JavaScriptWrapImports** (``bool``)
1519 Whether to wrap JavaScript import/export statements.
1520
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001521 .. code-block:: js
1522
1523 true:
1524 import {
1525 VeryLongImportsAreAnnoying,
1526 VeryLongImportsAreAnnoying,
1527 VeryLongImportsAreAnnoying,
1528 } from 'some/module.js'
1529
1530 false:
1531 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1532
Daniel Jasperb5524822014-04-09 14:05:49 +00001533**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001534 If true, the empty line at the start of blocks is kept.
1535
1536 .. code-block:: c++
1537
1538 true: false:
1539 if (foo) { vs. if (foo) {
1540 bar();
1541 bar(); }
1542 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001543
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001544**Language** (``LanguageKind``)
1545 Language, this format style is targeted at.
1546
1547 Possible values:
1548
1549 * ``LK_None`` (in configuration: ``None``)
1550 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001551
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001552 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001553 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001554
Daniel Jasper18210d72014-10-09 09:52:05 +00001555 * ``LK_Java`` (in configuration: ``Java``)
1556 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001557
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001558 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1559 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001560
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001561 * ``LK_ObjC`` (in configuration: ``ObjC``)
1562 Should be used for Objective-C, Objective-C++.
1563
Daniel Jasperee107ad2014-02-13 12:51:50 +00001564 * ``LK_Proto`` (in configuration: ``Proto``)
1565 Should be used for Protocol Buffers
1566 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001567
Alexander Kornienko1e048232016-02-23 16:11:51 +00001568 * ``LK_TableGen`` (in configuration: ``TableGen``)
1569 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001570
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001571 * ``LK_TextProto`` (in configuration: ``TextProto``)
1572 Should be used for Protocol Buffer messages in text format
1573 (https://developers.google.com/protocol-buffers/).
1574
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001575
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001576
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001577**MacroBlockBegin** (``std::string``)
1578 A regular expression matching macros that start a block.
1579
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001580 .. code-block:: c++
1581
1582 # With:
1583 MacroBlockBegin: "^NS_MAP_BEGIN|\
1584 NS_TABLE_HEAD$"
1585 MacroBlockEnd: "^\
1586 NS_MAP_END|\
1587 NS_TABLE_.*_END$"
1588
1589 NS_MAP_BEGIN
1590 foo();
1591 NS_MAP_END
1592
1593 NS_TABLE_HEAD
1594 bar();
1595 NS_TABLE_FOO_END
1596
1597 # Without:
1598 NS_MAP_BEGIN
1599 foo();
1600 NS_MAP_END
1601
1602 NS_TABLE_HEAD
1603 bar();
1604 NS_TABLE_FOO_END
1605
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001606**MacroBlockEnd** (``std::string``)
1607 A regular expression matching macros that end a block.
1608
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001609**MaxEmptyLinesToKeep** (``unsigned``)
1610 The maximum number of consecutive empty lines to keep.
1611
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001612 .. code-block:: c++
1613
1614 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1615 int f() { int f() {
1616 int = 1; int i = 1;
1617 i = foo();
1618 i = foo(); return i;
1619 }
1620 return i;
1621 }
1622
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001623**NamespaceIndentation** (``NamespaceIndentationKind``)
1624 The indentation used for namespaces.
1625
1626 Possible values:
1627
1628 * ``NI_None`` (in configuration: ``None``)
1629 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001630
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001631 .. code-block:: c++
1632
1633 namespace out {
1634 int i;
1635 namespace in {
1636 int i;
1637 }
1638 }
1639
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001640 * ``NI_Inner`` (in configuration: ``Inner``)
1641 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001642
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001643 .. code-block:: c++
1644
1645 namespace out {
1646 int i;
1647 namespace in {
1648 int i;
1649 }
1650 }
1651
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001652 * ``NI_All`` (in configuration: ``All``)
1653 Indent in all namespaces.
1654
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001655 .. code-block:: c++
1656
1657 namespace out {
1658 int i;
1659 namespace in {
1660 int i;
1661 }
1662 }
1663
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001664
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001665
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001666**ObjCBinPackProtocolList** (``BinPackStyle``)
1667 Controls bin-packing Objective-C protocol conformance list
1668 items into as few lines as possible when they go over ``ColumnLimit``.
1669
1670 If ``Auto`` (the default), delegates to the value in
1671 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1672 protocol conformance list items into as few lines as possible
1673 whenever they go over ``ColumnLimit``.
1674
1675 If ``Always``, always bin-packs Objective-C protocol conformance
1676 list items into as few lines as possible whenever they go over
1677 ``ColumnLimit``.
1678
1679 If ``Never``, lays out Objective-C protocol conformance list items
1680 onto individual lines whenever they go over ``ColumnLimit``.
1681
1682
Aaron Ballman37485fd2018-06-28 12:02:38 +00001683 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001684
1685 Always (or Auto, if BinPackParameters=true):
1686 @interface ccccccccccccc () <
1687 ccccccccccccc, ccccccccccccc,
1688 ccccccccccccc, ccccccccccccc> {
1689 }
1690
1691 Never (or Auto, if BinPackParameters=false):
1692 @interface ddddddddddddd () <
1693 ddddddddddddd,
1694 ddddddddddddd,
1695 ddddddddddddd,
1696 ddddddddddddd> {
1697 }
1698
1699 Possible values:
1700
1701 * ``BPS_Auto`` (in configuration: ``Auto``)
1702 Automatically determine parameter bin-packing behavior.
1703
1704 * ``BPS_Always`` (in configuration: ``Always``)
1705 Always bin-pack parameters.
1706
1707 * ``BPS_Never`` (in configuration: ``Never``)
1708 Never bin-pack parameters.
1709
1710
1711
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001712**ObjCBlockIndentWidth** (``unsigned``)
1713 The number of characters to use for indentation of ObjC blocks.
1714
Sylvestre Ledrude098242017-04-11 07:07:05 +00001715 .. code-block:: objc
1716
1717 ObjCBlockIndentWidth: 4
1718
1719 [operation setCompletionBlock:^{
1720 [self onOperationDone];
1721 }];
1722
Daniel Jasperee107ad2014-02-13 12:51:50 +00001723**ObjCSpaceAfterProperty** (``bool``)
1724 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001725 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001726
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001727**ObjCSpaceBeforeProtocolList** (``bool``)
1728 Add a space in front of an Objective-C protocol list, i.e. use
1729 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1730
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001731**PenaltyBreakAssignment** (``unsigned``)
1732 The penalty for breaking around an assignment operator.
1733
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001734**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001735 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001736
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001737**PenaltyBreakComment** (``unsigned``)
1738 The penalty for each line break introduced inside a comment.
1739
1740**PenaltyBreakFirstLessLess** (``unsigned``)
1741 The penalty for breaking before the first ``<<``.
1742
1743**PenaltyBreakString** (``unsigned``)
1744 The penalty for each line break introduced inside a string literal.
1745
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001746**PenaltyBreakTemplateDeclaration** (``unsigned``)
1747 The penalty for breaking after template declaration.
1748
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001749**PenaltyExcessCharacter** (``unsigned``)
1750 The penalty for each character outside of the column limit.
1751
1752**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1753 Penalty for putting the return type of a function onto its own
1754 line.
1755
Daniel Jasper553d4872014-06-17 12:40:34 +00001756**PointerAlignment** (``PointerAlignmentStyle``)
1757 Pointer and reference alignment style.
1758
1759 Possible values:
1760
1761 * ``PAS_Left`` (in configuration: ``Left``)
1762 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001763
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001764 .. code-block:: c++
1765
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001766 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001767
Daniel Jasper553d4872014-06-17 12:40:34 +00001768 * ``PAS_Right`` (in configuration: ``Right``)
1769 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001770
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001771 .. code-block:: c++
1772
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001773 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001774
Daniel Jasper553d4872014-06-17 12:40:34 +00001775 * ``PAS_Middle`` (in configuration: ``Middle``)
1776 Align pointer in the middle.
1777
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001778 .. code-block:: c++
1779
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001780 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001781
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001782
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001783
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001784**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001785 Defines hints for detecting supported languages code blocks in raw
1786 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001787
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001788 A raw string with a matching delimiter or a matching enclosing function
1789 name will be reformatted assuming the specified language based on the
1790 style for that language defined in the .clang-format file. If no style has
1791 been defined in the .clang-format file for the specific language, a
1792 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1793 found, the formatting is based on llvm style. A matching delimiter takes
1794 precedence over a matching enclosing function name for determining the
1795 language of the raw string contents.
1796
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001797 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001798 the same language will be updated to the canonical if possible.
1799
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001800 There should be at most one specification per language and each delimiter
1801 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001802
1803 To configure this in the .clang-format file, use:
1804
1805 .. code-block:: yaml
1806
1807 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001808 - Language: TextProto
1809 Delimiters:
1810 - 'pb'
1811 - 'proto'
1812 EnclosingFunctions:
1813 - 'PARSE_TEXT_PROTO'
1814 BasedOnStyle: google
1815 - Language: Cpp
1816 Delimiters:
1817 - 'cc'
1818 - 'cpp'
1819 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001820 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001821
Alexander Kornienko1e048232016-02-23 16:11:51 +00001822**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001823 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001824
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001825 .. code-block:: c++
1826
1827 false:
1828 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1829 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1830
1831 true:
1832 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1833 // information
1834 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1835 * information */
1836
Alexander Kornienko1e048232016-02-23 16:11:51 +00001837**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001838 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001839
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001840 .. code-block:: c++
1841
1842 false: true:
1843 #include "b.h" vs. #include "a.h"
1844 #include "a.h" #include "b.h"
1845
Krasimir Georgievac16a202017-06-23 11:46:03 +00001846**SortUsingDeclarations** (``bool``)
1847 If ``true``, clang-format will sort using declarations.
1848
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001849 The order of using declarations is defined as follows:
1850 Split the strings by "::" and discard any initial empty strings. The last
1851 element of each list is a non-namespace name; all others are namespace
1852 names. Sort the lists of names lexicographically, where the sort order of
1853 individual names is that all non-namespace names come before all namespace
1854 names, and within those groups, names are in case-insensitive
1855 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001856
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001857 .. code-block:: c++
1858
1859 false: true:
1860 using std::cout; vs. using std::cin;
1861 using std::cin; using std::cout;
1862
Daniel Jasperb87899b2014-09-10 13:11:45 +00001863**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001864 If ``true``, a space is inserted after C style casts.
1865
1866 .. code-block:: c++
1867
1868 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001869 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001870
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001871**SpaceAfterTemplateKeyword** (``bool``)
1872 If ``true``, a space will be inserted after the 'template' keyword.
1873
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001874 .. code-block:: c++
1875
1876 true: false:
1877 template <int> void foo(); vs. template<int> void foo();
1878
Daniel Jasperd94bff32013-09-25 15:15:02 +00001879**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001880 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001881
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001882 .. code-block:: c++
1883
1884 true: false:
1885 int a = 5; vs. int a=5;
1886 a += 42 a+=42;
1887
Hans Wennborgbfc34062018-06-14 08:01:09 +00001888**SpaceBeforeCpp11BracedList** (``bool``)
1889 If ``true``, a space will be inserted before a C++11 braced list
1890 used to initialize an object (after the preceding identifier or type).
1891
1892 .. code-block:: c++
1893
1894 true: false:
1895 Foo foo { bar }; vs. Foo foo{ bar };
1896 Foo {}; Foo{};
1897 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1898 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1899
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001900**SpaceBeforeCtorInitializerColon** (``bool``)
1901 If ``false``, spaces will be removed before constructor initializer
1902 colon.
1903
1904 .. code-block:: c++
1905
1906 true: false:
1907 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1908
1909**SpaceBeforeInheritanceColon** (``bool``)
1910 If ``false``, spaces will be removed before inheritance colon.
1911
1912 .. code-block:: c++
1913
1914 true: false:
1915 class Foo : Bar {} vs. class Foo: Bar {}
1916
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001917**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1918 Defines in which cases to put a space before opening parentheses.
1919
1920 Possible values:
1921
1922 * ``SBPO_Never`` (in configuration: ``Never``)
1923 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001924
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001925 .. code-block:: c++
1926
1927 void f() {
1928 if(true) {
1929 f();
1930 }
1931 }
1932
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001933 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1934 Put a space before opening parentheses only after control statement
1935 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001936
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001937 .. code-block:: c++
1938
1939 void f() {
1940 if (true) {
1941 f();
1942 }
1943 }
1944
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001945 * ``SBPO_Always`` (in configuration: ``Always``)
1946 Always put a space before opening parentheses, except when it's
1947 prohibited by the syntax rules (in function-like macro definitions) or
1948 when determined by other style rules (after unary operators, opening
1949 parentheses, etc.)
1950
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001951 .. code-block:: c++
1952
1953 void f () {
1954 if (true) {
1955 f ();
1956 }
1957 }
1958
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001959
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001960
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001961**SpaceBeforeRangeBasedForLoopColon** (``bool``)
1962 If ``false``, spaces will be removed before range-based for loop
1963 colon.
1964
1965 .. code-block:: c++
1966
1967 true: false:
1968 for (auto v : values) {} vs. for(auto v: values) {}
1969
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001970**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001971 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001972
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001973 .. code-block:: c++
1974
1975 true: false:
1976 void f( ) { vs. void f() {
1977 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1978 if (true) { if (true) {
1979 f( ); f();
1980 } }
1981 } }
1982
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001983**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00001984 The number of spaces before trailing line comments
1985 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00001986
Alexander Kornienko70f97c92016-02-27 14:02:08 +00001987 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001988 those commonly have different usage patterns and a number of special
1989 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001990
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001991 .. code-block:: c++
1992
1993 SpacesBeforeTrailingComments: 3
1994 void f() {
1995 if (true) { // foo1
1996 f(); // bar
1997 } // foo
1998 }
1999
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002000**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002001 If ``true``, spaces will be inserted after ``<`` and before ``>``
2002 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002003
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002004 .. code-block:: c++
2005
2006 true: false:
2007 static_cast< int >(arg); vs. static_cast<int>(arg);
2008 std::function< void(int) > fct; std::function<void(int)> fct;
2009
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002010**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002011 If ``true``, spaces may be inserted into C style casts.
2012
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002013 .. code-block:: c++
2014
2015 true: false:
2016 x = ( int32 )y vs. x = (int32)y
2017
Daniel Jasperee107ad2014-02-13 12:51:50 +00002018**SpacesInContainerLiterals** (``bool``)
2019 If ``true``, spaces are inserted inside container literals (e.g.
2020 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002021
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002022 .. code-block:: js
2023
2024 true: false:
2025 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2026 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2027
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002028**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002029 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002030
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002031 .. code-block:: c++
2032
2033 true: false:
2034 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2035
Daniel Jasperad981f82014-08-26 11:41:14 +00002036**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002037 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002038 Lambdas or unspecified size array declarations will not be affected.
2039
2040 .. code-block:: c++
2041
2042 true: false:
2043 int a[ 5 ]; vs. int a[5];
2044 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002045
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002046**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002047 Format compatible with this standard, e.g. use ``A<A<int> >``
2048 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002049
2050 Possible values:
2051
2052 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2053 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002054
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002055 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002056 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002057 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002058
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002059 * ``LS_Auto`` (in configuration: ``Auto``)
2060 Automatic detection based on the input.
2061
2062
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002063
Francois Ferrand6f40e212018-10-02 16:37:51 +00002064**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002065 A vector of macros that should be interpreted as complete
2066 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002067
2068 Typical macros are expressions, and require a semi-colon to be
2069 added; sometimes this is not the case, and this allows to make
2070 clang-format aware of such cases.
2071
2072 For example: Q_UNUSED
2073
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002074**TabWidth** (``unsigned``)
2075 The number of columns used for tab stops.
2076
2077**UseTab** (``UseTabStyle``)
2078 The way to use tab characters in the resulting file.
2079
2080 Possible values:
2081
2082 * ``UT_Never`` (in configuration: ``Never``)
2083 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002084
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002085 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2086 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002087
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002088 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2089 Use tabs only for line continuation and indentation.
2090
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002091 * ``UT_Always`` (in configuration: ``Always``)
2092 Use tabs whenever we need to fill whitespace that spans at least from
2093 one tab stop to the next one.
2094
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002095
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002096
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002097.. END_FORMAT_STYLE_OPTIONS
2098
Daniel Jasper49d3d582015-10-05 07:24:55 +00002099Adding additional style options
2100===============================
2101
2102Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002103these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002104sure that any given combination of options work and that new features don't
2105break any of the existing options in any way. There are also costs for end users
2106as options become less discoverable and people have to think about and make a
2107decision on options they don't really care about.
2108
2109The goal of the clang-format project is more on the side of supporting a
2110limited set of styles really well as opposed to supporting every single style
2111used by a codebase somewhere in the wild. Of course, we do want to support all
2112major projects and thus have established the following bar for adding style
2113options. Each new style option must ..
2114
Daniel Jasperfcbea712015-10-05 13:30:42 +00002115 * be used in a project of significant size (have dozens of contributors)
2116 * have a publicly accessible style guide
2117 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002118
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002119Examples
2120========
2121
2122A style similar to the `Linux Kernel style
2123<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2124
2125.. code-block:: yaml
2126
2127 BasedOnStyle: LLVM
2128 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002129 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002130 BreakBeforeBraces: Linux
2131 AllowShortIfStatementsOnASingleLine: false
2132 IndentCaseLabels: false
2133
2134The result is (imagine that tabs are used for indentation here):
2135
2136.. code-block:: c++
2137
2138 void test()
2139 {
2140 switch (x) {
2141 case 0:
2142 case 1:
2143 do_something();
2144 break;
2145 case 2:
2146 do_something_else();
2147 break;
2148 default:
2149 break;
2150 }
2151 if (condition)
2152 do_something_completely_different();
2153
2154 if (x == y) {
2155 q();
2156 } else if (x > y) {
2157 w();
2158 } else {
2159 r();
2160 }
2161 }
2162
2163A style similar to the default Visual Studio formatting style:
2164
2165.. code-block:: yaml
2166
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002167 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002168 IndentWidth: 4
2169 BreakBeforeBraces: Allman
2170 AllowShortIfStatementsOnASingleLine: false
2171 IndentCaseLabels: false
2172 ColumnLimit: 0
2173
2174The result is:
2175
2176.. code-block:: c++
2177
2178 void test()
2179 {
2180 switch (suffix)
2181 {
2182 case 0:
2183 case 1:
2184 do_something();
2185 break;
2186 case 2:
2187 do_something_else();
2188 break;
2189 default:
2190 break;
2191 }
2192 if (condition)
2193 do_somthing_completely_different();
2194
2195 if (x == y)
2196 {
2197 q();
2198 }
2199 else if (x > y)
2200 {
2201 w();
2202 }
2203 else
2204 {
2205 r();
2206 }
2207 }