blob: 1a783fd43069d5278fef4322b8670250bc879eef [file] [log] [blame]
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
Paul Hoadcbb726d2019-03-21 13:09:22 +000010the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
11create a custom style by configuring specific style options.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000012
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
Hans Wennborg9f6581b2013-09-10 15:41:12 +000019use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000021
22When using ``-style=file``, :program:`clang-format` for each input file will
23try to find the ``.clang-format`` file located in the closest parent directory
24of the input file. When the standard input is used, the search is started from
25the current directory.
26
27The ``.clang-format`` file uses YAML format:
28
29.. code-block:: yaml
30
31 key1: value1
32 key2: value2
33 # A comment.
34 ...
35
Alexander Kornienko092cb212014-08-12 13:34:22 +000036The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An example of a configuration file for multiple languages:
51
52.. code-block:: yaml
53
54 ---
55 # We'll use defaults from the LLVM style, but with 4 columns indentation.
56 BasedOnStyle: LLVM
57 IndentWidth: 4
58 ---
59 Language: Cpp
60 # Force pointers to the type for C++.
61 DerivePointerAlignment: false
62 PointerAlignment: Left
63 ---
64 Language: JavaScript
65 # Use 100 columns for JS.
66 ColumnLimit: 100
67 ---
68 Language: Proto
69 # Don't format .proto files.
70 DisableFormat: true
Paul Hoadcbb726d2019-03-21 13:09:22 +000071 ---
72 Language: CSharp
73 # Use 100 columns for C#.
74 ColumnLimit: 100
Alexander Kornienko092cb212014-08-12 13:34:22 +000075 ...
76
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000077An easy way to get a valid ``.clang-format`` file containing all configuration
78options of a certain predefined style is:
79
80.. code-block:: console
81
82 clang-format -style=llvm -dump-config > .clang-format
83
84When specifying configuration in the ``-style=`` option, the same configuration
85is applied for all input files. The format of the configuration is:
86
87.. code-block:: console
88
89 -style='{key1: value1, key2: value2, ...}'
90
91
Daniel Jasperd8b4ec02014-10-07 12:15:15 +000092Disabling Formatting on a Piece of Code
93=======================================
94
95Clang-format understands also special comments that switch formatting in a
96delimited range. The code between a comment ``// clang-format off`` or
97``/* clang-format off */`` up to a comment ``// clang-format on`` or
98``/* clang-format on */`` will not be formatted. The comments themselves
99will be formatted (aligned) normally.
100
101.. code-block:: c++
102
103 int formatted_code;
104 // clang-format off
105 void unformatted_code ;
106 // clang-format on
107 void formatted_code_again;
108
109
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000110Configuring Style in Code
111=========================
112
113When using ``clang::format::reformat(...)`` functions, the format is specified
114by supplying the `clang::format::FormatStyle
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000115<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000116structure.
117
118
119Configurable Format Style Options
120=================================
121
122This section lists the supported style options. Value type is specified for
123each option. For enumeration types possible values are specified both as a C++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000124enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
125the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000126
127
128**BasedOnStyle** (``string``)
129 The style used for all options not specifically set in the configuration.
130
131 This option is supported only in the :program:`clang-format` configuration
132 (both within ``-style='{...}'`` and the ``.clang-format`` file).
133
134 Possible values:
135
136 * ``LLVM``
137 A style complying with the `LLVM coding standards
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000138 <https://llvm.org/docs/CodingStandards.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000139 * ``Google``
140 A style complying with `Google's C++ style guide
141 <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
142 * ``Chromium``
143 A style complying with `Chromium's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000144 <https://www.chromium.org/developers/coding-style>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000145 * ``Mozilla``
146 A style complying with `Mozilla's style guide
147 <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
148 * ``WebKit``
149 A style complying with `WebKit's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000150 <https://www.webkit.org/coding/coding-style.html>`_
Paul Hoadcbb726d2019-03-21 13:09:22 +0000151 * ``Microsoft``
152 A style complying with `Microsoft's style guide
153 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000154
155.. START_FORMAT_STYLE_OPTIONS
156
157**AccessModifierOffset** (``int``)
Alexander Kornienkoe99a3a32016-02-23 16:12:08 +0000158 The extra indent or outdent of access modifiers, e.g. ``public:``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000159
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000160**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
Daniel Jasper3219e432014-12-02 13:24:51 +0000161 If ``true``, horizontally aligns arguments after an open bracket.
162
163 This applies to round brackets (parentheses), angle brackets and square
Alexander Kornienko1e048232016-02-23 16:11:51 +0000164 brackets.
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000165
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000166 Possible values:
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000167
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000168 * ``BAS_Align`` (in configuration: ``Align``)
169 Align parameters on the open bracket, e.g.:
170
171 .. code-block:: c++
172
173 someLongFunction(argument1,
174 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000175
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000176 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
177 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
178
179 .. code-block:: c++
180
181 someLongFunction(argument1,
182 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000183
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000184 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
185 Always break after an open bracket, if the parameters don't fit
186 on a single line, e.g.:
187
188 .. code-block:: c++
189
190 someLongFunction(
191 argument1, argument2);
192
Daniel Jasper3219e432014-12-02 13:24:51 +0000193
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000194
Daniel Jaspera44991332015-04-29 13:06:49 +0000195**AlignConsecutiveAssignments** (``bool``)
196 If ``true``, aligns consecutive assignments.
197
198 This will align the assignment operators of consecutive lines. This
199 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000200
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000201 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000202
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000203 int aaaa = 12;
204 int b = 23;
205 int ccc = 23;
206
207**AlignConsecutiveDeclarations** (``bool``)
208 If ``true``, aligns consecutive declarations.
209
210 This will align the declaration names of consecutive lines. This
211 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000212
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000213 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000214
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000215 int aaaa = 12;
216 float b = 23;
217 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000218
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000219**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
220 Options for aligning backslashes in escaped newlines.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000221
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000222 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000223
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000224 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
225 Don't align escaped newlines.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000226
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000227 .. code-block:: c++
228
229 #define A \
230 int aaaa; \
231 int b; \
232 int dddddddddd;
233
234 * ``ENAS_Left`` (in configuration: ``Left``)
235 Align escaped newlines as far left as possible.
236
237 .. code-block:: c++
238
239 true:
240 #define A \
241 int aaaa; \
242 int b; \
243 int dddddddddd;
244
245 false:
246
247 * ``ENAS_Right`` (in configuration: ``Right``)
248 Align escaped newlines in the right-most column.
249
250 .. code-block:: c++
251
252 #define A \
253 int aaaa; \
254 int b; \
255 int dddddddddd;
256
257
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000258
Daniel Jasper3219e432014-12-02 13:24:51 +0000259**AlignOperands** (``bool``)
260 If ``true``, horizontally align operands of binary and ternary
261 expressions.
262
Alexander Kornienko1e048232016-02-23 16:11:51 +0000263 Specifically, this aligns operands of a single expression that needs to be
264 split over multiple lines, e.g.:
265
266 .. code-block:: c++
267
268 int aaa = bbbbbbbbbbbbbbb +
269 ccccccccccccccc;
270
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000271**AlignTrailingComments** (``bool``)
272 If ``true``, aligns trailing comments.
273
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000274 .. code-block:: c++
275
Krasimir Georgiev818da9b2017-11-09 15:41:23 +0000276 true: false:
277 int a; // My comment a vs. int a; // My comment a
278 int b = 2; // comment b int b = 2; // comment about b
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000279
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000280**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000281 If the function declaration doesn't fit on a line,
282 allow putting all parameters of a function declaration onto
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000283 the next line even if ``BinPackParameters`` is ``false``.
284
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000285 .. code-block:: c++
286
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000287 true:
288 void myFunction(
289 int a, int b, int c, int d, int e);
290
291 false:
292 void myFunction(int a,
293 int b,
294 int c,
295 int d,
296 int e);
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000297
Daniel Jasper17605d32014-05-14 09:33:35 +0000298**AllowShortBlocksOnASingleLine** (``bool``)
299 Allows contracting simple braced statements to a single line.
300
301 E.g., this allows ``if (a) { return; }`` to be put on a single line.
302
Daniel Jasperb87899b2014-09-10 13:11:45 +0000303**AllowShortCaseLabelsOnASingleLine** (``bool``)
304 If ``true``, short case labels will be contracted to a single line.
305
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000306 .. code-block:: c++
307
308 true: false:
309 switch (a) { vs. switch (a) {
310 case 1: x = 1; break; case 1:
311 case 2: return; x = 1;
312 } break;
313 case 2:
314 return;
315 }
316
Daniel Jasperb5524822014-04-09 14:05:49 +0000317**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000318 Dependent on the value, ``int f() { return 0; }`` can be put on a
319 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000320
321 Possible values:
322
323 * ``SFS_None`` (in configuration: ``None``)
324 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000325
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000326 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
327 Only merge functions defined inside a class. Same as "inline",
328 except it does not implies "empty": i.e. top level empty functions
329 are not merged either.
330
331 .. code-block:: c++
332
333 class Foo {
334 void f() { foo(); }
335 };
336 void f() {
337 foo();
338 }
339 void f() {
340 }
341
Daniel Jasper3219e432014-12-02 13:24:51 +0000342 * ``SFS_Empty`` (in configuration: ``Empty``)
343 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000344
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000345 .. code-block:: c++
346
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000347 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000348 void f2() {
349 bar2();
350 }
351
Daniel Jasper20580fd2015-06-11 13:31:45 +0000352 * ``SFS_Inline`` (in configuration: ``Inline``)
353 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000354
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000355 .. code-block:: c++
356
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000357 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000358 void f() { foo(); }
359 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000360 void f() {
361 foo();
362 }
363 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000364
Daniel Jasperb5524822014-04-09 14:05:49 +0000365 * ``SFS_All`` (in configuration: ``All``)
366 Merge all functions fitting on a single line.
367
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000368 .. code-block:: c++
369
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000370 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000371 void f() { foo(); }
372 };
373 void f() { bar(); }
374
Paul Hoad15000a12019-03-13 08:26:39 +0000375**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
376 Dependent on the value, ``if (a) return 0;`` can be put on a
377 single line.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000378
Paul Hoad15000a12019-03-13 08:26:39 +0000379 Possible values:
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000380
Paul Hoad15000a12019-03-13 08:26:39 +0000381 * ``SIS_Never`` (in configuration: ``Never``)
382 Do not allow short if functions.
383
384 .. code-block:: c++
385
386 if (a)
387 return;
388 else
389 return;
390
391 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
392 Allow short if functions on the same line, as long as else
393 is not a compound statement.
394
395 .. code-block:: c++
396
397 if (a) return;
398 else
399 return;
400
401 if (a)
402 return;
403 else {
404 return;
405 }
406
407 * ``SIS_Always`` (in configuration: ``Always``)
408 Allow short if statements even if the else is a compound statement.
409
410 .. code-block:: c++
411
412 if (a) return;
413 else {
414 return;
415 }
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000416
417**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000418 If ``true``, ``while (true) continue;`` can be put on a single
419 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000420
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000421**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000422 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000423 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000424
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000425 Possible values:
426
427 * ``DRTBS_None`` (in configuration: ``None``)
428 Break after return type automatically.
429 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000430
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000431 * ``DRTBS_All`` (in configuration: ``All``)
432 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000433
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000434 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000435 Always break after the return types of top-level functions.
436
437
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000438
Zachary Turner448592e2015-12-18 22:20:15 +0000439**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
440 The function declaration return type breaking style to use.
441
442 Possible values:
443
444 * ``RTBS_None`` (in configuration: ``None``)
445 Break after return type automatically.
446 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000447
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000448 .. code-block:: c++
449
450 class A {
451 int f() { return 0; };
452 };
453 int f();
454 int f() { return 1; }
455
Zachary Turner448592e2015-12-18 22:20:15 +0000456 * ``RTBS_All`` (in configuration: ``All``)
457 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000458
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000459 .. code-block:: c++
460
461 class A {
462 int
463 f() {
464 return 0;
465 };
466 };
467 int
468 f();
469 int
470 f() {
471 return 1;
472 }
473
Zachary Turner448592e2015-12-18 22:20:15 +0000474 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
475 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000476
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000477 .. code-block:: c++
478
479 class A {
480 int f() { return 0; };
481 };
482 int
483 f();
484 int
485 f() {
486 return 1;
487 }
488
Zachary Turner448592e2015-12-18 22:20:15 +0000489 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
490 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000491
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000492 .. code-block:: c++
493
494 class A {
495 int
496 f() {
497 return 0;
498 };
499 };
500 int f();
501 int
502 f() {
503 return 1;
504 }
505
Zachary Turner448592e2015-12-18 22:20:15 +0000506 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
507 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000508
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000509 .. code-block:: c++
510
511 class A {
512 int f() { return 0; };
513 };
514 int f();
515 int
516 f() {
517 return 1;
518 }
519
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000520
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000521
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000522**AlwaysBreakBeforeMultilineStrings** (``bool``)
523 If ``true``, always break before multiline string literals.
524
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000525 This flag is mean to make cases where there are multiple multiline strings
526 in a file look more consistent. Thus, it will only take effect if wrapping
527 the string at that point leads to it being indented
528 ``ContinuationIndentWidth`` spaces from the start of the line.
529
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000530 .. code-block:: c++
531
532 true: false:
533 aaaa = vs. aaaa = "bbbb"
534 "bbbb" "cccc";
535 "cccc";
536
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000537**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
538 The template declaration breaking style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000539
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000540 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000541
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000542 * ``BTDS_No`` (in configuration: ``No``)
543 Do not force break before declaration.
544 ``PenaltyBreakTemplateDeclaration`` is taken into account.
545
546 .. code-block:: c++
547
548 template <typename T> T foo() {
549 }
550 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
551 int bbbbbbbbbbbbbbbbbbbbb) {
552 }
553
554 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
555 Force break after template declaration only when the following
556 declaration spans multiple lines.
557
558 .. code-block:: c++
559
560 template <typename T> T foo() {
561 }
562 template <typename T>
563 T foo(int aaaaaaaaaaaaaaaaaaaaa,
564 int bbbbbbbbbbbbbbbbbbbbb) {
565 }
566
567 * ``BTDS_Yes`` (in configuration: ``Yes``)
568 Always break after template declaration.
569
570 .. code-block:: c++
571
572 template <typename T>
573 T foo() {
574 }
575 template <typename T>
576 T foo(int aaaaaaaaaaaaaaaaaaaaa,
577 int bbbbbbbbbbbbbbbbbbbbb) {
578 }
579
580
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000581
Daniel Jasper18210d72014-10-09 09:52:05 +0000582**BinPackArguments** (``bool``)
583 If ``false``, a function call's arguments will either be all on the
584 same line or will have one line each.
585
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000586 .. code-block:: c++
587
588 true:
589 void f() {
590 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
591 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
592 }
593
594 false:
595 void f() {
596 f(aaaaaaaaaaaaaaaaaaaa,
597 aaaaaaaaaaaaaaaaaaaa,
598 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
599 }
600
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000601**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000602 If ``false``, a function declaration's or function definition's
603 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000604
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000605 .. code-block:: c++
606
607 true:
608 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
609 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
610
611 false:
612 void f(int aaaaaaaaaaaaaaaaaaaa,
613 int aaaaaaaaaaaaaaaaaaaa,
614 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
615
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000616**BraceWrapping** (``BraceWrappingFlags``)
617 Control of individual brace wrapping cases.
618
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000619 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
620 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000621
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000622 .. code-block:: yaml
623
624 # Example of usage:
625 BreakBeforeBraces: Custom
626 BraceWrapping:
627 AfterEnum: true
628 AfterStruct: false
629 SplitEmptyFunction: false
630
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000631 Nested configuration flags:
632
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000633
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000634 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000635
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000636 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000637
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000638 true:
639 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000640
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000641 false:
642 class foo
643 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000644
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000645 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000646
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000647 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000648
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000649 true:
650 if (foo())
651 {
652 } else
653 {}
654 for (int i = 0; i < 10; ++i)
655 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000656
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000657 false:
658 if (foo()) {
659 } else {
660 }
661 for (int i = 0; i < 10; ++i) {
662 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000663
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000664 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000665
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000666 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000667
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000668 true:
669 enum X : int
670 {
671 B
672 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000673
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000674 false:
675 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000676
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000677 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000678
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000679 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000680
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000681 true:
682 void foo()
683 {
684 bar();
685 bar2();
686 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000687
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000688 false:
689 void foo() {
690 bar();
691 bar2();
692 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000693
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000694 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000695
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000696 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000697
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000698 true:
699 namespace
700 {
701 int foo();
702 int bar();
703 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000704
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000705 false:
706 namespace {
707 int foo();
708 int bar();
709 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000710
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000711 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
712 @autoreleasepool and @synchronized blocks are wrapped
713 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000714
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000715 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000716
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000717 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000718
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000719 true:
720 struct foo
721 {
722 int x;
723 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000724
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000725 false:
726 struct foo {
727 int x;
728 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000729
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000730 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000731
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000732 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000733
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000734 true:
735 union foo
736 {
737 int x;
738 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000739
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000740 false:
741 union foo {
742 int x;
743 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000744
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000745 * ``bool AfterExternBlock`` Wrap extern blocks.
746
747 .. code-block:: c++
748
749 true:
750 extern "C"
751 {
752 int foo();
753 }
754
755 false:
756 extern "C" {
757 int foo();
758 }
759
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000760 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000761
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000762 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000763
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000764 true:
765 try {
766 foo();
767 }
768 catch () {
769 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000770
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000771 false:
772 try {
773 foo();
774 } catch () {
775 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000776
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000777 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000778
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000779 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000780
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000781 true:
782 if (foo()) {
783 }
784 else {
785 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000786
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000787 false:
788 if (foo()) {
789 } else {
790 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000791
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000792 * ``bool IndentBraces`` Indent the wrapped braces themselves.
793
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000794 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000795 This option is used only if the opening brace of the function has
796 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
797 set, and the function could/should not be put on a single line (as per
798 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000799
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000800 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000801
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000802 int f() vs. inf f()
803 {} {
804 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000805
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000806 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
807 can be put on a single line. This option is used only if the opening
808 brace of the record has already been wrapped, i.e. the `AfterClass`
809 (for classes) brace wrapping mode is set.
810
811 .. code-block:: c++
812
813 class Foo vs. class Foo
814 {} {
815 }
816
817 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
818 This option is used only if the opening brace of the namespace has
819 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
820 set.
821
822 .. code-block:: c++
823
824 namespace Foo vs. namespace Foo
825 {} {
826 }
827
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000828
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000829**BreakAfterJavaFieldAnnotations** (``bool``)
830 Break after each annotation on a field in Java files.
831
Sylvestre Ledrude098242017-04-11 07:07:05 +0000832 .. code-block:: java
833
834 true: false:
835 @Partial vs. @Partial @Mock DataLoad loader;
836 @Mock
837 DataLoad loader;
838
Daniel Jasperac043c92014-09-15 11:11:00 +0000839**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
840 The way to wrap binary operators.
841
842 Possible values:
843
844 * ``BOS_None`` (in configuration: ``None``)
845 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000846
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000847 .. code-block:: c++
848
849 LooooooooooongType loooooooooooooooooooooongVariable =
850 someLooooooooooooooooongFunction();
851
852 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
853 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
854 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
855 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
856 ccccccccccccccccccccccccccccccccccccccccc;
857
Daniel Jasperac043c92014-09-15 11:11:00 +0000858 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
859 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000860
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000861 .. code-block:: c++
862
863 LooooooooooongType loooooooooooooooooooooongVariable =
864 someLooooooooooooooooongFunction();
865
866 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
867 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
868 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
869 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
870 > ccccccccccccccccccccccccccccccccccccccccc;
871
Daniel Jasperac043c92014-09-15 11:11:00 +0000872 * ``BOS_All`` (in configuration: ``All``)
873 Break before operators.
874
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000875 .. code-block:: c++
876
877 LooooooooooongType loooooooooooooooooooooongVariable
878 = someLooooooooooooooooongFunction();
879
880 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
881 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
882 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
883 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
884 > ccccccccccccccccccccccccccccccccccccccccc;
885
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000886
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000887
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000888**BreakBeforeBraces** (``BraceBreakingStyle``)
889 The brace breaking style to use.
890
891 Possible values:
892
893 * ``BS_Attach`` (in configuration: ``Attach``)
894 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000895
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000896 .. code-block:: c++
897
898 try {
899 foo();
900 } catch () {
901 }
902 void foo() { bar(); }
903 class foo {};
904 if (foo()) {
905 } else {
906 }
907 enum X : int { A, B };
908
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000909 * ``BS_Linux`` (in configuration: ``Linux``)
910 Like ``Attach``, but break before braces on function, namespace and
911 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000912
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000913 .. code-block:: c++
914
915 try {
916 foo();
917 } catch () {
918 }
919 void foo() { bar(); }
920 class foo
921 {
922 };
923 if (foo()) {
924 } else {
925 }
926 enum X : int { A, B };
927
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000928 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
929 Like ``Attach``, but break before braces on enum, function, and record
930 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000931
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000932 .. code-block:: c++
933
934 try {
935 foo();
936 } catch () {
937 }
938 void foo() { bar(); }
939 class foo
940 {
941 };
942 if (foo()) {
943 } else {
944 }
945 enum X : int { A, B };
946
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000947 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000948 Like ``Attach``, but break before function definitions, ``catch``, and
949 ``else``.
950
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000951 .. code-block:: c++
952
953 try {
954 foo();
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000955 }
956 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000957 }
958 void foo() { bar(); }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000959 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000960 };
961 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000962 }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000963 else {
964 }
965 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000966
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000967 * ``BS_Allman`` (in configuration: ``Allman``)
968 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000969
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000970 .. code-block:: c++
971
Jan Korous3fd4a962019-03-05 01:45:31 +0000972 try
973 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000974 foo();
975 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000976 catch ()
977 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000978 }
979 void foo() { bar(); }
Jan Korous3fd4a962019-03-05 01:45:31 +0000980 class foo
981 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000982 };
Jan Korous3fd4a962019-03-05 01:45:31 +0000983 if (foo())
984 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000985 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000986 else
987 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000988 }
Jan Korous3fd4a962019-03-05 01:45:31 +0000989 enum X : int
990 {
991 A,
992 B
993 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000994
Daniel Jasperee107ad2014-02-13 12:51:50 +0000995 * ``BS_GNU`` (in configuration: ``GNU``)
996 Always break before braces and add an extra level of indentation to
997 braces of control statements, not to those of class, function
998 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000999
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001000 .. code-block:: c++
1001
1002 try
1003 {
1004 foo();
1005 }
1006 catch ()
1007 {
1008 }
1009 void foo() { bar(); }
1010 class foo
1011 {
1012 };
1013 if (foo())
1014 {
1015 }
1016 else
1017 {
1018 }
1019 enum X : int
1020 {
1021 A,
1022 B
1023 };
1024
Roman Kashitsyn291f64f2015-08-10 13:43:19 +00001025 * ``BS_WebKit`` (in configuration: ``WebKit``)
1026 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001027
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001028 .. code-block:: c++
1029
1030 try {
1031 foo();
1032 } catch () {
1033 }
1034 void foo() { bar(); }
1035 class foo {
1036 };
1037 if (foo()) {
1038 } else {
1039 }
1040 enum X : int { A, B };
1041
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001042 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001043 Configure each individual brace in `BraceWrapping`.
1044
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001045
1046
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001047**BreakBeforeTernaryOperators** (``bool``)
1048 If ``true``, ternary operators will be placed after line breaks.
1049
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001050 .. code-block:: c++
1051
1052 true:
1053 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1054 ? firstValue
1055 : SecondValueVeryVeryVeryVeryLong;
1056
Sylvestre Ledru121224d2017-06-06 07:26:19 +00001057 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001058 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1059 firstValue :
1060 SecondValueVeryVeryVeryVeryLong;
1061
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001062**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1063 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001064
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001065 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001066
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001067 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1068 Break constructor initializers before the colon and after the commas.
1069
1070 .. code-block:: c++
1071
Francois Ferrand767e1522018-06-14 13:32:14 +00001072 Constructor()
1073 : initializer1(),
1074 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001075
1076 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1077 Break constructor initializers before the colon and commas, and align
1078 the commas with the colon.
1079
1080 .. code-block:: c++
1081
Francois Ferrand767e1522018-06-14 13:32:14 +00001082 Constructor()
1083 : initializer1()
1084 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001085
1086 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1087 Break constructor initializers after the colon and commas.
1088
1089 .. code-block:: c++
1090
Francois Ferrand767e1522018-06-14 13:32:14 +00001091 Constructor() :
1092 initializer1(),
1093 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001094
1095
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001096
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001097**BreakInheritanceList** (``BreakInheritanceListStyle``)
1098 The inheritance list style to use.
1099
1100 Possible values:
1101
1102 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1103 Break inheritance list before the colon and after the commas.
1104
1105 .. code-block:: c++
1106
Francois Ferrand767e1522018-06-14 13:32:14 +00001107 class Foo
1108 : Base1,
1109 Base2
1110 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001111
1112 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1113 Break inheritance list before the colon and commas, and align
1114 the commas with the colon.
1115
1116 .. code-block:: c++
1117
Francois Ferrand767e1522018-06-14 13:32:14 +00001118 class Foo
1119 : Base1
1120 , Base2
1121 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001122
1123 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1124 Break inheritance list after the colon and commas.
1125
1126 .. code-block:: c++
1127
Francois Ferrand767e1522018-06-14 13:32:14 +00001128 class Foo :
1129 Base1,
1130 Base2
1131 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001132
1133
1134
Alexander Kornienko1e048232016-02-23 16:11:51 +00001135**BreakStringLiterals** (``bool``)
1136 Allow breaking string literals when formatting.
1137
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001138**ColumnLimit** (``unsigned``)
1139 The column limit.
1140
1141 A column limit of ``0`` means that there is no column limit. In this case,
1142 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001143 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001144
Daniel Jasperee107ad2014-02-13 12:51:50 +00001145**CommentPragmas** (``std::string``)
1146 A regular expression that describes comments with special meaning,
1147 which should not be split into lines or otherwise changed.
1148
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001149 .. code-block:: c++
1150
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001151 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001152 // Will leave the following line unaffected
1153 #include <vector> // FOOBAR pragma: keep
1154
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001155**CompactNamespaces** (``bool``)
1156 If ``true``, consecutive namespace declarations will be on the same
1157 line. If ``false``, each namespace is declared on a new line.
1158
1159 .. code-block:: c++
1160
1161 true:
1162 namespace Foo { namespace Bar {
1163 }}
1164
1165 false:
1166 namespace Foo {
1167 namespace Bar {
1168 }
1169 }
1170
1171 If it does not fit on a single line, the overflowing namespaces get
1172 wrapped:
1173
1174 .. code-block:: c++
1175
1176 namespace Foo { namespace Bar {
1177 namespace Extra {
1178 }}}
1179
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001180**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1181 If the constructor initializers don't fit on a line, put each
1182 initializer on its own line.
1183
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001184 .. code-block:: c++
1185
1186 true:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001187 SomeClass::Constructor()
1188 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1189 return 0;
1190 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001191
1192 false:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001193 SomeClass::Constructor()
1194 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1195 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1196 return 0;
1197 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001198
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001199**ConstructorInitializerIndentWidth** (``unsigned``)
1200 The number of characters to use for indentation of constructor
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001201 initializer lists as well as inheritance lists.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001202
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001203**ContinuationIndentWidth** (``unsigned``)
1204 Indent width for line continuations.
1205
Sylvestre Ledrude098242017-04-11 07:07:05 +00001206 .. code-block:: c++
1207
1208 ContinuationIndentWidth: 2
1209
1210 int i = // VeryVeryVeryVeryVeryLongComment
1211 longFunction( // Again a long comment
1212 arg);
1213
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001214**Cpp11BracedListStyle** (``bool``)
1215 If ``true``, format braced lists as best suited for C++11 braced
1216 lists.
1217
1218 Important differences:
1219 - No spaces inside the braced list.
1220 - No line break before the closing brace.
1221 - Indentation with the continuation indent, not with the block indent.
1222
1223 Fundamentally, C++11 braced lists are formatted exactly like function
1224 calls would be formatted in their place. If the braced list follows a name
1225 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1226 the parentheses of a function call with that name. If there is no name,
1227 a zero-length name is assumed.
1228
Sylvestre Ledrude098242017-04-11 07:07:05 +00001229 .. code-block:: c++
1230
1231 true: false:
1232 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1233 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1234 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1235 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1236
Daniel Jasper553d4872014-06-17 12:40:34 +00001237**DerivePointerAlignment** (``bool``)
1238 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001239 alignment of ``&`` and ``*``.
1240 Pointer and reference alignment styles are going to be updated according
1241 to the preferences found in the file.
1242 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001243
1244**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001245 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001246
1247**ExperimentalAutoDetectBinPacking** (``bool``)
1248 If ``true``, clang-format detects whether function calls and
1249 definitions are formatted with one parameter per line.
1250
1251 Each call can be bin-packed, one-per-line or inconclusive. If it is
1252 inconclusive, e.g. completely on one line, but a decision needs to be
1253 made, clang-format analyzes whether there are other bin-packed cases in
1254 the input file and act accordingly.
1255
1256 NOTE: This is an experimental flag, that might go away or be renamed. Do
1257 not use this in config files, etc. Use at your own risk.
1258
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001259**FixNamespaceComments** (``bool``)
1260 If ``true``, clang-format adds missing namespace end comments and
1261 fixes invalid existing ones.
1262
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001263 .. code-block:: c++
1264
1265 true: false:
1266 namespace a { vs. namespace a {
1267 foo(); foo();
1268 } // namespace a; }
1269
Daniel Jaspere1e43192014-04-01 12:55:11 +00001270**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001271 A vector of macros that should be interpreted as foreach loops
1272 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001273
Daniel Jasperb5524822014-04-09 14:05:49 +00001274 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001275
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001276 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001277
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001278 FOREACH(<variable-declaration>, ...)
1279 <loop-body>
1280
1281 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001282
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001283 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001284
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001285 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001286
1287 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001288
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001289**IncludeBlocks** (``IncludeBlocksStyle``)
1290 Dependent on the value, multiple ``#include`` blocks can be sorted
1291 as one and divided based on category.
1292
1293 Possible values:
1294
1295 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1296 Sort each ``#include`` block separately.
1297
1298 .. code-block:: c++
1299
1300 #include "b.h" into #include "b.h"
1301
1302 #include <lib/main.h> #include "a.h"
1303 #include "a.h" #include <lib/main.h>
1304
1305 * ``IBS_Merge`` (in configuration: ``Merge``)
1306 Merge multiple ``#include`` blocks together and sort as one.
1307
1308 .. code-block:: c++
1309
1310 #include "b.h" into #include "a.h"
1311 #include "b.h"
1312 #include <lib/main.h> #include <lib/main.h>
1313 #include "a.h"
1314
1315 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1316 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001317 Then split into groups based on category priority. See
1318 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001319
1320 .. code-block:: c++
1321
1322 #include "b.h" into #include "a.h"
1323 #include "b.h"
1324 #include <lib/main.h>
1325 #include "a.h" #include <lib/main.h>
1326
1327
1328
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001329**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001330 Regular expressions denoting the different ``#include`` categories
1331 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001332
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001333 `POSIX extended
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +00001334 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001335 regular expressions are supported.
1336
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001337 These regular expressions are matched against the filename of an include
1338 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001339 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001340 according to increasing category number and then alphabetically within
1341 each category.
1342
Alexander Kornienko1e048232016-02-23 16:11:51 +00001343 If none of the regular expressions match, INT_MAX is assigned as
1344 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001345 so that it is generally kept at the beginning of the ``#includes``
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +00001346 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
Alexander Kornienko1e048232016-02-23 16:11:51 +00001347 can also assign negative priorities if you have certain headers that
1348 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001349
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001350 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001351
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001352 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001353
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001354 IncludeCategories:
1355 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1356 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001357 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001358 Priority: 3
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001359 - Regex: '<[[:alnum:].]+>'
1360 Priority: 4
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001361 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001362 Priority: 1
1363
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001364**IncludeIsMainRegex** (``std::string``)
1365 Specify a regular expression of suffixes that are allowed in the
1366 file-to-main-include mapping.
1367
1368 When guessing whether a #include is the "main" include (to assign
1369 category 0, see above), use this regex of allowed suffixes to the header
1370 stem. A partial match is done, so that:
1371 - "" means "arbitrary suffix"
1372 - "$" means "no suffix"
1373
1374 For example, if configured to "(_test)?$", then a header a.h would be seen
1375 as the "main" include in both a.cc and a_test.cc.
1376
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001377**IndentCaseLabels** (``bool``)
1378 Indent case labels one level from the switch statement.
1379
1380 When ``false``, use the same indentation level as for the switch statement.
1381 Switch statement body is always indented one level more than case labels.
1382
Sylvestre Ledrude098242017-04-11 07:07:05 +00001383 .. code-block:: c++
1384
1385 false: true:
1386 switch (fool) { vs. switch (fool) {
1387 case 1: case 1:
1388 bar(); bar();
1389 break; break;
1390 default: default:
1391 plop(); plop();
1392 } }
1393
Krasimir Georgievad47c902017-08-30 14:34:57 +00001394**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001395 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001396
1397 Possible values:
1398
1399 * ``PPDIS_None`` (in configuration: ``None``)
1400 Does not indent any directives.
1401
1402 .. code-block:: c++
1403
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001404 #if FOO
1405 #if BAR
1406 #include <foo>
1407 #endif
1408 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001409
1410 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1411 Indents directives after the hash.
1412
1413 .. code-block:: c++
1414
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001415 #if FOO
1416 # if BAR
1417 # include <foo>
1418 # endif
1419 #endif
1420
Paul Hoad701a0d72019-03-20 20:49:43 +00001421 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1422 Indents directives before the hash.
1423
1424 .. code-block:: c++
1425
1426 #if FOO
1427 #if BAR
1428 #include <foo>
1429 #endif
1430 #endif
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001431
Krasimir Georgievad47c902017-08-30 14:34:57 +00001432
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001433**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001434 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001435
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001436 .. code-block:: c++
1437
1438 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001439
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001440 void f() {
1441 someFunction();
1442 if (true, false) {
1443 f();
1444 }
1445 }
1446
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001447**IndentWrappedFunctionNames** (``bool``)
1448 Indent if a function definition or declaration is wrapped after the
1449 type.
1450
Sylvestre Ledrude098242017-04-11 07:07:05 +00001451 .. code-block:: c++
1452
1453 true:
1454 LoooooooooooooooooooooooooooooooooooooooongReturnType
1455 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1456
1457 false:
1458 LoooooooooooooooooooooooooooooooooooooooongReturnType
1459 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1460
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001461**JavaImportGroups** (``std::vector<std::string>``)
1462 A vector of prefixes ordered by the desired groups for Java imports.
1463
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001464 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001465 same grouping convention above all non-static imports. One group's prefix
1466 can be a subset of another - the longest prefix is always matched. Within
1467 a group, the imports are ordered lexicographically.
1468
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001469 In the .clang-format configuration file, this can be configured like
1470 in the following yaml example. This will result in imports being
1471 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001472
1473 .. code-block:: yaml
1474
1475 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001476
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001477
1478 .. code-block:: java
1479
1480 import static com.example.function1;
1481
1482 import static com.test.function2;
1483
1484 import static org.example.function3;
1485
1486 import com.example.ClassA;
1487 import com.example.Test;
1488 import com.example.a.ClassB;
1489
1490 import com.test.ClassC;
1491
1492 import org.example.ClassD;
1493
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001494**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1495 The JavaScriptQuoteStyle to use for JavaScript strings.
1496
1497 Possible values:
1498
1499 * ``JSQS_Leave`` (in configuration: ``Leave``)
1500 Leave string quotes as they are.
1501
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001502 .. code-block:: js
1503
1504 string1 = "foo";
1505 string2 = 'bar';
1506
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001507 * ``JSQS_Single`` (in configuration: ``Single``)
1508 Always use single quotes.
1509
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001510 .. code-block:: js
1511
1512 string1 = 'foo';
1513 string2 = 'bar';
1514
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001515 * ``JSQS_Double`` (in configuration: ``Double``)
1516 Always use double quotes.
1517
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001518 .. code-block:: js
1519
1520 string1 = "foo";
1521 string2 = "bar";
1522
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001523
1524
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001525**JavaScriptWrapImports** (``bool``)
1526 Whether to wrap JavaScript import/export statements.
1527
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001528 .. code-block:: js
1529
1530 true:
1531 import {
1532 VeryLongImportsAreAnnoying,
1533 VeryLongImportsAreAnnoying,
1534 VeryLongImportsAreAnnoying,
1535 } from 'some/module.js'
1536
1537 false:
1538 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1539
Daniel Jasperb5524822014-04-09 14:05:49 +00001540**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001541 If true, the empty line at the start of blocks is kept.
1542
1543 .. code-block:: c++
1544
1545 true: false:
1546 if (foo) { vs. if (foo) {
1547 bar();
1548 bar(); }
1549 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001550
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001551**Language** (``LanguageKind``)
1552 Language, this format style is targeted at.
1553
1554 Possible values:
1555
1556 * ``LK_None`` (in configuration: ``None``)
1557 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001558
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001559 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001560 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001561
Paul Hoadcbb726d2019-03-21 13:09:22 +00001562 * ``LK_CSharp`` (in configuration: ``CSharp``)
1563 Should be used for C#.
1564
Daniel Jasper18210d72014-10-09 09:52:05 +00001565 * ``LK_Java`` (in configuration: ``Java``)
1566 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001567
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001568 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1569 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001570
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001571 * ``LK_ObjC`` (in configuration: ``ObjC``)
1572 Should be used for Objective-C, Objective-C++.
1573
Daniel Jasperee107ad2014-02-13 12:51:50 +00001574 * ``LK_Proto`` (in configuration: ``Proto``)
1575 Should be used for Protocol Buffers
1576 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001577
Alexander Kornienko1e048232016-02-23 16:11:51 +00001578 * ``LK_TableGen`` (in configuration: ``TableGen``)
1579 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001580
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001581 * ``LK_TextProto`` (in configuration: ``TextProto``)
1582 Should be used for Protocol Buffer messages in text format
1583 (https://developers.google.com/protocol-buffers/).
1584
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001585
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001586
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001587**MacroBlockBegin** (``std::string``)
1588 A regular expression matching macros that start a block.
1589
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001590 .. code-block:: c++
1591
1592 # With:
1593 MacroBlockBegin: "^NS_MAP_BEGIN|\
1594 NS_TABLE_HEAD$"
1595 MacroBlockEnd: "^\
1596 NS_MAP_END|\
1597 NS_TABLE_.*_END$"
1598
1599 NS_MAP_BEGIN
1600 foo();
1601 NS_MAP_END
1602
1603 NS_TABLE_HEAD
1604 bar();
1605 NS_TABLE_FOO_END
1606
1607 # Without:
1608 NS_MAP_BEGIN
1609 foo();
1610 NS_MAP_END
1611
1612 NS_TABLE_HEAD
1613 bar();
1614 NS_TABLE_FOO_END
1615
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001616**MacroBlockEnd** (``std::string``)
1617 A regular expression matching macros that end a block.
1618
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001619**MaxEmptyLinesToKeep** (``unsigned``)
1620 The maximum number of consecutive empty lines to keep.
1621
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001622 .. code-block:: c++
1623
1624 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1625 int f() { int f() {
1626 int = 1; int i = 1;
1627 i = foo();
1628 i = foo(); return i;
1629 }
1630 return i;
1631 }
1632
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001633**NamespaceIndentation** (``NamespaceIndentationKind``)
1634 The indentation used for namespaces.
1635
1636 Possible values:
1637
1638 * ``NI_None`` (in configuration: ``None``)
1639 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001640
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001641 .. code-block:: c++
1642
1643 namespace out {
1644 int i;
1645 namespace in {
1646 int i;
1647 }
1648 }
1649
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001650 * ``NI_Inner`` (in configuration: ``Inner``)
1651 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001652
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001653 .. code-block:: c++
1654
1655 namespace out {
1656 int i;
1657 namespace in {
1658 int i;
1659 }
1660 }
1661
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001662 * ``NI_All`` (in configuration: ``All``)
1663 Indent in all namespaces.
1664
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001665 .. code-block:: c++
1666
1667 namespace out {
1668 int i;
1669 namespace in {
1670 int i;
1671 }
1672 }
1673
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001674
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001675
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001676**ObjCBinPackProtocolList** (``BinPackStyle``)
1677 Controls bin-packing Objective-C protocol conformance list
1678 items into as few lines as possible when they go over ``ColumnLimit``.
1679
1680 If ``Auto`` (the default), delegates to the value in
1681 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1682 protocol conformance list items into as few lines as possible
1683 whenever they go over ``ColumnLimit``.
1684
1685 If ``Always``, always bin-packs Objective-C protocol conformance
1686 list items into as few lines as possible whenever they go over
1687 ``ColumnLimit``.
1688
1689 If ``Never``, lays out Objective-C protocol conformance list items
1690 onto individual lines whenever they go over ``ColumnLimit``.
1691
1692
Aaron Ballman37485fd2018-06-28 12:02:38 +00001693 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001694
1695 Always (or Auto, if BinPackParameters=true):
1696 @interface ccccccccccccc () <
1697 ccccccccccccc, ccccccccccccc,
1698 ccccccccccccc, ccccccccccccc> {
1699 }
1700
1701 Never (or Auto, if BinPackParameters=false):
1702 @interface ddddddddddddd () <
1703 ddddddddddddd,
1704 ddddddddddddd,
1705 ddddddddddddd,
1706 ddddddddddddd> {
1707 }
1708
1709 Possible values:
1710
1711 * ``BPS_Auto`` (in configuration: ``Auto``)
1712 Automatically determine parameter bin-packing behavior.
1713
1714 * ``BPS_Always`` (in configuration: ``Always``)
1715 Always bin-pack parameters.
1716
1717 * ``BPS_Never`` (in configuration: ``Never``)
1718 Never bin-pack parameters.
1719
1720
1721
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001722**ObjCBlockIndentWidth** (``unsigned``)
1723 The number of characters to use for indentation of ObjC blocks.
1724
Sylvestre Ledrude098242017-04-11 07:07:05 +00001725 .. code-block:: objc
1726
1727 ObjCBlockIndentWidth: 4
1728
1729 [operation setCompletionBlock:^{
1730 [self onOperationDone];
1731 }];
1732
Daniel Jasperee107ad2014-02-13 12:51:50 +00001733**ObjCSpaceAfterProperty** (``bool``)
1734 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001735 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001736
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001737**ObjCSpaceBeforeProtocolList** (``bool``)
1738 Add a space in front of an Objective-C protocol list, i.e. use
1739 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1740
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001741**PenaltyBreakAssignment** (``unsigned``)
1742 The penalty for breaking around an assignment operator.
1743
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001744**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001745 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001746
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001747**PenaltyBreakComment** (``unsigned``)
1748 The penalty for each line break introduced inside a comment.
1749
1750**PenaltyBreakFirstLessLess** (``unsigned``)
1751 The penalty for breaking before the first ``<<``.
1752
1753**PenaltyBreakString** (``unsigned``)
1754 The penalty for each line break introduced inside a string literal.
1755
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001756**PenaltyBreakTemplateDeclaration** (``unsigned``)
1757 The penalty for breaking after template declaration.
1758
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001759**PenaltyExcessCharacter** (``unsigned``)
1760 The penalty for each character outside of the column limit.
1761
1762**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1763 Penalty for putting the return type of a function onto its own
1764 line.
1765
Daniel Jasper553d4872014-06-17 12:40:34 +00001766**PointerAlignment** (``PointerAlignmentStyle``)
1767 Pointer and reference alignment style.
1768
1769 Possible values:
1770
1771 * ``PAS_Left`` (in configuration: ``Left``)
1772 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001773
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001774 .. code-block:: c++
1775
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001776 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001777
Daniel Jasper553d4872014-06-17 12:40:34 +00001778 * ``PAS_Right`` (in configuration: ``Right``)
1779 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001780
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001781 .. code-block:: c++
1782
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001783 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001784
Daniel Jasper553d4872014-06-17 12:40:34 +00001785 * ``PAS_Middle`` (in configuration: ``Middle``)
1786 Align pointer in the middle.
1787
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001788 .. code-block:: c++
1789
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001790 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001791
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001792
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001793
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001794**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001795 Defines hints for detecting supported languages code blocks in raw
1796 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001797
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001798 A raw string with a matching delimiter or a matching enclosing function
1799 name will be reformatted assuming the specified language based on the
1800 style for that language defined in the .clang-format file. If no style has
1801 been defined in the .clang-format file for the specific language, a
1802 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1803 found, the formatting is based on llvm style. A matching delimiter takes
1804 precedence over a matching enclosing function name for determining the
1805 language of the raw string contents.
1806
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001807 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001808 the same language will be updated to the canonical if possible.
1809
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001810 There should be at most one specification per language and each delimiter
1811 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001812
1813 To configure this in the .clang-format file, use:
1814
1815 .. code-block:: yaml
1816
1817 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001818 - Language: TextProto
1819 Delimiters:
1820 - 'pb'
1821 - 'proto'
1822 EnclosingFunctions:
1823 - 'PARSE_TEXT_PROTO'
1824 BasedOnStyle: google
1825 - Language: Cpp
1826 Delimiters:
1827 - 'cc'
1828 - 'cpp'
1829 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001830 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001831
Alexander Kornienko1e048232016-02-23 16:11:51 +00001832**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001833 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001834
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001835 .. code-block:: c++
1836
1837 false:
1838 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1839 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1840
1841 true:
1842 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1843 // information
1844 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1845 * information */
1846
Alexander Kornienko1e048232016-02-23 16:11:51 +00001847**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001848 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001849
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001850 .. code-block:: c++
1851
1852 false: true:
1853 #include "b.h" vs. #include "a.h"
1854 #include "a.h" #include "b.h"
1855
Krasimir Georgievac16a202017-06-23 11:46:03 +00001856**SortUsingDeclarations** (``bool``)
1857 If ``true``, clang-format will sort using declarations.
1858
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001859 The order of using declarations is defined as follows:
1860 Split the strings by "::" and discard any initial empty strings. The last
1861 element of each list is a non-namespace name; all others are namespace
1862 names. Sort the lists of names lexicographically, where the sort order of
1863 individual names is that all non-namespace names come before all namespace
1864 names, and within those groups, names are in case-insensitive
1865 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001866
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001867 .. code-block:: c++
1868
1869 false: true:
1870 using std::cout; vs. using std::cin;
1871 using std::cin; using std::cout;
1872
Daniel Jasperb87899b2014-09-10 13:11:45 +00001873**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001874 If ``true``, a space is inserted after C style casts.
1875
1876 .. code-block:: c++
1877
1878 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001879 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001880
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001881**SpaceAfterTemplateKeyword** (``bool``)
1882 If ``true``, a space will be inserted after the 'template' keyword.
1883
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001884 .. code-block:: c++
1885
1886 true: false:
1887 template <int> void foo(); vs. template<int> void foo();
1888
Daniel Jasperd94bff32013-09-25 15:15:02 +00001889**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001890 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001891
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001892 .. code-block:: c++
1893
1894 true: false:
1895 int a = 5; vs. int a=5;
1896 a += 42 a+=42;
1897
Hans Wennborgbfc34062018-06-14 08:01:09 +00001898**SpaceBeforeCpp11BracedList** (``bool``)
1899 If ``true``, a space will be inserted before a C++11 braced list
1900 used to initialize an object (after the preceding identifier or type).
1901
1902 .. code-block:: c++
1903
1904 true: false:
1905 Foo foo { bar }; vs. Foo foo{ bar };
1906 Foo {}; Foo{};
1907 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1908 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1909
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001910**SpaceBeforeCtorInitializerColon** (``bool``)
1911 If ``false``, spaces will be removed before constructor initializer
1912 colon.
1913
1914 .. code-block:: c++
1915
1916 true: false:
1917 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1918
1919**SpaceBeforeInheritanceColon** (``bool``)
1920 If ``false``, spaces will be removed before inheritance colon.
1921
1922 .. code-block:: c++
1923
1924 true: false:
1925 class Foo : Bar {} vs. class Foo: Bar {}
1926
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001927**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1928 Defines in which cases to put a space before opening parentheses.
1929
1930 Possible values:
1931
1932 * ``SBPO_Never`` (in configuration: ``Never``)
1933 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001934
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001935 .. code-block:: c++
1936
1937 void f() {
1938 if(true) {
1939 f();
1940 }
1941 }
1942
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001943 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1944 Put a space before opening parentheses only after control statement
1945 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001946
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001947 .. code-block:: c++
1948
1949 void f() {
1950 if (true) {
1951 f();
1952 }
1953 }
1954
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001955 * ``SBPO_Always`` (in configuration: ``Always``)
1956 Always put a space before opening parentheses, except when it's
1957 prohibited by the syntax rules (in function-like macro definitions) or
1958 when determined by other style rules (after unary operators, opening
1959 parentheses, etc.)
1960
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001961 .. code-block:: c++
1962
1963 void f () {
1964 if (true) {
1965 f ();
1966 }
1967 }
1968
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001969
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001970
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001971**SpaceBeforeRangeBasedForLoopColon** (``bool``)
1972 If ``false``, spaces will be removed before range-based for loop
1973 colon.
1974
1975 .. code-block:: c++
1976
1977 true: false:
1978 for (auto v : values) {} vs. for(auto v: values) {}
1979
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001980**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001981 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001982
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001983 .. code-block:: c++
1984
1985 true: false:
1986 void f( ) { vs. void f() {
1987 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1988 if (true) { if (true) {
1989 f( ); f();
1990 } }
1991 } }
1992
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001993**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00001994 The number of spaces before trailing line comments
1995 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00001996
Alexander Kornienko70f97c92016-02-27 14:02:08 +00001997 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001998 those commonly have different usage patterns and a number of special
1999 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002000
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002001 .. code-block:: c++
2002
2003 SpacesBeforeTrailingComments: 3
2004 void f() {
2005 if (true) { // foo1
2006 f(); // bar
2007 } // foo
2008 }
2009
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002010**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002011 If ``true``, spaces will be inserted after ``<`` and before ``>``
2012 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002013
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002014 .. code-block:: c++
2015
2016 true: false:
2017 static_cast< int >(arg); vs. static_cast<int>(arg);
2018 std::function< void(int) > fct; std::function<void(int)> fct;
2019
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002020**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002021 If ``true``, spaces may be inserted into C style casts.
2022
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002023 .. code-block:: c++
2024
2025 true: false:
2026 x = ( int32 )y vs. x = (int32)y
2027
Daniel Jasperee107ad2014-02-13 12:51:50 +00002028**SpacesInContainerLiterals** (``bool``)
2029 If ``true``, spaces are inserted inside container literals (e.g.
2030 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002031
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002032 .. code-block:: js
2033
2034 true: false:
2035 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2036 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2037
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002038**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002039 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002040
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002041 .. code-block:: c++
2042
2043 true: false:
2044 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2045
Daniel Jasperad981f82014-08-26 11:41:14 +00002046**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002047 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002048 Lambdas or unspecified size array declarations will not be affected.
2049
2050 .. code-block:: c++
2051
2052 true: false:
2053 int a[ 5 ]; vs. int a[5];
2054 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002055
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002056**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002057 Format compatible with this standard, e.g. use ``A<A<int> >``
2058 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002059
2060 Possible values:
2061
2062 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2063 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002064
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002065 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002066 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002067 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002068
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002069 * ``LS_Auto`` (in configuration: ``Auto``)
2070 Automatic detection based on the input.
2071
2072
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002073
Francois Ferrand6f40e212018-10-02 16:37:51 +00002074**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002075 A vector of macros that should be interpreted as complete
2076 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002077
2078 Typical macros are expressions, and require a semi-colon to be
2079 added; sometimes this is not the case, and this allows to make
2080 clang-format aware of such cases.
2081
2082 For example: Q_UNUSED
2083
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002084**TabWidth** (``unsigned``)
2085 The number of columns used for tab stops.
2086
2087**UseTab** (``UseTabStyle``)
2088 The way to use tab characters in the resulting file.
2089
2090 Possible values:
2091
2092 * ``UT_Never`` (in configuration: ``Never``)
2093 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002094
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002095 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2096 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002097
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002098 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2099 Use tabs only for line continuation and indentation.
2100
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002101 * ``UT_Always`` (in configuration: ``Always``)
2102 Use tabs whenever we need to fill whitespace that spans at least from
2103 one tab stop to the next one.
2104
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002105
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002106
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002107.. END_FORMAT_STYLE_OPTIONS
2108
Daniel Jasper49d3d582015-10-05 07:24:55 +00002109Adding additional style options
2110===============================
2111
2112Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002113these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002114sure that any given combination of options work and that new features don't
2115break any of the existing options in any way. There are also costs for end users
2116as options become less discoverable and people have to think about and make a
2117decision on options they don't really care about.
2118
2119The goal of the clang-format project is more on the side of supporting a
2120limited set of styles really well as opposed to supporting every single style
2121used by a codebase somewhere in the wild. Of course, we do want to support all
2122major projects and thus have established the following bar for adding style
2123options. Each new style option must ..
2124
Daniel Jasperfcbea712015-10-05 13:30:42 +00002125 * be used in a project of significant size (have dozens of contributors)
2126 * have a publicly accessible style guide
2127 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002128
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002129Examples
2130========
2131
2132A style similar to the `Linux Kernel style
2133<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2134
2135.. code-block:: yaml
2136
2137 BasedOnStyle: LLVM
2138 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002139 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002140 BreakBeforeBraces: Linux
2141 AllowShortIfStatementsOnASingleLine: false
2142 IndentCaseLabels: false
2143
2144The result is (imagine that tabs are used for indentation here):
2145
2146.. code-block:: c++
2147
2148 void test()
2149 {
2150 switch (x) {
2151 case 0:
2152 case 1:
2153 do_something();
2154 break;
2155 case 2:
2156 do_something_else();
2157 break;
2158 default:
2159 break;
2160 }
2161 if (condition)
2162 do_something_completely_different();
2163
2164 if (x == y) {
2165 q();
2166 } else if (x > y) {
2167 w();
2168 } else {
2169 r();
2170 }
2171 }
2172
2173A style similar to the default Visual Studio formatting style:
2174
2175.. code-block:: yaml
2176
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002177 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002178 IndentWidth: 4
2179 BreakBeforeBraces: Allman
2180 AllowShortIfStatementsOnASingleLine: false
2181 IndentCaseLabels: false
2182 ColumnLimit: 0
2183
2184The result is:
2185
2186.. code-block:: c++
2187
2188 void test()
2189 {
2190 switch (suffix)
2191 {
2192 case 0:
2193 case 1:
2194 do_something();
2195 break;
2196 case 2:
2197 do_something_else();
2198 break;
2199 default:
2200 break;
2201 }
2202 if (condition)
2203 do_somthing_completely_different();
2204
2205 if (x == y)
2206 {
2207 q();
2208 }
2209 else if (x > y)
2210 {
2211 w();
2212 }
2213 else
2214 {
2215 r();
2216 }
2217 }