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, Microsoft) or 11create a custom 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 Language: CSharp 73 # Use 100 columns for C#. 74 ColumnLimit: 100 75 ... 76 77An easy way to get a valid ``.clang-format`` file containing all configuration 78options of a certain predefined style is: 79 80.. code-block:: console 81 82 clang-format -style=llvm -dump-config > .clang-format 83 84When specifying configuration in the ``-style=`` option, the same configuration 85is applied for all input files. The format of the configuration is: 86 87.. code-block:: console 88 89 -style='{key1: value1, key2: value2, ...}' 90 91 92Disabling Formatting on a Piece of Code 93======================================= 94 95Clang-format understands also special comments that switch formatting in a 96delimited range. The code between a comment ``// clang-format off`` or 97``/* clang-format off */`` up to a comment ``// clang-format on`` or 98``/* clang-format on */`` will not be formatted. The comments themselves 99will be formatted (aligned) normally. 100 101.. code-block:: c++ 102 103 int formatted_code; 104 // clang-format off 105 void unformatted_code ; 106 // clang-format on 107 void formatted_code_again; 108 109 110Configuring Style in Code 111========================= 112 113When using ``clang::format::reformat(...)`` functions, the format is specified 114by supplying the `clang::format::FormatStyle 115<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_ 116structure. 117 118 119Configurable Format Style Options 120================================= 121 122This section lists the supported style options. Value type is specified for 123each option. For enumeration types possible values are specified both as a C++ 124enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in 125the configuration (without a prefix: ``Auto``). 126 127 128**BasedOnStyle** (``string``) 129 The style used for all options not specifically set in the configuration. 130 131 This option is supported only in the :program:`clang-format` configuration 132 (both within ``-style='{...}'`` and the ``.clang-format`` file). 133 134 Possible values: 135 136 * ``LLVM`` 137 A style complying with the `LLVM coding standards 138 <https://llvm.org/docs/CodingStandards.html>`_ 139 * ``Google`` 140 A style complying with `Google's C++ style guide 141 <https://google.github.io/styleguide/cppguide.html>`_ 142 * ``Chromium`` 143 A style complying with `Chromium's style guide 144 <https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md>`_ 145 * ``Mozilla`` 146 A style complying with `Mozilla's style guide 147 <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_ 148 * ``WebKit`` 149 A style complying with `WebKit's style guide 150 <https://www.webkit.org/coding/coding-style.html>`_ 151 * ``Microsoft`` 152 A style complying with `Microsoft's style guide 153 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_ 154 155.. START_FORMAT_STYLE_OPTIONS 156 157**AccessModifierOffset** (``int``) 158 The extra indent or outdent of access modifiers, e.g. ``public:``. 159 160**AlignAfterOpenBracket** (``BracketAlignmentStyle``) 161 If ``true``, horizontally aligns arguments after an open bracket. 162 163 This applies to round brackets (parentheses), angle brackets and square 164 brackets. 165 166 Possible values: 167 168 * ``BAS_Align`` (in configuration: ``Align``) 169 Align parameters on the open bracket, e.g.: 170 171 .. code-block:: c++ 172 173 someLongFunction(argument1, 174 argument2); 175 176 * ``BAS_DontAlign`` (in configuration: ``DontAlign``) 177 Don't align, instead use ``ContinuationIndentWidth``, e.g.: 178 179 .. code-block:: c++ 180 181 someLongFunction(argument1, 182 argument2); 183 184 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``) 185 Always break after an open bracket, if the parameters don't fit 186 on a single line, e.g.: 187 188 .. code-block:: c++ 189 190 someLongFunction( 191 argument1, argument2); 192 193 194 195**AlignConsecutiveAssignments** (``bool``) 196 If ``true``, aligns consecutive assignments. 197 198 This will align the assignment operators of consecutive lines. This 199 will result in formattings like 200 201 .. code-block:: c++ 202 203 int aaaa = 12; 204 int b = 23; 205 int ccc = 23; 206 207**AlignConsecutiveDeclarations** (``bool``) 208 If ``true``, aligns consecutive declarations. 209 210 This will align the declaration names of consecutive lines. This 211 will result in formattings like 212 213 .. code-block:: c++ 214 215 int aaaa = 12; 216 float b = 23; 217 std::string ccc = 23; 218 219**AlignConsecutiveMacros** (``bool``) 220 If ``true``, aligns consecutive C/C++ preprocessor macros. 221 222 This will align C/C++ preprocessor macros of consecutive lines. 223 Will result in formattings like 224 225 .. code-block:: c++ 226 227 #define SHORT_NAME 42 228 #define LONGER_NAME 0x007f 229 #define EVEN_LONGER_NAME (2) 230 #define foo(x) (x * x) 231 #define bar(y, z) (y + z) 232 233**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) 234 Options for aligning backslashes in escaped newlines. 235 236 Possible values: 237 238 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``) 239 Don't align escaped newlines. 240 241 .. code-block:: c++ 242 243 #define A \ 244 int aaaa; \ 245 int b; \ 246 int dddddddddd; 247 248 * ``ENAS_Left`` (in configuration: ``Left``) 249 Align escaped newlines as far left as possible. 250 251 .. code-block:: c++ 252 253 true: 254 #define A \ 255 int aaaa; \ 256 int b; \ 257 int dddddddddd; 258 259 false: 260 261 * ``ENAS_Right`` (in configuration: ``Right``) 262 Align escaped newlines in the right-most column. 263 264 .. code-block:: c++ 265 266 #define A \ 267 int aaaa; \ 268 int b; \ 269 int dddddddddd; 270 271 272 273**AlignOperands** (``bool``) 274 If ``true``, horizontally align operands of binary and ternary 275 expressions. 276 277 Specifically, this aligns operands of a single expression that needs to be 278 split over multiple lines, e.g.: 279 280 .. code-block:: c++ 281 282 int aaa = bbbbbbbbbbbbbbb + 283 ccccccccccccccc; 284 285**AlignTrailingComments** (``bool``) 286 If ``true``, aligns trailing comments. 287 288 .. code-block:: c++ 289 290 true: false: 291 int a; // My comment a vs. int a; // My comment a 292 int b = 2; // comment b int b = 2; // comment about b 293 294**AllowAllArgumentsOnNextLine** (``bool``) 295 If a function call or braced initializer list doesn't fit on a 296 line, allow putting all arguments onto the next line, even if 297 ``BinPackArguments`` is ``false``. 298 299 .. code-block:: c++ 300 301 true: 302 callFunction( 303 a, b, c, d); 304 305 false: 306 callFunction(a, 307 b, 308 c, 309 d); 310 311**AllowAllConstructorInitializersOnNextLine** (``bool``) 312 If a constructor definition with a member initializer list doesn't 313 fit on a single line, allow putting all member initializers onto the next 314 line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true. 315 Note that this parameter has no effect if 316 ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false. 317 318 .. code-block:: c++ 319 320 true: 321 MyClass::MyClass() : 322 member0(0), member1(2) {} 323 324 false: 325 MyClass::MyClass() : 326 member0(0), 327 member1(2) {} 328 329**AllowAllParametersOfDeclarationOnNextLine** (``bool``) 330 If the function declaration doesn't fit on a line, 331 allow putting all parameters of a function declaration onto 332 the next line even if ``BinPackParameters`` is ``false``. 333 334 .. code-block:: c++ 335 336 true: 337 void myFunction( 338 int a, int b, int c, int d, int e); 339 340 false: 341 void myFunction(int a, 342 int b, 343 int c, 344 int d, 345 int e); 346 347**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) 348 Dependent on the value, ``while (true) { continue; }`` can be put on a 349 single line. 350 351 Possible values: 352 353 * ``SBS_Never`` (in configuration: ``Never``) 354 Never merge blocks into a single line. 355 356 .. code-block:: c++ 357 358 while (true) { 359 } 360 while (true) { 361 continue; 362 } 363 364 * ``SBS_Empty`` (in configuration: ``Empty``) 365 Only merge empty blocks. 366 367 .. code-block:: c++ 368 369 while (true) {} 370 while (true) { 371 continue; 372 } 373 374 * ``SBS_Always`` (in configuration: ``Always``) 375 Always merge short blocks into a single line. 376 377 .. code-block:: c++ 378 379 while (true) {} 380 while (true) { continue; } 381 382 383 384**AllowShortCaseLabelsOnASingleLine** (``bool``) 385 If ``true``, short case labels will be contracted to a single line. 386 387 .. code-block:: c++ 388 389 true: false: 390 switch (a) { vs. switch (a) { 391 case 1: x = 1; break; case 1: 392 case 2: return; x = 1; 393 } break; 394 case 2: 395 return; 396 } 397 398**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) 399 Dependent on the value, ``int f() { return 0; }`` can be put on a 400 single line. 401 402 Possible values: 403 404 * ``SFS_None`` (in configuration: ``None``) 405 Never merge functions into a single line. 406 407 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) 408 Only merge functions defined inside a class. Same as "inline", 409 except it does not implies "empty": i.e. top level empty functions 410 are not merged either. 411 412 .. code-block:: c++ 413 414 class Foo { 415 void f() { foo(); } 416 }; 417 void f() { 418 foo(); 419 } 420 void f() { 421 } 422 423 * ``SFS_Empty`` (in configuration: ``Empty``) 424 Only merge empty functions. 425 426 .. code-block:: c++ 427 428 void f() {} 429 void f2() { 430 bar2(); 431 } 432 433 * ``SFS_Inline`` (in configuration: ``Inline``) 434 Only merge functions defined inside a class. Implies "empty". 435 436 .. code-block:: c++ 437 438 class Foo { 439 void f() { foo(); } 440 }; 441 void f() { 442 foo(); 443 } 444 void f() {} 445 446 * ``SFS_All`` (in configuration: ``All``) 447 Merge all functions fitting on a single line. 448 449 .. code-block:: c++ 450 451 class Foo { 452 void f() { foo(); } 453 }; 454 void f() { bar(); } 455 456 457 458**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) 459 If ``true``, ``if (a) return;`` can be put on a single line. 460 461 Possible values: 462 463 * ``SIS_Never`` (in configuration: ``Never``) 464 Never put short ifs on the same line. 465 466 .. code-block:: c++ 467 468 if (a) 469 return ; 470 else { 471 return; 472 } 473 474 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``) 475 Without else put short ifs on the same line only if 476 the else is not a compound statement. 477 478 .. code-block:: c++ 479 480 if (a) return; 481 else 482 return; 483 484 * ``SIS_Always`` (in configuration: ``Always``) 485 Always put short ifs on the same line if 486 the else is not a compound statement or not. 487 488 .. code-block:: c++ 489 490 if (a) return; 491 else { 492 return; 493 } 494 495 496 497**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) 498 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a 499 single line. 500 501 Possible values: 502 503 * ``SLS_None`` (in configuration: ``None``) 504 Never merge lambdas into a single line. 505 506 * ``SLS_Empty`` (in configuration: ``Empty``) 507 Only merge empty lambdas. 508 509 .. code-block:: c++ 510 511 auto lambda = [](int a) {} 512 auto lambda2 = [](int a) { 513 return a; 514 }; 515 516 * ``SLS_Inline`` (in configuration: ``Inline``) 517 Merge lambda into a single line if argument of a function. 518 519 .. code-block:: c++ 520 521 auto lambda = [](int a) { 522 return a; 523 }; 524 sort(a.begin(), a.end(), ()[] { return x < y; }) 525 526 * ``SLS_All`` (in configuration: ``All``) 527 Merge all lambdas fitting on a single line. 528 529 .. code-block:: c++ 530 531 auto lambda = [](int a) {} 532 auto lambda2 = [](int a) { return a; }; 533 534 535 536**AllowShortLoopsOnASingleLine** (``bool``) 537 If ``true``, ``while (true) continue;`` can be put on a single 538 line. 539 540**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) 541 The function definition return type breaking style to use. This 542 option is **deprecated** and is retained for backwards compatibility. 543 544 Possible values: 545 546 * ``DRTBS_None`` (in configuration: ``None``) 547 Break after return type automatically. 548 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 549 550 * ``DRTBS_All`` (in configuration: ``All``) 551 Always break after the return type. 552 553 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) 554 Always break after the return types of top-level functions. 555 556 557 558**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) 559 The function declaration return type breaking style to use. 560 561 Possible values: 562 563 * ``RTBS_None`` (in configuration: ``None``) 564 Break after return type automatically. 565 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 566 567 .. code-block:: c++ 568 569 class A { 570 int f() { return 0; }; 571 }; 572 int f(); 573 int f() { return 1; } 574 575 * ``RTBS_All`` (in configuration: ``All``) 576 Always break after the return type. 577 578 .. code-block:: c++ 579 580 class A { 581 int 582 f() { 583 return 0; 584 }; 585 }; 586 int 587 f(); 588 int 589 f() { 590 return 1; 591 } 592 593 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``) 594 Always break after the return types of top-level functions. 595 596 .. code-block:: c++ 597 598 class A { 599 int f() { return 0; }; 600 }; 601 int 602 f(); 603 int 604 f() { 605 return 1; 606 } 607 608 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) 609 Always break after the return type of function definitions. 610 611 .. code-block:: c++ 612 613 class A { 614 int 615 f() { 616 return 0; 617 }; 618 }; 619 int f(); 620 int 621 f() { 622 return 1; 623 } 624 625 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) 626 Always break after the return type of top-level definitions. 627 628 .. code-block:: c++ 629 630 class A { 631 int f() { return 0; }; 632 }; 633 int f(); 634 int 635 f() { 636 return 1; 637 } 638 639 640 641**AlwaysBreakBeforeMultilineStrings** (``bool``) 642 If ``true``, always break before multiline string literals. 643 644 This flag is mean to make cases where there are multiple multiline strings 645 in a file look more consistent. Thus, it will only take effect if wrapping 646 the string at that point leads to it being indented 647 ``ContinuationIndentWidth`` spaces from the start of the line. 648 649 .. code-block:: c++ 650 651 true: false: 652 aaaa = vs. aaaa = "bbbb" 653 "bbbb" "cccc"; 654 "cccc"; 655 656**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 657 The template declaration breaking style to use. 658 659 Possible values: 660 661 * ``BTDS_No`` (in configuration: ``No``) 662 Do not force break before declaration. 663 ``PenaltyBreakTemplateDeclaration`` is taken into account. 664 665 .. code-block:: c++ 666 667 template <typename T> T foo() { 668 } 669 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, 670 int bbbbbbbbbbbbbbbbbbbbb) { 671 } 672 673 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) 674 Force break after template declaration only when the following 675 declaration spans multiple lines. 676 677 .. code-block:: c++ 678 679 template <typename T> T foo() { 680 } 681 template <typename T> 682 T foo(int aaaaaaaaaaaaaaaaaaaaa, 683 int bbbbbbbbbbbbbbbbbbbbb) { 684 } 685 686 * ``BTDS_Yes`` (in configuration: ``Yes``) 687 Always break after template declaration. 688 689 .. code-block:: c++ 690 691 template <typename T> 692 T foo() { 693 } 694 template <typename T> 695 T foo(int aaaaaaaaaaaaaaaaaaaaa, 696 int bbbbbbbbbbbbbbbbbbbbb) { 697 } 698 699 700 701**BinPackArguments** (``bool``) 702 If ``false``, a function call's arguments will either be all on the 703 same line or will have one line each. 704 705 .. code-block:: c++ 706 707 true: 708 void f() { 709 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, 710 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 711 } 712 713 false: 714 void f() { 715 f(aaaaaaaaaaaaaaaaaaaa, 716 aaaaaaaaaaaaaaaaaaaa, 717 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 718 } 719 720**BinPackParameters** (``bool``) 721 If ``false``, a function declaration's or function definition's 722 parameters will either all be on the same line or will have one line each. 723 724 .. code-block:: c++ 725 726 true: 727 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, 728 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 729 730 false: 731 void f(int aaaaaaaaaaaaaaaaaaaa, 732 int aaaaaaaaaaaaaaaaaaaa, 733 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 734 735**BraceWrapping** (``BraceWrappingFlags``) 736 Control of individual brace wrapping cases. 737 738 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how 739 each individual brace case should be handled. Otherwise, this is ignored. 740 741 .. code-block:: yaml 742 743 # Example of usage: 744 BreakBeforeBraces: Custom 745 BraceWrapping: 746 AfterEnum: true 747 AfterStruct: false 748 SplitEmptyFunction: false 749 750 Nested configuration flags: 751 752 753 * ``bool AfterCaseLabel`` Wrap case labels. 754 755 .. code-block:: c++ 756 757 false: true: 758 switch (foo) { vs. switch (foo) { 759 case 1: { case 1: 760 bar(); { 761 break; bar(); 762 } break; 763 default: { } 764 plop(); default: 765 } { 766 } plop(); 767 } 768 } 769 770 * ``bool AfterClass`` Wrap class definitions. 771 772 .. code-block:: c++ 773 774 true: 775 class foo {}; 776 777 false: 778 class foo 779 {}; 780 781 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement`` 782 Wrap control statements (``if``/``for``/``while``/``switch``/..). 783 784 Possible values: 785 786 * ``BWACS_Never`` (in configuration: ``Never``) 787 Never wrap braces after a control statement. 788 789 .. code-block:: c++ 790 791 if (foo()) { 792 } else { 793 } 794 for (int i = 0; i < 10; ++i) { 795 } 796 797 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``) 798 Only wrap braces after a multi-line control statement. 799 800 .. code-block:: c++ 801 802 if (foo && bar && 803 baz) 804 { 805 quux(); 806 } 807 while (foo || bar) { 808 } 809 810 * ``BWACS_Always`` (in configuration: ``Always``) 811 Always wrap braces after a control statement. 812 813 .. code-block:: c++ 814 815 if (foo()) 816 { 817 } else 818 {} 819 for (int i = 0; i < 10; ++i) 820 {} 821 822 823 * ``bool AfterEnum`` Wrap enum definitions. 824 825 .. code-block:: c++ 826 827 true: 828 enum X : int 829 { 830 B 831 }; 832 833 false: 834 enum X : int { B }; 835 836 * ``bool AfterFunction`` Wrap function definitions. 837 838 .. code-block:: c++ 839 840 true: 841 void foo() 842 { 843 bar(); 844 bar2(); 845 } 846 847 false: 848 void foo() { 849 bar(); 850 bar2(); 851 } 852 853 * ``bool AfterNamespace`` Wrap namespace definitions. 854 855 .. code-block:: c++ 856 857 true: 858 namespace 859 { 860 int foo(); 861 int bar(); 862 } 863 864 false: 865 namespace { 866 int foo(); 867 int bar(); 868 } 869 870 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...). 871 @autoreleasepool and @synchronized blocks are wrapped 872 according to `AfterControlStatement` flag. 873 874 * ``bool AfterStruct`` Wrap struct definitions. 875 876 .. code-block:: c++ 877 878 true: 879 struct foo 880 { 881 int x; 882 }; 883 884 false: 885 struct foo { 886 int x; 887 }; 888 889 * ``bool AfterUnion`` Wrap union definitions. 890 891 .. code-block:: c++ 892 893 true: 894 union foo 895 { 896 int x; 897 } 898 899 false: 900 union foo { 901 int x; 902 } 903 904 * ``bool AfterExternBlock`` Wrap extern blocks. 905 906 .. code-block:: c++ 907 908 true: 909 extern "C" 910 { 911 int foo(); 912 } 913 914 false: 915 extern "C" { 916 int foo(); 917 } 918 919 * ``bool BeforeCatch`` Wrap before ``catch``. 920 921 .. code-block:: c++ 922 923 true: 924 try { 925 foo(); 926 } 927 catch () { 928 } 929 930 false: 931 try { 932 foo(); 933 } catch () { 934 } 935 936 * ``bool BeforeElse`` Wrap before ``else``. 937 938 .. code-block:: c++ 939 940 true: 941 if (foo()) { 942 } 943 else { 944 } 945 946 false: 947 if (foo()) { 948 } else { 949 } 950 951 * ``bool IndentBraces`` Indent the wrapped braces themselves. 952 953 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line. 954 This option is used only if the opening brace of the function has 955 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is 956 set, and the function could/should not be put on a single line (as per 957 `AllowShortFunctionsOnASingleLine` and constructor formatting options). 958 959 .. code-block:: c++ 960 961 int f() vs. inf f() 962 {} { 963 } 964 965 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body 966 can be put on a single line. This option is used only if the opening 967 brace of the record has already been wrapped, i.e. the `AfterClass` 968 (for classes) brace wrapping mode is set. 969 970 .. code-block:: c++ 971 972 class Foo vs. class Foo 973 {} { 974 } 975 976 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line. 977 This option is used only if the opening brace of the namespace has 978 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is 979 set. 980 981 .. code-block:: c++ 982 983 namespace Foo vs. namespace Foo 984 {} { 985 } 986 987 988**BreakAfterJavaFieldAnnotations** (``bool``) 989 Break after each annotation on a field in Java files. 990 991 .. code-block:: java 992 993 true: false: 994 @Partial vs. @Partial @Mock DataLoad loader; 995 @Mock 996 DataLoad loader; 997 998**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) 999 The way to wrap binary operators. 1000 1001 Possible values: 1002 1003 * ``BOS_None`` (in configuration: ``None``) 1004 Break after operators. 1005 1006 .. code-block:: c++ 1007 1008 LooooooooooongType loooooooooooooooooooooongVariable = 1009 someLooooooooooooooooongFunction(); 1010 1011 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 1012 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == 1013 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && 1014 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > 1015 ccccccccccccccccccccccccccccccccccccccccc; 1016 1017 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) 1018 Break before operators that aren't assignments. 1019 1020 .. code-block:: c++ 1021 1022 LooooooooooongType loooooooooooooooooooooongVariable = 1023 someLooooooooooooooooongFunction(); 1024 1025 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1026 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1027 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1028 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1029 > ccccccccccccccccccccccccccccccccccccccccc; 1030 1031 * ``BOS_All`` (in configuration: ``All``) 1032 Break before operators. 1033 1034 .. code-block:: c++ 1035 1036 LooooooooooongType loooooooooooooooooooooongVariable 1037 = someLooooooooooooooooongFunction(); 1038 1039 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1040 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1041 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1042 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1043 > ccccccccccccccccccccccccccccccccccccccccc; 1044 1045 1046 1047**BreakBeforeBraces** (``BraceBreakingStyle``) 1048 The brace breaking style to use. 1049 1050 Possible values: 1051 1052 * ``BS_Attach`` (in configuration: ``Attach``) 1053 Always attach braces to surrounding context. 1054 1055 .. code-block:: c++ 1056 1057 try { 1058 foo(); 1059 } catch () { 1060 } 1061 void foo() { bar(); } 1062 class foo {}; 1063 if (foo()) { 1064 } else { 1065 } 1066 enum X : int { A, B }; 1067 1068 * ``BS_Linux`` (in configuration: ``Linux``) 1069 Like ``Attach``, but break before braces on function, namespace and 1070 class definitions. 1071 1072 .. code-block:: c++ 1073 1074 try { 1075 foo(); 1076 } catch () { 1077 } 1078 void foo() { bar(); } 1079 class foo 1080 { 1081 }; 1082 if (foo()) { 1083 } else { 1084 } 1085 enum X : int { A, B }; 1086 1087 * ``BS_Mozilla`` (in configuration: ``Mozilla``) 1088 Like ``Attach``, but break before braces on enum, function, and record 1089 definitions. 1090 1091 .. code-block:: c++ 1092 1093 try { 1094 foo(); 1095 } catch () { 1096 } 1097 void foo() { bar(); } 1098 class foo 1099 { 1100 }; 1101 if (foo()) { 1102 } else { 1103 } 1104 enum X : int { A, B }; 1105 1106 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) 1107 Like ``Attach``, but break before function definitions, ``catch``, and 1108 ``else``. 1109 1110 .. code-block:: c++ 1111 1112 try { 1113 foo(); 1114 } 1115 catch () { 1116 } 1117 void foo() { bar(); } 1118 class foo { 1119 }; 1120 if (foo()) { 1121 } 1122 else { 1123 } 1124 enum X : int { A, B }; 1125 1126 * ``BS_Allman`` (in configuration: ``Allman``) 1127 Always break before braces. 1128 1129 .. code-block:: c++ 1130 1131 try 1132 { 1133 foo(); 1134 } 1135 catch () 1136 { 1137 } 1138 void foo() { bar(); } 1139 class foo 1140 { 1141 }; 1142 if (foo()) 1143 { 1144 } 1145 else 1146 { 1147 } 1148 enum X : int 1149 { 1150 A, 1151 B 1152 }; 1153 1154 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``) 1155 Like ``Allman`` but always indent braces and line up code with braces. 1156 1157 .. code-block:: c++ 1158 1159 try 1160 { 1161 foo(); 1162 } 1163 catch () 1164 { 1165 } 1166 void foo() { bar(); } 1167 class foo 1168 { 1169 }; 1170 if (foo()) 1171 { 1172 } 1173 else 1174 { 1175 } 1176 enum X : int 1177 { 1178 A, 1179 B 1180 }; 1181 1182 * ``BS_GNU`` (in configuration: ``GNU``) 1183 Always break before braces and add an extra level of indentation to 1184 braces of control statements, not to those of class, function 1185 or other definitions. 1186 1187 .. code-block:: c++ 1188 1189 try 1190 { 1191 foo(); 1192 } 1193 catch () 1194 { 1195 } 1196 void foo() { bar(); } 1197 class foo 1198 { 1199 }; 1200 if (foo()) 1201 { 1202 } 1203 else 1204 { 1205 } 1206 enum X : int 1207 { 1208 A, 1209 B 1210 }; 1211 1212 * ``BS_WebKit`` (in configuration: ``WebKit``) 1213 Like ``Attach``, but break before functions. 1214 1215 .. code-block:: c++ 1216 1217 try { 1218 foo(); 1219 } catch () { 1220 } 1221 void foo() { bar(); } 1222 class foo { 1223 }; 1224 if (foo()) { 1225 } else { 1226 } 1227 enum X : int { A, B }; 1228 1229 * ``BS_Custom`` (in configuration: ``Custom``) 1230 Configure each individual brace in `BraceWrapping`. 1231 1232 1233 1234**BreakBeforeTernaryOperators** (``bool``) 1235 If ``true``, ternary operators will be placed after line breaks. 1236 1237 .. code-block:: c++ 1238 1239 true: 1240 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription 1241 ? firstValue 1242 : SecondValueVeryVeryVeryVeryLong; 1243 1244 false: 1245 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? 1246 firstValue : 1247 SecondValueVeryVeryVeryVeryLong; 1248 1249**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) 1250 The constructor initializers style to use. 1251 1252 Possible values: 1253 1254 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) 1255 Break constructor initializers before the colon and after the commas. 1256 1257 .. code-block:: c++ 1258 1259 Constructor() 1260 : initializer1(), 1261 initializer2() 1262 1263 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) 1264 Break constructor initializers before the colon and commas, and align 1265 the commas with the colon. 1266 1267 .. code-block:: c++ 1268 1269 Constructor() 1270 : initializer1() 1271 , initializer2() 1272 1273 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``) 1274 Break constructor initializers after the colon and commas. 1275 1276 .. code-block:: c++ 1277 1278 Constructor() : 1279 initializer1(), 1280 initializer2() 1281 1282 1283 1284**BreakInheritanceList** (``BreakInheritanceListStyle``) 1285 The inheritance list style to use. 1286 1287 Possible values: 1288 1289 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``) 1290 Break inheritance list before the colon and after the commas. 1291 1292 .. code-block:: c++ 1293 1294 class Foo 1295 : Base1, 1296 Base2 1297 {}; 1298 1299 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``) 1300 Break inheritance list before the colon and commas, and align 1301 the commas with the colon. 1302 1303 .. code-block:: c++ 1304 1305 class Foo 1306 : Base1 1307 , Base2 1308 {}; 1309 1310 * ``BILS_AfterColon`` (in configuration: ``AfterColon``) 1311 Break inheritance list after the colon and commas. 1312 1313 .. code-block:: c++ 1314 1315 class Foo : 1316 Base1, 1317 Base2 1318 {}; 1319 1320 1321 1322**BreakStringLiterals** (``bool``) 1323 Allow breaking string literals when formatting. 1324 1325 .. code-block:: c++ 1326 1327 true: 1328 const char* x = "veryVeryVeryVeryVeryVe" 1329 "ryVeryVeryVeryVeryVery" 1330 "VeryLongString"; 1331 1332 false: 1333 const char* x = 1334 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; 1335 1336**ColumnLimit** (``unsigned``) 1337 The column limit. 1338 1339 A column limit of ``0`` means that there is no column limit. In this case, 1340 clang-format will respect the input's line breaking decisions within 1341 statements unless they contradict other rules. 1342 1343**CommentPragmas** (``std::string``) 1344 A regular expression that describes comments with special meaning, 1345 which should not be split into lines or otherwise changed. 1346 1347 .. code-block:: c++ 1348 1349 // CommentPragmas: '^ FOOBAR pragma:' 1350 // Will leave the following line unaffected 1351 #include <vector> // FOOBAR pragma: keep 1352 1353**CompactNamespaces** (``bool``) 1354 If ``true``, consecutive namespace declarations will be on the same 1355 line. If ``false``, each namespace is declared on a new line. 1356 1357 .. code-block:: c++ 1358 1359 true: 1360 namespace Foo { namespace Bar { 1361 }} 1362 1363 false: 1364 namespace Foo { 1365 namespace Bar { 1366 } 1367 } 1368 1369 If it does not fit on a single line, the overflowing namespaces get 1370 wrapped: 1371 1372 .. code-block:: c++ 1373 1374 namespace Foo { namespace Bar { 1375 namespace Extra { 1376 }}} 1377 1378**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) 1379 If the constructor initializers don't fit on a line, put each 1380 initializer on its own line. 1381 1382 .. code-block:: c++ 1383 1384 true: 1385 SomeClass::Constructor() 1386 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { 1387 return 0; 1388 } 1389 1390 false: 1391 SomeClass::Constructor() 1392 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), 1393 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { 1394 return 0; 1395 } 1396 1397**ConstructorInitializerIndentWidth** (``unsigned``) 1398 The number of characters to use for indentation of constructor 1399 initializer lists as well as inheritance lists. 1400 1401**ContinuationIndentWidth** (``unsigned``) 1402 Indent width for line continuations. 1403 1404 .. code-block:: c++ 1405 1406 ContinuationIndentWidth: 2 1407 1408 int i = // VeryVeryVeryVeryVeryLongComment 1409 longFunction( // Again a long comment 1410 arg); 1411 1412**Cpp11BracedListStyle** (``bool``) 1413 If ``true``, format braced lists as best suited for C++11 braced 1414 lists. 1415 1416 Important differences: 1417 - No spaces inside the braced list. 1418 - No line break before the closing brace. 1419 - Indentation with the continuation indent, not with the block indent. 1420 1421 Fundamentally, C++11 braced lists are formatted exactly like function 1422 calls would be formatted in their place. If the braced list follows a name 1423 (e.g. a type or variable name), clang-format formats as if the ``{}`` were 1424 the parentheses of a function call with that name. If there is no name, 1425 a zero-length name is assumed. 1426 1427 .. code-block:: c++ 1428 1429 true: false: 1430 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; 1431 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; 1432 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); 1433 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; 1434 1435**DerivePointerAlignment** (``bool``) 1436 If ``true``, analyze the formatted file for the most common 1437 alignment of ``&`` and ``*``. 1438 Pointer and reference alignment styles are going to be updated according 1439 to the preferences found in the file. 1440 ``PointerAlignment`` is then used only as fallback. 1441 1442**DisableFormat** (``bool``) 1443 Disables formatting completely. 1444 1445**ExperimentalAutoDetectBinPacking** (``bool``) 1446 If ``true``, clang-format detects whether function calls and 1447 definitions are formatted with one parameter per line. 1448 1449 Each call can be bin-packed, one-per-line or inconclusive. If it is 1450 inconclusive, e.g. completely on one line, but a decision needs to be 1451 made, clang-format analyzes whether there are other bin-packed cases in 1452 the input file and act accordingly. 1453 1454 NOTE: This is an experimental flag, that might go away or be renamed. Do 1455 not use this in config files, etc. Use at your own risk. 1456 1457**FixNamespaceComments** (``bool``) 1458 If ``true``, clang-format adds missing namespace end comments and 1459 fixes invalid existing ones. 1460 1461 .. code-block:: c++ 1462 1463 true: false: 1464 namespace a { vs. namespace a { 1465 foo(); foo(); 1466 } // namespace a } 1467 1468**ForEachMacros** (``std::vector<std::string>``) 1469 A vector of macros that should be interpreted as foreach loops 1470 instead of as function calls. 1471 1472 These are expected to be macros of the form: 1473 1474 .. code-block:: c++ 1475 1476 FOREACH(<variable-declaration>, ...) 1477 <loop-body> 1478 1479 In the .clang-format configuration file, this can be configured like: 1480 1481 .. code-block:: yaml 1482 1483 ForEachMacros: ['RANGES_FOR', 'FOREACH'] 1484 1485 For example: BOOST_FOREACH. 1486 1487**IncludeBlocks** (``IncludeBlocksStyle``) 1488 Dependent on the value, multiple ``#include`` blocks can be sorted 1489 as one and divided based on category. 1490 1491 Possible values: 1492 1493 * ``IBS_Preserve`` (in configuration: ``Preserve``) 1494 Sort each ``#include`` block separately. 1495 1496 .. code-block:: c++ 1497 1498 #include "b.h" into #include "b.h" 1499 1500 #include <lib/main.h> #include "a.h" 1501 #include "a.h" #include <lib/main.h> 1502 1503 * ``IBS_Merge`` (in configuration: ``Merge``) 1504 Merge multiple ``#include`` blocks together and sort as one. 1505 1506 .. code-block:: c++ 1507 1508 #include "b.h" into #include "a.h" 1509 #include "b.h" 1510 #include <lib/main.h> #include <lib/main.h> 1511 #include "a.h" 1512 1513 * ``IBS_Regroup`` (in configuration: ``Regroup``) 1514 Merge multiple ``#include`` blocks together and sort as one. 1515 Then split into groups based on category priority. See 1516 ``IncludeCategories``. 1517 1518 .. code-block:: c++ 1519 1520 #include "b.h" into #include "a.h" 1521 #include "b.h" 1522 #include <lib/main.h> 1523 #include "a.h" #include <lib/main.h> 1524 1525 1526 1527**IncludeCategories** (``std::vector<IncludeCategory>``) 1528 Regular expressions denoting the different ``#include`` categories 1529 used for ordering ``#includes``. 1530 1531 `POSIX extended 1532 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_ 1533 regular expressions are supported. 1534 1535 These regular expressions are matched against the filename of an include 1536 (including the <> or "") in order. The value belonging to the first 1537 matching regular expression is assigned and ``#includes`` are sorted first 1538 according to increasing category number and then alphabetically within 1539 each category. 1540 1541 If none of the regular expressions match, INT_MAX is assigned as 1542 category. The main header for a source file automatically gets category 0. 1543 so that it is generally kept at the beginning of the ``#includes`` 1544 (https://llvm.org/docs/CodingStandards.html#include-style). However, you 1545 can also assign negative priorities if you have certain headers that 1546 always need to be first. 1547 1548 There is a third and optional field ``SortPriority`` which can used while 1549 ``IncludeBloks = IBS_Regroup`` to define the priority in which ``#includes`` 1550 should be ordered, and value of ``Priority`` defines the order of 1551 ``#include blocks`` and also enables to group ``#includes`` of different 1552 priority for order.``SortPriority`` is set to the value of ``Priority`` 1553 as default if it is not assigned. 1554 1555 To configure this in the .clang-format file, use: 1556 1557 .. code-block:: yaml 1558 1559 IncludeCategories: 1560 - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 1561 Priority: 2 1562 SortPriority: 2 1563 - Regex: '^(<|"(gtest|gmock|isl|json)/)' 1564 Priority: 3 1565 - Regex: '<[[:alnum:].]+>' 1566 Priority: 4 1567 - Regex: '.*' 1568 Priority: 1 1569 SortPriority: 0 1570 1571**IncludeIsMainRegex** (``std::string``) 1572 Specify a regular expression of suffixes that are allowed in the 1573 file-to-main-include mapping. 1574 1575 When guessing whether a #include is the "main" include (to assign 1576 category 0, see above), use this regex of allowed suffixes to the header 1577 stem. A partial match is done, so that: 1578 - "" means "arbitrary suffix" 1579 - "$" means "no suffix" 1580 1581 For example, if configured to "(_test)?$", then a header a.h would be seen 1582 as the "main" include in both a.cc and a_test.cc. 1583 1584**IncludeIsMainSourceRegex** (``std::string``) 1585 Specify a regular expression for files being formatted 1586 that are allowed to be considered "main" in the 1587 file-to-main-include mapping. 1588 1589 By default, clang-format considers files as "main" only when they end 1590 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm`` 1591 extensions. 1592 For these files a guessing of "main" include takes place 1593 (to assign category 0, see above). This config option allows for 1594 additional suffixes and extensions for files to be considered as "main". 1595 1596 For example, if this option is configured to ``(Impl\.hpp)$``, 1597 then a file ``ClassImpl.hpp`` is considered "main" (in addition to 1598 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main 1599 include file" logic will be executed (with *IncludeIsMainRegex* setting 1600 also being respected in later phase). Without this option set, 1601 ``ClassImpl.hpp`` would not have the main include file put on top 1602 before any other include. 1603 1604**IndentCaseLabels** (``bool``) 1605 Indent case labels one level from the switch statement. 1606 1607 When ``false``, use the same indentation level as for the switch 1608 statement. Switch statement body is always indented one level more than 1609 case labels. 1610 1611 .. code-block:: c++ 1612 1613 false: true: 1614 switch (fool) { vs. switch (fool) { 1615 case 1: case 1: 1616 bar(); bar(); 1617 break; break; 1618 default: default: 1619 plop(); plop(); 1620 } } 1621 1622**IndentGotoLabels** (``bool``) 1623 Indent goto labels. 1624 1625 When ``false``, goto labels are flushed left. 1626 1627 .. code-block:: c++ 1628 1629 true: false: 1630 int f() { vs. int f() { 1631 if (foo()) { if (foo()) { 1632 label1: label1: 1633 bar(); bar(); 1634 } } 1635 label2: label2: 1636 return 1; return 1; 1637 } } 1638 1639**IndentPPDirectives** (``PPDirectiveIndentStyle``) 1640 The preprocessor directive indenting style to use. 1641 1642 Possible values: 1643 1644 * ``PPDIS_None`` (in configuration: ``None``) 1645 Does not indent any directives. 1646 1647 .. code-block:: c++ 1648 1649 #if FOO 1650 #if BAR 1651 #include <foo> 1652 #endif 1653 #endif 1654 1655 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) 1656 Indents directives after the hash. 1657 1658 .. code-block:: c++ 1659 1660 #if FOO 1661 # if BAR 1662 # include <foo> 1663 # endif 1664 #endif 1665 1666 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``) 1667 Indents directives before the hash. 1668 1669 .. code-block:: c++ 1670 1671 #if FOO 1672 #if BAR 1673 #include <foo> 1674 #endif 1675 #endif 1676 1677 1678 1679**IndentWidth** (``unsigned``) 1680 The number of columns to use for indentation. 1681 1682 .. code-block:: c++ 1683 1684 IndentWidth: 3 1685 1686 void f() { 1687 someFunction(); 1688 if (true, false) { 1689 f(); 1690 } 1691 } 1692 1693**IndentWrappedFunctionNames** (``bool``) 1694 Indent if a function definition or declaration is wrapped after the 1695 type. 1696 1697 .. code-block:: c++ 1698 1699 true: 1700 LoooooooooooooooooooooooooooooooooooooooongReturnType 1701 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 1702 1703 false: 1704 LoooooooooooooooooooooooooooooooooooooooongReturnType 1705 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 1706 1707**JavaImportGroups** (``std::vector<std::string>``) 1708 A vector of prefixes ordered by the desired groups for Java imports. 1709 1710 Each group is separated by a newline. Static imports will also follow the 1711 same grouping convention above all non-static imports. One group's prefix 1712 can be a subset of another - the longest prefix is always matched. Within 1713 a group, the imports are ordered lexicographically. 1714 1715 In the .clang-format configuration file, this can be configured like 1716 in the following yaml example. This will result in imports being 1717 formatted as in the Java example below. 1718 1719 .. code-block:: yaml 1720 1721 JavaImportGroups: ['com.example', 'com', 'org'] 1722 1723 1724 .. code-block:: java 1725 1726 import static com.example.function1; 1727 1728 import static com.test.function2; 1729 1730 import static org.example.function3; 1731 1732 import com.example.ClassA; 1733 import com.example.Test; 1734 import com.example.a.ClassB; 1735 1736 import com.test.ClassC; 1737 1738 import org.example.ClassD; 1739 1740**JavaScriptQuotes** (``JavaScriptQuoteStyle``) 1741 The JavaScriptQuoteStyle to use for JavaScript strings. 1742 1743 Possible values: 1744 1745 * ``JSQS_Leave`` (in configuration: ``Leave``) 1746 Leave string quotes as they are. 1747 1748 .. code-block:: js 1749 1750 string1 = "foo"; 1751 string2 = 'bar'; 1752 1753 * ``JSQS_Single`` (in configuration: ``Single``) 1754 Always use single quotes. 1755 1756 .. code-block:: js 1757 1758 string1 = 'foo'; 1759 string2 = 'bar'; 1760 1761 * ``JSQS_Double`` (in configuration: ``Double``) 1762 Always use double quotes. 1763 1764 .. code-block:: js 1765 1766 string1 = "foo"; 1767 string2 = "bar"; 1768 1769 1770 1771**JavaScriptWrapImports** (``bool``) 1772 Whether to wrap JavaScript import/export statements. 1773 1774 .. code-block:: js 1775 1776 true: 1777 import { 1778 VeryLongImportsAreAnnoying, 1779 VeryLongImportsAreAnnoying, 1780 VeryLongImportsAreAnnoying, 1781 } from 'some/module.js' 1782 1783 false: 1784 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" 1785 1786**KeepEmptyLinesAtTheStartOfBlocks** (``bool``) 1787 If true, the empty line at the start of blocks is kept. 1788 1789 .. code-block:: c++ 1790 1791 true: false: 1792 if (foo) { vs. if (foo) { 1793 bar(); 1794 bar(); } 1795 } 1796 1797**Language** (``LanguageKind``) 1798 Language, this format style is targeted at. 1799 1800 Possible values: 1801 1802 * ``LK_None`` (in configuration: ``None``) 1803 Do not use. 1804 1805 * ``LK_Cpp`` (in configuration: ``Cpp``) 1806 Should be used for C, C++. 1807 1808 * ``LK_CSharp`` (in configuration: ``CSharp``) 1809 Should be used for C#. 1810 1811 * ``LK_Java`` (in configuration: ``Java``) 1812 Should be used for Java. 1813 1814 * ``LK_JavaScript`` (in configuration: ``JavaScript``) 1815 Should be used for JavaScript. 1816 1817 * ``LK_ObjC`` (in configuration: ``ObjC``) 1818 Should be used for Objective-C, Objective-C++. 1819 1820 * ``LK_Proto`` (in configuration: ``Proto``) 1821 Should be used for Protocol Buffers 1822 (https://developers.google.com/protocol-buffers/). 1823 1824 * ``LK_TableGen`` (in configuration: ``TableGen``) 1825 Should be used for TableGen code. 1826 1827 * ``LK_TextProto`` (in configuration: ``TextProto``) 1828 Should be used for Protocol Buffer messages in text format 1829 (https://developers.google.com/protocol-buffers/). 1830 1831 1832 1833**MacroBlockBegin** (``std::string``) 1834 A regular expression matching macros that start a block. 1835 1836 .. code-block:: c++ 1837 1838 # With: 1839 MacroBlockBegin: "^NS_MAP_BEGIN|\ 1840 NS_TABLE_HEAD$" 1841 MacroBlockEnd: "^\ 1842 NS_MAP_END|\ 1843 NS_TABLE_.*_END$" 1844 1845 NS_MAP_BEGIN 1846 foo(); 1847 NS_MAP_END 1848 1849 NS_TABLE_HEAD 1850 bar(); 1851 NS_TABLE_FOO_END 1852 1853 # Without: 1854 NS_MAP_BEGIN 1855 foo(); 1856 NS_MAP_END 1857 1858 NS_TABLE_HEAD 1859 bar(); 1860 NS_TABLE_FOO_END 1861 1862**MacroBlockEnd** (``std::string``) 1863 A regular expression matching macros that end a block. 1864 1865**MaxEmptyLinesToKeep** (``unsigned``) 1866 The maximum number of consecutive empty lines to keep. 1867 1868 .. code-block:: c++ 1869 1870 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 1871 int f() { int f() { 1872 int = 1; int i = 1; 1873 i = foo(); 1874 i = foo(); return i; 1875 } 1876 return i; 1877 } 1878 1879**NamespaceIndentation** (``NamespaceIndentationKind``) 1880 The indentation used for namespaces. 1881 1882 Possible values: 1883 1884 * ``NI_None`` (in configuration: ``None``) 1885 Don't indent in namespaces. 1886 1887 .. code-block:: c++ 1888 1889 namespace out { 1890 int i; 1891 namespace in { 1892 int i; 1893 } 1894 } 1895 1896 * ``NI_Inner`` (in configuration: ``Inner``) 1897 Indent only in inner namespaces (nested in other namespaces). 1898 1899 .. code-block:: c++ 1900 1901 namespace out { 1902 int i; 1903 namespace in { 1904 int i; 1905 } 1906 } 1907 1908 * ``NI_All`` (in configuration: ``All``) 1909 Indent in all namespaces. 1910 1911 .. code-block:: c++ 1912 1913 namespace out { 1914 int i; 1915 namespace in { 1916 int i; 1917 } 1918 } 1919 1920 1921 1922**NamespaceMacros** (``std::vector<std::string>``) 1923 A vector of macros which are used to open namespace blocks. 1924 1925 These are expected to be macros of the form: 1926 1927 .. code-block:: c++ 1928 1929 NAMESPACE(<namespace-name>, ...) { 1930 <namespace-content> 1931 } 1932 1933 For example: TESTSUITE 1934 1935**ObjCBinPackProtocolList** (``BinPackStyle``) 1936 Controls bin-packing Objective-C protocol conformance list 1937 items into as few lines as possible when they go over ``ColumnLimit``. 1938 1939 If ``Auto`` (the default), delegates to the value in 1940 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C 1941 protocol conformance list items into as few lines as possible 1942 whenever they go over ``ColumnLimit``. 1943 1944 If ``Always``, always bin-packs Objective-C protocol conformance 1945 list items into as few lines as possible whenever they go over 1946 ``ColumnLimit``. 1947 1948 If ``Never``, lays out Objective-C protocol conformance list items 1949 onto individual lines whenever they go over ``ColumnLimit``. 1950 1951 1952 .. code-block:: objc 1953 1954 Always (or Auto, if BinPackParameters=true): 1955 @interface ccccccccccccc () < 1956 ccccccccccccc, ccccccccccccc, 1957 ccccccccccccc, ccccccccccccc> { 1958 } 1959 1960 Never (or Auto, if BinPackParameters=false): 1961 @interface ddddddddddddd () < 1962 ddddddddddddd, 1963 ddddddddddddd, 1964 ddddddddddddd, 1965 ddddddddddddd> { 1966 } 1967 1968 Possible values: 1969 1970 * ``BPS_Auto`` (in configuration: ``Auto``) 1971 Automatically determine parameter bin-packing behavior. 1972 1973 * ``BPS_Always`` (in configuration: ``Always``) 1974 Always bin-pack parameters. 1975 1976 * ``BPS_Never`` (in configuration: ``Never``) 1977 Never bin-pack parameters. 1978 1979 1980 1981**ObjCBlockIndentWidth** (``unsigned``) 1982 The number of characters to use for indentation of ObjC blocks. 1983 1984 .. code-block:: objc 1985 1986 ObjCBlockIndentWidth: 4 1987 1988 [operation setCompletionBlock:^{ 1989 [self onOperationDone]; 1990 }]; 1991 1992**ObjCSpaceAfterProperty** (``bool``) 1993 Add a space after ``@property`` in Objective-C, i.e. use 1994 ``@property (readonly)`` instead of ``@property(readonly)``. 1995 1996**ObjCSpaceBeforeProtocolList** (``bool``) 1997 Add a space in front of an Objective-C protocol list, i.e. use 1998 ``Foo <Protocol>`` instead of ``Foo<Protocol>``. 1999 2000**PenaltyBreakAssignment** (``unsigned``) 2001 The penalty for breaking around an assignment operator. 2002 2003**PenaltyBreakBeforeFirstCallParameter** (``unsigned``) 2004 The penalty for breaking a function call after ``call(``. 2005 2006**PenaltyBreakComment** (``unsigned``) 2007 The penalty for each line break introduced inside a comment. 2008 2009**PenaltyBreakFirstLessLess** (``unsigned``) 2010 The penalty for breaking before the first ``<<``. 2011 2012**PenaltyBreakString** (``unsigned``) 2013 The penalty for each line break introduced inside a string literal. 2014 2015**PenaltyBreakTemplateDeclaration** (``unsigned``) 2016 The penalty for breaking after template declaration. 2017 2018**PenaltyExcessCharacter** (``unsigned``) 2019 The penalty for each character outside of the column limit. 2020 2021**PenaltyReturnTypeOnItsOwnLine** (``unsigned``) 2022 Penalty for putting the return type of a function onto its own 2023 line. 2024 2025**PointerAlignment** (``PointerAlignmentStyle``) 2026 Pointer and reference alignment style. 2027 2028 Possible values: 2029 2030 * ``PAS_Left`` (in configuration: ``Left``) 2031 Align pointer to the left. 2032 2033 .. code-block:: c++ 2034 2035 int* a; 2036 2037 * ``PAS_Right`` (in configuration: ``Right``) 2038 Align pointer to the right. 2039 2040 .. code-block:: c++ 2041 2042 int *a; 2043 2044 * ``PAS_Middle`` (in configuration: ``Middle``) 2045 Align pointer in the middle. 2046 2047 .. code-block:: c++ 2048 2049 int * a; 2050 2051 2052 2053**RawStringFormats** (``std::vector<RawStringFormat>``) 2054 Defines hints for detecting supported languages code blocks in raw 2055 strings. 2056 2057 A raw string with a matching delimiter or a matching enclosing function 2058 name will be reformatted assuming the specified language based on the 2059 style for that language defined in the .clang-format file. If no style has 2060 been defined in the .clang-format file for the specific language, a 2061 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not 2062 found, the formatting is based on llvm style. A matching delimiter takes 2063 precedence over a matching enclosing function name for determining the 2064 language of the raw string contents. 2065 2066 If a canonical delimiter is specified, occurrences of other delimiters for 2067 the same language will be updated to the canonical if possible. 2068 2069 There should be at most one specification per language and each delimiter 2070 and enclosing function should not occur in multiple specifications. 2071 2072 To configure this in the .clang-format file, use: 2073 2074 .. code-block:: yaml 2075 2076 RawStringFormats: 2077 - Language: TextProto 2078 Delimiters: 2079 - 'pb' 2080 - 'proto' 2081 EnclosingFunctions: 2082 - 'PARSE_TEXT_PROTO' 2083 BasedOnStyle: google 2084 - Language: Cpp 2085 Delimiters: 2086 - 'cc' 2087 - 'cpp' 2088 BasedOnStyle: llvm 2089 CanonicalDelimiter: 'cc' 2090 2091**ReflowComments** (``bool``) 2092 If ``true``, clang-format will attempt to re-flow comments. 2093 2094 .. code-block:: c++ 2095 2096 false: 2097 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information 2098 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ 2099 2100 true: 2101 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 2102 // information 2103 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 2104 * information */ 2105 2106**SortIncludes** (``bool``) 2107 If ``true``, clang-format will sort ``#includes``. 2108 2109 .. code-block:: c++ 2110 2111 false: true: 2112 #include "b.h" vs. #include "a.h" 2113 #include "a.h" #include "b.h" 2114 2115**SortUsingDeclarations** (``bool``) 2116 If ``true``, clang-format will sort using declarations. 2117 2118 The order of using declarations is defined as follows: 2119 Split the strings by "::" and discard any initial empty strings. The last 2120 element of each list is a non-namespace name; all others are namespace 2121 names. Sort the lists of names lexicographically, where the sort order of 2122 individual names is that all non-namespace names come before all namespace 2123 names, and within those groups, names are in case-insensitive 2124 lexicographic order. 2125 2126 .. code-block:: c++ 2127 2128 false: true: 2129 using std::cout; vs. using std::cin; 2130 using std::cin; using std::cout; 2131 2132**SpaceAfterCStyleCast** (``bool``) 2133 If ``true``, a space is inserted after C style casts. 2134 2135 .. code-block:: c++ 2136 2137 true: false: 2138 (int) i; vs. (int)i; 2139 2140**SpaceAfterLogicalNot** (``bool``) 2141 If ``true``, a space is inserted after the logical not operator (``!``). 2142 2143 .. code-block:: c++ 2144 2145 true: false: 2146 ! someExpression(); vs. !someExpression(); 2147 2148**SpaceAfterTemplateKeyword** (``bool``) 2149 If ``true``, a space will be inserted after the 'template' keyword. 2150 2151 .. code-block:: c++ 2152 2153 true: false: 2154 template <int> void foo(); vs. template<int> void foo(); 2155 2156**SpaceBeforeAssignmentOperators** (``bool``) 2157 If ``false``, spaces will be removed before assignment operators. 2158 2159 .. code-block:: c++ 2160 2161 true: false: 2162 int a = 5; vs. int a= 5; 2163 a += 42; a+= 42; 2164 2165**SpaceBeforeCpp11BracedList** (``bool``) 2166 If ``true``, a space will be inserted before a C++11 braced list 2167 used to initialize an object (after the preceding identifier or type). 2168 2169 .. code-block:: c++ 2170 2171 true: false: 2172 Foo foo { bar }; vs. Foo foo{ bar }; 2173 Foo {}; Foo{}; 2174 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; 2175 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; 2176 2177**SpaceBeforeCtorInitializerColon** (``bool``) 2178 If ``false``, spaces will be removed before constructor initializer 2179 colon. 2180 2181 .. code-block:: c++ 2182 2183 true: false: 2184 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} 2185 2186**SpaceBeforeInheritanceColon** (``bool``) 2187 If ``false``, spaces will be removed before inheritance colon. 2188 2189 .. code-block:: c++ 2190 2191 true: false: 2192 class Foo : Bar {} vs. class Foo: Bar {} 2193 2194**SpaceBeforeParens** (``SpaceBeforeParensOptions``) 2195 Defines in which cases to put a space before opening parentheses. 2196 2197 Possible values: 2198 2199 * ``SBPO_Never`` (in configuration: ``Never``) 2200 Never put a space before opening parentheses. 2201 2202 .. code-block:: c++ 2203 2204 void f() { 2205 if(true) { 2206 f(); 2207 } 2208 } 2209 2210 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) 2211 Put a space before opening parentheses only after control statement 2212 keywords (``for/if/while...``). 2213 2214 .. code-block:: c++ 2215 2216 void f() { 2217 if (true) { 2218 f(); 2219 } 2220 } 2221 2222 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``) 2223 Put a space before opening parentheses only if the parentheses are not 2224 empty i.e. '()' 2225 2226 .. code-block:: c++ 2227 2228 void() { 2229 if (true) { 2230 f(); 2231 g (x, y, z); 2232 } 2233 } 2234 2235 * ``SBPO_Always`` (in configuration: ``Always``) 2236 Always put a space before opening parentheses, except when it's 2237 prohibited by the syntax rules (in function-like macro definitions) or 2238 when determined by other style rules (after unary operators, opening 2239 parentheses, etc.) 2240 2241 .. code-block:: c++ 2242 2243 void f () { 2244 if (true) { 2245 f (); 2246 } 2247 } 2248 2249 2250 2251**SpaceBeforeRangeBasedForLoopColon** (``bool``) 2252 If ``false``, spaces will be removed before range-based for loop 2253 colon. 2254 2255 .. code-block:: c++ 2256 2257 true: false: 2258 for (auto v : values) {} vs. for(auto v: values) {} 2259 2260**SpaceInEmptyBlock** (``bool``) 2261 If ``true``, spaces will be inserted into ``{}``. 2262 2263 .. code-block:: c++ 2264 2265 true: false: 2266 void f() { } vs. void f() {} 2267 while (true) { } while (true) {} 2268 2269**SpaceInEmptyParentheses** (``bool``) 2270 If ``true``, spaces may be inserted into ``()``. 2271 2272 .. code-block:: c++ 2273 2274 true: false: 2275 void f( ) { vs. void f() { 2276 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; 2277 if (true) { if (true) { 2278 f( ); f(); 2279 } } 2280 } } 2281 2282**SpacesBeforeTrailingComments** (``unsigned``) 2283 The number of spaces before trailing line comments 2284 (``//`` - comments). 2285 2286 This does not affect trailing block comments (``/*`` - comments) as 2287 those commonly have different usage patterns and a number of special 2288 cases. 2289 2290 .. code-block:: c++ 2291 2292 SpacesBeforeTrailingComments: 3 2293 void f() { 2294 if (true) { // foo1 2295 f(); // bar 2296 } // foo 2297 } 2298 2299**SpacesInAngles** (``bool``) 2300 If ``true``, spaces will be inserted after ``<`` and before ``>`` 2301 in template argument lists. 2302 2303 .. code-block:: c++ 2304 2305 true: false: 2306 static_cast< int >(arg); vs. static_cast<int>(arg); 2307 std::function< void(int) > fct; std::function<void(int)> fct; 2308 2309**SpacesInCStyleCastParentheses** (``bool``) 2310 If ``true``, spaces may be inserted into C style casts. 2311 2312 .. code-block:: c++ 2313 2314 true: false: 2315 x = ( int32 )y vs. x = (int32)y 2316 2317**SpacesInContainerLiterals** (``bool``) 2318 If ``true``, spaces are inserted inside container literals (e.g. 2319 ObjC and Javascript array and dict literals). 2320 2321 .. code-block:: js 2322 2323 true: false: 2324 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; 2325 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); 2326 2327**SpacesInParentheses** (``bool``) 2328 If ``true``, spaces will be inserted after ``(`` and before ``)``. 2329 2330 .. code-block:: c++ 2331 2332 true: false: 2333 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; 2334 2335**SpacesInSquareBrackets** (``bool``) 2336 If ``true``, spaces will be inserted after ``[`` and before ``]``. 2337 Lambdas without arguments or unspecified size array declarations will not 2338 be affected. 2339 2340 .. code-block:: c++ 2341 2342 true: false: 2343 int a[ 5 ]; vs. int a[5]; 2344 std::unique_ptr<int[]> foo() {} // Won't be affected 2345 2346**Standard** (``LanguageStandard``) 2347 Parse and format C++ constructs compatible with this standard. 2348 2349 .. code-block:: c++ 2350 2351 c++03: latest: 2352 vector<set<int> > x; vs. vector<set<int>> x; 2353 2354 Possible values: 2355 2356 * ``LS_Cpp03`` (in configuration: ``c++03``) 2357 Parse and format as C++03. 2358 ``Cpp03`` is a deprecated alias for ``c++03`` 2359 2360 * ``LS_Cpp11`` (in configuration: ``c++11``) 2361 Parse and format as C++11. 2362 2363 * ``LS_Cpp14`` (in configuration: ``c++14``) 2364 Parse and format as C++14. 2365 2366 * ``LS_Cpp17`` (in configuration: ``c++17``) 2367 Parse and format as C++17. 2368 2369 * ``LS_Cpp20`` (in configuration: ``c++20``) 2370 Parse and format as C++20. 2371 2372 * ``LS_Latest`` (in configuration: ``Latest``) 2373 Parse and format using the latest supported language version. 2374 ``Cpp11`` is a deprecated alias for ``Latest`` 2375 2376 * ``LS_Auto`` (in configuration: ``Auto``) 2377 Automatic detection based on the input. 2378 2379 2380 2381**StatementMacros** (``std::vector<std::string>``) 2382 A vector of macros that should be interpreted as complete 2383 statements. 2384 2385 Typical macros are expressions, and require a semi-colon to be 2386 added; sometimes this is not the case, and this allows to make 2387 clang-format aware of such cases. 2388 2389 For example: Q_UNUSED 2390 2391**TabWidth** (``unsigned``) 2392 The number of columns used for tab stops. 2393 2394**TypenameMacros** (``std::vector<std::string>``) 2395 A vector of macros that should be interpreted as type declarations 2396 instead of as function calls. 2397 2398 These are expected to be macros of the form: 2399 2400 .. code-block:: c++ 2401 2402 STACK_OF(...) 2403 2404 In the .clang-format configuration file, this can be configured like: 2405 2406 .. code-block:: yaml 2407 2408 TypenameMacros: ['STACK_OF', 'LIST'] 2409 2410 For example: OpenSSL STACK_OF, BSD LIST_ENTRY. 2411 2412**UseTab** (``UseTabStyle``) 2413 The way to use tab characters in the resulting file. 2414 2415 Possible values: 2416 2417 * ``UT_Never`` (in configuration: ``Never``) 2418 Never use tab. 2419 2420 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) 2421 Use tabs only for indentation. 2422 2423 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) 2424 Use tabs only for line continuation and indentation. 2425 2426 * ``UT_Always`` (in configuration: ``Always``) 2427 Use tabs whenever we need to fill whitespace that spans at least from 2428 one tab stop to the next one. 2429 2430 2431 2432.. END_FORMAT_STYLE_OPTIONS 2433 2434Adding additional style options 2435=============================== 2436 2437Each additional style option adds costs to the clang-format project. Some of 2438these costs affect the clang-format development itself, as we need to make 2439sure that any given combination of options work and that new features don't 2440break any of the existing options in any way. There are also costs for end users 2441as options become less discoverable and people have to think about and make a 2442decision on options they don't really care about. 2443 2444The goal of the clang-format project is more on the side of supporting a 2445limited set of styles really well as opposed to supporting every single style 2446used by a codebase somewhere in the wild. Of course, we do want to support all 2447major projects and thus have established the following bar for adding style 2448options. Each new style option must .. 2449 2450 * be used in a project of significant size (have dozens of contributors) 2451 * have a publicly accessible style guide 2452 * have a person willing to contribute and maintain patches 2453 2454Examples 2455======== 2456 2457A style similar to the `Linux Kernel style 2458<https://www.kernel.org/doc/Documentation/CodingStyle>`_: 2459 2460.. code-block:: yaml 2461 2462 BasedOnStyle: LLVM 2463 IndentWidth: 8 2464 UseTab: Always 2465 BreakBeforeBraces: Linux 2466 AllowShortIfStatementsOnASingleLine: false 2467 IndentCaseLabels: false 2468 2469The result is (imagine that tabs are used for indentation here): 2470 2471.. code-block:: c++ 2472 2473 void test() 2474 { 2475 switch (x) { 2476 case 0: 2477 case 1: 2478 do_something(); 2479 break; 2480 case 2: 2481 do_something_else(); 2482 break; 2483 default: 2484 break; 2485 } 2486 if (condition) 2487 do_something_completely_different(); 2488 2489 if (x == y) { 2490 q(); 2491 } else if (x > y) { 2492 w(); 2493 } else { 2494 r(); 2495 } 2496 } 2497 2498A style similar to the default Visual Studio formatting style: 2499 2500.. code-block:: yaml 2501 2502 UseTab: Never 2503 IndentWidth: 4 2504 BreakBeforeBraces: Allman 2505 AllowShortIfStatementsOnASingleLine: false 2506 IndentCaseLabels: false 2507 ColumnLimit: 0 2508 2509The result is: 2510 2511.. code-block:: c++ 2512 2513 void test() 2514 { 2515 switch (suffix) 2516 { 2517 case 0: 2518 case 1: 2519 do_something(); 2520 break; 2521 case 2: 2522 do_something_else(); 2523 break; 2524 default: 2525 break; 2526 } 2527 if (condition) 2528 do_somthing_completely_different(); 2529 2530 if (x == y) 2531 { 2532 q(); 2533 } 2534 else if (x > y) 2535 { 2536 w(); 2537 } 2538 else 2539 { 2540 r(); 2541 } 2542 } 2543