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**IndentPPDirectives** (``PPDirectiveIndentStyle``) 1183 Indent preprocessor directives on conditionals. 1184 1185 Possible values: 1186 1187 * ``PPDIS_None`` (in configuration: ``None``) 1188 Does not indent any directives. 1189 1190 .. code-block:: c++ 1191 1192 #if FOO 1193 #if BAR 1194 #include <foo> 1195 #endif 1196 #endif 1197 1198 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) 1199 Indents directives after the hash. 1200 1201 .. code-block:: c++ 1202 1203 #if FOO 1204 # if BAR 1205 # include <foo> 1206 # endif 1207 #endif 1208 1209**IndentWidth** (``unsigned``) 1210 The number of columns to use for indentation. 1211 1212 .. code-block:: c++ 1213 1214 IndentWidth: 3 1215 1216 void f() { 1217 someFunction(); 1218 if (true, false) { 1219 f(); 1220 } 1221 } 1222 1223**IndentWrappedFunctionNames** (``bool``) 1224 Indent if a function definition or declaration is wrapped after the 1225 type. 1226 1227 .. code-block:: c++ 1228 1229 true: 1230 LoooooooooooooooooooooooooooooooooooooooongReturnType 1231 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 1232 1233 false: 1234 LoooooooooooooooooooooooooooooooooooooooongReturnType 1235 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 1236 1237**JavaScriptQuotes** (``JavaScriptQuoteStyle``) 1238 The JavaScriptQuoteStyle to use for JavaScript strings. 1239 1240 Possible values: 1241 1242 * ``JSQS_Leave`` (in configuration: ``Leave``) 1243 Leave string quotes as they are. 1244 1245 .. code-block:: js 1246 1247 string1 = "foo"; 1248 string2 = 'bar'; 1249 1250 * ``JSQS_Single`` (in configuration: ``Single``) 1251 Always use single quotes. 1252 1253 .. code-block:: js 1254 1255 string1 = 'foo'; 1256 string2 = 'bar'; 1257 1258 * ``JSQS_Double`` (in configuration: ``Double``) 1259 Always use double quotes. 1260 1261 .. code-block:: js 1262 1263 string1 = "foo"; 1264 string2 = "bar"; 1265 1266 1267 1268**JavaScriptWrapImports** (``bool``) 1269 Whether to wrap JavaScript import/export statements. 1270 1271 .. code-block:: js 1272 1273 true: 1274 import { 1275 VeryLongImportsAreAnnoying, 1276 VeryLongImportsAreAnnoying, 1277 VeryLongImportsAreAnnoying, 1278 } from 'some/module.js' 1279 1280 false: 1281 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" 1282 1283**KeepEmptyLinesAtTheStartOfBlocks** (``bool``) 1284 If true, the empty line at the start of blocks is kept. 1285 1286 .. code-block:: c++ 1287 1288 true: false: 1289 if (foo) { vs. if (foo) { 1290 bar(); 1291 bar(); } 1292 } 1293 1294**Language** (``LanguageKind``) 1295 Language, this format style is targeted at. 1296 1297 Possible values: 1298 1299 * ``LK_None`` (in configuration: ``None``) 1300 Do not use. 1301 1302 * ``LK_Cpp`` (in configuration: ``Cpp``) 1303 Should be used for C, C++. 1304 1305 * ``LK_Java`` (in configuration: ``Java``) 1306 Should be used for Java. 1307 1308 * ``LK_JavaScript`` (in configuration: ``JavaScript``) 1309 Should be used for JavaScript. 1310 1311 * ``LK_ObjC`` (in configuration: ``ObjC``) 1312 Should be used for Objective-C, Objective-C++. 1313 1314 * ``LK_Proto`` (in configuration: ``Proto``) 1315 Should be used for Protocol Buffers 1316 (https://developers.google.com/protocol-buffers/). 1317 1318 * ``LK_TableGen`` (in configuration: ``TableGen``) 1319 Should be used for TableGen code. 1320 1321 1322 1323**MacroBlockBegin** (``std::string``) 1324 A regular expression matching macros that start a block. 1325 1326 .. code-block:: c++ 1327 1328 # With: 1329 MacroBlockBegin: "^NS_MAP_BEGIN|\ 1330 NS_TABLE_HEAD$" 1331 MacroBlockEnd: "^\ 1332 NS_MAP_END|\ 1333 NS_TABLE_.*_END$" 1334 1335 NS_MAP_BEGIN 1336 foo(); 1337 NS_MAP_END 1338 1339 NS_TABLE_HEAD 1340 bar(); 1341 NS_TABLE_FOO_END 1342 1343 # Without: 1344 NS_MAP_BEGIN 1345 foo(); 1346 NS_MAP_END 1347 1348 NS_TABLE_HEAD 1349 bar(); 1350 NS_TABLE_FOO_END 1351 1352**MacroBlockEnd** (``std::string``) 1353 A regular expression matching macros that end a block. 1354 1355**MaxEmptyLinesToKeep** (``unsigned``) 1356 The maximum number of consecutive empty lines to keep. 1357 1358 .. code-block:: c++ 1359 1360 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 1361 int f() { int f() { 1362 int = 1; int i = 1; 1363 i = foo(); 1364 i = foo(); return i; 1365 } 1366 return i; 1367 } 1368 1369**NamespaceIndentation** (``NamespaceIndentationKind``) 1370 The indentation used for namespaces. 1371 1372 Possible values: 1373 1374 * ``NI_None`` (in configuration: ``None``) 1375 Don't indent in namespaces. 1376 1377 .. code-block:: c++ 1378 1379 namespace out { 1380 int i; 1381 namespace in { 1382 int i; 1383 } 1384 } 1385 1386 * ``NI_Inner`` (in configuration: ``Inner``) 1387 Indent only in inner namespaces (nested in other namespaces). 1388 1389 .. code-block:: c++ 1390 1391 namespace out { 1392 int i; 1393 namespace in { 1394 int i; 1395 } 1396 } 1397 1398 * ``NI_All`` (in configuration: ``All``) 1399 Indent in all namespaces. 1400 1401 .. code-block:: c++ 1402 1403 namespace out { 1404 int i; 1405 namespace in { 1406 int i; 1407 } 1408 } 1409 1410 1411 1412**ObjCBlockIndentWidth** (``unsigned``) 1413 The number of characters to use for indentation of ObjC blocks. 1414 1415 .. code-block:: objc 1416 1417 ObjCBlockIndentWidth: 4 1418 1419 [operation setCompletionBlock:^{ 1420 [self onOperationDone]; 1421 }]; 1422 1423**ObjCSpaceAfterProperty** (``bool``) 1424 Add a space after ``@property`` in Objective-C, i.e. use 1425 ``@property (readonly)`` instead of ``@property(readonly)``. 1426 1427**ObjCSpaceBeforeProtocolList** (``bool``) 1428 Add a space in front of an Objective-C protocol list, i.e. use 1429 ``Foo <Protocol>`` instead of ``Foo<Protocol>``. 1430 1431**PenaltyBreakAssignment** (``unsigned``) 1432 The penalty for breaking around an assignment operator. 1433 1434**PenaltyBreakBeforeFirstCallParameter** (``unsigned``) 1435 The penalty for breaking a function call after ``call(``. 1436 1437**PenaltyBreakComment** (``unsigned``) 1438 The penalty for each line break introduced inside a comment. 1439 1440**PenaltyBreakFirstLessLess** (``unsigned``) 1441 The penalty for breaking before the first ``<<``. 1442 1443**PenaltyBreakString** (``unsigned``) 1444 The penalty for each line break introduced inside a string literal. 1445 1446**PenaltyExcessCharacter** (``unsigned``) 1447 The penalty for each character outside of the column limit. 1448 1449**PenaltyReturnTypeOnItsOwnLine** (``unsigned``) 1450 Penalty for putting the return type of a function onto its own 1451 line. 1452 1453**PointerAlignment** (``PointerAlignmentStyle``) 1454 Pointer and reference alignment style. 1455 1456 Possible values: 1457 1458 * ``PAS_Left`` (in configuration: ``Left``) 1459 Align pointer to the left. 1460 1461 .. code-block:: c++ 1462 1463 int* a; 1464 1465 * ``PAS_Right`` (in configuration: ``Right``) 1466 Align pointer to the right. 1467 1468 .. code-block:: c++ 1469 1470 int *a; 1471 1472 * ``PAS_Middle`` (in configuration: ``Middle``) 1473 Align pointer in the middle. 1474 1475 .. code-block:: c++ 1476 1477 int * a; 1478 1479 1480 1481**ReflowComments** (``bool``) 1482 If ``true``, clang-format will attempt to re-flow comments. 1483 1484 .. code-block:: c++ 1485 1486 false: 1487 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information 1488 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ 1489 1490 true: 1491 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 1492 // information 1493 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 1494 * information */ 1495 1496**SortIncludes** (``bool``) 1497 If ``true``, clang-format will sort ``#includes``. 1498 1499 .. code-block:: c++ 1500 1501 false: true: 1502 #include "b.h" vs. #include "a.h" 1503 #include "a.h" #include "b.h" 1504 1505**SortUsingDeclarations** (``bool``) 1506 If ``true``, clang-format will sort using declarations. 1507 1508 .. code-block:: c++ 1509 1510 false: true: 1511 using std::cout; vs. using std::cin; 1512 using std::cin; using std::cout; 1513 1514**SpaceAfterCStyleCast** (``bool``) 1515 If ``true``, a space is inserted after C style casts. 1516 1517 .. code-block:: c++ 1518 1519 true: false: 1520 (int)i; vs. (int) i; 1521 1522**SpaceAfterTemplateKeyword** (``bool``) 1523 If ``true``, a space will be inserted after the 'template' keyword. 1524 1525 .. code-block:: c++ 1526 1527 true: false: 1528 template <int> void foo(); vs. template<int> void foo(); 1529 1530**SpaceBeforeAssignmentOperators** (``bool``) 1531 If ``false``, spaces will be removed before assignment operators. 1532 1533 .. code-block:: c++ 1534 1535 true: false: 1536 int a = 5; vs. int a=5; 1537 a += 42 a+=42; 1538 1539**SpaceBeforeParens** (``SpaceBeforeParensOptions``) 1540 Defines in which cases to put a space before opening parentheses. 1541 1542 Possible values: 1543 1544 * ``SBPO_Never`` (in configuration: ``Never``) 1545 Never put a space before opening parentheses. 1546 1547 .. code-block:: c++ 1548 1549 void f() { 1550 if(true) { 1551 f(); 1552 } 1553 } 1554 1555 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) 1556 Put a space before opening parentheses only after control statement 1557 keywords (``for/if/while...``). 1558 1559 .. code-block:: c++ 1560 1561 void f() { 1562 if (true) { 1563 f(); 1564 } 1565 } 1566 1567 * ``SBPO_Always`` (in configuration: ``Always``) 1568 Always put a space before opening parentheses, except when it's 1569 prohibited by the syntax rules (in function-like macro definitions) or 1570 when determined by other style rules (after unary operators, opening 1571 parentheses, etc.) 1572 1573 .. code-block:: c++ 1574 1575 void f () { 1576 if (true) { 1577 f (); 1578 } 1579 } 1580 1581 1582 1583**SpaceInEmptyParentheses** (``bool``) 1584 If ``true``, spaces may be inserted into ``()``. 1585 1586 .. code-block:: c++ 1587 1588 true: false: 1589 void f( ) { vs. void f() { 1590 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; 1591 if (true) { if (true) { 1592 f( ); f(); 1593 } } 1594 } } 1595 1596**SpacesBeforeTrailingComments** (``unsigned``) 1597 The number of spaces before trailing line comments 1598 (``//`` - comments). 1599 1600 This does not affect trailing block comments (``/*`` - comments) as 1601 those commonly have different usage patterns and a number of special 1602 cases. 1603 1604 .. code-block:: c++ 1605 1606 SpacesBeforeTrailingComments: 3 1607 void f() { 1608 if (true) { // foo1 1609 f(); // bar 1610 } // foo 1611 } 1612 1613**SpacesInAngles** (``bool``) 1614 If ``true``, spaces will be inserted after ``<`` and before ``>`` 1615 in template argument lists. 1616 1617 .. code-block:: c++ 1618 1619 true: false: 1620 static_cast< int >(arg); vs. static_cast<int>(arg); 1621 std::function< void(int) > fct; std::function<void(int)> fct; 1622 1623**SpacesInCStyleCastParentheses** (``bool``) 1624 If ``true``, spaces may be inserted into C style casts. 1625 1626 .. code-block:: c++ 1627 1628 true: false: 1629 x = ( int32 )y vs. x = (int32)y 1630 1631**SpacesInContainerLiterals** (``bool``) 1632 If ``true``, spaces are inserted inside container literals (e.g. 1633 ObjC and Javascript array and dict literals). 1634 1635 .. code-block:: js 1636 1637 true: false: 1638 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; 1639 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); 1640 1641**SpacesInParentheses** (``bool``) 1642 If ``true``, spaces will be inserted after ``(`` and before ``)``. 1643 1644 .. code-block:: c++ 1645 1646 true: false: 1647 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; 1648 1649**SpacesInSquareBrackets** (``bool``) 1650 If ``true``, spaces will be inserted after ``[`` and before ``]``. 1651 Lambdas or unspecified size array declarations will not be affected. 1652 1653 .. code-block:: c++ 1654 1655 true: false: 1656 int a[ 5 ]; vs. int a[5]; 1657 std::unique_ptr<int[]> foo() {} // Won't be affected 1658 1659**Standard** (``LanguageStandard``) 1660 Format compatible with this standard, e.g. use ``A<A<int> >`` 1661 instead of ``A<A<int>>`` for ``LS_Cpp03``. 1662 1663 Possible values: 1664 1665 * ``LS_Cpp03`` (in configuration: ``Cpp03``) 1666 Use C++03-compatible syntax. 1667 1668 * ``LS_Cpp11`` (in configuration: ``Cpp11``) 1669 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of 1670 ``A<A<int> >``). 1671 1672 * ``LS_Auto`` (in configuration: ``Auto``) 1673 Automatic detection based on the input. 1674 1675 1676 1677**TabWidth** (``unsigned``) 1678 The number of columns used for tab stops. 1679 1680**UseTab** (``UseTabStyle``) 1681 The way to use tab characters in the resulting file. 1682 1683 Possible values: 1684 1685 * ``UT_Never`` (in configuration: ``Never``) 1686 Never use tab. 1687 1688 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) 1689 Use tabs only for indentation. 1690 1691 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) 1692 Use tabs only for line continuation and indentation. 1693 1694 * ``UT_Always`` (in configuration: ``Always``) 1695 Use tabs whenever we need to fill whitespace that spans at least from 1696 one tab stop to the next one. 1697 1698 1699 1700.. END_FORMAT_STYLE_OPTIONS 1701 1702Adding additional style options 1703=============================== 1704 1705Each additional style option adds costs to the clang-format project. Some of 1706these costs affect the clang-format development itself, as we need to make 1707sure that any given combination of options work and that new features don't 1708break any of the existing options in any way. There are also costs for end users 1709as options become less discoverable and people have to think about and make a 1710decision on options they don't really care about. 1711 1712The goal of the clang-format project is more on the side of supporting a 1713limited set of styles really well as opposed to supporting every single style 1714used by a codebase somewhere in the wild. Of course, we do want to support all 1715major projects and thus have established the following bar for adding style 1716options. Each new style option must .. 1717 1718 * be used in a project of significant size (have dozens of contributors) 1719 * have a publicly accessible style guide 1720 * have a person willing to contribute and maintain patches 1721 1722Examples 1723======== 1724 1725A style similar to the `Linux Kernel style 1726<https://www.kernel.org/doc/Documentation/CodingStyle>`_: 1727 1728.. code-block:: yaml 1729 1730 BasedOnStyle: LLVM 1731 IndentWidth: 8 1732 UseTab: Always 1733 BreakBeforeBraces: Linux 1734 AllowShortIfStatementsOnASingleLine: false 1735 IndentCaseLabels: false 1736 1737The result is (imagine that tabs are used for indentation here): 1738 1739.. code-block:: c++ 1740 1741 void test() 1742 { 1743 switch (x) { 1744 case 0: 1745 case 1: 1746 do_something(); 1747 break; 1748 case 2: 1749 do_something_else(); 1750 break; 1751 default: 1752 break; 1753 } 1754 if (condition) 1755 do_something_completely_different(); 1756 1757 if (x == y) { 1758 q(); 1759 } else if (x > y) { 1760 w(); 1761 } else { 1762 r(); 1763 } 1764 } 1765 1766A style similar to the default Visual Studio formatting style: 1767 1768.. code-block:: yaml 1769 1770 UseTab: Never 1771 IndentWidth: 4 1772 BreakBeforeBraces: Allman 1773 AllowShortIfStatementsOnASingleLine: false 1774 IndentCaseLabels: false 1775 ColumnLimit: 0 1776 1777The result is: 1778 1779.. code-block:: c++ 1780 1781 void test() 1782 { 1783 switch (suffix) 1784 { 1785 case 0: 1786 case 1: 1787 do_something(); 1788 break; 1789 case 2: 1790 do_something_else(); 1791 break; 1792 default: 1793 break; 1794 } 1795 if (condition) 1796 do_somthing_completely_different(); 1797 1798 if (x == y) 1799 { 1800 q(); 1801 } 1802 else if (x > y) 1803 { 1804 w(); 1805 } 1806 else 1807 { 1808 r(); 1809 } 1810 } 1811