blob: d4a56d3bb3ccc76a1730852d139e6c2afee5bdec [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
1414
Krasimir Georgievad47c902017-08-30 14:34:57 +00001415
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001416**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001417 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001418
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001419 .. code-block:: c++
1420
1421 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001422
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001423 void f() {
1424 someFunction();
1425 if (true, false) {
1426 f();
1427 }
1428 }
1429
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001430**IndentWrappedFunctionNames** (``bool``)
1431 Indent if a function definition or declaration is wrapped after the
1432 type.
1433
Sylvestre Ledrude098242017-04-11 07:07:05 +00001434 .. code-block:: c++
1435
1436 true:
1437 LoooooooooooooooooooooooooooooooooooooooongReturnType
1438 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1439
1440 false:
1441 LoooooooooooooooooooooooooooooooooooooooongReturnType
1442 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1443
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001444**JavaImportGroups** (``std::vector<std::string>``)
1445 A vector of prefixes ordered by the desired groups for Java imports.
1446
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001447 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001448 same grouping convention above all non-static imports. One group's prefix
1449 can be a subset of another - the longest prefix is always matched. Within
1450 a group, the imports are ordered lexicographically.
1451
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001452 In the .clang-format configuration file, this can be configured like
1453 in the following yaml example. This will result in imports being
1454 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001455
1456 .. code-block:: yaml
1457
1458 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001459
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001460
1461 .. code-block:: java
1462
1463 import static com.example.function1;
1464
1465 import static com.test.function2;
1466
1467 import static org.example.function3;
1468
1469 import com.example.ClassA;
1470 import com.example.Test;
1471 import com.example.a.ClassB;
1472
1473 import com.test.ClassC;
1474
1475 import org.example.ClassD;
1476
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001477**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1478 The JavaScriptQuoteStyle to use for JavaScript strings.
1479
1480 Possible values:
1481
1482 * ``JSQS_Leave`` (in configuration: ``Leave``)
1483 Leave string quotes as they are.
1484
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001485 .. code-block:: js
1486
1487 string1 = "foo";
1488 string2 = 'bar';
1489
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001490 * ``JSQS_Single`` (in configuration: ``Single``)
1491 Always use single quotes.
1492
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001493 .. code-block:: js
1494
1495 string1 = 'foo';
1496 string2 = 'bar';
1497
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001498 * ``JSQS_Double`` (in configuration: ``Double``)
1499 Always use double quotes.
1500
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001501 .. code-block:: js
1502
1503 string1 = "foo";
1504 string2 = "bar";
1505
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001506
1507
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001508**JavaScriptWrapImports** (``bool``)
1509 Whether to wrap JavaScript import/export statements.
1510
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001511 .. code-block:: js
1512
1513 true:
1514 import {
1515 VeryLongImportsAreAnnoying,
1516 VeryLongImportsAreAnnoying,
1517 VeryLongImportsAreAnnoying,
1518 } from 'some/module.js'
1519
1520 false:
1521 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1522
Daniel Jasperb5524822014-04-09 14:05:49 +00001523**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001524 If true, the empty line at the start of blocks is kept.
1525
1526 .. code-block:: c++
1527
1528 true: false:
1529 if (foo) { vs. if (foo) {
1530 bar();
1531 bar(); }
1532 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001533
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001534**Language** (``LanguageKind``)
1535 Language, this format style is targeted at.
1536
1537 Possible values:
1538
1539 * ``LK_None`` (in configuration: ``None``)
1540 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001541
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001542 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001543 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001544
Daniel Jasper18210d72014-10-09 09:52:05 +00001545 * ``LK_Java`` (in configuration: ``Java``)
1546 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001547
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001548 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1549 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001550
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001551 * ``LK_ObjC`` (in configuration: ``ObjC``)
1552 Should be used for Objective-C, Objective-C++.
1553
Daniel Jasperee107ad2014-02-13 12:51:50 +00001554 * ``LK_Proto`` (in configuration: ``Proto``)
1555 Should be used for Protocol Buffers
1556 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001557
Alexander Kornienko1e048232016-02-23 16:11:51 +00001558 * ``LK_TableGen`` (in configuration: ``TableGen``)
1559 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001560
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001561 * ``LK_TextProto`` (in configuration: ``TextProto``)
1562 Should be used for Protocol Buffer messages in text format
1563 (https://developers.google.com/protocol-buffers/).
1564
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001565
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001566
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001567**MacroBlockBegin** (``std::string``)
1568 A regular expression matching macros that start a block.
1569
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001570 .. code-block:: c++
1571
1572 # With:
1573 MacroBlockBegin: "^NS_MAP_BEGIN|\
1574 NS_TABLE_HEAD$"
1575 MacroBlockEnd: "^\
1576 NS_MAP_END|\
1577 NS_TABLE_.*_END$"
1578
1579 NS_MAP_BEGIN
1580 foo();
1581 NS_MAP_END
1582
1583 NS_TABLE_HEAD
1584 bar();
1585 NS_TABLE_FOO_END
1586
1587 # Without:
1588 NS_MAP_BEGIN
1589 foo();
1590 NS_MAP_END
1591
1592 NS_TABLE_HEAD
1593 bar();
1594 NS_TABLE_FOO_END
1595
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001596**MacroBlockEnd** (``std::string``)
1597 A regular expression matching macros that end a block.
1598
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001599**MaxEmptyLinesToKeep** (``unsigned``)
1600 The maximum number of consecutive empty lines to keep.
1601
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001602 .. code-block:: c++
1603
1604 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1605 int f() { int f() {
1606 int = 1; int i = 1;
1607 i = foo();
1608 i = foo(); return i;
1609 }
1610 return i;
1611 }
1612
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001613**NamespaceIndentation** (``NamespaceIndentationKind``)
1614 The indentation used for namespaces.
1615
1616 Possible values:
1617
1618 * ``NI_None`` (in configuration: ``None``)
1619 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001620
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001621 .. code-block:: c++
1622
1623 namespace out {
1624 int i;
1625 namespace in {
1626 int i;
1627 }
1628 }
1629
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001630 * ``NI_Inner`` (in configuration: ``Inner``)
1631 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001632
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001633 .. code-block:: c++
1634
1635 namespace out {
1636 int i;
1637 namespace in {
1638 int i;
1639 }
1640 }
1641
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001642 * ``NI_All`` (in configuration: ``All``)
1643 Indent in all namespaces.
1644
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001645 .. code-block:: c++
1646
1647 namespace out {
1648 int i;
1649 namespace in {
1650 int i;
1651 }
1652 }
1653
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001654
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001655
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001656**ObjCBinPackProtocolList** (``BinPackStyle``)
1657 Controls bin-packing Objective-C protocol conformance list
1658 items into as few lines as possible when they go over ``ColumnLimit``.
1659
1660 If ``Auto`` (the default), delegates to the value in
1661 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1662 protocol conformance list items into as few lines as possible
1663 whenever they go over ``ColumnLimit``.
1664
1665 If ``Always``, always bin-packs Objective-C protocol conformance
1666 list items into as few lines as possible whenever they go over
1667 ``ColumnLimit``.
1668
1669 If ``Never``, lays out Objective-C protocol conformance list items
1670 onto individual lines whenever they go over ``ColumnLimit``.
1671
1672
Aaron Ballman37485fd2018-06-28 12:02:38 +00001673 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001674
1675 Always (or Auto, if BinPackParameters=true):
1676 @interface ccccccccccccc () <
1677 ccccccccccccc, ccccccccccccc,
1678 ccccccccccccc, ccccccccccccc> {
1679 }
1680
1681 Never (or Auto, if BinPackParameters=false):
1682 @interface ddddddddddddd () <
1683 ddddddddddddd,
1684 ddddddddddddd,
1685 ddddddddddddd,
1686 ddddddddddddd> {
1687 }
1688
1689 Possible values:
1690
1691 * ``BPS_Auto`` (in configuration: ``Auto``)
1692 Automatically determine parameter bin-packing behavior.
1693
1694 * ``BPS_Always`` (in configuration: ``Always``)
1695 Always bin-pack parameters.
1696
1697 * ``BPS_Never`` (in configuration: ``Never``)
1698 Never bin-pack parameters.
1699
1700
1701
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001702**ObjCBlockIndentWidth** (``unsigned``)
1703 The number of characters to use for indentation of ObjC blocks.
1704
Sylvestre Ledrude098242017-04-11 07:07:05 +00001705 .. code-block:: objc
1706
1707 ObjCBlockIndentWidth: 4
1708
1709 [operation setCompletionBlock:^{
1710 [self onOperationDone];
1711 }];
1712
Daniel Jasperee107ad2014-02-13 12:51:50 +00001713**ObjCSpaceAfterProperty** (``bool``)
1714 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001715 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001716
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001717**ObjCSpaceBeforeProtocolList** (``bool``)
1718 Add a space in front of an Objective-C protocol list, i.e. use
1719 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1720
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001721**PenaltyBreakAssignment** (``unsigned``)
1722 The penalty for breaking around an assignment operator.
1723
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001724**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001725 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001726
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001727**PenaltyBreakComment** (``unsigned``)
1728 The penalty for each line break introduced inside a comment.
1729
1730**PenaltyBreakFirstLessLess** (``unsigned``)
1731 The penalty for breaking before the first ``<<``.
1732
1733**PenaltyBreakString** (``unsigned``)
1734 The penalty for each line break introduced inside a string literal.
1735
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001736**PenaltyBreakTemplateDeclaration** (``unsigned``)
1737 The penalty for breaking after template declaration.
1738
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001739**PenaltyExcessCharacter** (``unsigned``)
1740 The penalty for each character outside of the column limit.
1741
1742**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1743 Penalty for putting the return type of a function onto its own
1744 line.
1745
Daniel Jasper553d4872014-06-17 12:40:34 +00001746**PointerAlignment** (``PointerAlignmentStyle``)
1747 Pointer and reference alignment style.
1748
1749 Possible values:
1750
1751 * ``PAS_Left`` (in configuration: ``Left``)
1752 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001753
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001754 .. code-block:: c++
1755
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001756 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001757
Daniel Jasper553d4872014-06-17 12:40:34 +00001758 * ``PAS_Right`` (in configuration: ``Right``)
1759 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001760
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001761 .. code-block:: c++
1762
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001763 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001764
Daniel Jasper553d4872014-06-17 12:40:34 +00001765 * ``PAS_Middle`` (in configuration: ``Middle``)
1766 Align pointer in the middle.
1767
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001768 .. code-block:: c++
1769
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001770 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001771
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001772
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001773
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001774**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001775 Defines hints for detecting supported languages code blocks in raw
1776 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001777
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001778 A raw string with a matching delimiter or a matching enclosing function
1779 name will be reformatted assuming the specified language based on the
1780 style for that language defined in the .clang-format file. If no style has
1781 been defined in the .clang-format file for the specific language, a
1782 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1783 found, the formatting is based on llvm style. A matching delimiter takes
1784 precedence over a matching enclosing function name for determining the
1785 language of the raw string contents.
1786
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001787 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001788 the same language will be updated to the canonical if possible.
1789
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001790 There should be at most one specification per language and each delimiter
1791 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001792
1793 To configure this in the .clang-format file, use:
1794
1795 .. code-block:: yaml
1796
1797 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001798 - Language: TextProto
1799 Delimiters:
1800 - 'pb'
1801 - 'proto'
1802 EnclosingFunctions:
1803 - 'PARSE_TEXT_PROTO'
1804 BasedOnStyle: google
1805 - Language: Cpp
1806 Delimiters:
1807 - 'cc'
1808 - 'cpp'
1809 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001810 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001811
Alexander Kornienko1e048232016-02-23 16:11:51 +00001812**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001813 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001814
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001815 .. code-block:: c++
1816
1817 false:
1818 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1819 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1820
1821 true:
1822 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1823 // information
1824 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1825 * information */
1826
Alexander Kornienko1e048232016-02-23 16:11:51 +00001827**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001828 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001829
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001830 .. code-block:: c++
1831
1832 false: true:
1833 #include "b.h" vs. #include "a.h"
1834 #include "a.h" #include "b.h"
1835
Krasimir Georgievac16a202017-06-23 11:46:03 +00001836**SortUsingDeclarations** (``bool``)
1837 If ``true``, clang-format will sort using declarations.
1838
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001839 The order of using declarations is defined as follows:
1840 Split the strings by "::" and discard any initial empty strings. The last
1841 element of each list is a non-namespace name; all others are namespace
1842 names. Sort the lists of names lexicographically, where the sort order of
1843 individual names is that all non-namespace names come before all namespace
1844 names, and within those groups, names are in case-insensitive
1845 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001846
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001847 .. code-block:: c++
1848
1849 false: true:
1850 using std::cout; vs. using std::cin;
1851 using std::cin; using std::cout;
1852
Daniel Jasperb87899b2014-09-10 13:11:45 +00001853**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001854 If ``true``, a space is inserted after C style casts.
1855
1856 .. code-block:: c++
1857
1858 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001859 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001860
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001861**SpaceAfterTemplateKeyword** (``bool``)
1862 If ``true``, a space will be inserted after the 'template' keyword.
1863
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001864 .. code-block:: c++
1865
1866 true: false:
1867 template <int> void foo(); vs. template<int> void foo();
1868
Daniel Jasperd94bff32013-09-25 15:15:02 +00001869**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001870 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001871
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001872 .. code-block:: c++
1873
1874 true: false:
1875 int a = 5; vs. int a=5;
1876 a += 42 a+=42;
1877
Hans Wennborgbfc34062018-06-14 08:01:09 +00001878**SpaceBeforeCpp11BracedList** (``bool``)
1879 If ``true``, a space will be inserted before a C++11 braced list
1880 used to initialize an object (after the preceding identifier or type).
1881
1882 .. code-block:: c++
1883
1884 true: false:
1885 Foo foo { bar }; vs. Foo foo{ bar };
1886 Foo {}; Foo{};
1887 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1888 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1889
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001890**SpaceBeforeCtorInitializerColon** (``bool``)
1891 If ``false``, spaces will be removed before constructor initializer
1892 colon.
1893
1894 .. code-block:: c++
1895
1896 true: false:
1897 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1898
1899**SpaceBeforeInheritanceColon** (``bool``)
1900 If ``false``, spaces will be removed before inheritance colon.
1901
1902 .. code-block:: c++
1903
1904 true: false:
1905 class Foo : Bar {} vs. class Foo: Bar {}
1906
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001907**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1908 Defines in which cases to put a space before opening parentheses.
1909
1910 Possible values:
1911
1912 * ``SBPO_Never`` (in configuration: ``Never``)
1913 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001914
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001915 .. code-block:: c++
1916
1917 void f() {
1918 if(true) {
1919 f();
1920 }
1921 }
1922
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001923 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1924 Put a space before opening parentheses only after control statement
1925 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001926
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001927 .. code-block:: c++
1928
1929 void f() {
1930 if (true) {
1931 f();
1932 }
1933 }
1934
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001935 * ``SBPO_Always`` (in configuration: ``Always``)
1936 Always put a space before opening parentheses, except when it's
1937 prohibited by the syntax rules (in function-like macro definitions) or
1938 when determined by other style rules (after unary operators, opening
1939 parentheses, etc.)
1940
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001941 .. code-block:: c++
1942
1943 void f () {
1944 if (true) {
1945 f ();
1946 }
1947 }
1948
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001949
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001950
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001951**SpaceBeforeRangeBasedForLoopColon** (``bool``)
1952 If ``false``, spaces will be removed before range-based for loop
1953 colon.
1954
1955 .. code-block:: c++
1956
1957 true: false:
1958 for (auto v : values) {} vs. for(auto v: values) {}
1959
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001960**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001961 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001962
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001963 .. code-block:: c++
1964
1965 true: false:
1966 void f( ) { vs. void f() {
1967 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1968 if (true) { if (true) {
1969 f( ); f();
1970 } }
1971 } }
1972
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001973**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00001974 The number of spaces before trailing line comments
1975 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00001976
Alexander Kornienko70f97c92016-02-27 14:02:08 +00001977 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001978 those commonly have different usage patterns and a number of special
1979 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001980
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001981 .. code-block:: c++
1982
1983 SpacesBeforeTrailingComments: 3
1984 void f() {
1985 if (true) { // foo1
1986 f(); // bar
1987 } // foo
1988 }
1989
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001990**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001991 If ``true``, spaces will be inserted after ``<`` and before ``>``
1992 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001993
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001994 .. code-block:: c++
1995
1996 true: false:
1997 static_cast< int >(arg); vs. static_cast<int>(arg);
1998 std::function< void(int) > fct; std::function<void(int)> fct;
1999
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002000**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002001 If ``true``, spaces may be inserted into C style casts.
2002
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002003 .. code-block:: c++
2004
2005 true: false:
2006 x = ( int32 )y vs. x = (int32)y
2007
Daniel Jasperee107ad2014-02-13 12:51:50 +00002008**SpacesInContainerLiterals** (``bool``)
2009 If ``true``, spaces are inserted inside container literals (e.g.
2010 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002011
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002012 .. code-block:: js
2013
2014 true: false:
2015 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2016 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2017
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002018**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002019 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002020
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002021 .. code-block:: c++
2022
2023 true: false:
2024 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2025
Daniel Jasperad981f82014-08-26 11:41:14 +00002026**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002027 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002028 Lambdas or unspecified size array declarations will not be affected.
2029
2030 .. code-block:: c++
2031
2032 true: false:
2033 int a[ 5 ]; vs. int a[5];
2034 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002035
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002036**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002037 Format compatible with this standard, e.g. use ``A<A<int> >``
2038 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002039
2040 Possible values:
2041
2042 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2043 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002044
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002045 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002046 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002047 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002048
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002049 * ``LS_Auto`` (in configuration: ``Auto``)
2050 Automatic detection based on the input.
2051
2052
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002053
Francois Ferrand6f40e212018-10-02 16:37:51 +00002054**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002055 A vector of macros that should be interpreted as complete
2056 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002057
2058 Typical macros are expressions, and require a semi-colon to be
2059 added; sometimes this is not the case, and this allows to make
2060 clang-format aware of such cases.
2061
2062 For example: Q_UNUSED
2063
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002064**TabWidth** (``unsigned``)
2065 The number of columns used for tab stops.
2066
2067**UseTab** (``UseTabStyle``)
2068 The way to use tab characters in the resulting file.
2069
2070 Possible values:
2071
2072 * ``UT_Never`` (in configuration: ``Never``)
2073 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002074
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002075 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2076 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002077
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002078 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2079 Use tabs only for line continuation and indentation.
2080
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002081 * ``UT_Always`` (in configuration: ``Always``)
2082 Use tabs whenever we need to fill whitespace that spans at least from
2083 one tab stop to the next one.
2084
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002085
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002086
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002087.. END_FORMAT_STYLE_OPTIONS
2088
Daniel Jasper49d3d582015-10-05 07:24:55 +00002089Adding additional style options
2090===============================
2091
2092Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002093these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002094sure that any given combination of options work and that new features don't
2095break any of the existing options in any way. There are also costs for end users
2096as options become less discoverable and people have to think about and make a
2097decision on options they don't really care about.
2098
2099The goal of the clang-format project is more on the side of supporting a
2100limited set of styles really well as opposed to supporting every single style
2101used by a codebase somewhere in the wild. Of course, we do want to support all
2102major projects and thus have established the following bar for adding style
2103options. Each new style option must ..
2104
Daniel Jasperfcbea712015-10-05 13:30:42 +00002105 * be used in a project of significant size (have dozens of contributors)
2106 * have a publicly accessible style guide
2107 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002108
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002109Examples
2110========
2111
2112A style similar to the `Linux Kernel style
2113<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2114
2115.. code-block:: yaml
2116
2117 BasedOnStyle: LLVM
2118 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002119 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002120 BreakBeforeBraces: Linux
2121 AllowShortIfStatementsOnASingleLine: false
2122 IndentCaseLabels: false
2123
2124The result is (imagine that tabs are used for indentation here):
2125
2126.. code-block:: c++
2127
2128 void test()
2129 {
2130 switch (x) {
2131 case 0:
2132 case 1:
2133 do_something();
2134 break;
2135 case 2:
2136 do_something_else();
2137 break;
2138 default:
2139 break;
2140 }
2141 if (condition)
2142 do_something_completely_different();
2143
2144 if (x == y) {
2145 q();
2146 } else if (x > y) {
2147 w();
2148 } else {
2149 r();
2150 }
2151 }
2152
2153A style similar to the default Visual Studio formatting style:
2154
2155.. code-block:: yaml
2156
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002157 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002158 IndentWidth: 4
2159 BreakBeforeBraces: Allman
2160 AllowShortIfStatementsOnASingleLine: false
2161 IndentCaseLabels: false
2162 ColumnLimit: 0
2163
2164The result is:
2165
2166.. code-block:: c++
2167
2168 void test()
2169 {
2170 switch (suffix)
2171 {
2172 case 0:
2173 case 1:
2174 do_something();
2175 break;
2176 case 2:
2177 do_something_else();
2178 break;
2179 default:
2180 break;
2181 }
2182 if (condition)
2183 do_somthing_completely_different();
2184
2185 if (x == y)
2186 {
2187 q();
2188 }
2189 else if (x > y)
2190 {
2191 w();
2192 }
2193 else
2194 {
2195 r();
2196 }
2197 }