blob: 0ddc313d27aa4c0b1bf5befcb8d288bea373de76 [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
452**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000453 If ``true``, ``while (true) continue;`` can be put on a single
454 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000455
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000456**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000457 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000458 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000459
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000460 Possible values:
461
462 * ``DRTBS_None`` (in configuration: ``None``)
463 Break after return type automatically.
464 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000465
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000466 * ``DRTBS_All`` (in configuration: ``All``)
467 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000468
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000469 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000470 Always break after the return types of top-level functions.
471
472
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000473
Zachary Turner448592e2015-12-18 22:20:15 +0000474**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
475 The function declaration return type breaking style to use.
476
477 Possible values:
478
479 * ``RTBS_None`` (in configuration: ``None``)
480 Break after return type automatically.
481 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000482
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000483 .. code-block:: c++
484
485 class A {
486 int f() { return 0; };
487 };
488 int f();
489 int f() { return 1; }
490
Zachary Turner448592e2015-12-18 22:20:15 +0000491 * ``RTBS_All`` (in configuration: ``All``)
492 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000493
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000494 .. code-block:: c++
495
496 class A {
497 int
498 f() {
499 return 0;
500 };
501 };
502 int
503 f();
504 int
505 f() {
506 return 1;
507 }
508
Zachary Turner448592e2015-12-18 22:20:15 +0000509 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
510 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000511
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000512 .. code-block:: c++
513
514 class A {
515 int f() { return 0; };
516 };
517 int
518 f();
519 int
520 f() {
521 return 1;
522 }
523
Zachary Turner448592e2015-12-18 22:20:15 +0000524 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
525 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000526
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000527 .. code-block:: c++
528
529 class A {
530 int
531 f() {
532 return 0;
533 };
534 };
535 int f();
536 int
537 f() {
538 return 1;
539 }
540
Zachary Turner448592e2015-12-18 22:20:15 +0000541 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
542 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000543
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000544 .. code-block:: c++
545
546 class A {
547 int f() { return 0; };
548 };
549 int f();
550 int
551 f() {
552 return 1;
553 }
554
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000555
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000556
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000557**AlwaysBreakBeforeMultilineStrings** (``bool``)
558 If ``true``, always break before multiline string literals.
559
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000560 This flag is mean to make cases where there are multiple multiline strings
561 in a file look more consistent. Thus, it will only take effect if wrapping
562 the string at that point leads to it being indented
563 ``ContinuationIndentWidth`` spaces from the start of the line.
564
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000565 .. code-block:: c++
566
567 true: false:
568 aaaa = vs. aaaa = "bbbb"
569 "bbbb" "cccc";
570 "cccc";
571
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000572**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
573 The template declaration breaking style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000574
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000575 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000576
Francois Ferrand58e6fe52018-05-16 08:25:03 +0000577 * ``BTDS_No`` (in configuration: ``No``)
578 Do not force break before declaration.
579 ``PenaltyBreakTemplateDeclaration`` is taken into account.
580
581 .. code-block:: c++
582
583 template <typename T> T foo() {
584 }
585 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
586 int bbbbbbbbbbbbbbbbbbbbb) {
587 }
588
589 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
590 Force break after template declaration only when the following
591 declaration spans multiple lines.
592
593 .. code-block:: c++
594
595 template <typename T> T foo() {
596 }
597 template <typename T>
598 T foo(int aaaaaaaaaaaaaaaaaaaaa,
599 int bbbbbbbbbbbbbbbbbbbbb) {
600 }
601
602 * ``BTDS_Yes`` (in configuration: ``Yes``)
603 Always break after template declaration.
604
605 .. code-block:: c++
606
607 template <typename T>
608 T foo() {
609 }
610 template <typename T>
611 T foo(int aaaaaaaaaaaaaaaaaaaaa,
612 int bbbbbbbbbbbbbbbbbbbbb) {
613 }
614
615
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000616
Daniel Jasper18210d72014-10-09 09:52:05 +0000617**BinPackArguments** (``bool``)
618 If ``false``, a function call's arguments will either be all on the
619 same line or will have one line each.
620
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000621 .. code-block:: c++
622
623 true:
624 void f() {
625 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
626 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
627 }
628
629 false:
630 void f() {
631 f(aaaaaaaaaaaaaaaaaaaa,
632 aaaaaaaaaaaaaaaaaaaa,
633 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
634 }
635
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000636**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000637 If ``false``, a function declaration's or function definition's
638 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000639
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000640 .. code-block:: c++
641
642 true:
643 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
644 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
645
646 false:
647 void f(int aaaaaaaaaaaaaaaaaaaa,
648 int aaaaaaaaaaaaaaaaaaaa,
649 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
650
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000651**BraceWrapping** (``BraceWrappingFlags``)
652 Control of individual brace wrapping cases.
653
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000654 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
655 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000656
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000657 .. code-block:: yaml
658
659 # Example of usage:
660 BreakBeforeBraces: Custom
661 BraceWrapping:
662 AfterEnum: true
663 AfterStruct: false
664 SplitEmptyFunction: false
665
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000666 Nested configuration flags:
667
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000668
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000669 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000670
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000671 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000672
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000673 true:
674 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000675
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000676 false:
677 class foo
678 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000679
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000680 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000681
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000682 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000683
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000684 true:
685 if (foo())
686 {
687 } else
688 {}
689 for (int i = 0; i < 10; ++i)
690 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000691
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000692 false:
693 if (foo()) {
694 } else {
695 }
696 for (int i = 0; i < 10; ++i) {
697 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000698
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000699 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000700
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000701 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000702
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000703 true:
704 enum X : int
705 {
706 B
707 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000708
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000709 false:
710 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000711
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000712 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000713
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000714 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000715
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000716 true:
717 void foo()
718 {
719 bar();
720 bar2();
721 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000722
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000723 false:
724 void foo() {
725 bar();
726 bar2();
727 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000728
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000729 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000730
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000731 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000732
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000733 true:
734 namespace
735 {
736 int foo();
737 int bar();
738 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000739
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000740 false:
741 namespace {
742 int foo();
743 int bar();
744 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000745
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000746 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
747 @autoreleasepool and @synchronized blocks are wrapped
748 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000749
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000750 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000751
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000752 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000753
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000754 true:
755 struct foo
756 {
757 int x;
758 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000759
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000760 false:
761 struct foo {
762 int x;
763 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000764
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000765 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000766
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000767 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000768
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000769 true:
770 union foo
771 {
772 int x;
773 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000774
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000775 false:
776 union foo {
777 int x;
778 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000779
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000780 * ``bool AfterExternBlock`` Wrap extern blocks.
781
782 .. code-block:: c++
783
784 true:
785 extern "C"
786 {
787 int foo();
788 }
789
790 false:
791 extern "C" {
792 int foo();
793 }
794
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000795 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000796
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000797 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000798
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000799 true:
800 try {
801 foo();
802 }
803 catch () {
804 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000805
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000806 false:
807 try {
808 foo();
809 } catch () {
810 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000811
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000812 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000813
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000814 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000815
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000816 true:
817 if (foo()) {
818 }
819 else {
820 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000821
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000822 false:
823 if (foo()) {
824 } else {
825 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000826
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000827 * ``bool IndentBraces`` Indent the wrapped braces themselves.
828
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000829 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000830 This option is used only if the opening brace of the function has
831 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
832 set, and the function could/should not be put on a single line (as per
833 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000834
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000835 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000836
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000837 int f() vs. inf f()
838 {} {
839 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000840
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000841 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
842 can be put on a single line. This option is used only if the opening
843 brace of the record has already been wrapped, i.e. the `AfterClass`
844 (for classes) brace wrapping mode is set.
845
846 .. code-block:: c++
847
848 class Foo vs. class Foo
849 {} {
850 }
851
852 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
853 This option is used only if the opening brace of the namespace has
854 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
855 set.
856
857 .. code-block:: c++
858
859 namespace Foo vs. namespace Foo
860 {} {
861 }
862
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000863
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000864**BreakAfterJavaFieldAnnotations** (``bool``)
865 Break after each annotation on a field in Java files.
866
Sylvestre Ledrude098242017-04-11 07:07:05 +0000867 .. code-block:: java
868
869 true: false:
870 @Partial vs. @Partial @Mock DataLoad loader;
871 @Mock
872 DataLoad loader;
873
Daniel Jasperac043c92014-09-15 11:11:00 +0000874**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
875 The way to wrap binary operators.
876
877 Possible values:
878
879 * ``BOS_None`` (in configuration: ``None``)
880 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000881
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000882 .. code-block:: c++
883
884 LooooooooooongType loooooooooooooooooooooongVariable =
885 someLooooooooooooooooongFunction();
886
887 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
888 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
889 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
890 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
891 ccccccccccccccccccccccccccccccccccccccccc;
892
Daniel Jasperac043c92014-09-15 11:11:00 +0000893 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
894 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000895
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000896 .. code-block:: c++
897
898 LooooooooooongType loooooooooooooooooooooongVariable =
899 someLooooooooooooooooongFunction();
900
901 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
902 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
903 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
904 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
905 > ccccccccccccccccccccccccccccccccccccccccc;
906
Daniel Jasperac043c92014-09-15 11:11:00 +0000907 * ``BOS_All`` (in configuration: ``All``)
908 Break before operators.
909
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000910 .. code-block:: c++
911
912 LooooooooooongType loooooooooooooooooooooongVariable
913 = someLooooooooooooooooongFunction();
914
915 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
916 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
917 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
918 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
919 > ccccccccccccccccccccccccccccccccccccccccc;
920
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000921
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000922
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000923**BreakBeforeBraces** (``BraceBreakingStyle``)
924 The brace breaking style to use.
925
926 Possible values:
927
928 * ``BS_Attach`` (in configuration: ``Attach``)
929 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000930
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000931 .. code-block:: c++
932
933 try {
934 foo();
935 } catch () {
936 }
937 void foo() { bar(); }
938 class foo {};
939 if (foo()) {
940 } else {
941 }
942 enum X : int { A, B };
943
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000944 * ``BS_Linux`` (in configuration: ``Linux``)
945 Like ``Attach``, but break before braces on function, namespace and
946 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000947
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000948 .. code-block:: c++
949
950 try {
951 foo();
952 } catch () {
953 }
954 void foo() { bar(); }
955 class foo
956 {
957 };
958 if (foo()) {
959 } else {
960 }
961 enum X : int { A, B };
962
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000963 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
964 Like ``Attach``, but break before braces on enum, function, and record
965 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000966
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000967 .. code-block:: c++
968
969 try {
970 foo();
971 } catch () {
972 }
973 void foo() { bar(); }
974 class foo
975 {
976 };
977 if (foo()) {
978 } else {
979 }
980 enum X : int { A, B };
981
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000982 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000983 Like ``Attach``, but break before function definitions, ``catch``, and
984 ``else``.
985
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000986 .. code-block:: c++
987
988 try {
989 foo();
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000990 }
991 catch () {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000992 }
993 void foo() { bar(); }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000994 class foo {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000995 };
996 if (foo()) {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000997 }
Sylvestre Ledrua060aa82018-10-26 07:25:37 +0000998 else {
999 }
1000 enum X : int { A, B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001001
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001002 * ``BS_Allman`` (in configuration: ``Allman``)
1003 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001004
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001005 .. code-block:: c++
1006
Jan Korous3fd4a962019-03-05 01:45:31 +00001007 try
1008 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001009 foo();
1010 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001011 catch ()
1012 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001013 }
1014 void foo() { bar(); }
Jan Korous3fd4a962019-03-05 01:45:31 +00001015 class foo
1016 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001017 };
Jan Korous3fd4a962019-03-05 01:45:31 +00001018 if (foo())
1019 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001020 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001021 else
1022 {
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001023 }
Jan Korous3fd4a962019-03-05 01:45:31 +00001024 enum X : int
1025 {
1026 A,
1027 B
1028 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001029
Daniel Jasperee107ad2014-02-13 12:51:50 +00001030 * ``BS_GNU`` (in configuration: ``GNU``)
1031 Always break before braces and add an extra level of indentation to
1032 braces of control statements, not to those of class, function
1033 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001034
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001035 .. code-block:: c++
1036
1037 try
1038 {
1039 foo();
1040 }
1041 catch ()
1042 {
1043 }
1044 void foo() { bar(); }
1045 class foo
1046 {
1047 };
1048 if (foo())
1049 {
1050 }
1051 else
1052 {
1053 }
1054 enum X : int
1055 {
1056 A,
1057 B
1058 };
1059
Roman Kashitsyn291f64f2015-08-10 13:43:19 +00001060 * ``BS_WebKit`` (in configuration: ``WebKit``)
1061 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001062
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001063 .. code-block:: c++
1064
1065 try {
1066 foo();
1067 } catch () {
1068 }
1069 void foo() { bar(); }
1070 class foo {
1071 };
1072 if (foo()) {
1073 } else {
1074 }
1075 enum X : int { A, B };
1076
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001077 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001078 Configure each individual brace in `BraceWrapping`.
1079
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001080
1081
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001082**BreakBeforeTernaryOperators** (``bool``)
1083 If ``true``, ternary operators will be placed after line breaks.
1084
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001085 .. code-block:: c++
1086
1087 true:
1088 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1089 ? firstValue
1090 : SecondValueVeryVeryVeryVeryLong;
1091
Sylvestre Ledru121224d2017-06-06 07:26:19 +00001092 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001093 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1094 firstValue :
1095 SecondValueVeryVeryVeryVeryLong;
1096
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001097**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1098 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001099
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001100 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001101
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001102 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1103 Break constructor initializers before the colon and after the commas.
1104
1105 .. code-block:: c++
1106
Francois Ferrand767e1522018-06-14 13:32:14 +00001107 Constructor()
1108 : initializer1(),
1109 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001110
1111 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1112 Break constructor initializers before the colon and commas, and align
1113 the commas with the colon.
1114
1115 .. code-block:: c++
1116
Francois Ferrand767e1522018-06-14 13:32:14 +00001117 Constructor()
1118 : initializer1()
1119 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001120
1121 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1122 Break constructor initializers after the colon and commas.
1123
1124 .. code-block:: c++
1125
Francois Ferrand767e1522018-06-14 13:32:14 +00001126 Constructor() :
1127 initializer1(),
1128 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001129
1130
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001131
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001132**BreakInheritanceList** (``BreakInheritanceListStyle``)
1133 The inheritance list style to use.
1134
1135 Possible values:
1136
1137 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1138 Break inheritance list before the colon and after the commas.
1139
1140 .. code-block:: c++
1141
Francois Ferrand767e1522018-06-14 13:32:14 +00001142 class Foo
1143 : Base1,
1144 Base2
1145 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001146
1147 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1148 Break inheritance list before the colon and commas, and align
1149 the commas with the colon.
1150
1151 .. code-block:: c++
1152
Francois Ferrand767e1522018-06-14 13:32:14 +00001153 class Foo
1154 : Base1
1155 , Base2
1156 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001157
1158 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1159 Break inheritance list after the colon and commas.
1160
1161 .. code-block:: c++
1162
Francois Ferrand767e1522018-06-14 13:32:14 +00001163 class Foo :
1164 Base1,
1165 Base2
1166 {};
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001167
1168
1169
Alexander Kornienko1e048232016-02-23 16:11:51 +00001170**BreakStringLiterals** (``bool``)
1171 Allow breaking string literals when formatting.
1172
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001173**ColumnLimit** (``unsigned``)
1174 The column limit.
1175
1176 A column limit of ``0`` means that there is no column limit. In this case,
1177 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001178 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001179
Daniel Jasperee107ad2014-02-13 12:51:50 +00001180**CommentPragmas** (``std::string``)
1181 A regular expression that describes comments with special meaning,
1182 which should not be split into lines or otherwise changed.
1183
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001184 .. code-block:: c++
1185
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001186 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001187 // Will leave the following line unaffected
1188 #include <vector> // FOOBAR pragma: keep
1189
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001190**CompactNamespaces** (``bool``)
1191 If ``true``, consecutive namespace declarations will be on the same
1192 line. If ``false``, each namespace is declared on a new line.
1193
1194 .. code-block:: c++
1195
1196 true:
1197 namespace Foo { namespace Bar {
1198 }}
1199
1200 false:
1201 namespace Foo {
1202 namespace Bar {
1203 }
1204 }
1205
1206 If it does not fit on a single line, the overflowing namespaces get
1207 wrapped:
1208
1209 .. code-block:: c++
1210
1211 namespace Foo { namespace Bar {
1212 namespace Extra {
1213 }}}
1214
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001215**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1216 If the constructor initializers don't fit on a line, put each
1217 initializer on its own line.
1218
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001219 .. code-block:: c++
1220
1221 true:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001222 SomeClass::Constructor()
1223 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1224 return 0;
1225 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001226
1227 false:
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001228 SomeClass::Constructor()
1229 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1230 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1231 return 0;
1232 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001233
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001234**ConstructorInitializerIndentWidth** (``unsigned``)
1235 The number of characters to use for indentation of constructor
Francois Ferrand6bb103f2018-06-11 14:41:26 +00001236 initializer lists as well as inheritance lists.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001237
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001238**ContinuationIndentWidth** (``unsigned``)
1239 Indent width for line continuations.
1240
Sylvestre Ledrude098242017-04-11 07:07:05 +00001241 .. code-block:: c++
1242
1243 ContinuationIndentWidth: 2
1244
1245 int i = // VeryVeryVeryVeryVeryLongComment
1246 longFunction( // Again a long comment
1247 arg);
1248
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001249**Cpp11BracedListStyle** (``bool``)
1250 If ``true``, format braced lists as best suited for C++11 braced
1251 lists.
1252
1253 Important differences:
1254 - No spaces inside the braced list.
1255 - No line break before the closing brace.
1256 - Indentation with the continuation indent, not with the block indent.
1257
1258 Fundamentally, C++11 braced lists are formatted exactly like function
1259 calls would be formatted in their place. If the braced list follows a name
1260 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1261 the parentheses of a function call with that name. If there is no name,
1262 a zero-length name is assumed.
1263
Sylvestre Ledrude098242017-04-11 07:07:05 +00001264 .. code-block:: c++
1265
1266 true: false:
1267 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1268 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1269 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1270 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1271
Daniel Jasper553d4872014-06-17 12:40:34 +00001272**DerivePointerAlignment** (``bool``)
1273 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001274 alignment of ``&`` and ``*``.
1275 Pointer and reference alignment styles are going to be updated according
1276 to the preferences found in the file.
1277 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001278
1279**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001280 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001281
1282**ExperimentalAutoDetectBinPacking** (``bool``)
1283 If ``true``, clang-format detects whether function calls and
1284 definitions are formatted with one parameter per line.
1285
1286 Each call can be bin-packed, one-per-line or inconclusive. If it is
1287 inconclusive, e.g. completely on one line, but a decision needs to be
1288 made, clang-format analyzes whether there are other bin-packed cases in
1289 the input file and act accordingly.
1290
1291 NOTE: This is an experimental flag, that might go away or be renamed. Do
1292 not use this in config files, etc. Use at your own risk.
1293
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001294**FixNamespaceComments** (``bool``)
1295 If ``true``, clang-format adds missing namespace end comments and
1296 fixes invalid existing ones.
1297
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001298 .. code-block:: c++
1299
1300 true: false:
1301 namespace a { vs. namespace a {
1302 foo(); foo();
1303 } // namespace a; }
1304
Daniel Jaspere1e43192014-04-01 12:55:11 +00001305**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001306 A vector of macros that should be interpreted as foreach loops
1307 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001308
Daniel Jasperb5524822014-04-09 14:05:49 +00001309 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001310
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001311 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001312
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001313 FOREACH(<variable-declaration>, ...)
1314 <loop-body>
1315
1316 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001317
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001318 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001319
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001320 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001321
1322 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001323
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001324**IncludeBlocks** (``IncludeBlocksStyle``)
1325 Dependent on the value, multiple ``#include`` blocks can be sorted
1326 as one and divided based on category.
1327
1328 Possible values:
1329
1330 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1331 Sort each ``#include`` block separately.
1332
1333 .. code-block:: c++
1334
1335 #include "b.h" into #include "b.h"
1336
1337 #include <lib/main.h> #include "a.h"
1338 #include "a.h" #include <lib/main.h>
1339
1340 * ``IBS_Merge`` (in configuration: ``Merge``)
1341 Merge multiple ``#include`` blocks together and sort as one.
1342
1343 .. code-block:: c++
1344
1345 #include "b.h" into #include "a.h"
1346 #include "b.h"
1347 #include <lib/main.h> #include <lib/main.h>
1348 #include "a.h"
1349
1350 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1351 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001352 Then split into groups based on category priority. See
1353 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001354
1355 .. code-block:: c++
1356
1357 #include "b.h" into #include "a.h"
1358 #include "b.h"
1359 #include <lib/main.h>
1360 #include "a.h" #include <lib/main.h>
1361
1362
1363
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001364**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001365 Regular expressions denoting the different ``#include`` categories
1366 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001367
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001368 `POSIX extended
Eugene Zelenkoadcb3f52019-01-23 20:39:07 +00001369 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001370 regular expressions are supported.
1371
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001372 These regular expressions are matched against the filename of an include
1373 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001374 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001375 according to increasing category number and then alphabetically within
1376 each category.
1377
Alexander Kornienko1e048232016-02-23 16:11:51 +00001378 If none of the regular expressions match, INT_MAX is assigned as
1379 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001380 so that it is generally kept at the beginning of the ``#includes``
Sylvestre Ledrubc5c3f52018-11-04 17:02:00 +00001381 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
Alexander Kornienko1e048232016-02-23 16:11:51 +00001382 can also assign negative priorities if you have certain headers that
1383 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001384
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001385 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001386
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001387 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001388
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001389 IncludeCategories:
1390 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1391 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001392 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001393 Priority: 3
Krasimir Georgievcf699ad2018-07-25 10:21:47 +00001394 - Regex: '<[[:alnum:].]+>'
1395 Priority: 4
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001396 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001397 Priority: 1
1398
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001399**IncludeIsMainRegex** (``std::string``)
1400 Specify a regular expression of suffixes that are allowed in the
1401 file-to-main-include mapping.
1402
1403 When guessing whether a #include is the "main" include (to assign
1404 category 0, see above), use this regex of allowed suffixes to the header
1405 stem. A partial match is done, so that:
1406 - "" means "arbitrary suffix"
1407 - "$" means "no suffix"
1408
1409 For example, if configured to "(_test)?$", then a header a.h would be seen
1410 as the "main" include in both a.cc and a_test.cc.
1411
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001412**IndentCaseLabels** (``bool``)
1413 Indent case labels one level from the switch statement.
1414
1415 When ``false``, use the same indentation level as for the switch statement.
1416 Switch statement body is always indented one level more than case labels.
1417
Sylvestre Ledrude098242017-04-11 07:07:05 +00001418 .. code-block:: c++
1419
1420 false: true:
1421 switch (fool) { vs. switch (fool) {
1422 case 1: case 1:
1423 bar(); bar();
1424 break; break;
1425 default: default:
1426 plop(); plop();
1427 } }
1428
Krasimir Georgievad47c902017-08-30 14:34:57 +00001429**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001430 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001431
1432 Possible values:
1433
1434 * ``PPDIS_None`` (in configuration: ``None``)
1435 Does not indent any directives.
1436
1437 .. code-block:: c++
1438
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001439 #if FOO
1440 #if BAR
1441 #include <foo>
1442 #endif
1443 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001444
1445 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1446 Indents directives after the hash.
1447
1448 .. code-block:: c++
1449
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001450 #if FOO
1451 # if BAR
1452 # include <foo>
1453 # endif
1454 #endif
1455
Paul Hoad701a0d72019-03-20 20:49:43 +00001456 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1457 Indents directives before the hash.
1458
1459 .. code-block:: c++
1460
1461 #if FOO
1462 #if BAR
1463 #include <foo>
1464 #endif
1465 #endif
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001466
Krasimir Georgievad47c902017-08-30 14:34:57 +00001467
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001468**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001469 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001470
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001471 .. code-block:: c++
1472
1473 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001474
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001475 void f() {
1476 someFunction();
1477 if (true, false) {
1478 f();
1479 }
1480 }
1481
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001482**IndentWrappedFunctionNames** (``bool``)
1483 Indent if a function definition or declaration is wrapped after the
1484 type.
1485
Sylvestre Ledrude098242017-04-11 07:07:05 +00001486 .. code-block:: c++
1487
1488 true:
1489 LoooooooooooooooooooooooooooooooooooooooongReturnType
1490 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1491
1492 false:
1493 LoooooooooooooooooooooooooooooooooooooooongReturnType
1494 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1495
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001496**JavaImportGroups** (``std::vector<std::string>``)
1497 A vector of prefixes ordered by the desired groups for Java imports.
1498
Sylvestre Ledru90f1dfb2019-01-01 12:51:14 +00001499 Each group is separated by a newline. Static imports will also follow the
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001500 same grouping convention above all non-static imports. One group's prefix
1501 can be a subset of another - the longest prefix is always matched. Within
1502 a group, the imports are ordered lexicographically.
1503
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001504 In the .clang-format configuration file, this can be configured like
1505 in the following yaml example. This will result in imports being
1506 formatted as in the Java example below.
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001507
1508 .. code-block:: yaml
1509
1510 JavaImportGroups: ['com.example', 'com', 'org']
Sylvestre Ledruc2e58e72018-10-22 19:07:29 +00001511
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00001512
1513 .. code-block:: java
1514
1515 import static com.example.function1;
1516
1517 import static com.test.function2;
1518
1519 import static org.example.function3;
1520
1521 import com.example.ClassA;
1522 import com.example.Test;
1523 import com.example.a.ClassB;
1524
1525 import com.test.ClassC;
1526
1527 import org.example.ClassD;
1528
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001529**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1530 The JavaScriptQuoteStyle to use for JavaScript strings.
1531
1532 Possible values:
1533
1534 * ``JSQS_Leave`` (in configuration: ``Leave``)
1535 Leave string quotes as they are.
1536
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001537 .. code-block:: js
1538
1539 string1 = "foo";
1540 string2 = 'bar';
1541
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001542 * ``JSQS_Single`` (in configuration: ``Single``)
1543 Always use single quotes.
1544
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001545 .. code-block:: js
1546
1547 string1 = 'foo';
1548 string2 = 'bar';
1549
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001550 * ``JSQS_Double`` (in configuration: ``Double``)
1551 Always use double quotes.
1552
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001553 .. code-block:: js
1554
1555 string1 = "foo";
1556 string2 = "bar";
1557
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001558
1559
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001560**JavaScriptWrapImports** (``bool``)
1561 Whether to wrap JavaScript import/export statements.
1562
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001563 .. code-block:: js
1564
1565 true:
1566 import {
1567 VeryLongImportsAreAnnoying,
1568 VeryLongImportsAreAnnoying,
1569 VeryLongImportsAreAnnoying,
1570 } from 'some/module.js'
1571
1572 false:
1573 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1574
Daniel Jasperb5524822014-04-09 14:05:49 +00001575**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001576 If true, the empty line at the start of blocks is kept.
1577
1578 .. code-block:: c++
1579
1580 true: false:
1581 if (foo) { vs. if (foo) {
1582 bar();
1583 bar(); }
1584 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001585
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001586**Language** (``LanguageKind``)
1587 Language, this format style is targeted at.
1588
1589 Possible values:
1590
1591 * ``LK_None`` (in configuration: ``None``)
1592 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001593
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001594 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001595 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001596
Paul Hoadcbb726d2019-03-21 13:09:22 +00001597 * ``LK_CSharp`` (in configuration: ``CSharp``)
1598 Should be used for C#.
1599
Daniel Jasper18210d72014-10-09 09:52:05 +00001600 * ``LK_Java`` (in configuration: ``Java``)
1601 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001602
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001603 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1604 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001605
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001606 * ``LK_ObjC`` (in configuration: ``ObjC``)
1607 Should be used for Objective-C, Objective-C++.
1608
Daniel Jasperee107ad2014-02-13 12:51:50 +00001609 * ``LK_Proto`` (in configuration: ``Proto``)
1610 Should be used for Protocol Buffers
1611 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001612
Alexander Kornienko1e048232016-02-23 16:11:51 +00001613 * ``LK_TableGen`` (in configuration: ``TableGen``)
1614 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001615
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001616 * ``LK_TextProto`` (in configuration: ``TextProto``)
1617 Should be used for Protocol Buffer messages in text format
1618 (https://developers.google.com/protocol-buffers/).
1619
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001620
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001621
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001622**MacroBlockBegin** (``std::string``)
1623 A regular expression matching macros that start a block.
1624
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001625 .. code-block:: c++
1626
1627 # With:
1628 MacroBlockBegin: "^NS_MAP_BEGIN|\
1629 NS_TABLE_HEAD$"
1630 MacroBlockEnd: "^\
1631 NS_MAP_END|\
1632 NS_TABLE_.*_END$"
1633
1634 NS_MAP_BEGIN
1635 foo();
1636 NS_MAP_END
1637
1638 NS_TABLE_HEAD
1639 bar();
1640 NS_TABLE_FOO_END
1641
1642 # Without:
1643 NS_MAP_BEGIN
1644 foo();
1645 NS_MAP_END
1646
1647 NS_TABLE_HEAD
1648 bar();
1649 NS_TABLE_FOO_END
1650
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001651**MacroBlockEnd** (``std::string``)
1652 A regular expression matching macros that end a block.
1653
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001654**MaxEmptyLinesToKeep** (``unsigned``)
1655 The maximum number of consecutive empty lines to keep.
1656
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001657 .. code-block:: c++
1658
1659 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1660 int f() { int f() {
1661 int = 1; int i = 1;
1662 i = foo();
1663 i = foo(); return i;
1664 }
1665 return i;
1666 }
1667
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001668**NamespaceIndentation** (``NamespaceIndentationKind``)
1669 The indentation used for namespaces.
1670
1671 Possible values:
1672
1673 * ``NI_None`` (in configuration: ``None``)
1674 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001675
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001676 .. code-block:: c++
1677
1678 namespace out {
1679 int i;
1680 namespace in {
1681 int i;
1682 }
1683 }
1684
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001685 * ``NI_Inner`` (in configuration: ``Inner``)
1686 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001687
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001688 .. code-block:: c++
1689
1690 namespace out {
1691 int i;
1692 namespace in {
1693 int i;
1694 }
1695 }
1696
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001697 * ``NI_All`` (in configuration: ``All``)
1698 Indent in all namespaces.
1699
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001700 .. code-block:: c++
1701
1702 namespace out {
1703 int i;
1704 namespace in {
1705 int i;
1706 }
1707 }
1708
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001709
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001710
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001711**ObjCBinPackProtocolList** (``BinPackStyle``)
1712 Controls bin-packing Objective-C protocol conformance list
1713 items into as few lines as possible when they go over ``ColumnLimit``.
1714
1715 If ``Auto`` (the default), delegates to the value in
1716 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1717 protocol conformance list items into as few lines as possible
1718 whenever they go over ``ColumnLimit``.
1719
1720 If ``Always``, always bin-packs Objective-C protocol conformance
1721 list items into as few lines as possible whenever they go over
1722 ``ColumnLimit``.
1723
1724 If ``Never``, lays out Objective-C protocol conformance list items
1725 onto individual lines whenever they go over ``ColumnLimit``.
1726
1727
Aaron Ballman37485fd2018-06-28 12:02:38 +00001728 .. code-block:: objc
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001729
1730 Always (or Auto, if BinPackParameters=true):
1731 @interface ccccccccccccc () <
1732 ccccccccccccc, ccccccccccccc,
1733 ccccccccccccc, ccccccccccccc> {
1734 }
1735
1736 Never (or Auto, if BinPackParameters=false):
1737 @interface ddddddddddddd () <
1738 ddddddddddddd,
1739 ddddddddddddd,
1740 ddddddddddddd,
1741 ddddddddddddd> {
1742 }
1743
1744 Possible values:
1745
1746 * ``BPS_Auto`` (in configuration: ``Auto``)
1747 Automatically determine parameter bin-packing behavior.
1748
1749 * ``BPS_Always`` (in configuration: ``Always``)
1750 Always bin-pack parameters.
1751
1752 * ``BPS_Never`` (in configuration: ``Never``)
1753 Never bin-pack parameters.
1754
1755
1756
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001757**ObjCBlockIndentWidth** (``unsigned``)
1758 The number of characters to use for indentation of ObjC blocks.
1759
Sylvestre Ledrude098242017-04-11 07:07:05 +00001760 .. code-block:: objc
1761
1762 ObjCBlockIndentWidth: 4
1763
1764 [operation setCompletionBlock:^{
1765 [self onOperationDone];
1766 }];
1767
Daniel Jasperee107ad2014-02-13 12:51:50 +00001768**ObjCSpaceAfterProperty** (``bool``)
1769 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001770 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001771
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001772**ObjCSpaceBeforeProtocolList** (``bool``)
1773 Add a space in front of an Objective-C protocol list, i.e. use
1774 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1775
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001776**PenaltyBreakAssignment** (``unsigned``)
1777 The penalty for breaking around an assignment operator.
1778
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001779**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001780 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001781
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001782**PenaltyBreakComment** (``unsigned``)
1783 The penalty for each line break introduced inside a comment.
1784
1785**PenaltyBreakFirstLessLess** (``unsigned``)
1786 The penalty for breaking before the first ``<<``.
1787
1788**PenaltyBreakString** (``unsigned``)
1789 The penalty for each line break introduced inside a string literal.
1790
Francois Ferrand58e6fe52018-05-16 08:25:03 +00001791**PenaltyBreakTemplateDeclaration** (``unsigned``)
1792 The penalty for breaking after template declaration.
1793
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001794**PenaltyExcessCharacter** (``unsigned``)
1795 The penalty for each character outside of the column limit.
1796
1797**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1798 Penalty for putting the return type of a function onto its own
1799 line.
1800
Daniel Jasper553d4872014-06-17 12:40:34 +00001801**PointerAlignment** (``PointerAlignmentStyle``)
1802 Pointer and reference alignment style.
1803
1804 Possible values:
1805
1806 * ``PAS_Left`` (in configuration: ``Left``)
1807 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001808
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001809 .. code-block:: c++
1810
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001811 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001812
Daniel Jasper553d4872014-06-17 12:40:34 +00001813 * ``PAS_Right`` (in configuration: ``Right``)
1814 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001815
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001816 .. code-block:: c++
1817
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001818 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001819
Daniel Jasper553d4872014-06-17 12:40:34 +00001820 * ``PAS_Middle`` (in configuration: ``Middle``)
1821 Align pointer in the middle.
1822
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001823 .. code-block:: c++
1824
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001825 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001826
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001827
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001828
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001829**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001830 Defines hints for detecting supported languages code blocks in raw
1831 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001832
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001833 A raw string with a matching delimiter or a matching enclosing function
1834 name will be reformatted assuming the specified language based on the
1835 style for that language defined in the .clang-format file. If no style has
1836 been defined in the .clang-format file for the specific language, a
1837 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1838 found, the formatting is based on llvm style. A matching delimiter takes
1839 precedence over a matching enclosing function name for determining the
1840 language of the raw string contents.
1841
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001842 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001843 the same language will be updated to the canonical if possible.
1844
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001845 There should be at most one specification per language and each delimiter
1846 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001847
1848 To configure this in the .clang-format file, use:
1849
1850 .. code-block:: yaml
1851
1852 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001853 - Language: TextProto
1854 Delimiters:
1855 - 'pb'
1856 - 'proto'
1857 EnclosingFunctions:
1858 - 'PARSE_TEXT_PROTO'
1859 BasedOnStyle: google
1860 - Language: Cpp
1861 Delimiters:
1862 - 'cc'
1863 - 'cpp'
1864 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001865 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001866
Alexander Kornienko1e048232016-02-23 16:11:51 +00001867**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001868 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001869
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001870 .. code-block:: c++
1871
1872 false:
1873 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1874 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1875
1876 true:
1877 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1878 // information
1879 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1880 * information */
1881
Alexander Kornienko1e048232016-02-23 16:11:51 +00001882**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001883 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001884
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001885 .. code-block:: c++
1886
1887 false: true:
1888 #include "b.h" vs. #include "a.h"
1889 #include "a.h" #include "b.h"
1890
Krasimir Georgievac16a202017-06-23 11:46:03 +00001891**SortUsingDeclarations** (``bool``)
1892 If ``true``, clang-format will sort using declarations.
1893
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001894 The order of using declarations is defined as follows:
1895 Split the strings by "::" and discard any initial empty strings. The last
1896 element of each list is a non-namespace name; all others are namespace
1897 names. Sort the lists of names lexicographically, where the sort order of
1898 individual names is that all non-namespace names come before all namespace
1899 names, and within those groups, names are in case-insensitive
1900 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001901
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001902 .. code-block:: c++
1903
1904 false: true:
1905 using std::cout; vs. using std::cin;
1906 using std::cin; using std::cout;
1907
Daniel Jasperb87899b2014-09-10 13:11:45 +00001908**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001909 If ``true``, a space is inserted after C style casts.
1910
1911 .. code-block:: c++
1912
1913 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001914 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001915
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001916**SpaceAfterTemplateKeyword** (``bool``)
1917 If ``true``, a space will be inserted after the 'template' keyword.
1918
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001919 .. code-block:: c++
1920
1921 true: false:
1922 template <int> void foo(); vs. template<int> void foo();
1923
Daniel Jasperd94bff32013-09-25 15:15:02 +00001924**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001925 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001926
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001927 .. code-block:: c++
1928
1929 true: false:
1930 int a = 5; vs. int a=5;
1931 a += 42 a+=42;
1932
Hans Wennborgbfc34062018-06-14 08:01:09 +00001933**SpaceBeforeCpp11BracedList** (``bool``)
1934 If ``true``, a space will be inserted before a C++11 braced list
1935 used to initialize an object (after the preceding identifier or type).
1936
1937 .. code-block:: c++
1938
1939 true: false:
1940 Foo foo { bar }; vs. Foo foo{ bar };
1941 Foo {}; Foo{};
1942 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1943 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1944
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001945**SpaceBeforeCtorInitializerColon** (``bool``)
1946 If ``false``, spaces will be removed before constructor initializer
1947 colon.
1948
1949 .. code-block:: c++
1950
1951 true: false:
1952 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1953
1954**SpaceBeforeInheritanceColon** (``bool``)
1955 If ``false``, spaces will be removed before inheritance colon.
1956
1957 .. code-block:: c++
1958
1959 true: false:
1960 class Foo : Bar {} vs. class Foo: Bar {}
1961
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001962**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1963 Defines in which cases to put a space before opening parentheses.
1964
1965 Possible values:
1966
1967 * ``SBPO_Never`` (in configuration: ``Never``)
1968 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001969
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001970 .. code-block:: c++
1971
1972 void f() {
1973 if(true) {
1974 f();
1975 }
1976 }
1977
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001978 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1979 Put a space before opening parentheses only after control statement
1980 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001981
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001982 .. code-block:: c++
1983
1984 void f() {
1985 if (true) {
1986 f();
1987 }
1988 }
1989
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001990 * ``SBPO_Always`` (in configuration: ``Always``)
1991 Always put a space before opening parentheses, except when it's
1992 prohibited by the syntax rules (in function-like macro definitions) or
1993 when determined by other style rules (after unary operators, opening
1994 parentheses, etc.)
1995
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001996 .. code-block:: c++
1997
1998 void f () {
1999 if (true) {
2000 f ();
2001 }
2002 }
2003
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002004
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002005
Francois Ferrand2a9ea782018-03-01 10:09:13 +00002006**SpaceBeforeRangeBasedForLoopColon** (``bool``)
2007 If ``false``, spaces will be removed before range-based for loop
2008 colon.
2009
2010 .. code-block:: c++
2011
2012 true: false:
2013 for (auto v : values) {} vs. for(auto v: values) {}
2014
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002015**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002016 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002017
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002018 .. code-block:: c++
2019
2020 true: false:
2021 void f( ) { vs. void f() {
2022 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
2023 if (true) { if (true) {
2024 f( ); f();
2025 } }
2026 } }
2027
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002028**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00002029 The number of spaces before trailing line comments
2030 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00002031
Alexander Kornienko70f97c92016-02-27 14:02:08 +00002032 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002033 those commonly have different usage patterns and a number of special
2034 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002035
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002036 .. code-block:: c++
2037
2038 SpacesBeforeTrailingComments: 3
2039 void f() {
2040 if (true) { // foo1
2041 f(); // bar
2042 } // foo
2043 }
2044
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002045**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002046 If ``true``, spaces will be inserted after ``<`` and before ``>``
2047 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00002048
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002049 .. code-block:: c++
2050
2051 true: false:
2052 static_cast< int >(arg); vs. static_cast<int>(arg);
2053 std::function< void(int) > fct; std::function<void(int)> fct;
2054
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002055**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00002056 If ``true``, spaces may be inserted into C style casts.
2057
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002058 .. code-block:: c++
2059
2060 true: false:
2061 x = ( int32 )y vs. x = (int32)y
2062
Daniel Jasperee107ad2014-02-13 12:51:50 +00002063**SpacesInContainerLiterals** (``bool``)
2064 If ``true``, spaces are inserted inside container literals (e.g.
2065 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002066
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00002067 .. code-block:: js
2068
2069 true: false:
2070 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
2071 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
2072
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002073**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002074 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002075
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002076 .. code-block:: c++
2077
2078 true: false:
2079 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
2080
Daniel Jasperad981f82014-08-26 11:41:14 +00002081**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002082 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00002083 Lambdas or unspecified size array declarations will not be affected.
2084
2085 .. code-block:: c++
2086
2087 true: false:
2088 int a[ 5 ]; vs. int a[5];
2089 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00002090
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002091**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002092 Format compatible with this standard, e.g. use ``A<A<int> >``
2093 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002094
2095 Possible values:
2096
2097 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2098 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002099
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002100 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00002101 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00002102 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002103
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002104 * ``LS_Auto`` (in configuration: ``Auto``)
2105 Automatic detection based on the input.
2106
2107
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002108
Francois Ferrand6f40e212018-10-02 16:37:51 +00002109**StatementMacros** (``std::vector<std::string>``)
Sylvestre Ledru49cc6172018-10-22 18:48:58 +00002110 A vector of macros that should be interpreted as complete
2111 statements.
Francois Ferrand6f40e212018-10-02 16:37:51 +00002112
2113 Typical macros are expressions, and require a semi-colon to be
2114 added; sometimes this is not the case, and this allows to make
2115 clang-format aware of such cases.
2116
2117 For example: Q_UNUSED
2118
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002119**TabWidth** (``unsigned``)
2120 The number of columns used for tab stops.
2121
2122**UseTab** (``UseTabStyle``)
2123 The way to use tab characters in the resulting file.
2124
2125 Possible values:
2126
2127 * ``UT_Never`` (in configuration: ``Never``)
2128 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002129
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002130 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2131 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002132
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00002133 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2134 Use tabs only for line continuation and indentation.
2135
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00002136 * ``UT_Always`` (in configuration: ``Always``)
2137 Use tabs whenever we need to fill whitespace that spans at least from
2138 one tab stop to the next one.
2139
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002140
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00002141
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002142.. END_FORMAT_STYLE_OPTIONS
2143
Daniel Jasper49d3d582015-10-05 07:24:55 +00002144Adding additional style options
2145===============================
2146
2147Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00002148these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00002149sure that any given combination of options work and that new features don't
2150break any of the existing options in any way. There are also costs for end users
2151as options become less discoverable and people have to think about and make a
2152decision on options they don't really care about.
2153
2154The goal of the clang-format project is more on the side of supporting a
2155limited set of styles really well as opposed to supporting every single style
2156used by a codebase somewhere in the wild. Of course, we do want to support all
2157major projects and thus have established the following bar for adding style
2158options. Each new style option must ..
2159
Daniel Jasperfcbea712015-10-05 13:30:42 +00002160 * be used in a project of significant size (have dozens of contributors)
2161 * have a publicly accessible style guide
2162 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00002163
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002164Examples
2165========
2166
2167A style similar to the `Linux Kernel style
2168<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2169
2170.. code-block:: yaml
2171
2172 BasedOnStyle: LLVM
2173 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002174 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002175 BreakBeforeBraces: Linux
2176 AllowShortIfStatementsOnASingleLine: false
2177 IndentCaseLabels: false
2178
2179The result is (imagine that tabs are used for indentation here):
2180
2181.. code-block:: c++
2182
2183 void test()
2184 {
2185 switch (x) {
2186 case 0:
2187 case 1:
2188 do_something();
2189 break;
2190 case 2:
2191 do_something_else();
2192 break;
2193 default:
2194 break;
2195 }
2196 if (condition)
2197 do_something_completely_different();
2198
2199 if (x == y) {
2200 q();
2201 } else if (x > y) {
2202 w();
2203 } else {
2204 r();
2205 }
2206 }
2207
2208A style similar to the default Visual Studio formatting style:
2209
2210.. code-block:: yaml
2211
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00002212 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00002213 IndentWidth: 4
2214 BreakBeforeBraces: Allman
2215 AllowShortIfStatementsOnASingleLine: false
2216 IndentCaseLabels: false
2217 ColumnLimit: 0
2218
2219The result is:
2220
2221.. code-block:: c++
2222
2223 void test()
2224 {
2225 switch (suffix)
2226 {
2227 case 0:
2228 case 1:
2229 do_something();
2230 break;
2231 case 2:
2232 do_something_else();
2233 break;
2234 default:
2235 break;
2236 }
2237 if (condition)
2238 do_somthing_completely_different();
2239
2240 if (x == y)
2241 {
2242 q();
2243 }
2244 else if (x > y)
2245 {
2246 w();
2247 }
2248 else
2249 {
2250 r();
2251 }
2252 }