1==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
10the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
11custom style by configuring specific style options.
12
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
19use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
21
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
36The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An example of a configuration file for multiple languages:
51
52.. code-block:: yaml
53
54  ---
55  # We'll use defaults from the LLVM style, but with 4 columns indentation.
56  BasedOnStyle: LLVM
57  IndentWidth: 4
58  ---
59  Language: Cpp
60  # Force pointers to the type for C++.
61  DerivePointerAlignment: false
62  PointerAlignment: Left
63  ---
64  Language: JavaScript
65  # Use 100 columns for JS.
66  ColumnLimit: 100
67  ---
68  Language: Proto
69  # Don't format .proto files.
70  DisableFormat: true
71  ...
72
73An easy way to get a valid ``.clang-format`` file containing all configuration
74options of a certain predefined style is:
75
76.. code-block:: console
77
78  clang-format -style=llvm -dump-config > .clang-format
79
80When specifying configuration in the ``-style=`` option, the same configuration
81is applied for all input files. The format of the configuration is:
82
83.. code-block:: console
84
85  -style='{key1: value1, key2: value2, ...}'
86
87
88Disabling Formatting on a Piece of Code
89=======================================
90
91Clang-format understands also special comments that switch formatting in a
92delimited range. The code between a comment ``// clang-format off`` or
93``/* clang-format off */`` up to a comment ``// clang-format on`` or
94``/* clang-format on */`` will not be formatted. The comments themselves
95will be formatted (aligned) normally.
96
97.. code-block:: c++
98
99  int formatted_code;
100  // clang-format off
101      void    unformatted_code  ;
102  // clang-format on
103  void formatted_code_again;
104
105
106Configuring Style in Code
107=========================
108
109When using ``clang::format::reformat(...)`` functions, the format is specified
110by supplying the `clang::format::FormatStyle
111<http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
112structure.
113
114
115Configurable Format Style Options
116=================================
117
118This section lists the supported style options. Value type is specified for
119each option. For enumeration types possible values are specified both as a C++
120enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
121the configuration (without a prefix: ``Auto``).
122
123
124**BasedOnStyle** (``string``)
125  The style used for all options not specifically set in the configuration.
126
127  This option is supported only in the :program:`clang-format` configuration
128  (both within ``-style='{...}'`` and the ``.clang-format`` file).
129
130  Possible values:
131
132  * ``LLVM``
133    A style complying with the `LLVM coding standards
134    <http://llvm.org/docs/CodingStandards.html>`_
135  * ``Google``
136    A style complying with `Google's C++ style guide
137    <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
138  * ``Chromium``
139    A style complying with `Chromium's style guide
140    <http://www.chromium.org/developers/coding-style>`_
141  * ``Mozilla``
142    A style complying with `Mozilla's style guide
143    <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
144  * ``WebKit``
145    A style complying with `WebKit's style guide
146    <http://www.webkit.org/coding/coding-style.html>`_
147
148.. START_FORMAT_STYLE_OPTIONS
149
150**AccessModifierOffset** (``int``)
151  The extra indent or outdent of access modifiers, e.g. ``public:``.
152
153**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
154  If ``true``, horizontally aligns arguments after an open bracket.
155
156  This applies to round brackets (parentheses), angle brackets and square
157  brackets.
158
159  Possible values:
160
161  * ``BAS_Align`` (in configuration: ``Align``)
162    Align parameters on the open bracket, e.g.:
163
164    .. code-block:: c++
165
166      someLongFunction(argument1,
167                       argument2);
168
169  * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
170    Don't align, instead use ``ContinuationIndentWidth``, e.g.:
171
172    .. code-block:: c++
173
174      someLongFunction(argument1,
175          argument2);
176
177  * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
178    Always break after an open bracket, if the parameters don't fit
179    on a single line, e.g.:
180
181    .. code-block:: c++
182
183      someLongFunction(
184          argument1, argument2);
185
186
187
188**AlignConsecutiveAssignments** (``bool``)
189  If ``true``, aligns consecutive assignments.
190
191  This will align the assignment operators of consecutive lines. This
192  will result in formattings like
193
194  .. code-block:: c++
195
196    int aaaa = 12;
197    int b    = 23;
198    int ccc  = 23;
199
200**AlignConsecutiveDeclarations** (``bool``)
201  If ``true``, aligns consecutive declarations.
202
203  This will align the declaration names of consecutive lines. This
204  will result in formattings like
205
206  .. code-block:: c++
207
208    int         aaaa = 12;
209    float       b = 23;
210    std::string ccc = 23;
211
212**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
213  Options for aligning backslashes in escaped newlines.
214
215  Possible values:
216
217  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
218    Don't align escaped newlines.
219
220    .. code-block:: c++
221
222      #define A \
223        int aaaa; \
224        int b; \
225        int dddddddddd;
226
227  * ``ENAS_Left`` (in configuration: ``Left``)
228    Align escaped newlines as far left as possible.
229
230    .. code-block:: c++
231
232      true:
233      #define A   \
234        int aaaa; \
235        int b;    \
236        int dddddddddd;
237
238      false:
239
240  * ``ENAS_Right`` (in configuration: ``Right``)
241    Align escaped newlines in the right-most column.
242
243    .. code-block:: c++
244
245      #define A                                                                      \
246        int aaaa;                                                                    \
247        int b;                                                                       \
248        int dddddddddd;
249
250
251
252**AlignOperands** (``bool``)
253  If ``true``, horizontally align operands of binary and ternary
254  expressions.
255
256  Specifically, this aligns operands of a single expression that needs to be
257  split over multiple lines, e.g.:
258
259  .. code-block:: c++
260
261    int aaa = bbbbbbbbbbbbbbb +
262              ccccccccccccccc;
263
264**AlignTrailingComments** (``bool``)
265  If ``true``, aligns trailing comments.
266
267  .. code-block:: c++
268
269    true:                                   false:
270    int a;     // My comment a      vs.     int a; // My comment a
271    int b = 2; // comment  b                int b = 2; // comment about b
272
273**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
274  Allow putting all parameters of a function declaration onto
275  the next line even if ``BinPackParameters`` is ``false``.
276
277  .. code-block:: c++
278
279    true:                                   false:
280    myFunction(foo,                 vs.     myFunction(foo, bar, plop);
281               bar,
282               plop);
283
284**AllowShortBlocksOnASingleLine** (``bool``)
285  Allows contracting simple braced statements to a single line.
286
287  E.g., this allows ``if (a) { return; }`` to be put on a single line.
288
289**AllowShortCaseLabelsOnASingleLine** (``bool``)
290  If ``true``, short case labels will be contracted to a single line.
291
292  .. code-block:: c++
293
294    true:                                   false:
295    switch (a) {                    vs.     switch (a) {
296    case 1: x = 1; break;                   case 1:
297    case 2: return;                           x = 1;
298    }                                         break;
299                                            case 2:
300                                              return;
301                                            }
302
303**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
304  Dependent on the value, ``int f() { return 0; }`` can be put on a
305  single line.
306
307  Possible values:
308
309  * ``SFS_None`` (in configuration: ``None``)
310    Never merge functions into a single line.
311
312  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
313    Only merge functions defined inside a class. Same as "inline",
314    except it does not implies "empty": i.e. top level empty functions
315    are not merged either.
316
317    .. code-block:: c++
318
319      class Foo {
320        void f() { foo(); }
321      };
322      void f() {
323        foo();
324      }
325      void f() {
326      }
327
328  * ``SFS_Empty`` (in configuration: ``Empty``)
329    Only merge empty functions.
330
331    .. code-block:: c++
332
333      void f() {}
334      void f2() {
335        bar2();
336      }
337
338  * ``SFS_Inline`` (in configuration: ``Inline``)
339    Only merge functions defined inside a class. Implies "empty".
340
341    .. code-block:: c++
342
343      class Foo {
344        void f() { foo(); }
345      };
346      void f() {
347        foo();
348      }
349      void f() {}
350
351  * ``SFS_All`` (in configuration: ``All``)
352    Merge all functions fitting on a single line.
353
354    .. code-block:: c++
355
356      class Foo {
357        void f() { foo(); }
358      };
359      void f() { bar(); }
360
361
362
363**AllowShortIfStatementsOnASingleLine** (``bool``)
364  If ``true``, ``if (a) return;`` can be put on a single line.
365
366**AllowShortLoopsOnASingleLine** (``bool``)
367  If ``true``, ``while (true) continue;`` can be put on a single
368  line.
369
370**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
371  The function definition return type breaking style to use.  This
372  option is **deprecated** and is retained for backwards compatibility.
373
374  Possible values:
375
376  * ``DRTBS_None`` (in configuration: ``None``)
377    Break after return type automatically.
378    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
379
380  * ``DRTBS_All`` (in configuration: ``All``)
381    Always break after the return type.
382
383  * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
384    Always break after the return types of top-level functions.
385
386
387
388**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
389  The function declaration return type breaking style to use.
390
391  Possible values:
392
393  * ``RTBS_None`` (in configuration: ``None``)
394    Break after return type automatically.
395    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
396
397    .. code-block:: c++
398
399      class A {
400        int f() { return 0; };
401      };
402      int f();
403      int f() { return 1; }
404
405  * ``RTBS_All`` (in configuration: ``All``)
406    Always break after the return type.
407
408    .. code-block:: c++
409
410      class A {
411        int
412        f() {
413          return 0;
414        };
415      };
416      int
417      f();
418      int
419      f() {
420        return 1;
421      }
422
423  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
424    Always break after the return types of top-level functions.
425
426    .. code-block:: c++
427
428      class A {
429        int f() { return 0; };
430      };
431      int
432      f();
433      int
434      f() {
435        return 1;
436      }
437
438  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
439    Always break after the return type of function definitions.
440
441    .. code-block:: c++
442
443      class A {
444        int
445        f() {
446          return 0;
447        };
448      };
449      int f();
450      int
451      f() {
452        return 1;
453      }
454
455  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
456    Always break after the return type of top-level definitions.
457
458    .. code-block:: c++
459
460      class A {
461        int f() { return 0; };
462      };
463      int f();
464      int
465      f() {
466        return 1;
467      }
468
469
470
471**AlwaysBreakBeforeMultilineStrings** (``bool``)
472  If ``true``, always break before multiline string literals.
473
474  This flag is mean to make cases where there are multiple multiline strings
475  in a file look more consistent. Thus, it will only take effect if wrapping
476  the string at that point leads to it being indented
477  ``ContinuationIndentWidth`` spaces from the start of the line.
478
479  .. code-block:: c++
480
481     true:                                  false:
482     aaaa =                         vs.     aaaa = "bbbb"
483         "bbbb"                                    "cccc";
484         "cccc";
485
486**AlwaysBreakTemplateDeclarations** (``bool``)
487  If ``true``, always break after the ``template<...>`` of a template
488  declaration.
489
490  .. code-block:: c++
491
492     true:                                  false:
493     template <typename T>          vs.     template <typename T> class C {};
494     class C {};
495
496**BinPackArguments** (``bool``)
497  If ``false``, a function call's arguments will either be all on the
498  same line or will have one line each.
499
500  .. code-block:: c++
501
502    true:
503    void f() {
504      f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
505        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
506    }
507
508    false:
509    void f() {
510      f(aaaaaaaaaaaaaaaaaaaa,
511        aaaaaaaaaaaaaaaaaaaa,
512        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
513    }
514
515**BinPackParameters** (``bool``)
516  If ``false``, a function declaration's or function definition's
517  parameters will either all be on the same line or will have one line each.
518
519  .. code-block:: c++
520
521    true:
522    void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
523           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
524
525    false:
526    void f(int aaaaaaaaaaaaaaaaaaaa,
527           int aaaaaaaaaaaaaaaaaaaa,
528           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
529
530**BraceWrapping** (``BraceWrappingFlags``)
531  Control of individual brace wrapping cases.
532
533  If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
534  each individual brace case should be handled. Otherwise, this is ignored.
535
536  Nested configuration flags:
537
538
539  * ``bool AfterClass`` Wrap class definitions.
540
541    .. code-block:: c++
542
543      true:
544      class foo {};
545
546      false:
547      class foo
548      {};
549
550  * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
551
552    .. code-block:: c++
553
554      true:
555      if (foo())
556      {
557      } else
558      {}
559      for (int i = 0; i < 10; ++i)
560      {}
561
562      false:
563      if (foo()) {
564      } else {
565      }
566      for (int i = 0; i < 10; ++i) {
567      }
568
569  * ``bool AfterEnum`` Wrap enum definitions.
570
571    .. code-block:: c++
572
573      true:
574      enum X : int
575      {
576        B
577      };
578
579      false:
580      enum X : int { B };
581
582  * ``bool AfterFunction`` Wrap function definitions.
583
584    .. code-block:: c++
585
586      true:
587      void foo()
588      {
589        bar();
590        bar2();
591      }
592
593      false:
594      void foo() {
595        bar();
596        bar2();
597      }
598
599  * ``bool AfterNamespace`` Wrap namespace definitions.
600
601    .. code-block:: c++
602
603      true:
604      namespace
605      {
606      int foo();
607      int bar();
608      }
609
610      false:
611      namespace {
612      int foo();
613      int bar();
614      }
615
616  * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
617
618  * ``bool AfterStruct`` Wrap struct definitions.
619
620    .. code-block:: c++
621
622      true:
623      struct foo
624      {
625        int x;
626      };
627
628      false:
629      struct foo {
630        int x;
631      };
632
633  * ``bool AfterUnion`` Wrap union definitions.
634
635    .. code-block:: c++
636
637      true:
638      union foo
639      {
640        int x;
641      }
642
643      false:
644      union foo {
645        int x;
646      }
647
648  * ``bool BeforeCatch`` Wrap before ``catch``.
649
650    .. code-block:: c++
651
652      true:
653      try {
654        foo();
655      }
656      catch () {
657      }
658
659      false:
660      try {
661        foo();
662      } catch () {
663      }
664
665  * ``bool BeforeElse`` Wrap before ``else``.
666
667    .. code-block:: c++
668
669      true:
670      if (foo()) {
671      }
672      else {
673      }
674
675      false:
676      if (foo()) {
677      } else {
678      }
679
680  * ``bool IndentBraces`` Indent the wrapped braces themselves.
681
682  * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
683    This option is used only if the opening brace of the function has
684    already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
685    set, and the function could/should not be put on a single line (as per
686    `AllowShortFunctionsOnASingleLine` and constructor formatting options).
687
688    .. code-block:: c++
689
690      int f()   vs.   inf f()
691      {}              {
692                      }
693
694
695**BreakAfterJavaFieldAnnotations** (``bool``)
696  Break after each annotation on a field in Java files.
697
698  .. code-block:: java
699
700     true:                                  false:
701     @Partial                       vs.     @Partial @Mock DataLoad loader;
702     @Mock
703     DataLoad loader;
704
705**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
706  The way to wrap binary operators.
707
708  Possible values:
709
710  * ``BOS_None`` (in configuration: ``None``)
711    Break after operators.
712
713    .. code-block:: c++
714
715       LooooooooooongType loooooooooooooooooooooongVariable =
716           someLooooooooooooooooongFunction();
717
718       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
719                            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
720                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
721                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
722                        ccccccccccccccccccccccccccccccccccccccccc;
723
724  * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
725    Break before operators that aren't assignments.
726
727    .. code-block:: c++
728
729       LooooooooooongType loooooooooooooooooooooongVariable =
730           someLooooooooooooooooongFunction();
731
732       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
733                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
734                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
735                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
736                           > ccccccccccccccccccccccccccccccccccccccccc;
737
738  * ``BOS_All`` (in configuration: ``All``)
739    Break before operators.
740
741    .. code-block:: c++
742
743       LooooooooooongType loooooooooooooooooooooongVariable
744           = someLooooooooooooooooongFunction();
745
746       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
747                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
748                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
749                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
750                           > ccccccccccccccccccccccccccccccccccccccccc;
751
752
753
754**BreakBeforeBraces** (``BraceBreakingStyle``)
755  The brace breaking style to use.
756
757  Possible values:
758
759  * ``BS_Attach`` (in configuration: ``Attach``)
760    Always attach braces to surrounding context.
761
762    .. code-block:: c++
763
764      try {
765        foo();
766      } catch () {
767      }
768      void foo() { bar(); }
769      class foo {};
770      if (foo()) {
771      } else {
772      }
773      enum X : int { A, B };
774
775  * ``BS_Linux`` (in configuration: ``Linux``)
776    Like ``Attach``, but break before braces on function, namespace and
777    class definitions.
778
779    .. code-block:: c++
780
781      try {
782        foo();
783      } catch () {
784      }
785      void foo() { bar(); }
786      class foo
787      {
788      };
789      if (foo()) {
790      } else {
791      }
792      enum X : int { A, B };
793
794  * ``BS_Mozilla`` (in configuration: ``Mozilla``)
795    Like ``Attach``, but break before braces on enum, function, and record
796    definitions.
797
798    .. code-block:: c++
799
800      try {
801        foo();
802      } catch () {
803      }
804      void foo() { bar(); }
805      class foo
806      {
807      };
808      if (foo()) {
809      } else {
810      }
811      enum X : int { A, B };
812
813  * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
814    Like ``Attach``, but break before function definitions, ``catch``, and
815    ``else``.
816
817    .. code-block:: c++
818
819      try {
820        foo();
821      } catch () {
822      }
823      void foo() { bar(); }
824      class foo
825      {
826      };
827      if (foo()) {
828      } else {
829      }
830      enum X : int
831      {
832        A,
833        B
834      };
835
836  * ``BS_Allman`` (in configuration: ``Allman``)
837    Always break before braces.
838
839    .. code-block:: c++
840
841      try {
842        foo();
843      }
844      catch () {
845      }
846      void foo() { bar(); }
847      class foo {
848      };
849      if (foo()) {
850      }
851      else {
852      }
853      enum X : int { A, B };
854
855  * ``BS_GNU`` (in configuration: ``GNU``)
856    Always break before braces and add an extra level of indentation to
857    braces of control statements, not to those of class, function
858    or other definitions.
859
860    .. code-block:: c++
861
862      try
863        {
864          foo();
865        }
866      catch ()
867        {
868        }
869      void foo() { bar(); }
870      class foo
871      {
872      };
873      if (foo())
874        {
875        }
876      else
877        {
878        }
879      enum X : int
880      {
881        A,
882        B
883      };
884
885  * ``BS_WebKit`` (in configuration: ``WebKit``)
886    Like ``Attach``, but break before functions.
887
888    .. code-block:: c++
889
890      try {
891        foo();
892      } catch () {
893      }
894      void foo() { bar(); }
895      class foo {
896      };
897      if (foo()) {
898      } else {
899      }
900      enum X : int { A, B };
901
902  * ``BS_Custom`` (in configuration: ``Custom``)
903    Configure each individual brace in `BraceWrapping`.
904
905
906
907**BreakBeforeInheritanceComma** (``bool``)
908  If ``true``, in the class inheritance expression clang-format will
909  break before ``:`` and ``,`` if there is multiple inheritance.
910
911  .. code-block:: c++
912
913     true:                                  false:
914     class MyClass                  vs.     class MyClass : public X, public Y {
915         : public X                         };
916         , public Y {
917     };
918
919**BreakBeforeTernaryOperators** (``bool``)
920  If ``true``, ternary operators will be placed after line breaks.
921
922  .. code-block:: c++
923
924     true:
925     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
926         ? firstValue
927         : SecondValueVeryVeryVeryVeryLong;
928
929     false:
930     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
931         firstValue :
932         SecondValueVeryVeryVeryVeryLong;
933
934**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
935  The constructor initializers style to use.
936
937  Possible values:
938
939  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
940    Break constructor initializers before the colon and after the commas.
941
942    .. code-block:: c++
943
944    Constructor()
945        : initializer1(),
946          initializer2()
947
948  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
949    Break constructor initializers before the colon and commas, and align
950    the commas with the colon.
951
952    .. code-block:: c++
953
954    Constructor()
955        : initializer1()
956        , initializer2()
957
958  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
959    Break constructor initializers after the colon and commas.
960
961    .. code-block:: c++
962
963    Constructor() :
964        initializer1(),
965        initializer2()
966
967
968
969**BreakStringLiterals** (``bool``)
970  Allow breaking string literals when formatting.
971
972**ColumnLimit** (``unsigned``)
973  The column limit.
974
975  A column limit of ``0`` means that there is no column limit. In this case,
976  clang-format will respect the input's line breaking decisions within
977  statements unless they contradict other rules.
978
979**CommentPragmas** (``std::string``)
980  A regular expression that describes comments with special meaning,
981  which should not be split into lines or otherwise changed.
982
983  .. code-block:: c++
984
985     // CommentPragmas: '^ FOOBAR pragma:'
986     // Will leave the following line unaffected
987     #include <vector> // FOOBAR pragma: keep
988
989**CompactNamespaces** (``bool``)
990  If ``true``, consecutive namespace declarations will be on the same
991  line. If ``false``, each namespace is declared on a new line.
992
993  .. code-block:: c++
994
995    true:
996    namespace Foo { namespace Bar {
997    }}
998
999    false:
1000    namespace Foo {
1001    namespace Bar {
1002    }
1003    }
1004
1005  If it does not fit on a single line, the overflowing namespaces get
1006  wrapped:
1007
1008  .. code-block:: c++
1009
1010    namespace Foo { namespace Bar {
1011    namespace Extra {
1012    }}}
1013
1014**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1015  If the constructor initializers don't fit on a line, put each
1016  initializer on its own line.
1017
1018  .. code-block:: c++
1019
1020    true:
1021    SomeClass::Constructor()
1022        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1023      return 0;
1024    }
1025
1026    false:
1027    SomeClass::Constructor()
1028        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1029          aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1030      return 0;
1031    }
1032
1033**ConstructorInitializerIndentWidth** (``unsigned``)
1034  The number of characters to use for indentation of constructor
1035  initializer lists.
1036
1037**ContinuationIndentWidth** (``unsigned``)
1038  Indent width for line continuations.
1039
1040  .. code-block:: c++
1041
1042     ContinuationIndentWidth: 2
1043
1044     int i =         //  VeryVeryVeryVeryVeryLongComment
1045       longFunction( // Again a long comment
1046         arg);
1047
1048**Cpp11BracedListStyle** (``bool``)
1049  If ``true``, format braced lists as best suited for C++11 braced
1050  lists.
1051
1052  Important differences:
1053  - No spaces inside the braced list.
1054  - No line break before the closing brace.
1055  - Indentation with the continuation indent, not with the block indent.
1056
1057  Fundamentally, C++11 braced lists are formatted exactly like function
1058  calls would be formatted in their place. If the braced list follows a name
1059  (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1060  the parentheses of a function call with that name. If there is no name,
1061  a zero-length name is assumed.
1062
1063  .. code-block:: c++
1064
1065     true:                                  false:
1066     vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
1067     vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
1068     f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
1069     new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
1070
1071**DerivePointerAlignment** (``bool``)
1072  If ``true``, analyze the formatted file for the most common
1073  alignment of ``&`` and ``*``.
1074  Pointer and reference alignment styles are going to be updated according
1075  to the preferences found in the file.
1076  ``PointerAlignment`` is then used only as fallback.
1077
1078**DisableFormat** (``bool``)
1079  Disables formatting completely.
1080
1081**ExperimentalAutoDetectBinPacking** (``bool``)
1082  If ``true``, clang-format detects whether function calls and
1083  definitions are formatted with one parameter per line.
1084
1085  Each call can be bin-packed, one-per-line or inconclusive. If it is
1086  inconclusive, e.g. completely on one line, but a decision needs to be
1087  made, clang-format analyzes whether there are other bin-packed cases in
1088  the input file and act accordingly.
1089
1090  NOTE: This is an experimental flag, that might go away or be renamed. Do
1091  not use this in config files, etc. Use at your own risk.
1092
1093**FixNamespaceComments** (``bool``)
1094  If ``true``, clang-format adds missing namespace end comments and
1095  fixes invalid existing ones.
1096
1097  .. code-block:: c++
1098
1099     true:                                  false:
1100     namespace a {                  vs.     namespace a {
1101     foo();                                 foo();
1102     } // namespace a;                      }
1103
1104**ForEachMacros** (``std::vector<std::string>``)
1105  A vector of macros that should be interpreted as foreach loops
1106  instead of as function calls.
1107
1108  These are expected to be macros of the form:
1109
1110  .. code-block:: c++
1111
1112    FOREACH(<variable-declaration>, ...)
1113      <loop-body>
1114
1115  In the .clang-format configuration file, this can be configured like:
1116
1117  .. code-block:: yaml
1118
1119    ForEachMacros: ['RANGES_FOR', 'FOREACH']
1120
1121  For example: BOOST_FOREACH.
1122
1123**IncludeCategories** (``std::vector<IncludeCategory>``)
1124  Regular expressions denoting the different ``#include`` categories
1125  used for ordering ``#includes``.
1126
1127  These regular expressions are matched against the filename of an include
1128  (including the <> or "") in order. The value belonging to the first
1129  matching regular expression is assigned and ``#includes`` are sorted first
1130  according to increasing category number and then alphabetically within
1131  each category.
1132
1133  If none of the regular expressions match, INT_MAX is assigned as
1134  category. The main header for a source file automatically gets category 0.
1135  so that it is generally kept at the beginning of the ``#includes``
1136  (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1137  can also assign negative priorities if you have certain headers that
1138  always need to be first.
1139
1140  To configure this in the .clang-format file, use:
1141
1142  .. code-block:: yaml
1143
1144    IncludeCategories:
1145      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
1146        Priority:        2
1147      - Regex:           '^(<|"(gtest|isl|json)/)'
1148        Priority:        3
1149      - Regex:           '.*'
1150        Priority:        1
1151
1152**IncludeIsMainRegex** (``std::string``)
1153  Specify a regular expression of suffixes that are allowed in the
1154  file-to-main-include mapping.
1155
1156  When guessing whether a #include is the "main" include (to assign
1157  category 0, see above), use this regex of allowed suffixes to the header
1158  stem. A partial match is done, so that:
1159  - "" means "arbitrary suffix"
1160  - "$" means "no suffix"
1161
1162  For example, if configured to "(_test)?$", then a header a.h would be seen
1163  as the "main" include in both a.cc and a_test.cc.
1164
1165**IndentCaseLabels** (``bool``)
1166  Indent case labels one level from the switch statement.
1167
1168  When ``false``, use the same indentation level as for the switch statement.
1169  Switch statement body is always indented one level more than case labels.
1170
1171  .. code-block:: c++
1172
1173     false:                                 true:
1174     switch (fool) {                vs.     switch (fool) {
1175     case 1:                                  case 1:
1176       bar();                                   bar();
1177       break;                                   break;
1178     default:                                 default:
1179       plop();                                  plop();
1180     }                                      }
1181
1182**IndentWidth** (``unsigned``)
1183  The number of columns to use for indentation.
1184
1185  .. code-block:: c++
1186
1187     IndentWidth: 3
1188
1189     void f() {
1190        someFunction();
1191        if (true, false) {
1192           f();
1193        }
1194     }
1195
1196**IndentWrappedFunctionNames** (``bool``)
1197  Indent if a function definition or declaration is wrapped after the
1198  type.
1199
1200  .. code-block:: c++
1201
1202     true:
1203     LoooooooooooooooooooooooooooooooooooooooongReturnType
1204         LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1205
1206     false:
1207     LoooooooooooooooooooooooooooooooooooooooongReturnType
1208     LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1209
1210**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1211  The JavaScriptQuoteStyle to use for JavaScript strings.
1212
1213  Possible values:
1214
1215  * ``JSQS_Leave`` (in configuration: ``Leave``)
1216    Leave string quotes as they are.
1217
1218    .. code-block:: js
1219
1220       string1 = "foo";
1221       string2 = 'bar';
1222
1223  * ``JSQS_Single`` (in configuration: ``Single``)
1224    Always use single quotes.
1225
1226    .. code-block:: js
1227
1228       string1 = 'foo';
1229       string2 = 'bar';
1230
1231  * ``JSQS_Double`` (in configuration: ``Double``)
1232    Always use double quotes.
1233
1234    .. code-block:: js
1235
1236       string1 = "foo";
1237       string2 = "bar";
1238
1239
1240
1241**JavaScriptWrapImports** (``bool``)
1242  Whether to wrap JavaScript import/export statements.
1243
1244  .. code-block:: js
1245
1246     true:
1247     import {
1248         VeryLongImportsAreAnnoying,
1249         VeryLongImportsAreAnnoying,
1250         VeryLongImportsAreAnnoying,
1251     } from 'some/module.js'
1252
1253     false:
1254     import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1255
1256**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
1257  If true, the empty line at the start of blocks is kept.
1258
1259  .. code-block:: c++
1260
1261     true:                                  false:
1262     if (foo) {                     vs.     if (foo) {
1263                                              bar();
1264       bar();                               }
1265     }
1266
1267**Language** (``LanguageKind``)
1268  Language, this format style is targeted at.
1269
1270  Possible values:
1271
1272  * ``LK_None`` (in configuration: ``None``)
1273    Do not use.
1274
1275  * ``LK_Cpp`` (in configuration: ``Cpp``)
1276    Should be used for C, C++.
1277
1278  * ``LK_Java`` (in configuration: ``Java``)
1279    Should be used for Java.
1280
1281  * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1282    Should be used for JavaScript.
1283
1284  * ``LK_ObjC`` (in configuration: ``ObjC``)
1285    Should be used for Objective-C, Objective-C++.
1286
1287  * ``LK_Proto`` (in configuration: ``Proto``)
1288    Should be used for Protocol Buffers
1289    (https://developers.google.com/protocol-buffers/).
1290
1291  * ``LK_TableGen`` (in configuration: ``TableGen``)
1292    Should be used for TableGen code.
1293
1294
1295
1296**MacroBlockBegin** (``std::string``)
1297  A regular expression matching macros that start a block.
1298
1299  .. code-block:: c++
1300
1301     # With:
1302     MacroBlockBegin: "^NS_MAP_BEGIN|\
1303     NS_TABLE_HEAD$"
1304     MacroBlockEnd: "^\
1305     NS_MAP_END|\
1306     NS_TABLE_.*_END$"
1307
1308     NS_MAP_BEGIN
1309       foo();
1310     NS_MAP_END
1311
1312     NS_TABLE_HEAD
1313       bar();
1314     NS_TABLE_FOO_END
1315
1316     # Without:
1317     NS_MAP_BEGIN
1318     foo();
1319     NS_MAP_END
1320
1321     NS_TABLE_HEAD
1322     bar();
1323     NS_TABLE_FOO_END
1324
1325**MacroBlockEnd** (``std::string``)
1326  A regular expression matching macros that end a block.
1327
1328**MaxEmptyLinesToKeep** (``unsigned``)
1329  The maximum number of consecutive empty lines to keep.
1330
1331  .. code-block:: c++
1332
1333     MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
1334     int f() {                              int f() {
1335       int = 1;                                 int i = 1;
1336                                                i = foo();
1337       i = foo();                               return i;
1338                                            }
1339       return i;
1340     }
1341
1342**NamespaceIndentation** (``NamespaceIndentationKind``)
1343  The indentation used for namespaces.
1344
1345  Possible values:
1346
1347  * ``NI_None`` (in configuration: ``None``)
1348    Don't indent in namespaces.
1349
1350    .. code-block:: c++
1351
1352       namespace out {
1353       int i;
1354       namespace in {
1355       int i;
1356       }
1357       }
1358
1359  * ``NI_Inner`` (in configuration: ``Inner``)
1360    Indent only in inner namespaces (nested in other namespaces).
1361
1362    .. code-block:: c++
1363
1364       namespace out {
1365       int i;
1366       namespace in {
1367         int i;
1368       }
1369       }
1370
1371  * ``NI_All`` (in configuration: ``All``)
1372    Indent in all namespaces.
1373
1374    .. code-block:: c++
1375
1376       namespace out {
1377         int i;
1378         namespace in {
1379           int i;
1380         }
1381       }
1382
1383
1384
1385**ObjCBlockIndentWidth** (``unsigned``)
1386  The number of characters to use for indentation of ObjC blocks.
1387
1388  .. code-block:: objc
1389
1390     ObjCBlockIndentWidth: 4
1391
1392     [operation setCompletionBlock:^{
1393         [self onOperationDone];
1394     }];
1395
1396**ObjCSpaceAfterProperty** (``bool``)
1397  Add a space after ``@property`` in Objective-C, i.e. use
1398  ``@property (readonly)`` instead of ``@property(readonly)``.
1399
1400**ObjCSpaceBeforeProtocolList** (``bool``)
1401  Add a space in front of an Objective-C protocol list, i.e. use
1402  ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1403
1404**PenaltyBreakAssignment** (``unsigned``)
1405  The penalty for breaking around an assignment operator.
1406
1407**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
1408  The penalty for breaking a function call after ``call(``.
1409
1410**PenaltyBreakComment** (``unsigned``)
1411  The penalty for each line break introduced inside a comment.
1412
1413**PenaltyBreakFirstLessLess** (``unsigned``)
1414  The penalty for breaking before the first ``<<``.
1415
1416**PenaltyBreakString** (``unsigned``)
1417  The penalty for each line break introduced inside a string literal.
1418
1419**PenaltyExcessCharacter** (``unsigned``)
1420  The penalty for each character outside of the column limit.
1421
1422**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1423  Penalty for putting the return type of a function onto its own
1424  line.
1425
1426**PointerAlignment** (``PointerAlignmentStyle``)
1427  Pointer and reference alignment style.
1428
1429  Possible values:
1430
1431  * ``PAS_Left`` (in configuration: ``Left``)
1432    Align pointer to the left.
1433
1434    .. code-block:: c++
1435
1436      int* a;
1437
1438  * ``PAS_Right`` (in configuration: ``Right``)
1439    Align pointer to the right.
1440
1441    .. code-block:: c++
1442
1443      int *a;
1444
1445  * ``PAS_Middle`` (in configuration: ``Middle``)
1446    Align pointer in the middle.
1447
1448    .. code-block:: c++
1449
1450      int * a;
1451
1452
1453
1454**ReflowComments** (``bool``)
1455  If ``true``, clang-format will attempt to re-flow comments.
1456
1457  .. code-block:: c++
1458
1459     false:
1460     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1461     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1462
1463     true:
1464     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1465     // information
1466     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1467      * information */
1468
1469**SortIncludes** (``bool``)
1470  If ``true``, clang-format will sort ``#includes``.
1471
1472  .. code-block:: c++
1473
1474     false:                                 true:
1475     #include "b.h"                 vs.     #include "a.h"
1476     #include "a.h"                         #include "b.h"
1477
1478**SortUsingDeclarations** (``bool``)
1479  If ``true``, clang-format will sort using declarations.
1480
1481  .. code-block:: c++
1482
1483     false:                                 true:
1484     using std::cout;               vs.     using std::cin;
1485     using std::cin;                        using std::cout;
1486
1487**SpaceAfterCStyleCast** (``bool``)
1488  If ``true``, a space is inserted after C style casts.
1489
1490  .. code-block:: c++
1491
1492     true:                                  false:
1493     (int)i;                        vs.     (int) i;
1494
1495**SpaceAfterTemplateKeyword** (``bool``)
1496  If ``true``, a space will be inserted after the 'template' keyword.
1497
1498  .. code-block:: c++
1499
1500     true:                                  false:
1501     template <int> void foo();     vs.     template<int> void foo();
1502
1503**SpaceBeforeAssignmentOperators** (``bool``)
1504  If ``false``, spaces will be removed before assignment operators.
1505
1506  .. code-block:: c++
1507
1508     true:                                  false:
1509     int a = 5;                     vs.     int a=5;
1510     a += 42                                a+=42;
1511
1512**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1513  Defines in which cases to put a space before opening parentheses.
1514
1515  Possible values:
1516
1517  * ``SBPO_Never`` (in configuration: ``Never``)
1518    Never put a space before opening parentheses.
1519
1520    .. code-block:: c++
1521
1522       void f() {
1523         if(true) {
1524           f();
1525         }
1526       }
1527
1528  * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1529    Put a space before opening parentheses only after control statement
1530    keywords (``for/if/while...``).
1531
1532    .. code-block:: c++
1533
1534       void f() {
1535         if (true) {
1536           f();
1537         }
1538       }
1539
1540  * ``SBPO_Always`` (in configuration: ``Always``)
1541    Always put a space before opening parentheses, except when it's
1542    prohibited by the syntax rules (in function-like macro definitions) or
1543    when determined by other style rules (after unary operators, opening
1544    parentheses, etc.)
1545
1546    .. code-block:: c++
1547
1548       void f () {
1549         if (true) {
1550           f ();
1551         }
1552       }
1553
1554
1555
1556**SpaceInEmptyParentheses** (``bool``)
1557  If ``true``, spaces may be inserted into ``()``.
1558
1559  .. code-block:: c++
1560
1561     true:                                false:
1562     void f( ) {                    vs.   void f() {
1563       int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
1564       if (true) {                          if (true) {
1565         f( );                                f();
1566       }                                    }
1567     }                                    }
1568
1569**SpacesBeforeTrailingComments** (``unsigned``)
1570  The number of spaces before trailing line comments
1571  (``//`` - comments).
1572
1573  This does not affect trailing block comments (``/*`` - comments) as
1574  those commonly have different usage patterns and a number of special
1575  cases.
1576
1577  .. code-block:: c++
1578
1579     SpacesBeforeTrailingComments: 3
1580     void f() {
1581       if (true) {   // foo1
1582         f();        // bar
1583       }             // foo
1584     }
1585
1586**SpacesInAngles** (``bool``)
1587  If ``true``, spaces will be inserted after ``<`` and before ``>``
1588  in template argument lists.
1589
1590  .. code-block:: c++
1591
1592     true:                                  false:
1593     static_cast< int >(arg);       vs.     static_cast<int>(arg);
1594     std::function< void(int) > fct;        std::function<void(int)> fct;
1595
1596**SpacesInCStyleCastParentheses** (``bool``)
1597  If ``true``, spaces may be inserted into C style casts.
1598
1599  .. code-block:: c++
1600
1601     true:                                  false:
1602     x = ( int32 )y                 vs.     x = (int32)y
1603
1604**SpacesInContainerLiterals** (``bool``)
1605  If ``true``, spaces are inserted inside container literals (e.g.
1606  ObjC and Javascript array and dict literals).
1607
1608  .. code-block:: js
1609
1610     true:                                  false:
1611     var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
1612     f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
1613
1614**SpacesInParentheses** (``bool``)
1615  If ``true``, spaces will be inserted after ``(`` and before ``)``.
1616
1617  .. code-block:: c++
1618
1619     true:                                  false:
1620     t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
1621
1622**SpacesInSquareBrackets** (``bool``)
1623  If ``true``, spaces will be inserted after ``[`` and before ``]``.
1624  Lambdas or unspecified size array declarations will not be affected.
1625
1626  .. code-block:: c++
1627
1628     true:                                  false:
1629     int a[ 5 ];                    vs.     int a[5];
1630     std::unique_ptr<int[]> foo() {} // Won't be affected
1631
1632**Standard** (``LanguageStandard``)
1633  Format compatible with this standard, e.g. use ``A<A<int> >``
1634  instead of ``A<A<int>>`` for ``LS_Cpp03``.
1635
1636  Possible values:
1637
1638  * ``LS_Cpp03`` (in configuration: ``Cpp03``)
1639    Use C++03-compatible syntax.
1640
1641  * ``LS_Cpp11`` (in configuration: ``Cpp11``)
1642    Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
1643    ``A<A<int> >``).
1644
1645  * ``LS_Auto`` (in configuration: ``Auto``)
1646    Automatic detection based on the input.
1647
1648
1649
1650**TabWidth** (``unsigned``)
1651  The number of columns used for tab stops.
1652
1653**UseTab** (``UseTabStyle``)
1654  The way to use tab characters in the resulting file.
1655
1656  Possible values:
1657
1658  * ``UT_Never`` (in configuration: ``Never``)
1659    Never use tab.
1660
1661  * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
1662    Use tabs only for indentation.
1663
1664  * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
1665    Use tabs only for line continuation and indentation.
1666
1667  * ``UT_Always`` (in configuration: ``Always``)
1668    Use tabs whenever we need to fill whitespace that spans at least from
1669    one tab stop to the next one.
1670
1671
1672
1673.. END_FORMAT_STYLE_OPTIONS
1674
1675Adding additional style options
1676===============================
1677
1678Each additional style option adds costs to the clang-format project. Some of
1679these costs affect the clang-format development itself, as we need to make
1680sure that any given combination of options work and that new features don't
1681break any of the existing options in any way. There are also costs for end users
1682as options become less discoverable and people have to think about and make a
1683decision on options they don't really care about.
1684
1685The goal of the clang-format project is more on the side of supporting a
1686limited set of styles really well as opposed to supporting every single style
1687used by a codebase somewhere in the wild. Of course, we do want to support all
1688major projects and thus have established the following bar for adding style
1689options. Each new style option must ..
1690
1691  * be used in a project of significant size (have dozens of contributors)
1692  * have a publicly accessible style guide
1693  * have a person willing to contribute and maintain patches
1694
1695Examples
1696========
1697
1698A style similar to the `Linux Kernel style
1699<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
1700
1701.. code-block:: yaml
1702
1703  BasedOnStyle: LLVM
1704  IndentWidth: 8
1705  UseTab: Always
1706  BreakBeforeBraces: Linux
1707  AllowShortIfStatementsOnASingleLine: false
1708  IndentCaseLabels: false
1709
1710The result is (imagine that tabs are used for indentation here):
1711
1712.. code-block:: c++
1713
1714  void test()
1715  {
1716          switch (x) {
1717          case 0:
1718          case 1:
1719                  do_something();
1720                  break;
1721          case 2:
1722                  do_something_else();
1723                  break;
1724          default:
1725                  break;
1726          }
1727          if (condition)
1728                  do_something_completely_different();
1729
1730          if (x == y) {
1731                  q();
1732          } else if (x > y) {
1733                  w();
1734          } else {
1735                  r();
1736          }
1737  }
1738
1739A style similar to the default Visual Studio formatting style:
1740
1741.. code-block:: yaml
1742
1743  UseTab: Never
1744  IndentWidth: 4
1745  BreakBeforeBraces: Allman
1746  AllowShortIfStatementsOnASingleLine: false
1747  IndentCaseLabels: false
1748  ColumnLimit: 0
1749
1750The result is:
1751
1752.. code-block:: c++
1753
1754  void test()
1755  {
1756      switch (suffix)
1757      {
1758      case 0:
1759      case 1:
1760          do_something();
1761          break;
1762      case 2:
1763          do_something_else();
1764          break;
1765      default:
1766          break;
1767      }
1768      if (condition)
1769          do_somthing_completely_different();
1770
1771      if (x == y)
1772      {
1773          q();
1774      }
1775      else if (x > y)
1776      {
1777          w();
1778      }
1779      else
1780      {
1781          r();
1782      }
1783  }
1784