blob: dc517e44e978e72917f161884d642527f794a083 [file] [log] [blame]
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
Paul Hoadcbb726d2019-03-21 13:09:22 +000010the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
11create a custom style by configuring specific style options.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000012
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
Hans Wennborg9f6581b2013-09-10 15:41:12 +000019use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000021
22When using ``-style=file``, :program:`clang-format` for each input file will
23try to find the ``.clang-format`` file located in the closest parent directory
24of the input file. When the standard input is used, the search is started from
25the current directory.
26
27The ``.clang-format`` file uses YAML format:
28
29.. code-block:: yaml
30
31 key1: value1
32 key2: value2
33 # A comment.
34 ...
35
Alexander Kornienko092cb212014-08-12 13:34:22 +000036The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An example of a configuration file for multiple languages:
51
52.. code-block:: yaml
53
54 ---
55 # We'll use defaults from the LLVM style, but with 4 columns indentation.
56 BasedOnStyle: LLVM
57 IndentWidth: 4
58 ---
59 Language: Cpp
60 # Force pointers to the type for C++.
61 DerivePointerAlignment: false
62 PointerAlignment: Left
63 ---
64 Language: JavaScript
65 # Use 100 columns for JS.
66 ColumnLimit: 100
67 ---
68 Language: Proto
69 # Don't format .proto files.
70 DisableFormat: true
Paul Hoadcbb726d2019-03-21 13:09:22 +000071 ---
72 Language: CSharp
73 # Use 100 columns for C#.
74 ColumnLimit: 100
Alexander Kornienko092cb212014-08-12 13:34:22 +000075 ...
76
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000077An easy way to get a valid ``.clang-format`` file containing all configuration
78options of a certain predefined style is:
79
80.. code-block:: console
81
82 clang-format -style=llvm -dump-config > .clang-format
83
84When specifying configuration in the ``-style=`` option, the same configuration
85is applied for all input files. The format of the configuration is:
86
87.. code-block:: console
88
89 -style='{key1: value1, key2: value2, ...}'
90
91
Daniel Jasperd8b4ec02014-10-07 12:15:15 +000092Disabling Formatting on a Piece of Code
93=======================================
94
95Clang-format understands also special comments that switch formatting in a
96delimited range. The code between a comment ``// clang-format off`` or
97``/* clang-format off */`` up to a comment ``// clang-format on`` or
98``/* clang-format on */`` will not be formatted. The comments themselves
99will be formatted (aligned) normally.
100
101.. code-block:: c++
102
103 int formatted_code;
104 // clang-format off
105 void unformatted_code ;
106 // clang-format on
107 void formatted_code_again;
108
109
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000110Configuring Style in Code
111=========================
112
113When using ``clang::format::reformat(...)`` functions, the format is specified
114by supplying the `clang::format::FormatStyle
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000115<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000116structure.
117
118
119Configurable Format Style Options
120=================================
121
122This section lists the supported style options. Value type is specified for
123each option. For enumeration types possible values are specified both as a C++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000124enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
125the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000126
127
128**BasedOnStyle** (``string``)
129 The style used for all options not specifically set in the configuration.
130
131 This option is supported only in the :program:`clang-format` configuration
132 (both within ``-style='{...}'`` and the ``.clang-format`` file).
133
134 Possible values:
135
136 * ``LLVM``
137 A style complying with the `LLVM coding standards
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +0000138 <https://llvm.org/docs/CodingStandards.html>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000139 * ``Google``
140 A style complying with `Google's C++ style guide
141 <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
142 * ``Chromium``
143 A style complying with `Chromium's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000144 <https://www.chromium.org/developers/coding-style>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000145 * ``Mozilla``
146 A style complying with `Mozilla's style guide
147 <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
148 * ``WebKit``
149 A style complying with `WebKit's style guide
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +0000150 <https://www.webkit.org/coding/coding-style.html>`_
Paul Hoadcbb726d2019-03-21 13:09:22 +0000151 * ``Microsoft``
152 A style complying with `Microsoft's style guide
153 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000154
155.. START_FORMAT_STYLE_OPTIONS
156
157**AccessModifierOffset** (``int``)
Alexander Kornienkoe99a3a32016-02-23 16:12:08 +0000158 The extra indent or outdent of access modifiers, e.g. ``public:``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000159
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000160**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
Daniel Jasper3219e432014-12-02 13:24:51 +0000161 If ``true``, horizontally aligns arguments after an open bracket.
162
163 This applies to round brackets (parentheses), angle brackets and square
Alexander Kornienko1e048232016-02-23 16:11:51 +0000164 brackets.
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000165
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000166 Possible values:
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000167
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000168 * ``BAS_Align`` (in configuration: ``Align``)
169 Align parameters on the open bracket, e.g.:
170
171 .. code-block:: c++
172
173 someLongFunction(argument1,
174 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000175
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000176 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
177 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
178
179 .. code-block:: c++
180
181 someLongFunction(argument1,
182 argument2);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000183
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000184 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
185 Always break after an open bracket, if the parameters don't fit
186 on a single line, e.g.:
187
188 .. code-block:: c++
189
190 someLongFunction(
191 argument1, argument2);
192
Daniel Jasper3219e432014-12-02 13:24:51 +0000193
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000194
Daniel Jaspera44991332015-04-29 13:06:49 +0000195**AlignConsecutiveAssignments** (``bool``)
196 If ``true``, aligns consecutive assignments.
197
198 This will align the assignment operators of consecutive lines. This
199 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000200
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000201 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000202
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000203 int aaaa = 12;
204 int b = 23;
205 int ccc = 23;
206
207**AlignConsecutiveDeclarations** (``bool``)
208 If ``true``, aligns consecutive declarations.
209
210 This will align the declaration names of consecutive lines. This
211 will result in formattings like
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000212
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000213 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000214
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000215 int aaaa = 12;
216 float b = 23;
217 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000218
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000219**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
220 Options for aligning backslashes in escaped newlines.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000221
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000222 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000223
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000224 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
225 Don't align escaped newlines.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000226
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000227 .. code-block:: c++
228
229 #define A \
230 int aaaa; \
231 int b; \
232 int dddddddddd;
233
234 * ``ENAS_Left`` (in configuration: ``Left``)
235 Align escaped newlines as far left as possible.
236
237 .. code-block:: c++
238
239 true:
240 #define A \
241 int aaaa; \
242 int b; \
243 int dddddddddd;
244
245 false:
246
247 * ``ENAS_Right`` (in configuration: ``Right``)
248 Align escaped newlines in the right-most column.
249
250 .. code-block:: c++
251
252 #define A \
253 int aaaa; \
254 int b; \
255 int dddddddddd;
256
257
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000258
Daniel Jasper3219e432014-12-02 13:24:51 +0000259**AlignOperands** (``bool``)
260 If ``true``, horizontally align operands of binary and ternary
261 expressions.
262
Alexander Kornienko1e048232016-02-23 16:11:51 +0000263 Specifically, this aligns operands of a single expression that needs to be
264 split over multiple lines, e.g.:
265
266 .. code-block:: c++
267
268 int aaa = bbbbbbbbbbbbbbb +
269 ccccccccccccccc;
270
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000271**AlignTrailingComments** (``bool``)
272 If ``true``, aligns trailing comments.
273
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000274 .. code-block:: c++
275
Krasimir Georgiev818da9b2017-11-09 15:41:23 +0000276 true: false:
277 int a; // My comment a vs. int a; // My comment a
278 int b = 2; // comment b int b = 2; // comment about b
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000279
Paul Hoadc6deae42019-03-23 14:37:58 +0000280**AllowAllArgumentsOnNextLine** (``bool``)
281 If a function call or braced initializer list doesn't fit on a
282 line, allow putting all arguments onto the next line, even if
283 ``BinPackArguments`` is ``false``.
284
285 .. code-block:: c++
286
287 true:
288 callFunction(
289 a, b, c, d);
290
291 false:
292 callFunction(a,
293 b,
294 c,
295 d);
296
297**AllowAllConstructorInitializersOnNextLine** (``bool``)
298 If a constructor definition with a member initializer list doesn't
299 fit on a single line, allow putting all member initializers onto the next
300 line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
301 Note that this parameter has no effect if
302 ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
303
304 .. code-block:: c++
305
306 true:
307 MyClass::MyClass() :
308 member0(0), member1(2) {}
309
310 false:
311 MyClass::MyClass() :
312 member0(0),
313 member1(2) {}
314
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000315**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000316 If the function declaration doesn't fit on a line,
317 allow putting all parameters of a function declaration onto
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000318 the next line even if ``BinPackParameters`` is ``false``.
319
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000320 .. code-block:: c++
321
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000322 true:
323 void myFunction(
324 int a, int b, int c, int d, int e);
325
326 false:
327 void myFunction(int a,
328 int b,
329 int c,
330 int d,
331 int e);
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000332
Daniel Jasper17605d32014-05-14 09:33:35 +0000333**AllowShortBlocksOnASingleLine** (``bool``)
334 Allows contracting simple braced statements to a single line.
335
336 E.g., this allows ``if (a) { return; }`` to be put on a single line.
337
Daniel Jasperb87899b2014-09-10 13:11:45 +0000338**AllowShortCaseLabelsOnASingleLine** (``bool``)
339 If ``true``, short case labels will be contracted to a single line.
340
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000341 .. code-block:: c++
342
343 true: false:
344 switch (a) { vs. switch (a) {
345 case 1: x = 1; break; case 1:
346 case 2: return; x = 1;
347 } break;
348 case 2:
349 return;
350 }
351
Daniel Jasperb5524822014-04-09 14:05:49 +0000352**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000353 Dependent on the value, ``int f() { return 0; }`` can be put on a
354 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000355
356 Possible values:
357
358 * ``SFS_None`` (in configuration: ``None``)
359 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000360
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000361 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
362 Only merge functions defined inside a class. Same as "inline",
363 except it does not implies "empty": i.e. top level empty functions
364 are not merged either.
365
366 .. code-block:: c++
367
368 class Foo {
369 void f() { foo(); }
370 };
371 void f() {
372 foo();
373 }
374 void f() {
375 }
376
Daniel Jasper3219e432014-12-02 13:24:51 +0000377 * ``SFS_Empty`` (in configuration: ``Empty``)
378 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000379
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000380 .. code-block:: c++
381
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000382 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000383 void f2() {
384 bar2();
385 }
386
Daniel Jasper20580fd2015-06-11 13:31:45 +0000387 * ``SFS_Inline`` (in configuration: ``Inline``)
388 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000389
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000390 .. code-block:: c++
391
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000392 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000393 void f() { foo(); }
394 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000395 void f() {
396 foo();
397 }
398 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000399
Daniel Jasperb5524822014-04-09 14:05:49 +0000400 * ``SFS_All`` (in configuration: ``All``)
401 Merge all functions fitting on a single line.
402
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000403 .. code-block:: c++
404
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000405 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000406 void f() { foo(); }
407 };
408 void f() { bar(); }
409
Paul Hoad15000a12019-03-13 08:26:39 +0000410**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
411 Dependent on the value, ``if (a) return 0;`` can be put on a
412 single line.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000413
Paul Hoad15000a12019-03-13 08:26:39 +0000414 Possible values:
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000415
Paul Hoad15000a12019-03-13 08:26:39 +0000416 * ``SIS_Never`` (in configuration: ``Never``)
417 Do not allow short if functions.
418
419 .. code-block:: c++
420
421 if (a)
422 return;
423 else
424 return;
425
426 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
427 Allow short if functions on the same line, as long as else
428 is not a compound statement.
429
430 .. code-block:: c++
431
432 if (a) return;
433 else
434 return;
435
436 if (a)
437 return;
438 else {
439 return;
440 }
441
442 * ``SIS_Always`` (in configuration: ``Always``)
443 Allow short if statements even if the else is a compound statement.
444
445 .. code-block:: c++
446
447 if (a) return;
448 else {
449 return;
450 }
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000451
Ronald Wamplera83e2db2019-03-26 20:18:14 +0000452**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
453 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
454 single line.
455
456 Possible values:
457
458 * ``SLS_None`` (in configuration: ``None``)
459 Never merge lambdas into a single line.
460
461 * ``SLS_Empty`` (in configuration: ``Empty``)
462 Only merge empty lambdas.
463
464 .. code-block:: c++
465
466 auto lambda = [](int a) {}
467 auto lambda2 = [](int a) {
468 return a;
469 };
470
471 * ``SLS_Inline`` (in configuration: ``Inline``)
472 Merge lambda into a single line if argument of a function.
473
474 .. code-block:: c++
475
476 auto lambda = [](int a) {
477 return a;
478 };
479 sort(a.begin(), a.end(), ()[] { return x < y; })
480
481 * ``SLS_All`` (in configuration: ``All``)
482 Merge all lambdas fitting on a single line.
483
484 .. code-block:: c++
485
486 auto lambda = [](int a) {}
487 auto lambda2 = [](int a) { return a; };
488
489
490
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000491**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000492 If ``true``, ``while (true) continue;`` can be put on a single
493 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000494
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000495**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000496 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000497 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000498
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000499 Possible values:
500
501 * ``DRTBS_None`` (in configuration: ``None``)
502 Break after return type automatically.
503 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000504
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000505 * ``DRTBS_All`` (in configuration: ``All``)
506 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000507
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000508 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000509 Always break after the return types of top-level functions.
510
511
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000512
Zachary Turner448592e2015-12-18 22:20:15 +0000513**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
514 The function declaration return type breaking style to use.
515
516 Possible values:
517
518 * ``RTBS_None`` (in configuration: ``None``)
519 Break after return type automatically.
520 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000521
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000522 .. code-block:: c++
523
524 class A {
525 int f() { return 0; };
526 };
527 int f();
528 int f() { return 1; }
529
Zachary Turner448592e2015-12-18 22:20:15 +0000530 * ``RTBS_All`` (in configuration: ``All``)
531 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000532
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000533 .. code-block:: c++
534
535 class A {
536 int
537 f() {
538 return 0;
539 };
540 };
541 int
542 f();
543 int
544 f() {
545 return 1;
546 }
547
Zachary Turner448592e2015-12-18 22:20:15 +0000548 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
549 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000550
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000551 .. code-block:: c++
552
553 class A {
554 int f() { return 0; };
555 };
556 int
557 f();
558 int
559 f() {
560 return 1;
561 }
562
Zachary Turner448592e2015-12-18 22:20:15 +0000563 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
564 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000565
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000566 .. code-block:: c++
567
568 class A {
569 int
570 f() {
571 return 0;
572 };
573 };
574 int f();
575 int
576 f() {
577 return 1;
578 }
579
Zachary Turner448592e2015-12-18 22:20:15 +0000580 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
581 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000582
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000583 .. code-block:: c++
584
585 class A {
586 int f() { return 0; };
587 };
588 int f();
589 int
590 f() {
591 return 1;
592 }
593
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000594
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000595
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000596**AlwaysBreakBeforeMultilineStrings** (``bool``)
597 If ``true``, always break before multiline string literals.
598
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000599 This flag is mean to make cases where there are multiple multiline strings
600 in a file look more consistent. Thus, it will only take effect if wrapping
601 the string at that point leads to it being indented
602 ``ContinuationIndentWidth`` spaces from the start of the line.
603
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000604 .. code-block:: c++
605
606 true: false:
607 aaaa = vs. aaaa = "bbbb"
608 "bbbb" "cccc";
609 "cccc";
610
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000611**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
612 The template declaration breaking style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000613
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000614 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000615
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000616 * ``BTDS_No`` (in configuration: ``No``)
617 Do not force break before declaration.
618 ``PenaltyBreakTemplateDeclaration`` is taken into account.
619
620 .. code-block:: c++
621
622 template <typename T> T foo() {
623 }
624 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
625 int bbbbbbbbbbbbbbbbbbbbb) {
626 }
627
628 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
629 Force break after template declaration only when the following
630 declaration spans multiple lines.
631
632 .. code-block:: c++
633
634 template <typename T> T foo() {
635 }
636 template <typename T>
637 T foo(int aaaaaaaaaaaaaaaaaaaaa,
638 int bbbbbbbbbbbbbbbbbbbbb) {
639 }
640
641 * ``BTDS_Yes`` (in configuration: ``Yes``)
642 Always break after template declaration.
643
644 .. code-block:: c++
645
646 template <typename T>
647 T foo() {
648 }
649 template <typename T>
650 T foo(int aaaaaaaaaaaaaaaaaaaaa,
651 int bbbbbbbbbbbbbbbbbbbbb) {
652 }
653
654
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000655
Daniel Jasper18210d72014-10-09 09:52:05 +0000656**BinPackArguments** (``bool``)
657 If ``false``, a function call's arguments will either be all on the
658 same line or will have one line each.
659
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000660 .. code-block:: c++
661
662 true:
663 void f() {
664 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
665 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
666 }
667
668 false:
669 void f() {
670 f(aaaaaaaaaaaaaaaaaaaa,
671 aaaaaaaaaaaaaaaaaaaa,
672 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
673 }
674
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000675**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000676 If ``false``, a function declaration's or function definition's
677 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000678
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000679 .. code-block:: c++
680
681 true:
682 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
683 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
684
685 false:
686 void f(int aaaaaaaaaaaaaaaaaaaa,
687 int aaaaaaaaaaaaaaaaaaaa,
688 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
689
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000690**BraceWrapping** (``BraceWrappingFlags``)
691 Control of individual brace wrapping cases.
692
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000693 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
694 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000695
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000696 .. code-block:: yaml
697
698 # Example of usage:
699 BreakBeforeBraces: Custom
700 BraceWrapping:
701 AfterEnum: true
702 AfterStruct: false
703 SplitEmptyFunction: false
704
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000705 Nested configuration flags:
706
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000707
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000708 * ``bool AfterClass`` Wrap class 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 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000714
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000715 false:
716 class foo
717 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000718
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000719 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000720
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000721 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000722
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000723 true:
724 if (foo())
725 {
726 } else
727 {}
728 for (int i = 0; i < 10; ++i)
729 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000730
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000731 false:
732 if (foo()) {
733 } else {
734 }
735 for (int i = 0; i < 10; ++i) {
736 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000737
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000738 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000739
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000740 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000741
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000742 true:
743 enum X : int
744 {
745 B
746 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000747
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000748 false:
749 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000750
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000751 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000752
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000753 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000754
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000755 true:
756 void foo()
757 {
758 bar();
759 bar2();
760 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000761
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000762 false:
763 void foo() {
764 bar();
765 bar2();
766 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000767
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000768 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000769
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000770 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000771
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000772 true:
773 namespace
774 {
775 int foo();
776 int bar();
777 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000778
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000779 false:
780 namespace {
781 int foo();
782 int bar();
783 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000784
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000785 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
786 @autoreleasepool and @synchronized blocks are wrapped
787 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000788
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000789 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000790
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000791 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000792
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000793 true:
794 struct foo
795 {
796 int x;
797 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000798
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000799 false:
800 struct foo {
801 int x;
802 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000803
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000804 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000805
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000806 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000807
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000808 true:
809 union foo
810 {
811 int x;
812 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000813
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000814 false:
815 union foo {
816 int x;
817 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000818
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000819 * ``bool AfterExternBlock`` Wrap extern blocks.
820
821 .. code-block:: c++
822
823 true:
824 extern "C"
825 {
826 int foo();
827 }
828
829 false:
830 extern "C" {
831 int foo();
832 }
833
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000834 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000835
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000836 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000837
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000838 true:
839 try {
840 foo();
841 }
842 catch () {
843 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000844
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000845 false:
846 try {
847 foo();
848 } catch () {
849 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000850
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000851 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000852
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000853 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000854
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000855 true:
856 if (foo()) {
857 }
858 else {
859 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000860
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000861 false:
862 if (foo()) {
863 } else {
864 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000865
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000866 * ``bool IndentBraces`` Indent the wrapped braces themselves.
867
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000868 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000869 This option is used only if the opening brace of the function has
870 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
871 set, and the function could/should not be put on a single line (as per
872 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000873
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000874 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000875
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000876 int f() vs. inf f()
877 {} {
878 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000879
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000880 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
881 can be put on a single line. This option is used only if the opening
882 brace of the record has already been wrapped, i.e. the `AfterClass`
883 (for classes) brace wrapping mode is set.
884
885 .. code-block:: c++
886
887 class Foo vs. class Foo
888 {} {
889 }
890
891 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
892 This option is used only if the opening brace of the namespace has
893 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
894 set.
895
896 .. code-block:: c++
897
898 namespace Foo vs. namespace Foo
899 {} {
900 }
901
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000902
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000903**BreakAfterJavaFieldAnnotations** (``bool``)
904 Break after each annotation on a field in Java files.
905
Sylvestre Ledrude098242017-04-11 07:07:05 +0000906 .. code-block:: java
907
908 true: false:
909 @Partial vs. @Partial @Mock DataLoad loader;
910 @Mock
911 DataLoad loader;
912
Daniel Jasperac043c92014-09-15 11:11:00 +0000913**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
914 The way to wrap binary operators.
915
916 Possible values:
917
918 * ``BOS_None`` (in configuration: ``None``)
919 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000920
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000921 .. code-block:: c++
922
923 LooooooooooongType loooooooooooooooooooooongVariable =
924 someLooooooooooooooooongFunction();
925
926 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
927 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
928 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
929 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
930 ccccccccccccccccccccccccccccccccccccccccc;
931
Daniel Jasperac043c92014-09-15 11:11:00 +0000932 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
933 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000934
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000935 .. code-block:: c++
936
937 LooooooooooongType loooooooooooooooooooooongVariable =
938 someLooooooooooooooooongFunction();
939
940 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
941 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
942 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
943 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
944 > ccccccccccccccccccccccccccccccccccccccccc;
945
Daniel Jasperac043c92014-09-15 11:11:00 +0000946 * ``BOS_All`` (in configuration: ``All``)
947 Break before operators.
948
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000949 .. code-block:: c++
950
951 LooooooooooongType loooooooooooooooooooooongVariable
952 = someLooooooooooooooooongFunction();
953
954 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
955 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
956 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
957 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
958 > ccccccccccccccccccccccccccccccccccccccccc;
959
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000960
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000961
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000962**BreakBeforeBraces** (``BraceBreakingStyle``)
963 The brace breaking style to use.
964
965 Possible values:
966
967 * ``BS_Attach`` (in configuration: ``Attach``)
968 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000969
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000970 .. code-block:: c++
971
972 try {
973 foo();
974 } catch () {
975 }
976 void foo() { bar(); }
977 class foo {};
978 if (foo()) {
979 } else {
980 }
981 enum X : int { A, B };
982
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000983 * ``BS_Linux`` (in configuration: ``Linux``)
984 Like ``Attach``, but break before braces on function, namespace and
985 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000986
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000987 .. code-block:: c++
988
989 try {
990 foo();
991 } catch () {
992 }
993 void foo() { bar(); }
994 class foo
995 {
996 };
997 if (foo()) {
998 } else {
999 }
1000 enum X : int { A, B };
1001
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +00001002 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1003 Like ``Attach``, but break before braces on enum, function, and record
1004 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001005
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001006 .. code-block:: c++
1007
1008 try {
1009 foo();
1010 } catch () {
1011 }
1012 void foo() { bar(); }
1013 class foo
1014 {
1015 };
1016 if (foo()) {
1017 } else {
1018 }
1019 enum X : int { A, B };
1020
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001021 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001022 Like ``Attach``, but break before function definitions, ``catch``, and
1023 ``else``.
1024
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001025 .. code-block:: c++
1026
1027 try {
1028 foo();
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001029 }
1030 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001031 }
1032 void foo() { bar(); }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001033 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001034 };
1035 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001036 }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +00001037 else {
1038 }
1039 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001040
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001041 * ``BS_Allman`` (in configuration: ``Allman``)
1042 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001043
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001044 .. code-block:: c++
1045
Jan Korous3fd4a962019-03-05 01:45:31 +00001046 try
1047 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001048 foo();
1049 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001050 catch ()
1051 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001052 }
1053 void foo() { bar(); }
Jan Korous3fd4a962019-03-05 01:45:31 +00001054 class foo
1055 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001056 };
Jan Korous3fd4a962019-03-05 01:45:31 +00001057 if (foo())
1058 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001059 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001060 else
1061 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001062 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001063 enum X : int
1064 {
1065 A,
1066 B
1067 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001068
Daniel Jasperee107ad2014-02-13 12:51:50 +00001069 * ``BS_GNU`` (in configuration: ``GNU``)
1070 Always break before braces and add an extra level of indentation to
1071 braces of control statements, not to those of class, function
1072 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001073
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001074 .. code-block:: c++
1075
1076 try
1077 {
1078 foo();
1079 }
1080 catch ()
1081 {
1082 }
1083 void foo() { bar(); }
1084 class foo
1085 {
1086 };
1087 if (foo())
1088 {
1089 }
1090 else
1091 {
1092 }
1093 enum X : int
1094 {
1095 A,
1096 B
1097 };
1098
Roman Kashitsyn291f64f2015-08-10 13:43:19 +00001099 * ``BS_WebKit`` (in configuration: ``WebKit``)
1100 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001101
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001102 .. code-block:: c++
1103
1104 try {
1105 foo();
1106 } catch () {
1107 }
1108 void foo() { bar(); }
1109 class foo {
1110 };
1111 if (foo()) {
1112 } else {
1113 }
1114 enum X : int { A, B };
1115
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001116 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001117 Configure each individual brace in `BraceWrapping`.
1118
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001119
1120
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001121**BreakBeforeTernaryOperators** (``bool``)
1122 If ``true``, ternary operators will be placed after line breaks.
1123
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001124 .. code-block:: c++
1125
1126 true:
1127 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1128 ? firstValue
1129 : SecondValueVeryVeryVeryVeryLong;
1130
Sylvestre Ledru121224d2017-06-06 07:26:19 +00001131 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001132 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1133 firstValue :
1134 SecondValueVeryVeryVeryVeryLong;
1135
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001136**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1137 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001138
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001139 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001140
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001141 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1142 Break constructor initializers before the colon and after the commas.
1143
1144 .. code-block:: c++
1145
Francois Ferrand767e1522018-06-14 13:32:14 +00001146 Constructor()
1147 : initializer1(),
1148 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001149
1150 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1151 Break constructor initializers before the colon and commas, and align
1152 the commas with the colon.
1153
1154 .. code-block:: c++
1155
Francois Ferrand767e1522018-06-14 13:32:14 +00001156 Constructor()
1157 : initializer1()
1158 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001159
1160 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1161 Break constructor initializers after the colon and commas.
1162
1163 .. code-block:: c++
1164
Francois Ferrand767e1522018-06-14 13:32:14 +00001165 Constructor() :
1166 initializer1(),
1167 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001168
1169
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001170
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001171**BreakInheritanceList** (``BreakInheritanceListStyle``)
1172 The inheritance list style to use.
1173
1174 Possible values:
1175
1176 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1177 Break inheritance list before the colon and after the commas.
1178
1179 .. code-block:: c++
1180
Francois Ferrand767e1522018-06-14 13:32:14 +00001181 class Foo
1182 : Base1,
1183 Base2
1184 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001185
1186 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1187 Break inheritance list before the colon and commas, and align
1188 the commas with the colon.
1189
1190 .. code-block:: c++
1191
Francois Ferrand767e1522018-06-14 13:32:14 +00001192 class Foo
1193 : Base1
1194 , Base2
1195 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001196
1197 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1198 Break inheritance list after the colon and commas.
1199
1200 .. code-block:: c++
1201
Francois Ferrand767e1522018-06-14 13:32:14 +00001202 class Foo :
1203 Base1,
1204 Base2
1205 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001206
1207
1208
Alexander Kornienko1e048232016-02-23 16:11:51 +00001209**BreakStringLiterals** (``bool``)
1210 Allow breaking string literals when formatting.
1211
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001212**ColumnLimit** (``unsigned``)
1213 The column limit.
1214
1215 A column limit of ``0`` means that there is no column limit. In this case,
1216 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001217 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001218
Daniel Jasperee107ad2014-02-13 12:51:50 +00001219**CommentPragmas** (``std::string``)
1220 A regular expression that describes comments with special meaning,
1221 which should not be split into lines or otherwise changed.
1222
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001223 .. code-block:: c++
1224
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001225 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001226 // Will leave the following line unaffected
1227 #include <vector> // FOOBAR pragma: keep
1228
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001229**CompactNamespaces** (``bool``)
1230 If ``true``, consecutive namespace declarations will be on the same
1231 line. If ``false``, each namespace is declared on a new line.
1232
1233 .. code-block:: c++
1234
1235 true:
1236 namespace Foo { namespace Bar {
1237 }}
1238
1239 false:
1240 namespace Foo {
1241 namespace Bar {
1242 }
1243 }
1244
1245 If it does not fit on a single line, the overflowing namespaces get
1246 wrapped:
1247
1248 .. code-block:: c++
1249
1250 namespace Foo { namespace Bar {
1251 namespace Extra {
1252 }}}
1253
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001254**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1255 If the constructor initializers don't fit on a line, put each
1256 initializer on its own line.
1257
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001258 .. code-block:: c++
1259
1260 true:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001261 SomeClass::Constructor()
1262 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1263 return 0;
1264 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001265
1266 false:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001267 SomeClass::Constructor()
1268 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1269 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1270 return 0;
1271 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001272
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001273**ConstructorInitializerIndentWidth** (``unsigned``)
1274 The number of characters to use for indentation of constructor
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001275 initializer lists as well as inheritance lists.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001276
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001277**ContinuationIndentWidth** (``unsigned``)
1278 Indent width for line continuations.
1279
Sylvestre Ledrude098242017-04-11 07:07:05 +00001280 .. code-block:: c++
1281
1282 ContinuationIndentWidth: 2
1283
1284 int i = // VeryVeryVeryVeryVeryLongComment
1285 longFunction( // Again a long comment
1286 arg);
1287
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001288**Cpp11BracedListStyle** (``bool``)
1289 If ``true``, format braced lists as best suited for C++11 braced
1290 lists.
1291
1292 Important differences:
1293 - No spaces inside the braced list.
1294 - No line break before the closing brace.
1295 - Indentation with the continuation indent, not with the block indent.
1296
1297 Fundamentally, C++11 braced lists are formatted exactly like function
1298 calls would be formatted in their place. If the braced list follows a name
1299 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1300 the parentheses of a function call with that name. If there is no name,
1301 a zero-length name is assumed.
1302
Sylvestre Ledrude098242017-04-11 07:07:05 +00001303 .. code-block:: c++
1304
1305 true: false:
1306 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1307 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1308 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1309 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1310
Daniel Jasper553d4872014-06-17 12:40:34 +00001311**DerivePointerAlignment** (``bool``)
1312 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001313 alignment of ``&`` and ``*``.
1314 Pointer and reference alignment styles are going to be updated according
1315 to the preferences found in the file.
1316 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001317
1318**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001319 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001320
1321**ExperimentalAutoDetectBinPacking** (``bool``)
1322 If ``true``, clang-format detects whether function calls and
1323 definitions are formatted with one parameter per line.
1324
1325 Each call can be bin-packed, one-per-line or inconclusive. If it is
1326 inconclusive, e.g. completely on one line, but a decision needs to be
1327 made, clang-format analyzes whether there are other bin-packed cases in
1328 the input file and act accordingly.
1329
1330 NOTE: This is an experimental flag, that might go away or be renamed. Do
1331 not use this in config files, etc. Use at your own risk.
1332
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001333**FixNamespaceComments** (``bool``)
1334 If ``true``, clang-format adds missing namespace end comments and
1335 fixes invalid existing ones.
1336
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001337 .. code-block:: c++
1338
1339 true: false:
1340 namespace a { vs. namespace a {
1341 foo(); foo();
1342 } // namespace a; }
1343
Daniel Jaspere1e43192014-04-01 12:55:11 +00001344**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001345 A vector of macros that should be interpreted as foreach loops
1346 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001347
Daniel Jasperb5524822014-04-09 14:05:49 +00001348 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001349
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001350 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001351
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001352 FOREACH(<variable-declaration>, ...)
1353 <loop-body>
1354
1355 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001356
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001357 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001358
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001359 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001360
1361 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001362
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001363**IncludeBlocks** (``IncludeBlocksStyle``)
1364 Dependent on the value, multiple ``#include`` blocks can be sorted
1365 as one and divided based on category.
1366
1367 Possible values:
1368
1369 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1370 Sort each ``#include`` block separately.
1371
1372 .. code-block:: c++
1373
1374 #include "b.h" into #include "b.h"
1375
1376 #include <lib/main.h> #include "a.h"
1377 #include "a.h" #include <lib/main.h>
1378
1379 * ``IBS_Merge`` (in configuration: ``Merge``)
1380 Merge multiple ``#include`` blocks together and sort as one.
1381
1382 .. code-block:: c++
1383
1384 #include "b.h" into #include "a.h"
1385 #include "b.h"
1386 #include <lib/main.h> #include <lib/main.h>
1387 #include "a.h"
1388
1389 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1390 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001391 Then split into groups based on category priority. See
1392 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001393
1394 .. code-block:: c++
1395
1396 #include "b.h" into #include "a.h"
1397 #include "b.h"
1398 #include <lib/main.h>
1399 #include "a.h" #include <lib/main.h>
1400
1401
1402
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001403**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001404 Regular expressions denoting the different ``#include`` categories
1405 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001406
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001407 `POSIX extended
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +00001408 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001409 regular expressions are supported.
1410
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001411 These regular expressions are matched against the filename of an include
1412 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001413 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001414 according to increasing category number and then alphabetically within
1415 each category.
1416
Alexander Kornienko1e048232016-02-23 16:11:51 +00001417 If none of the regular expressions match, INT_MAX is assigned as
1418 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001419 so that it is generally kept at the beginning of the ``#includes``
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +00001420 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
Alexander Kornienko1e048232016-02-23 16:11:51 +00001421 can also assign negative priorities if you have certain headers that
1422 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001423
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001424 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001425
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001426 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001427
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001428 IncludeCategories:
1429 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1430 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001431 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001432 Priority: 3
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001433 - Regex: '<[[:alnum:].]+>'
1434 Priority: 4
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001435 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001436 Priority: 1
1437
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001438**IncludeIsMainRegex** (``std::string``)
1439 Specify a regular expression of suffixes that are allowed in the
1440 file-to-main-include mapping.
1441
1442 When guessing whether a #include is the "main" include (to assign
1443 category 0, see above), use this regex of allowed suffixes to the header
1444 stem. A partial match is done, so that:
1445 - "" means "arbitrary suffix"
1446 - "$" means "no suffix"
1447
1448 For example, if configured to "(_test)?$", then a header a.h would be seen
1449 as the "main" include in both a.cc and a_test.cc.
1450
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001451**IndentCaseLabels** (``bool``)
1452 Indent case labels one level from the switch statement.
1453
1454 When ``false``, use the same indentation level as for the switch statement.
1455 Switch statement body is always indented one level more than case labels.
1456
Sylvestre Ledrude098242017-04-11 07:07:05 +00001457 .. code-block:: c++
1458
1459 false: true:
1460 switch (fool) { vs. switch (fool) {
1461 case 1: case 1:
1462 bar(); bar();
1463 break; break;
1464 default: default:
1465 plop(); plop();
1466 } }
1467
Krasimir Georgievad47c902017-08-30 14:34:57 +00001468**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001469 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001470
1471 Possible values:
1472
1473 * ``PPDIS_None`` (in configuration: ``None``)
1474 Does not indent any directives.
1475
1476 .. code-block:: c++
1477
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001478 #if FOO
1479 #if BAR
1480 #include <foo>
1481 #endif
1482 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001483
1484 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1485 Indents directives after the hash.
1486
1487 .. code-block:: c++
1488
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001489 #if FOO
1490 # if BAR
1491 # include <foo>
1492 # endif
1493 #endif
1494
Paul Hoad701a0d72019-03-20 20:49:43 +00001495 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1496 Indents directives before the hash.
1497
1498 .. code-block:: c++
1499
1500 #if FOO
1501 #if BAR
1502 #include <foo>
1503 #endif
1504 #endif
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001505
Krasimir Georgievad47c902017-08-30 14:34:57 +00001506
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001507**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001508 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001509
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001510 .. code-block:: c++
1511
1512 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001513
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001514 void f() {
1515 someFunction();
1516 if (true, false) {
1517 f();
1518 }
1519 }
1520
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001521**IndentWrappedFunctionNames** (``bool``)
1522 Indent if a function definition or declaration is wrapped after the
1523 type.
1524
Sylvestre Ledrude098242017-04-11 07:07:05 +00001525 .. code-block:: c++
1526
1527 true:
1528 LoooooooooooooooooooooooooooooooooooooooongReturnType
1529 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1530
1531 false:
1532 LoooooooooooooooooooooooooooooooooooooooongReturnType
1533 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1534
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001535**JavaImportGroups** (``std::vector<std::string>``)
1536 A vector of prefixes ordered by the desired groups for Java imports.
1537
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001538 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001539 same grouping convention above all non-static imports. One group's prefix
1540 can be a subset of another - the longest prefix is always matched. Within
1541 a group, the imports are ordered lexicographically.
1542
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001543 In the .clang-format configuration file, this can be configured like
1544 in the following yaml example. This will result in imports being
1545 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001546
1547 .. code-block:: yaml
1548
1549 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001550
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001551
1552 .. code-block:: java
1553
1554 import static com.example.function1;
1555
1556 import static com.test.function2;
1557
1558 import static org.example.function3;
1559
1560 import com.example.ClassA;
1561 import com.example.Test;
1562 import com.example.a.ClassB;
1563
1564 import com.test.ClassC;
1565
1566 import org.example.ClassD;
1567
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001568**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1569 The JavaScriptQuoteStyle to use for JavaScript strings.
1570
1571 Possible values:
1572
1573 * ``JSQS_Leave`` (in configuration: ``Leave``)
1574 Leave string quotes as they are.
1575
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001576 .. code-block:: js
1577
1578 string1 = "foo";
1579 string2 = 'bar';
1580
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001581 * ``JSQS_Single`` (in configuration: ``Single``)
1582 Always use single quotes.
1583
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001584 .. code-block:: js
1585
1586 string1 = 'foo';
1587 string2 = 'bar';
1588
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001589 * ``JSQS_Double`` (in configuration: ``Double``)
1590 Always use double quotes.
1591
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001592 .. code-block:: js
1593
1594 string1 = "foo";
1595 string2 = "bar";
1596
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001597
1598
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001599**JavaScriptWrapImports** (``bool``)
1600 Whether to wrap JavaScript import/export statements.
1601
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001602 .. code-block:: js
1603
1604 true:
1605 import {
1606 VeryLongImportsAreAnnoying,
1607 VeryLongImportsAreAnnoying,
1608 VeryLongImportsAreAnnoying,
1609 } from 'some/module.js'
1610
1611 false:
1612 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1613
Daniel Jasperb5524822014-04-09 14:05:49 +00001614**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001615 If true, the empty line at the start of blocks is kept.
1616
1617 .. code-block:: c++
1618
1619 true: false:
1620 if (foo) { vs. if (foo) {
1621 bar();
1622 bar(); }
1623 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001624
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001625**Language** (``LanguageKind``)
1626 Language, this format style is targeted at.
1627
1628 Possible values:
1629
1630 * ``LK_None`` (in configuration: ``None``)
1631 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001632
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001633 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001634 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001635
Paul Hoadcbb726d2019-03-21 13:09:22 +00001636 * ``LK_CSharp`` (in configuration: ``CSharp``)
1637 Should be used for C#.
1638
Daniel Jasper18210d72014-10-09 09:52:05 +00001639 * ``LK_Java`` (in configuration: ``Java``)
1640 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001641
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001642 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1643 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001644
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001645 * ``LK_ObjC`` (in configuration: ``ObjC``)
1646 Should be used for Objective-C, Objective-C++.
1647
Daniel Jasperee107ad2014-02-13 12:51:50 +00001648 * ``LK_Proto`` (in configuration: ``Proto``)
1649 Should be used for Protocol Buffers
1650 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001651
Alexander Kornienko1e048232016-02-23 16:11:51 +00001652 * ``LK_TableGen`` (in configuration: ``TableGen``)
1653 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001654
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001655 * ``LK_TextProto`` (in configuration: ``TextProto``)
1656 Should be used for Protocol Buffer messages in text format
1657 (https://developers.google.com/protocol-buffers/).
1658
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001659
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001660
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001661**MacroBlockBegin** (``std::string``)
1662 A regular expression matching macros that start a block.
1663
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001664 .. code-block:: c++
1665
1666 # With:
1667 MacroBlockBegin: "^NS_MAP_BEGIN|\
1668 NS_TABLE_HEAD$"
1669 MacroBlockEnd: "^\
1670 NS_MAP_END|\
1671 NS_TABLE_.*_END$"
1672
1673 NS_MAP_BEGIN
1674 foo();
1675 NS_MAP_END
1676
1677 NS_TABLE_HEAD
1678 bar();
1679 NS_TABLE_FOO_END
1680
1681 # Without:
1682 NS_MAP_BEGIN
1683 foo();
1684 NS_MAP_END
1685
1686 NS_TABLE_HEAD
1687 bar();
1688 NS_TABLE_FOO_END
1689
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001690**MacroBlockEnd** (``std::string``)
1691 A regular expression matching macros that end a block.
1692
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001693**MaxEmptyLinesToKeep** (``unsigned``)
1694 The maximum number of consecutive empty lines to keep.
1695
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001696 .. code-block:: c++
1697
1698 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1699 int f() { int f() {
1700 int = 1; int i = 1;
1701 i = foo();
1702 i = foo(); return i;
1703 }
1704 return i;
1705 }
1706
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001707**NamespaceIndentation** (``NamespaceIndentationKind``)
1708 The indentation used for namespaces.
1709
1710 Possible values:
1711
1712 * ``NI_None`` (in configuration: ``None``)
1713 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001714
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001715 .. code-block:: c++
1716
1717 namespace out {
1718 int i;
1719 namespace in {
1720 int i;
1721 }
1722 }
1723
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001724 * ``NI_Inner`` (in configuration: ``Inner``)
1725 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001726
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001727 .. code-block:: c++
1728
1729 namespace out {
1730 int i;
1731 namespace in {
1732 int i;
1733 }
1734 }
1735
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001736 * ``NI_All`` (in configuration: ``All``)
1737 Indent in all namespaces.
1738
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001739 .. code-block:: c++
1740
1741 namespace out {
1742 int i;
1743 namespace in {
1744 int i;
1745 }
1746 }
1747
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001748
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001749
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001750**ObjCBinPackProtocolList** (``BinPackStyle``)
1751 Controls bin-packing Objective-C protocol conformance list
1752 items into as few lines as possible when they go over ``ColumnLimit``.
1753
1754 If ``Auto`` (the default), delegates to the value in
1755 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1756 protocol conformance list items into as few lines as possible
1757 whenever they go over ``ColumnLimit``.
1758
1759 If ``Always``, always bin-packs Objective-C protocol conformance
1760 list items into as few lines as possible whenever they go over
1761 ``ColumnLimit``.
1762
1763 If ``Never``, lays out Objective-C protocol conformance list items
1764 onto individual lines whenever they go over ``ColumnLimit``.
1765
1766
Aaron Ballman37485fd2018-06-28 12:02:38 +00001767 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001768
1769 Always (or Auto, if BinPackParameters=true):
1770 @interface ccccccccccccc () <
1771 ccccccccccccc, ccccccccccccc,
1772 ccccccccccccc, ccccccccccccc> {
1773 }
1774
1775 Never (or Auto, if BinPackParameters=false):
1776 @interface ddddddddddddd () <
1777 ddddddddddddd,
1778 ddddddddddddd,
1779 ddddddddddddd,
1780 ddddddddddddd> {
1781 }
1782
1783 Possible values:
1784
1785 * ``BPS_Auto`` (in configuration: ``Auto``)
1786 Automatically determine parameter bin-packing behavior.
1787
1788 * ``BPS_Always`` (in configuration: ``Always``)
1789 Always bin-pack parameters.
1790
1791 * ``BPS_Never`` (in configuration: ``Never``)
1792 Never bin-pack parameters.
1793
1794
1795
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001796**ObjCBlockIndentWidth** (``unsigned``)
1797 The number of characters to use for indentation of ObjC blocks.
1798
Sylvestre Ledrude098242017-04-11 07:07:05 +00001799 .. code-block:: objc
1800
1801 ObjCBlockIndentWidth: 4
1802
1803 [operation setCompletionBlock:^{
1804 [self onOperationDone];
1805 }];
1806
Daniel Jasperee107ad2014-02-13 12:51:50 +00001807**ObjCSpaceAfterProperty** (``bool``)
1808 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001809 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001810
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001811**ObjCSpaceBeforeProtocolList** (``bool``)
1812 Add a space in front of an Objective-C protocol list, i.e. use
1813 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1814
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001815**PenaltyBreakAssignment** (``unsigned``)
1816 The penalty for breaking around an assignment operator.
1817
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001818**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001819 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001820
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001821**PenaltyBreakComment** (``unsigned``)
1822 The penalty for each line break introduced inside a comment.
1823
1824**PenaltyBreakFirstLessLess** (``unsigned``)
1825 The penalty for breaking before the first ``<<``.
1826
1827**PenaltyBreakString** (``unsigned``)
1828 The penalty for each line break introduced inside a string literal.
1829
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001830**PenaltyBreakTemplateDeclaration** (``unsigned``)
1831 The penalty for breaking after template declaration.
1832
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001833**PenaltyExcessCharacter** (``unsigned``)
1834 The penalty for each character outside of the column limit.
1835
1836**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1837 Penalty for putting the return type of a function onto its own
1838 line.
1839
Daniel Jasper553d4872014-06-17 12:40:34 +00001840**PointerAlignment** (``PointerAlignmentStyle``)
1841 Pointer and reference alignment style.
1842
1843 Possible values:
1844
1845 * ``PAS_Left`` (in configuration: ``Left``)
1846 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001847
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001848 .. code-block:: c++
1849
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001850 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001851
Daniel Jasper553d4872014-06-17 12:40:34 +00001852 * ``PAS_Right`` (in configuration: ``Right``)
1853 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001854
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001855 .. code-block:: c++
1856
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001857 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001858
Daniel Jasper553d4872014-06-17 12:40:34 +00001859 * ``PAS_Middle`` (in configuration: ``Middle``)
1860 Align pointer in the middle.
1861
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001862 .. code-block:: c++
1863
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001864 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001865
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001866
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001867
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001868**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001869 Defines hints for detecting supported languages code blocks in raw
1870 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001871
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001872 A raw string with a matching delimiter or a matching enclosing function
1873 name will be reformatted assuming the specified language based on the
1874 style for that language defined in the .clang-format file. If no style has
1875 been defined in the .clang-format file for the specific language, a
1876 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1877 found, the formatting is based on llvm style. A matching delimiter takes
1878 precedence over a matching enclosing function name for determining the
1879 language of the raw string contents.
1880
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001881 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001882 the same language will be updated to the canonical if possible.
1883
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001884 There should be at most one specification per language and each delimiter
1885 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001886
1887 To configure this in the .clang-format file, use:
1888
1889 .. code-block:: yaml
1890
1891 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001892 - Language: TextProto
1893 Delimiters:
1894 - 'pb'
1895 - 'proto'
1896 EnclosingFunctions:
1897 - 'PARSE_TEXT_PROTO'
1898 BasedOnStyle: google
1899 - Language: Cpp
1900 Delimiters:
1901 - 'cc'
1902 - 'cpp'
1903 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001904 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001905
Alexander Kornienko1e048232016-02-23 16:11:51 +00001906**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001907 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001908
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001909 .. code-block:: c++
1910
1911 false:
1912 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1913 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1914
1915 true:
1916 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1917 // information
1918 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1919 * information */
1920
Alexander Kornienko1e048232016-02-23 16:11:51 +00001921**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001922 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001923
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001924 .. code-block:: c++
1925
1926 false: true:
1927 #include "b.h" vs. #include "a.h"
1928 #include "a.h" #include "b.h"
1929
Krasimir Georgievac16a202017-06-23 11:46:03 +00001930**SortUsingDeclarations** (``bool``)
1931 If ``true``, clang-format will sort using declarations.
1932
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001933 The order of using declarations is defined as follows:
1934 Split the strings by "::" and discard any initial empty strings. The last
1935 element of each list is a non-namespace name; all others are namespace
1936 names. Sort the lists of names lexicographically, where the sort order of
1937 individual names is that all non-namespace names come before all namespace
1938 names, and within those groups, names are in case-insensitive
1939 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001940
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001941 .. code-block:: c++
1942
1943 false: true:
1944 using std::cout; vs. using std::cin;
1945 using std::cin; using std::cout;
1946
Daniel Jasperb87899b2014-09-10 13:11:45 +00001947**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001948 If ``true``, a space is inserted after C style casts.
1949
1950 .. code-block:: c++
1951
1952 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001953 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001954
Reuben Thomas91f60b42019-04-08 12:54:48 +00001955**SpaceAfterLogicalNot** (``bool``)
1956 If ``true``, a space is inserted after the logical not operator (``!``).
1957 .. code-block:: c++
1958
1959 true: false:
1960 ! someExpression(); vs. !someExpression();
1961
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001962**SpaceAfterTemplateKeyword** (``bool``)
1963 If ``true``, a space will be inserted after the 'template' keyword.
1964
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001965 .. code-block:: c++
1966
1967 true: false:
1968 template <int> void foo(); vs. template<int> void foo();
1969
Daniel Jasperd94bff32013-09-25 15:15:02 +00001970**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001971 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001972
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001973 .. code-block:: c++
1974
1975 true: false:
1976 int a = 5; vs. int a=5;
1977 a += 42 a+=42;
1978
Hans Wennborgbfc34062018-06-14 08:01:09 +00001979**SpaceBeforeCpp11BracedList** (``bool``)
1980 If ``true``, a space will be inserted before a C++11 braced list
1981 used to initialize an object (after the preceding identifier or type).
1982
1983 .. code-block:: c++
1984
1985 true: false:
1986 Foo foo { bar }; vs. Foo foo{ bar };
1987 Foo {}; Foo{};
1988 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1989 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1990
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001991**SpaceBeforeCtorInitializerColon** (``bool``)
1992 If ``false``, spaces will be removed before constructor initializer
1993 colon.
1994
1995 .. code-block:: c++
1996
1997 true: false:
1998 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1999
2000**SpaceBeforeInheritanceColon** (``bool``)
2001 If ``false``, spaces will be removed before inheritance colon.
2002
2003 .. code-block:: c++
2004
2005 true: false:
2006 class Foo : Bar {} vs. class Foo: Bar {}
2007
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002008**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
2009 Defines in which cases to put a space before opening parentheses.
2010
2011 Possible values:
2012
2013 * ``SBPO_Never`` (in configuration: ``Never``)
2014 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002015
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002016 .. code-block:: c++
2017
2018 void f() {
2019 if(true) {
2020 f();
2021 }
2022 }
2023
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002024 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
2025 Put a space before opening parentheses only after control statement
2026 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002027
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002028 .. code-block:: c++
2029
2030 void f() {
2031 if (true) {
2032 f();
2033 }
2034 }
2035
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002036 * ``SBPO_Always`` (in configuration: ``Always``)
2037 Always put a space before opening parentheses, except when it's
2038 prohibited by the syntax rules (in function-like macro definitions) or
2039 when determined by other style rules (after unary operators, opening
2040 parentheses, etc.)
2041
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002042 .. code-block:: c++
2043
2044 void f () {
2045 if (true) {
2046 f ();
2047 }
2048 }
2049
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002050
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002051
Francois Ferrand2a9ea782018-03-01 10:09:13 +00002052**SpaceBeforeRangeBasedForLoopColon** (``bool``)
2053 If ``false``, spaces will be removed before range-based for loop
2054 colon.
2055
2056 .. code-block:: c++
2057
2058 true: false:
2059 for (auto v : values) {} vs. for(auto v: values) {}
2060
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002061**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002062 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002063
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002064 .. code-block:: c++
2065
2066 true: false:
2067 void f( ) { vs. void f() {
2068 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
2069 if (true) { if (true) {
2070 f( ); f();
2071 } }
2072 } }
2073
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002074**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00002075 The number of spaces before trailing line comments
2076 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00002077
Alexander Kornienko70f97c92016-02-27 14:02:08 +00002078 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002079 those commonly have different usage patterns and a number of special
2080 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002081
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002082 .. code-block:: c++
2083
2084 SpacesBeforeTrailingComments: 3
2085 void f() {
2086 if (true) { // foo1
2087 f(); // bar
2088 } // foo
2089 }
2090
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002091**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002092 If ``true``, spaces will be inserted after ``<`` and before ``>``
2093 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002094
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002095 .. code-block:: c++
2096
2097 true: false:
2098 static_cast< int >(arg); vs. static_cast<int>(arg);
2099 std::function< void(int) > fct; std::function<void(int)> fct;
2100
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002101**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002102 If ``true``, spaces may be inserted into C style casts.
2103
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002104 .. code-block:: c++
2105
2106 true: false:
2107 x = ( int32 )y vs. x = (int32)y
2108
Daniel Jasperee107ad2014-02-13 12:51:50 +00002109**SpacesInContainerLiterals** (``bool``)
2110 If ``true``, spaces are inserted inside container literals (e.g.
2111 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002112
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002113 .. code-block:: js
2114
2115 true: false:
2116 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2117 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2118
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002119**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002120 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002121
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002122 .. code-block:: c++
2123
2124 true: false:
2125 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2126
Daniel Jasperad981f82014-08-26 11:41:14 +00002127**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002128 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002129 Lambdas or unspecified size array declarations will not be affected.
2130
2131 .. code-block:: c++
2132
2133 true: false:
2134 int a[ 5 ]; vs. int a[5];
2135 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002136
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002137**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002138 Format compatible with this standard, e.g. use ``A<A<int> >``
2139 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002140
2141 Possible values:
2142
2143 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2144 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002145
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002146 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002147 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002148 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002149
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002150 * ``LS_Auto`` (in configuration: ``Auto``)
2151 Automatic detection based on the input.
2152
2153
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002154
Francois Ferrand6f40e212018-10-02 16:37:51 +00002155**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002156 A vector of macros that should be interpreted as complete
2157 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002158
2159 Typical macros are expressions, and require a semi-colon to be
2160 added; sometimes this is not the case, and this allows to make
2161 clang-format aware of such cases.
2162
2163 For example: Q_UNUSED
2164
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002165**TabWidth** (``unsigned``)
2166 The number of columns used for tab stops.
2167
2168**UseTab** (``UseTabStyle``)
2169 The way to use tab characters in the resulting file.
2170
2171 Possible values:
2172
2173 * ``UT_Never`` (in configuration: ``Never``)
2174 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002175
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002176 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2177 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002178
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002179 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2180 Use tabs only for line continuation and indentation.
2181
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002182 * ``UT_Always`` (in configuration: ``Always``)
2183 Use tabs whenever we need to fill whitespace that spans at least from
2184 one tab stop to the next one.
2185
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002186
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002187
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002188.. END_FORMAT_STYLE_OPTIONS
2189
Daniel Jasper49d3d582015-10-05 07:24:55 +00002190Adding additional style options
2191===============================
2192
2193Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002194these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002195sure that any given combination of options work and that new features don't
2196break any of the existing options in any way. There are also costs for end users
2197as options become less discoverable and people have to think about and make a
2198decision on options they don't really care about.
2199
2200The goal of the clang-format project is more on the side of supporting a
2201limited set of styles really well as opposed to supporting every single style
2202used by a codebase somewhere in the wild. Of course, we do want to support all
2203major projects and thus have established the following bar for adding style
2204options. Each new style option must ..
2205
Daniel Jasperfcbea712015-10-05 13:30:42 +00002206 * be used in a project of significant size (have dozens of contributors)
2207 * have a publicly accessible style guide
2208 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002209
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002210Examples
2211========
2212
2213A style similar to the `Linux Kernel style
2214<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2215
2216.. code-block:: yaml
2217
2218 BasedOnStyle: LLVM
2219 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002220 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002221 BreakBeforeBraces: Linux
2222 AllowShortIfStatementsOnASingleLine: false
2223 IndentCaseLabels: false
2224
2225The result is (imagine that tabs are used for indentation here):
2226
2227.. code-block:: c++
2228
2229 void test()
2230 {
2231 switch (x) {
2232 case 0:
2233 case 1:
2234 do_something();
2235 break;
2236 case 2:
2237 do_something_else();
2238 break;
2239 default:
2240 break;
2241 }
2242 if (condition)
2243 do_something_completely_different();
2244
2245 if (x == y) {
2246 q();
2247 } else if (x > y) {
2248 w();
2249 } else {
2250 r();
2251 }
2252 }
2253
2254A style similar to the default Visual Studio formatting style:
2255
2256.. code-block:: yaml
2257
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002258 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002259 IndentWidth: 4
2260 BreakBeforeBraces: Allman
2261 AllowShortIfStatementsOnASingleLine: false
2262 IndentCaseLabels: false
2263 ColumnLimit: 0
2264
2265The result is:
2266
2267.. code-block:: c++
2268
2269 void test()
2270 {
2271 switch (suffix)
2272 {
2273 case 0:
2274 case 1:
2275 do_something();
2276 break;
2277 case 2:
2278 do_something_else();
2279 break;
2280 default:
2281 break;
2282 }
2283 if (condition)
2284 do_somthing_completely_different();
2285
2286 if (x == y)
2287 {
2288 q();
2289 }
2290 else if (x > y)
2291 {
2292 w();
2293 }
2294 else
2295 {
2296 r();
2297 }
2298 }