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