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 | |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 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 |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 272 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 273 | **AllowAllParametersOfDeclarationOnNextLine** (``bool``) |
Daniel Jasper | 392c2ba | 2017-09-07 13:45:41 +0000 | [diff] [blame] | 274 | If the function declaration doesn't fit on a line, |
| 275 | allow putting all parameters of a function declaration onto |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 276 | the next line even if ``BinPackParameters`` is ``false``. |
| 277 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 278 | .. code-block:: c++ |
| 279 | |
Daniel Jasper | 392c2ba | 2017-09-07 13:45:41 +0000 | [diff] [blame] | 280 | true: |
| 281 | void myFunction( |
| 282 | int a, int b, int c, int d, int e); |
| 283 | |
| 284 | false: |
| 285 | void myFunction(int a, |
| 286 | int b, |
| 287 | int c, |
| 288 | int d, |
| 289 | int e); |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 290 | |
Daniel Jasper | 17605d3 | 2014-05-14 09:33:35 +0000 | [diff] [blame] | 291 | **AllowShortBlocksOnASingleLine** (``bool``) |
| 292 | Allows contracting simple braced statements to a single line. |
| 293 | |
| 294 | E.g., this allows ``if (a) { return; }`` to be put on a single line. |
| 295 | |
Daniel Jasper | b87899b | 2014-09-10 13:11:45 +0000 | [diff] [blame] | 296 | **AllowShortCaseLabelsOnASingleLine** (``bool``) |
| 297 | If ``true``, short case labels will be contracted to a single line. |
| 298 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 299 | .. code-block:: c++ |
| 300 | |
| 301 | true: false: |
| 302 | switch (a) { vs. switch (a) { |
| 303 | case 1: x = 1; break; case 1: |
| 304 | case 2: return; x = 1; |
| 305 | } break; |
| 306 | case 2: |
| 307 | return; |
| 308 | } |
| 309 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 310 | **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 311 | Dependent on the value, ``int f() { return 0; }`` can be put on a |
| 312 | single line. |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 313 | |
| 314 | Possible values: |
| 315 | |
| 316 | * ``SFS_None`` (in configuration: ``None``) |
| 317 | Never merge functions into a single line. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 318 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 319 | * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) |
| 320 | Only merge functions defined inside a class. Same as "inline", |
| 321 | except it does not implies "empty": i.e. top level empty functions |
| 322 | are not merged either. |
| 323 | |
| 324 | .. code-block:: c++ |
| 325 | |
| 326 | class Foo { |
| 327 | void f() { foo(); } |
| 328 | }; |
| 329 | void f() { |
| 330 | foo(); |
| 331 | } |
| 332 | void f() { |
| 333 | } |
| 334 | |
Daniel Jasper | 3219e43 | 2014-12-02 13:24:51 +0000 | [diff] [blame] | 335 | * ``SFS_Empty`` (in configuration: ``Empty``) |
| 336 | Only merge empty functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 337 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 338 | .. code-block:: c++ |
| 339 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 340 | void f() {} |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 341 | void f2() { |
| 342 | bar2(); |
| 343 | } |
| 344 | |
Daniel Jasper | 20580fd | 2015-06-11 13:31:45 +0000 | [diff] [blame] | 345 | * ``SFS_Inline`` (in configuration: ``Inline``) |
| 346 | Only merge functions defined inside a class. Implies "empty". |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 347 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 348 | .. code-block:: c++ |
| 349 | |
Jonathan Roelofs | 335777b | 2017-03-20 17:07:49 +0000 | [diff] [blame] | 350 | class Foo { |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 351 | void f() { foo(); } |
| 352 | }; |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 353 | void f() { |
| 354 | foo(); |
| 355 | } |
| 356 | void f() {} |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 357 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 358 | * ``SFS_All`` (in configuration: ``All``) |
| 359 | Merge all functions fitting on a single line. |
| 360 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 361 | .. code-block:: c++ |
| 362 | |
Jonathan Roelofs | 335777b | 2017-03-20 17:07:49 +0000 | [diff] [blame] | 363 | class Foo { |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 364 | void f() { foo(); } |
| 365 | }; |
| 366 | void f() { bar(); } |
| 367 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 368 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 369 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 370 | **AllowShortIfStatementsOnASingleLine** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 371 | If ``true``, ``if (a) return;`` can be put on a single line. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 372 | |
| 373 | **AllowShortLoopsOnASingleLine** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 374 | If ``true``, ``while (true) continue;`` can be put on a single |
| 375 | line. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 376 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 377 | **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 378 | The function definition return type breaking style to use. This |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 379 | option is **deprecated** and is retained for backwards compatibility. |
Daniel Jasper | ca4ea1c | 2014-08-05 12:16:31 +0000 | [diff] [blame] | 380 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 381 | Possible values: |
| 382 | |
| 383 | * ``DRTBS_None`` (in configuration: ``None``) |
| 384 | Break after return type automatically. |
| 385 | ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 386 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 387 | * ``DRTBS_All`` (in configuration: ``All``) |
| 388 | Always break after the return type. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 389 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 390 | * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 391 | Always break after the return types of top-level functions. |
| 392 | |
| 393 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 394 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 395 | **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) |
| 396 | The function declaration return type breaking style to use. |
| 397 | |
| 398 | Possible values: |
| 399 | |
| 400 | * ``RTBS_None`` (in configuration: ``None``) |
| 401 | Break after return type automatically. |
| 402 | ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 403 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 404 | .. code-block:: c++ |
| 405 | |
| 406 | class A { |
| 407 | int f() { return 0; }; |
| 408 | }; |
| 409 | int f(); |
| 410 | int f() { return 1; } |
| 411 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 412 | * ``RTBS_All`` (in configuration: ``All``) |
| 413 | Always break after the return type. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 414 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 415 | .. code-block:: c++ |
| 416 | |
| 417 | class A { |
| 418 | int |
| 419 | f() { |
| 420 | return 0; |
| 421 | }; |
| 422 | }; |
| 423 | int |
| 424 | f(); |
| 425 | int |
| 426 | f() { |
| 427 | return 1; |
| 428 | } |
| 429 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 430 | * ``RTBS_TopLevel`` (in configuration: ``TopLevel``) |
| 431 | Always break after the return types of top-level functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 432 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 433 | .. code-block:: c++ |
| 434 | |
| 435 | class A { |
| 436 | int f() { return 0; }; |
| 437 | }; |
| 438 | int |
| 439 | f(); |
| 440 | int |
| 441 | f() { |
| 442 | return 1; |
| 443 | } |
| 444 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 445 | * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) |
| 446 | Always break after the return type of function definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 447 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 448 | .. code-block:: c++ |
| 449 | |
| 450 | class A { |
| 451 | int |
| 452 | f() { |
| 453 | return 0; |
| 454 | }; |
| 455 | }; |
| 456 | int f(); |
| 457 | int |
| 458 | f() { |
| 459 | return 1; |
| 460 | } |
| 461 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 462 | * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) |
| 463 | Always break after the return type of top-level definitions. |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 464 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 465 | .. code-block:: c++ |
| 466 | |
| 467 | class A { |
| 468 | int f() { return 0; }; |
| 469 | }; |
| 470 | int f(); |
| 471 | int |
| 472 | f() { |
| 473 | return 1; |
| 474 | } |
| 475 | |
Daniel Jasper | ca4ea1c | 2014-08-05 12:16:31 +0000 | [diff] [blame] | 476 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 477 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 478 | **AlwaysBreakBeforeMultilineStrings** (``bool``) |
| 479 | If ``true``, always break before multiline string literals. |
| 480 | |
Daniel Jasper | 2aaedd3 | 2015-06-18 09:12:47 +0000 | [diff] [blame] | 481 | This flag is mean to make cases where there are multiple multiline strings |
| 482 | in a file look more consistent. Thus, it will only take effect if wrapping |
| 483 | the string at that point leads to it being indented |
| 484 | ``ContinuationIndentWidth`` spaces from the start of the line. |
| 485 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 486 | .. code-block:: c++ |
| 487 | |
| 488 | true: false: |
| 489 | aaaa = vs. aaaa = "bbbb" |
| 490 | "bbbb" "cccc"; |
| 491 | "cccc"; |
| 492 | |
Francois Ferrand | 58e6fe5 | 2018-05-16 08:25:03 +0000 | [diff] [blame] | 493 | **AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) |
| 494 | The template declaration breaking style to use. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 495 | |
Francois Ferrand | 58e6fe5 | 2018-05-16 08:25:03 +0000 | [diff] [blame] | 496 | Possible values: |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 497 | |
Francois Ferrand | 58e6fe5 | 2018-05-16 08:25:03 +0000 | [diff] [blame] | 498 | * ``BTDS_No`` (in configuration: ``No``) |
| 499 | Do not force break before declaration. |
| 500 | ``PenaltyBreakTemplateDeclaration`` is taken into account. |
| 501 | |
| 502 | .. code-block:: c++ |
| 503 | |
| 504 | template <typename T> T foo() { |
| 505 | } |
| 506 | template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 507 | int bbbbbbbbbbbbbbbbbbbbb) { |
| 508 | } |
| 509 | |
| 510 | * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) |
| 511 | Force break after template declaration only when the following |
| 512 | declaration spans multiple lines. |
| 513 | |
| 514 | .. code-block:: c++ |
| 515 | |
| 516 | template <typename T> T foo() { |
| 517 | } |
| 518 | template <typename T> |
| 519 | T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 520 | int bbbbbbbbbbbbbbbbbbbbb) { |
| 521 | } |
| 522 | |
| 523 | * ``BTDS_Yes`` (in configuration: ``Yes``) |
| 524 | Always break after template declaration. |
| 525 | |
| 526 | .. code-block:: c++ |
| 527 | |
| 528 | template <typename T> |
| 529 | T foo() { |
| 530 | } |
| 531 | template <typename T> |
| 532 | T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 533 | int bbbbbbbbbbbbbbbbbbbbb) { |
| 534 | } |
| 535 | |
| 536 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 537 | |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 538 | **BinPackArguments** (``bool``) |
| 539 | If ``false``, a function call's arguments will either be all on the |
| 540 | same line or will have one line each. |
| 541 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 542 | .. code-block:: c++ |
| 543 | |
| 544 | true: |
| 545 | void f() { |
| 546 | f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, |
| 547 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
| 548 | } |
| 549 | |
| 550 | false: |
| 551 | void f() { |
| 552 | f(aaaaaaaaaaaaaaaaaaaa, |
| 553 | aaaaaaaaaaaaaaaaaaaa, |
| 554 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
| 555 | } |
| 556 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 557 | **BinPackParameters** (``bool``) |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 558 | If ``false``, a function declaration's or function definition's |
| 559 | 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] | 560 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 561 | .. code-block:: c++ |
| 562 | |
| 563 | true: |
| 564 | void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, |
| 565 | int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
| 566 | |
| 567 | false: |
| 568 | void f(int aaaaaaaaaaaaaaaaaaaa, |
| 569 | int aaaaaaaaaaaaaaaaaaaa, |
| 570 | int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
| 571 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 572 | **BraceWrapping** (``BraceWrappingFlags``) |
| 573 | Control of individual brace wrapping cases. |
| 574 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 575 | If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how |
| 576 | each individual brace case should be handled. Otherwise, this is ignored. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 577 | |
Sylvestre Ledru | 7372d48 | 2017-09-07 12:09:14 +0000 | [diff] [blame] | 578 | .. code-block:: yaml |
| 579 | |
| 580 | # Example of usage: |
| 581 | BreakBeforeBraces: Custom |
| 582 | BraceWrapping: |
| 583 | AfterEnum: true |
| 584 | AfterStruct: false |
| 585 | SplitEmptyFunction: false |
| 586 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 587 | Nested configuration flags: |
| 588 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 589 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 590 | * ``bool AfterClass`` Wrap class definitions. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 591 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 592 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 593 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 594 | true: |
| 595 | class foo {}; |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 596 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 597 | false: |
| 598 | class foo |
| 599 | {}; |
Eric Fiselier | 1571fae | 2017-06-15 03:38:08 +0000 | [diff] [blame] | 600 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 601 | * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..). |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 602 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 603 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 604 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 605 | true: |
| 606 | if (foo()) |
| 607 | { |
| 608 | } else |
| 609 | {} |
| 610 | for (int i = 0; i < 10; ++i) |
| 611 | {} |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 612 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 613 | false: |
| 614 | if (foo()) { |
| 615 | } else { |
| 616 | } |
| 617 | for (int i = 0; i < 10; ++i) { |
| 618 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 619 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 620 | * ``bool AfterEnum`` Wrap enum definitions. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 621 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 622 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 623 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 624 | true: |
| 625 | enum X : int |
| 626 | { |
| 627 | B |
| 628 | }; |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 629 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 630 | false: |
| 631 | enum X : int { B }; |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 632 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 633 | * ``bool AfterFunction`` Wrap function definitions. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 634 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 635 | .. code-block:: c++ |
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 | true: |
| 638 | void foo() |
| 639 | { |
| 640 | bar(); |
| 641 | bar2(); |
| 642 | } |
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 | false: |
| 645 | void foo() { |
| 646 | bar(); |
| 647 | bar2(); |
| 648 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 649 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 650 | * ``bool AfterNamespace`` Wrap namespace definitions. |
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 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 653 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 654 | true: |
| 655 | namespace |
| 656 | { |
| 657 | int foo(); |
| 658 | int bar(); |
| 659 | } |
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 | false: |
| 662 | namespace { |
| 663 | int foo(); |
| 664 | int bar(); |
| 665 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 666 | |
Krasimir Georgiev | c5be6af | 2018-03-06 13:24:01 +0000 | [diff] [blame] | 667 | * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...). |
| 668 | @autoreleasepool and @synchronized blocks are wrapped |
| 669 | according to `AfterControlStatement` flag. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 670 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 671 | * ``bool AfterStruct`` Wrap struct definitions. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 672 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 673 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 674 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 675 | true: |
| 676 | struct foo |
| 677 | { |
| 678 | int x; |
| 679 | }; |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 680 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 681 | false: |
| 682 | struct foo { |
| 683 | int x; |
| 684 | }; |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 685 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 686 | * ``bool AfterUnion`` Wrap union definitions. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 687 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 688 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 689 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 690 | true: |
| 691 | union foo |
| 692 | { |
| 693 | int x; |
| 694 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 695 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 696 | false: |
| 697 | union foo { |
| 698 | int x; |
| 699 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 700 | |
Krasimir Georgiev | d6ce937 | 2017-09-15 11:23:50 +0000 | [diff] [blame] | 701 | * ``bool AfterExternBlock`` Wrap extern blocks. |
| 702 | |
| 703 | .. code-block:: c++ |
| 704 | |
| 705 | true: |
| 706 | extern "C" |
| 707 | { |
| 708 | int foo(); |
| 709 | } |
| 710 | |
| 711 | false: |
| 712 | extern "C" { |
| 713 | int foo(); |
| 714 | } |
| 715 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 716 | * ``bool BeforeCatch`` Wrap before ``catch``. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 717 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 718 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 719 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 720 | true: |
| 721 | try { |
| 722 | foo(); |
| 723 | } |
| 724 | catch () { |
| 725 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 726 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 727 | false: |
| 728 | try { |
| 729 | foo(); |
| 730 | } catch () { |
| 731 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 732 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 733 | * ``bool BeforeElse`` Wrap before ``else``. |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 734 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 735 | .. code-block:: c++ |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 736 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 737 | true: |
| 738 | if (foo()) { |
| 739 | } |
| 740 | else { |
| 741 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 742 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 743 | false: |
| 744 | if (foo()) { |
| 745 | } else { |
| 746 | } |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 747 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 748 | * ``bool IndentBraces`` Indent the wrapped braces themselves. |
| 749 | |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 750 | * ``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] | 751 | This option is used only if the opening brace of the function has |
| 752 | already been wrapped, i.e. the `AfterFunction` brace wrapping mode is |
| 753 | set, and the function could/should not be put on a single line (as per |
| 754 | `AllowShortFunctionsOnASingleLine` and constructor formatting options). |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 755 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 756 | .. code-block:: c++ |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 757 | |
Krasimir Georgiev | 90b4ce3 | 2017-06-23 11:29:40 +0000 | [diff] [blame] | 758 | int f() vs. inf f() |
| 759 | {} { |
| 760 | } |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 761 | |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 762 | * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body |
| 763 | can be put on a single line. This option is used only if the opening |
| 764 | brace of the record has already been wrapped, i.e. the `AfterClass` |
| 765 | (for classes) brace wrapping mode is set. |
| 766 | |
| 767 | .. code-block:: c++ |
| 768 | |
| 769 | class Foo vs. class Foo |
| 770 | {} { |
| 771 | } |
| 772 | |
| 773 | * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line. |
| 774 | This option is used only if the opening brace of the namespace has |
| 775 | already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is |
| 776 | set. |
| 777 | |
| 778 | .. code-block:: c++ |
| 779 | |
| 780 | namespace Foo vs. namespace Foo |
| 781 | {} { |
| 782 | } |
| 783 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 784 | |
Daniel Jasper | 6501f7e | 2015-10-27 12:38:37 +0000 | [diff] [blame] | 785 | **BreakAfterJavaFieldAnnotations** (``bool``) |
| 786 | Break after each annotation on a field in Java files. |
| 787 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 788 | .. code-block:: java |
| 789 | |
| 790 | true: false: |
| 791 | @Partial vs. @Partial @Mock DataLoad loader; |
| 792 | @Mock |
| 793 | DataLoad loader; |
| 794 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 795 | **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) |
| 796 | The way to wrap binary operators. |
| 797 | |
| 798 | Possible values: |
| 799 | |
| 800 | * ``BOS_None`` (in configuration: ``None``) |
| 801 | Break after operators. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 802 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 803 | .. code-block:: c++ |
| 804 | |
| 805 | LooooooooooongType loooooooooooooooooooooongVariable = |
| 806 | someLooooooooooooooooongFunction(); |
| 807 | |
| 808 | bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + |
| 809 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == |
| 810 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && |
| 811 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > |
| 812 | ccccccccccccccccccccccccccccccccccccccccc; |
| 813 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 814 | * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) |
| 815 | Break before operators that aren't assignments. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 816 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 817 | .. code-block:: c++ |
| 818 | |
| 819 | LooooooooooongType loooooooooooooooooooooongVariable = |
| 820 | someLooooooooooooooooongFunction(); |
| 821 | |
| 822 | bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 823 | + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 824 | == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 825 | && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 826 | > ccccccccccccccccccccccccccccccccccccccccc; |
| 827 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 828 | * ``BOS_All`` (in configuration: ``All``) |
| 829 | Break before operators. |
| 830 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 831 | .. code-block:: c++ |
| 832 | |
| 833 | LooooooooooongType loooooooooooooooooooooongVariable |
| 834 | = someLooooooooooooooooongFunction(); |
| 835 | |
| 836 | bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 837 | + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 838 | == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 839 | && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 840 | > ccccccccccccccccccccccccccccccccccccccccc; |
| 841 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 842 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 843 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 844 | **BreakBeforeBraces** (``BraceBreakingStyle``) |
| 845 | The brace breaking style to use. |
| 846 | |
| 847 | Possible values: |
| 848 | |
| 849 | * ``BS_Attach`` (in configuration: ``Attach``) |
| 850 | Always attach braces to surrounding context. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 851 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 852 | .. code-block:: c++ |
| 853 | |
| 854 | try { |
| 855 | foo(); |
| 856 | } catch () { |
| 857 | } |
| 858 | void foo() { bar(); } |
| 859 | class foo {}; |
| 860 | if (foo()) { |
| 861 | } else { |
| 862 | } |
| 863 | enum X : int { A, B }; |
| 864 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 865 | * ``BS_Linux`` (in configuration: ``Linux``) |
| 866 | Like ``Attach``, but break before braces on function, namespace and |
| 867 | class definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 868 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 869 | .. code-block:: c++ |
| 870 | |
| 871 | try { |
| 872 | foo(); |
| 873 | } catch () { |
| 874 | } |
| 875 | void foo() { bar(); } |
| 876 | class foo |
| 877 | { |
| 878 | }; |
| 879 | if (foo()) { |
| 880 | } else { |
| 881 | } |
| 882 | enum X : int { A, B }; |
| 883 | |
Birunthan Mohanathas | 305fa9c | 2015-07-12 03:13:54 +0000 | [diff] [blame] | 884 | * ``BS_Mozilla`` (in configuration: ``Mozilla``) |
| 885 | Like ``Attach``, but break before braces on enum, function, and record |
| 886 | definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 887 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 888 | .. code-block:: c++ |
| 889 | |
| 890 | try { |
| 891 | foo(); |
| 892 | } catch () { |
| 893 | } |
| 894 | void foo() { bar(); } |
| 895 | class foo |
| 896 | { |
| 897 | }; |
| 898 | if (foo()) { |
| 899 | } else { |
| 900 | } |
| 901 | enum X : int { A, B }; |
| 902 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 903 | * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 904 | Like ``Attach``, but break before function definitions, ``catch``, and |
| 905 | ``else``. |
| 906 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 907 | .. code-block:: c++ |
| 908 | |
| 909 | try { |
| 910 | foo(); |
| 911 | } catch () { |
| 912 | } |
| 913 | void foo() { bar(); } |
| 914 | class foo |
| 915 | { |
| 916 | }; |
| 917 | if (foo()) { |
| 918 | } else { |
| 919 | } |
| 920 | enum X : int |
| 921 | { |
| 922 | A, |
| 923 | B |
| 924 | }; |
| 925 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 926 | * ``BS_Allman`` (in configuration: ``Allman``) |
| 927 | Always break before braces. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 928 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 929 | .. code-block:: c++ |
| 930 | |
| 931 | try { |
| 932 | foo(); |
| 933 | } |
| 934 | catch () { |
| 935 | } |
| 936 | void foo() { bar(); } |
| 937 | class foo { |
| 938 | }; |
| 939 | if (foo()) { |
| 940 | } |
| 941 | else { |
| 942 | } |
| 943 | enum X : int { A, B }; |
| 944 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 945 | * ``BS_GNU`` (in configuration: ``GNU``) |
| 946 | Always break before braces and add an extra level of indentation to |
| 947 | braces of control statements, not to those of class, function |
| 948 | or other definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 949 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 950 | .. code-block:: c++ |
| 951 | |
| 952 | try |
| 953 | { |
| 954 | foo(); |
| 955 | } |
| 956 | catch () |
| 957 | { |
| 958 | } |
| 959 | void foo() { bar(); } |
| 960 | class foo |
| 961 | { |
| 962 | }; |
| 963 | if (foo()) |
| 964 | { |
| 965 | } |
| 966 | else |
| 967 | { |
| 968 | } |
| 969 | enum X : int |
| 970 | { |
| 971 | A, |
| 972 | B |
| 973 | }; |
| 974 | |
Roman Kashitsyn | 291f64f | 2015-08-10 13:43:19 +0000 | [diff] [blame] | 975 | * ``BS_WebKit`` (in configuration: ``WebKit``) |
| 976 | Like ``Attach``, but break before functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 977 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 978 | .. code-block:: c++ |
| 979 | |
| 980 | try { |
| 981 | foo(); |
| 982 | } catch () { |
| 983 | } |
| 984 | void foo() { bar(); } |
| 985 | class foo { |
| 986 | }; |
| 987 | if (foo()) { |
| 988 | } else { |
| 989 | } |
| 990 | enum X : int { A, B }; |
| 991 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 992 | * ``BS_Custom`` (in configuration: ``Custom``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 993 | Configure each individual brace in `BraceWrapping`. |
| 994 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 995 | |
| 996 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 997 | **BreakBeforeTernaryOperators** (``bool``) |
| 998 | If ``true``, ternary operators will be placed after line breaks. |
| 999 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 1000 | .. code-block:: c++ |
| 1001 | |
| 1002 | true: |
| 1003 | veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription |
| 1004 | ? firstValue |
| 1005 | : SecondValueVeryVeryVeryVeryLong; |
| 1006 | |
Sylvestre Ledru | 121224d | 2017-06-06 07:26:19 +0000 | [diff] [blame] | 1007 | false: |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 1008 | veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? |
| 1009 | firstValue : |
| 1010 | SecondValueVeryVeryVeryVeryLong; |
| 1011 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1012 | **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) |
| 1013 | The constructor initializers style to use. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1014 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1015 | Possible values: |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1016 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1017 | * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) |
| 1018 | Break constructor initializers before the colon and after the commas. |
| 1019 | |
| 1020 | .. code-block:: c++ |
| 1021 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1022 | Constructor() |
| 1023 | : initializer1(), |
| 1024 | initializer2() |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1025 | |
| 1026 | * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) |
| 1027 | Break constructor initializers before the colon and commas, and align |
| 1028 | the commas with the colon. |
| 1029 | |
| 1030 | .. code-block:: c++ |
| 1031 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1032 | Constructor() |
| 1033 | : initializer1() |
| 1034 | , initializer2() |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1035 | |
| 1036 | * ``BCIS_AfterColon`` (in configuration: ``AfterColon``) |
| 1037 | Break constructor initializers after the colon and commas. |
| 1038 | |
| 1039 | .. code-block:: c++ |
| 1040 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1041 | Constructor() : |
| 1042 | initializer1(), |
| 1043 | initializer2() |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1044 | |
| 1045 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1046 | |
Francois Ferrand | 6bb103f | 2018-06-11 14:41:26 +0000 | [diff] [blame] | 1047 | **BreakInheritanceList** (``BreakInheritanceListStyle``) |
| 1048 | The inheritance list style to use. |
| 1049 | |
| 1050 | Possible values: |
| 1051 | |
| 1052 | * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``) |
| 1053 | Break inheritance list before the colon and after the commas. |
| 1054 | |
| 1055 | .. code-block:: c++ |
| 1056 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1057 | class Foo |
| 1058 | : Base1, |
| 1059 | Base2 |
| 1060 | {}; |
Francois Ferrand | 6bb103f | 2018-06-11 14:41:26 +0000 | [diff] [blame] | 1061 | |
| 1062 | * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``) |
| 1063 | Break inheritance list before the colon and commas, and align |
| 1064 | the commas with the colon. |
| 1065 | |
| 1066 | .. code-block:: c++ |
| 1067 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1068 | class Foo |
| 1069 | : Base1 |
| 1070 | , Base2 |
| 1071 | {}; |
Francois Ferrand | 6bb103f | 2018-06-11 14:41:26 +0000 | [diff] [blame] | 1072 | |
| 1073 | * ``BILS_AfterColon`` (in configuration: ``AfterColon``) |
| 1074 | Break inheritance list after the colon and commas. |
| 1075 | |
| 1076 | .. code-block:: c++ |
| 1077 | |
Francois Ferrand | 767e152 | 2018-06-14 13:32:14 +0000 | [diff] [blame] | 1078 | class Foo : |
| 1079 | Base1, |
| 1080 | Base2 |
| 1081 | {}; |
Francois Ferrand | 6bb103f | 2018-06-11 14:41:26 +0000 | [diff] [blame] | 1082 | |
| 1083 | |
| 1084 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1085 | **BreakStringLiterals** (``bool``) |
| 1086 | Allow breaking string literals when formatting. |
| 1087 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1088 | **ColumnLimit** (``unsigned``) |
| 1089 | The column limit. |
| 1090 | |
| 1091 | A column limit of ``0`` means that there is no column limit. In this case, |
| 1092 | clang-format will respect the input's line breaking decisions within |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1093 | statements unless they contradict other rules. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1094 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1095 | **CommentPragmas** (``std::string``) |
| 1096 | A regular expression that describes comments with special meaning, |
| 1097 | which should not be split into lines or otherwise changed. |
| 1098 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1099 | .. code-block:: c++ |
| 1100 | |
Jonathan Roelofs | 335777b | 2017-03-20 17:07:49 +0000 | [diff] [blame] | 1101 | // CommentPragmas: '^ FOOBAR pragma:' |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1102 | // Will leave the following line unaffected |
| 1103 | #include <vector> // FOOBAR pragma: keep |
| 1104 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1105 | **CompactNamespaces** (``bool``) |
| 1106 | If ``true``, consecutive namespace declarations will be on the same |
| 1107 | line. If ``false``, each namespace is declared on a new line. |
| 1108 | |
| 1109 | .. code-block:: c++ |
| 1110 | |
| 1111 | true: |
| 1112 | namespace Foo { namespace Bar { |
| 1113 | }} |
| 1114 | |
| 1115 | false: |
| 1116 | namespace Foo { |
| 1117 | namespace Bar { |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | If it does not fit on a single line, the overflowing namespaces get |
| 1122 | wrapped: |
| 1123 | |
| 1124 | .. code-block:: c++ |
| 1125 | |
| 1126 | namespace Foo { namespace Bar { |
| 1127 | namespace Extra { |
| 1128 | }}} |
| 1129 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1130 | **ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) |
| 1131 | If the constructor initializers don't fit on a line, put each |
| 1132 | initializer on its own line. |
| 1133 | |
Sylvestre Ledru | 7d21a3d | 2017-03-13 14:42:47 +0000 | [diff] [blame] | 1134 | .. code-block:: c++ |
| 1135 | |
| 1136 | true: |
| 1137 | SomeClass::Constructor() |
| 1138 | : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | false: |
| 1143 | SomeClass::Constructor() |
| 1144 | : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), |
| 1145 | aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1149 | **ConstructorInitializerIndentWidth** (``unsigned``) |
| 1150 | The number of characters to use for indentation of constructor |
Francois Ferrand | 6bb103f | 2018-06-11 14:41:26 +0000 | [diff] [blame] | 1151 | initializer lists as well as inheritance lists. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1152 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1153 | **ContinuationIndentWidth** (``unsigned``) |
| 1154 | Indent width for line continuations. |
| 1155 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1156 | .. code-block:: c++ |
| 1157 | |
| 1158 | ContinuationIndentWidth: 2 |
| 1159 | |
| 1160 | int i = // VeryVeryVeryVeryVeryLongComment |
| 1161 | longFunction( // Again a long comment |
| 1162 | arg); |
| 1163 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1164 | **Cpp11BracedListStyle** (``bool``) |
| 1165 | If ``true``, format braced lists as best suited for C++11 braced |
| 1166 | lists. |
| 1167 | |
| 1168 | Important differences: |
| 1169 | - No spaces inside the braced list. |
| 1170 | - No line break before the closing brace. |
| 1171 | - Indentation with the continuation indent, not with the block indent. |
| 1172 | |
| 1173 | Fundamentally, C++11 braced lists are formatted exactly like function |
| 1174 | calls would be formatted in their place. If the braced list follows a name |
| 1175 | (e.g. a type or variable name), clang-format formats as if the ``{}`` were |
| 1176 | the parentheses of a function call with that name. If there is no name, |
| 1177 | a zero-length name is assumed. |
| 1178 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1179 | .. code-block:: c++ |
| 1180 | |
| 1181 | true: false: |
| 1182 | vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; |
| 1183 | vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; |
| 1184 | f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); |
| 1185 | new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; |
| 1186 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 1187 | **DerivePointerAlignment** (``bool``) |
| 1188 | If ``true``, analyze the formatted file for the most common |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1189 | alignment of ``&`` and ``*``. |
| 1190 | Pointer and reference alignment styles are going to be updated according |
| 1191 | to the preferences found in the file. |
| 1192 | ``PointerAlignment`` is then used only as fallback. |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 1193 | |
| 1194 | **DisableFormat** (``bool``) |
Birunthan Mohanathas | b744e72 | 2015-06-27 09:25:28 +0000 | [diff] [blame] | 1195 | Disables formatting completely. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1196 | |
| 1197 | **ExperimentalAutoDetectBinPacking** (``bool``) |
| 1198 | If ``true``, clang-format detects whether function calls and |
| 1199 | definitions are formatted with one parameter per line. |
| 1200 | |
| 1201 | Each call can be bin-packed, one-per-line or inconclusive. If it is |
| 1202 | inconclusive, e.g. completely on one line, but a decision needs to be |
| 1203 | made, clang-format analyzes whether there are other bin-packed cases in |
| 1204 | the input file and act accordingly. |
| 1205 | |
| 1206 | NOTE: This is an experimental flag, that might go away or be renamed. Do |
| 1207 | not use this in config files, etc. Use at your own risk. |
| 1208 | |
Krasimir Georgiev | 32eaa86 | 2017-03-01 15:35:39 +0000 | [diff] [blame] | 1209 | **FixNamespaceComments** (``bool``) |
| 1210 | If ``true``, clang-format adds missing namespace end comments and |
| 1211 | fixes invalid existing ones. |
| 1212 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1213 | .. code-block:: c++ |
| 1214 | |
| 1215 | true: false: |
| 1216 | namespace a { vs. namespace a { |
| 1217 | foo(); foo(); |
| 1218 | } // namespace a; } |
| 1219 | |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 1220 | **ForEachMacros** (``std::vector<std::string>``) |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1221 | A vector of macros that should be interpreted as foreach loops |
| 1222 | instead of as function calls. |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 1223 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1224 | These are expected to be macros of the form: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 1225 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1226 | .. code-block:: c++ |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 1227 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1228 | FOREACH(<variable-declaration>, ...) |
| 1229 | <loop-body> |
| 1230 | |
| 1231 | In the .clang-format configuration file, this can be configured like: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 1232 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1233 | .. code-block:: yaml |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 1234 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1235 | ForEachMacros: ['RANGES_FOR', 'FOREACH'] |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1236 | |
| 1237 | For example: BOOST_FOREACH. |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 1238 | |
Krasimir Georgiev | 4c2c9c3 | 2017-11-27 13:23:45 +0000 | [diff] [blame] | 1239 | **IncludeBlocks** (``IncludeBlocksStyle``) |
| 1240 | Dependent on the value, multiple ``#include`` blocks can be sorted |
| 1241 | as one and divided based on category. |
| 1242 | |
| 1243 | Possible values: |
| 1244 | |
| 1245 | * ``IBS_Preserve`` (in configuration: ``Preserve``) |
| 1246 | Sort each ``#include`` block separately. |
| 1247 | |
| 1248 | .. code-block:: c++ |
| 1249 | |
| 1250 | #include "b.h" into #include "b.h" |
| 1251 | |
| 1252 | #include <lib/main.h> #include "a.h" |
| 1253 | #include "a.h" #include <lib/main.h> |
| 1254 | |
| 1255 | * ``IBS_Merge`` (in configuration: ``Merge``) |
| 1256 | Merge multiple ``#include`` blocks together and sort as one. |
| 1257 | |
| 1258 | .. code-block:: c++ |
| 1259 | |
| 1260 | #include "b.h" into #include "a.h" |
| 1261 | #include "b.h" |
| 1262 | #include <lib/main.h> #include <lib/main.h> |
| 1263 | #include "a.h" |
| 1264 | |
| 1265 | * ``IBS_Regroup`` (in configuration: ``Regroup``) |
| 1266 | Merge multiple ``#include`` blocks together and sort as one. |
Krasimir Georgiev | 2537e22 | 2018-01-17 16:17:26 +0000 | [diff] [blame] | 1267 | Then split into groups based on category priority. See |
| 1268 | ``IncludeCategories``. |
Krasimir Georgiev | 4c2c9c3 | 2017-11-27 13:23:45 +0000 | [diff] [blame] | 1269 | |
| 1270 | .. code-block:: c++ |
| 1271 | |
| 1272 | #include "b.h" into #include "a.h" |
| 1273 | #include "b.h" |
| 1274 | #include <lib/main.h> |
| 1275 | #include "a.h" #include <lib/main.h> |
| 1276 | |
| 1277 | |
| 1278 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1279 | **IncludeCategories** (``std::vector<IncludeCategory>``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1280 | Regular expressions denoting the different ``#include`` categories |
| 1281 | used for ordering ``#includes``. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 1282 | |
| 1283 | These regular expressions are matched against the filename of an include |
| 1284 | (including the <> or "") in order. The value belonging to the first |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1285 | matching regular expression is assigned and ``#includes`` are sorted first |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 1286 | according to increasing category number and then alphabetically within |
| 1287 | each category. |
| 1288 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1289 | If none of the regular expressions match, INT_MAX is assigned as |
| 1290 | category. The main header for a source file automatically gets category 0. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1291 | so that it is generally kept at the beginning of the ``#includes`` |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1292 | (http://llvm.org/docs/CodingStandards.html#include-style). However, you |
| 1293 | can also assign negative priorities if you have certain headers that |
| 1294 | always need to be first. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 1295 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1296 | To configure this in the .clang-format file, use: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 1297 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1298 | .. code-block:: yaml |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 1299 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1300 | IncludeCategories: |
| 1301 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' |
| 1302 | Priority: 2 |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 1303 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1304 | Priority: 3 |
Sylvestre Ledru | f3e295a | 2017-03-09 06:41:08 +0000 | [diff] [blame] | 1305 | - Regex: '.*' |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 1306 | Priority: 1 |
| 1307 | |
Daniel Jasper | 9c8ff35 | 2016-03-21 14:11:27 +0000 | [diff] [blame] | 1308 | **IncludeIsMainRegex** (``std::string``) |
| 1309 | Specify a regular expression of suffixes that are allowed in the |
| 1310 | file-to-main-include mapping. |
| 1311 | |
| 1312 | When guessing whether a #include is the "main" include (to assign |
| 1313 | category 0, see above), use this regex of allowed suffixes to the header |
| 1314 | stem. A partial match is done, so that: |
| 1315 | - "" means "arbitrary suffix" |
| 1316 | - "$" means "no suffix" |
| 1317 | |
| 1318 | For example, if configured to "(_test)?$", then a header a.h would be seen |
| 1319 | as the "main" include in both a.cc and a_test.cc. |
| 1320 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1321 | **IndentCaseLabels** (``bool``) |
| 1322 | Indent case labels one level from the switch statement. |
| 1323 | |
| 1324 | When ``false``, use the same indentation level as for the switch statement. |
| 1325 | Switch statement body is always indented one level more than case labels. |
| 1326 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1327 | .. code-block:: c++ |
| 1328 | |
| 1329 | false: true: |
| 1330 | switch (fool) { vs. switch (fool) { |
| 1331 | case 1: case 1: |
| 1332 | bar(); bar(); |
| 1333 | break; break; |
| 1334 | default: default: |
| 1335 | plop(); plop(); |
| 1336 | } } |
| 1337 | |
Krasimir Georgiev | ad47c90 | 2017-08-30 14:34:57 +0000 | [diff] [blame] | 1338 | **IndentPPDirectives** (``PPDirectiveIndentStyle``) |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 1339 | The preprocessor directive indenting style to use. |
Krasimir Georgiev | ad47c90 | 2017-08-30 14:34:57 +0000 | [diff] [blame] | 1340 | |
| 1341 | Possible values: |
| 1342 | |
| 1343 | * ``PPDIS_None`` (in configuration: ``None``) |
| 1344 | Does not indent any directives. |
| 1345 | |
| 1346 | .. code-block:: c++ |
| 1347 | |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 1348 | #if FOO |
| 1349 | #if BAR |
| 1350 | #include <foo> |
| 1351 | #endif |
| 1352 | #endif |
Krasimir Georgiev | ad47c90 | 2017-08-30 14:34:57 +0000 | [diff] [blame] | 1353 | |
| 1354 | * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) |
| 1355 | Indents directives after the hash. |
| 1356 | |
| 1357 | .. code-block:: c++ |
| 1358 | |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 1359 | #if FOO |
| 1360 | # if BAR |
| 1361 | # include <foo> |
| 1362 | # endif |
| 1363 | #endif |
| 1364 | |
| 1365 | |
Krasimir Georgiev | ad47c90 | 2017-08-30 14:34:57 +0000 | [diff] [blame] | 1366 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1367 | **IndentWidth** (``unsigned``) |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 1368 | The number of columns to use for indentation. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1369 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1370 | .. code-block:: c++ |
| 1371 | |
| 1372 | IndentWidth: 3 |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1373 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1374 | void f() { |
| 1375 | someFunction(); |
| 1376 | if (true, false) { |
| 1377 | f(); |
| 1378 | } |
| 1379 | } |
| 1380 | |
Daniel Jasper | c75e1ef | 2014-07-09 08:42:42 +0000 | [diff] [blame] | 1381 | **IndentWrappedFunctionNames** (``bool``) |
| 1382 | Indent if a function definition or declaration is wrapped after the |
| 1383 | type. |
| 1384 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1385 | .. code-block:: c++ |
| 1386 | |
| 1387 | true: |
| 1388 | LoooooooooooooooooooooooooooooooooooooooongReturnType |
| 1389 | LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
| 1390 | |
| 1391 | false: |
| 1392 | LoooooooooooooooooooooooooooooooooooooooongReturnType |
| 1393 | LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
| 1394 | |
Daniel Jasper | 9c8ff35 | 2016-03-21 14:11:27 +0000 | [diff] [blame] | 1395 | **JavaScriptQuotes** (``JavaScriptQuoteStyle``) |
| 1396 | The JavaScriptQuoteStyle to use for JavaScript strings. |
| 1397 | |
| 1398 | Possible values: |
| 1399 | |
| 1400 | * ``JSQS_Leave`` (in configuration: ``Leave``) |
| 1401 | Leave string quotes as they are. |
| 1402 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1403 | .. code-block:: js |
| 1404 | |
| 1405 | string1 = "foo"; |
| 1406 | string2 = 'bar'; |
| 1407 | |
Daniel Jasper | 9c8ff35 | 2016-03-21 14:11:27 +0000 | [diff] [blame] | 1408 | * ``JSQS_Single`` (in configuration: ``Single``) |
| 1409 | Always use single quotes. |
| 1410 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1411 | .. code-block:: js |
| 1412 | |
| 1413 | string1 = 'foo'; |
| 1414 | string2 = 'bar'; |
| 1415 | |
Daniel Jasper | 9c8ff35 | 2016-03-21 14:11:27 +0000 | [diff] [blame] | 1416 | * ``JSQS_Double`` (in configuration: ``Double``) |
| 1417 | Always use double quotes. |
| 1418 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1419 | .. code-block:: js |
| 1420 | |
| 1421 | string1 = "foo"; |
| 1422 | string2 = "bar"; |
| 1423 | |
Daniel Jasper | 9c8ff35 | 2016-03-21 14:11:27 +0000 | [diff] [blame] | 1424 | |
| 1425 | |
Krasimir Georgiev | 32eaa86 | 2017-03-01 15:35:39 +0000 | [diff] [blame] | 1426 | **JavaScriptWrapImports** (``bool``) |
| 1427 | Whether to wrap JavaScript import/export statements. |
| 1428 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1429 | .. code-block:: js |
| 1430 | |
| 1431 | true: |
| 1432 | import { |
| 1433 | VeryLongImportsAreAnnoying, |
| 1434 | VeryLongImportsAreAnnoying, |
| 1435 | VeryLongImportsAreAnnoying, |
| 1436 | } from 'some/module.js' |
| 1437 | |
| 1438 | false: |
| 1439 | import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" |
| 1440 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1441 | **KeepEmptyLinesAtTheStartOfBlocks** (``bool``) |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1442 | If true, the empty line at the start of blocks is kept. |
| 1443 | |
| 1444 | .. code-block:: c++ |
| 1445 | |
| 1446 | true: false: |
| 1447 | if (foo) { vs. if (foo) { |
| 1448 | bar(); |
| 1449 | bar(); } |
| 1450 | } |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1451 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1452 | **Language** (``LanguageKind``) |
| 1453 | Language, this format style is targeted at. |
| 1454 | |
| 1455 | Possible values: |
| 1456 | |
| 1457 | * ``LK_None`` (in configuration: ``None``) |
| 1458 | Do not use. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1459 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1460 | * ``LK_Cpp`` (in configuration: ``Cpp``) |
Krasimir Georgiev | 32eaa86 | 2017-03-01 15:35:39 +0000 | [diff] [blame] | 1461 | Should be used for C, C++. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1462 | |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 1463 | * ``LK_Java`` (in configuration: ``Java``) |
| 1464 | Should be used for Java. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1465 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1466 | * ``LK_JavaScript`` (in configuration: ``JavaScript``) |
| 1467 | Should be used for JavaScript. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1468 | |
Krasimir Georgiev | 32eaa86 | 2017-03-01 15:35:39 +0000 | [diff] [blame] | 1469 | * ``LK_ObjC`` (in configuration: ``ObjC``) |
| 1470 | Should be used for Objective-C, Objective-C++. |
| 1471 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1472 | * ``LK_Proto`` (in configuration: ``Proto``) |
| 1473 | Should be used for Protocol Buffers |
| 1474 | (https://developers.google.com/protocol-buffers/). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1475 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1476 | * ``LK_TableGen`` (in configuration: ``TableGen``) |
| 1477 | Should be used for TableGen code. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1478 | |
Sylvestre Ledru | 44d1ef1 | 2017-09-07 12:08:49 +0000 | [diff] [blame] | 1479 | * ``LK_TextProto`` (in configuration: ``TextProto``) |
| 1480 | Should be used for Protocol Buffer messages in text format |
| 1481 | (https://developers.google.com/protocol-buffers/). |
| 1482 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1483 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1484 | |
Birunthan Mohanathas | b001a0b | 2015-07-03 17:25:16 +0000 | [diff] [blame] | 1485 | **MacroBlockBegin** (``std::string``) |
| 1486 | A regular expression matching macros that start a block. |
| 1487 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1488 | .. code-block:: c++ |
| 1489 | |
| 1490 | # With: |
| 1491 | MacroBlockBegin: "^NS_MAP_BEGIN|\ |
| 1492 | NS_TABLE_HEAD$" |
| 1493 | MacroBlockEnd: "^\ |
| 1494 | NS_MAP_END|\ |
| 1495 | NS_TABLE_.*_END$" |
| 1496 | |
| 1497 | NS_MAP_BEGIN |
| 1498 | foo(); |
| 1499 | NS_MAP_END |
| 1500 | |
| 1501 | NS_TABLE_HEAD |
| 1502 | bar(); |
| 1503 | NS_TABLE_FOO_END |
| 1504 | |
| 1505 | # Without: |
| 1506 | NS_MAP_BEGIN |
| 1507 | foo(); |
| 1508 | NS_MAP_END |
| 1509 | |
| 1510 | NS_TABLE_HEAD |
| 1511 | bar(); |
| 1512 | NS_TABLE_FOO_END |
| 1513 | |
Birunthan Mohanathas | b001a0b | 2015-07-03 17:25:16 +0000 | [diff] [blame] | 1514 | **MacroBlockEnd** (``std::string``) |
| 1515 | A regular expression matching macros that end a block. |
| 1516 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1517 | **MaxEmptyLinesToKeep** (``unsigned``) |
| 1518 | The maximum number of consecutive empty lines to keep. |
| 1519 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1520 | .. code-block:: c++ |
| 1521 | |
| 1522 | MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 |
| 1523 | int f() { int f() { |
| 1524 | int = 1; int i = 1; |
| 1525 | i = foo(); |
| 1526 | i = foo(); return i; |
| 1527 | } |
| 1528 | return i; |
| 1529 | } |
| 1530 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1531 | **NamespaceIndentation** (``NamespaceIndentationKind``) |
| 1532 | The indentation used for namespaces. |
| 1533 | |
| 1534 | Possible values: |
| 1535 | |
| 1536 | * ``NI_None`` (in configuration: ``None``) |
| 1537 | Don't indent in namespaces. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1538 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1539 | .. code-block:: c++ |
| 1540 | |
| 1541 | namespace out { |
| 1542 | int i; |
| 1543 | namespace in { |
| 1544 | int i; |
| 1545 | } |
| 1546 | } |
| 1547 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1548 | * ``NI_Inner`` (in configuration: ``Inner``) |
| 1549 | Indent only in inner namespaces (nested in other namespaces). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1550 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1551 | .. code-block:: c++ |
| 1552 | |
| 1553 | namespace out { |
| 1554 | int i; |
| 1555 | namespace in { |
| 1556 | int i; |
| 1557 | } |
| 1558 | } |
| 1559 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1560 | * ``NI_All`` (in configuration: ``All``) |
| 1561 | Indent in all namespaces. |
| 1562 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1563 | .. code-block:: c++ |
| 1564 | |
| 1565 | namespace out { |
| 1566 | int i; |
| 1567 | namespace in { |
| 1568 | int i; |
| 1569 | } |
| 1570 | } |
| 1571 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1572 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1573 | |
Krasimir Georgiev | c5be6af | 2018-03-06 13:24:01 +0000 | [diff] [blame] | 1574 | **ObjCBinPackProtocolList** (``BinPackStyle``) |
| 1575 | Controls bin-packing Objective-C protocol conformance list |
| 1576 | items into as few lines as possible when they go over ``ColumnLimit``. |
| 1577 | |
| 1578 | If ``Auto`` (the default), delegates to the value in |
| 1579 | ``BinPackParameters``. If that is ``true``, bin-packs Objective-C |
| 1580 | protocol conformance list items into as few lines as possible |
| 1581 | whenever they go over ``ColumnLimit``. |
| 1582 | |
| 1583 | If ``Always``, always bin-packs Objective-C protocol conformance |
| 1584 | list items into as few lines as possible whenever they go over |
| 1585 | ``ColumnLimit``. |
| 1586 | |
| 1587 | If ``Never``, lays out Objective-C protocol conformance list items |
| 1588 | onto individual lines whenever they go over ``ColumnLimit``. |
| 1589 | |
| 1590 | |
Aaron Ballman | 37485fd | 2018-06-28 12:02:38 +0000 | [diff] [blame] | 1591 | .. code-block:: objc |
Krasimir Georgiev | c5be6af | 2018-03-06 13:24:01 +0000 | [diff] [blame] | 1592 | |
| 1593 | Always (or Auto, if BinPackParameters=true): |
| 1594 | @interface ccccccccccccc () < |
| 1595 | ccccccccccccc, ccccccccccccc, |
| 1596 | ccccccccccccc, ccccccccccccc> { |
| 1597 | } |
| 1598 | |
| 1599 | Never (or Auto, if BinPackParameters=false): |
| 1600 | @interface ddddddddddddd () < |
| 1601 | ddddddddddddd, |
| 1602 | ddddddddddddd, |
| 1603 | ddddddddddddd, |
| 1604 | ddddddddddddd> { |
| 1605 | } |
| 1606 | |
| 1607 | Possible values: |
| 1608 | |
| 1609 | * ``BPS_Auto`` (in configuration: ``Auto``) |
| 1610 | Automatically determine parameter bin-packing behavior. |
| 1611 | |
| 1612 | * ``BPS_Always`` (in configuration: ``Always``) |
| 1613 | Always bin-pack parameters. |
| 1614 | |
| 1615 | * ``BPS_Never`` (in configuration: ``Never``) |
| 1616 | Never bin-pack parameters. |
| 1617 | |
| 1618 | |
| 1619 | |
Daniel Jasper | eb2226e | 2014-10-28 16:56:37 +0000 | [diff] [blame] | 1620 | **ObjCBlockIndentWidth** (``unsigned``) |
| 1621 | The number of characters to use for indentation of ObjC blocks. |
| 1622 | |
Sylvestre Ledru | de09824 | 2017-04-11 07:07:05 +0000 | [diff] [blame] | 1623 | .. code-block:: objc |
| 1624 | |
| 1625 | ObjCBlockIndentWidth: 4 |
| 1626 | |
| 1627 | [operation setCompletionBlock:^{ |
| 1628 | [self onOperationDone]; |
| 1629 | }]; |
| 1630 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1631 | **ObjCSpaceAfterProperty** (``bool``) |
| 1632 | Add a space after ``@property`` in Objective-C, i.e. use |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1633 | ``@property (readonly)`` instead of ``@property(readonly)``. |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1634 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1635 | **ObjCSpaceBeforeProtocolList** (``bool``) |
| 1636 | Add a space in front of an Objective-C protocol list, i.e. use |
| 1637 | ``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
| 1638 | |
Krasimir Georgiev | 575b25f | 2017-06-23 08:48:00 +0000 | [diff] [blame] | 1639 | **PenaltyBreakAssignment** (``unsigned``) |
| 1640 | The penalty for breaking around an assignment operator. |
| 1641 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1642 | **PenaltyBreakBeforeFirstCallParameter** (``unsigned``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1643 | The penalty for breaking a function call after ``call(``. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1644 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1645 | **PenaltyBreakComment** (``unsigned``) |
| 1646 | The penalty for each line break introduced inside a comment. |
| 1647 | |
| 1648 | **PenaltyBreakFirstLessLess** (``unsigned``) |
| 1649 | The penalty for breaking before the first ``<<``. |
| 1650 | |
| 1651 | **PenaltyBreakString** (``unsigned``) |
| 1652 | The penalty for each line break introduced inside a string literal. |
| 1653 | |
Francois Ferrand | 58e6fe5 | 2018-05-16 08:25:03 +0000 | [diff] [blame] | 1654 | **PenaltyBreakTemplateDeclaration** (``unsigned``) |
| 1655 | The penalty for breaking after template declaration. |
| 1656 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1657 | **PenaltyExcessCharacter** (``unsigned``) |
| 1658 | The penalty for each character outside of the column limit. |
| 1659 | |
| 1660 | **PenaltyReturnTypeOnItsOwnLine** (``unsigned``) |
| 1661 | Penalty for putting the return type of a function onto its own |
| 1662 | line. |
| 1663 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 1664 | **PointerAlignment** (``PointerAlignmentStyle``) |
| 1665 | Pointer and reference alignment style. |
| 1666 | |
| 1667 | Possible values: |
| 1668 | |
| 1669 | * ``PAS_Left`` (in configuration: ``Left``) |
| 1670 | Align pointer to the left. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1671 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1672 | .. code-block:: c++ |
| 1673 | |
Sylvestre Ledru | f3e295a | 2017-03-09 06:41:08 +0000 | [diff] [blame] | 1674 | int* a; |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1675 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 1676 | * ``PAS_Right`` (in configuration: ``Right``) |
| 1677 | Align pointer to the right. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1678 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1679 | .. code-block:: c++ |
| 1680 | |
Sylvestre Ledru | f3e295a | 2017-03-09 06:41:08 +0000 | [diff] [blame] | 1681 | int *a; |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1682 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 1683 | * ``PAS_Middle`` (in configuration: ``Middle``) |
| 1684 | Align pointer in the middle. |
| 1685 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1686 | .. code-block:: c++ |
| 1687 | |
Sylvestre Ledru | f3e295a | 2017-03-09 06:41:08 +0000 | [diff] [blame] | 1688 | int * a; |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1689 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1690 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1691 | |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 1692 | **RawStringFormats** (``std::vector<RawStringFormat>``) |
Krasimir Georgiev | 2537e22 | 2018-01-17 16:17:26 +0000 | [diff] [blame] | 1693 | Defines hints for detecting supported languages code blocks in raw |
| 1694 | strings. |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 1695 | |
Krasimir Georgiev | 2537e22 | 2018-01-17 16:17:26 +0000 | [diff] [blame] | 1696 | A raw string with a matching delimiter or a matching enclosing function |
| 1697 | name will be reformatted assuming the specified language based on the |
| 1698 | style for that language defined in the .clang-format file. If no style has |
| 1699 | been defined in the .clang-format file for the specific language, a |
| 1700 | predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not |
| 1701 | found, the formatting is based on llvm style. A matching delimiter takes |
| 1702 | precedence over a matching enclosing function name for determining the |
| 1703 | language of the raw string contents. |
| 1704 | |
Malcolm Parsons | 51d3fb0 | 2018-01-24 10:26:09 +0000 | [diff] [blame] | 1705 | If a canonical delimiter is specified, occurrences of other delimiters for |
Krasimir Georgiev | 412ed09 | 2018-01-19 16:18:47 +0000 | [diff] [blame] | 1706 | the same language will be updated to the canonical if possible. |
| 1707 | |
Krasimir Georgiev | 2537e22 | 2018-01-17 16:17:26 +0000 | [diff] [blame] | 1708 | There should be at most one specification per language and each delimiter |
| 1709 | and enclosing function should not occur in multiple specifications. |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 1710 | |
| 1711 | To configure this in the .clang-format file, use: |
| 1712 | |
| 1713 | .. code-block:: yaml |
| 1714 | |
| 1715 | RawStringFormats: |
Krasimir Georgiev | 2537e22 | 2018-01-17 16:17:26 +0000 | [diff] [blame] | 1716 | - Language: TextProto |
| 1717 | Delimiters: |
| 1718 | - 'pb' |
| 1719 | - 'proto' |
| 1720 | EnclosingFunctions: |
| 1721 | - 'PARSE_TEXT_PROTO' |
| 1722 | BasedOnStyle: google |
| 1723 | - Language: Cpp |
| 1724 | Delimiters: |
| 1725 | - 'cc' |
| 1726 | - 'cpp' |
| 1727 | BasedOnStyle: llvm |
Krasimir Georgiev | 412ed09 | 2018-01-19 16:18:47 +0000 | [diff] [blame] | 1728 | CanonicalDelimiter: 'cc' |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 1729 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1730 | **ReflowComments** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1731 | If ``true``, clang-format will attempt to re-flow comments. |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1732 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1733 | .. code-block:: c++ |
| 1734 | |
| 1735 | false: |
| 1736 | // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information |
| 1737 | /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ |
| 1738 | |
| 1739 | true: |
| 1740 | // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
| 1741 | // information |
| 1742 | /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
| 1743 | * information */ |
| 1744 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1745 | **SortIncludes** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1746 | If ``true``, clang-format will sort ``#includes``. |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 1747 | |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1748 | .. code-block:: c++ |
| 1749 | |
| 1750 | false: true: |
| 1751 | #include "b.h" vs. #include "a.h" |
| 1752 | #include "a.h" #include "b.h" |
| 1753 | |
Krasimir Georgiev | ac16a20 | 2017-06-23 11:46:03 +0000 | [diff] [blame] | 1754 | **SortUsingDeclarations** (``bool``) |
| 1755 | If ``true``, clang-format will sort using declarations. |
| 1756 | |
Krasimir Georgiev | 818da9b | 2017-11-09 15:41:23 +0000 | [diff] [blame] | 1757 | The order of using declarations is defined as follows: |
| 1758 | Split the strings by "::" and discard any initial empty strings. The last |
| 1759 | element of each list is a non-namespace name; all others are namespace |
| 1760 | names. Sort the lists of names lexicographically, where the sort order of |
| 1761 | individual names is that all non-namespace names come before all namespace |
| 1762 | names, and within those groups, names are in case-insensitive |
| 1763 | lexicographic order. |
Krasimir Georgiev | ac16a20 | 2017-06-23 11:46:03 +0000 | [diff] [blame] | 1764 | |
Krasimir Georgiev | d4102df | 2017-11-09 15:54:59 +0000 | [diff] [blame] | 1765 | .. code-block:: c++ |
| 1766 | |
| 1767 | false: true: |
| 1768 | using std::cout; vs. using std::cin; |
| 1769 | using std::cin; using std::cout; |
| 1770 | |
Daniel Jasper | b87899b | 2014-09-10 13:11:45 +0000 | [diff] [blame] | 1771 | **SpaceAfterCStyleCast** (``bool``) |
Sylvestre Ledru | 0385ccb | 2017-03-08 13:24:46 +0000 | [diff] [blame] | 1772 | If ``true``, a space is inserted after C style casts. |
| 1773 | |
| 1774 | .. code-block:: c++ |
| 1775 | |
| 1776 | true: false: |
Krasimir Georgiev | c5be6af | 2018-03-06 13:24:01 +0000 | [diff] [blame] | 1777 | (int) i; vs. (int)i; |
Daniel Jasper | b87899b | 2014-09-10 13:11:45 +0000 | [diff] [blame] | 1778 | |
Sylvestre Ledru | 83bbd57 | 2016-08-09 14:24:40 +0000 | [diff] [blame] | 1779 | **SpaceAfterTemplateKeyword** (``bool``) |
| 1780 | If ``true``, a space will be inserted after the 'template' keyword. |
| 1781 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1782 | .. code-block:: c++ |
| 1783 | |
| 1784 | true: false: |
| 1785 | template <int> void foo(); vs. template<int> void foo(); |
| 1786 | |
Daniel Jasper | d94bff3 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 1787 | **SpaceBeforeAssignmentOperators** (``bool``) |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 1788 | If ``false``, spaces will be removed before assignment operators. |
Daniel Jasper | d94bff3 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 1789 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1790 | .. code-block:: c++ |
| 1791 | |
| 1792 | true: false: |
| 1793 | int a = 5; vs. int a=5; |
| 1794 | a += 42 a+=42; |
| 1795 | |
Hans Wennborg | bfc3406 | 2018-06-14 08:01:09 +0000 | [diff] [blame] | 1796 | **SpaceBeforeCpp11BracedList** (``bool``) |
| 1797 | If ``true``, a space will be inserted before a C++11 braced list |
| 1798 | used to initialize an object (after the preceding identifier or type). |
| 1799 | |
| 1800 | .. code-block:: c++ |
| 1801 | |
| 1802 | true: false: |
| 1803 | Foo foo { bar }; vs. Foo foo{ bar }; |
| 1804 | Foo {}; Foo{}; |
| 1805 | vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; |
| 1806 | new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; |
| 1807 | |
Francois Ferrand | 2a9ea78 | 2018-03-01 10:09:13 +0000 | [diff] [blame] | 1808 | **SpaceBeforeCtorInitializerColon** (``bool``) |
| 1809 | If ``false``, spaces will be removed before constructor initializer |
| 1810 | colon. |
| 1811 | |
| 1812 | .. code-block:: c++ |
| 1813 | |
| 1814 | true: false: |
| 1815 | Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} |
| 1816 | |
| 1817 | **SpaceBeforeInheritanceColon** (``bool``) |
| 1818 | If ``false``, spaces will be removed before inheritance colon. |
| 1819 | |
| 1820 | .. code-block:: c++ |
| 1821 | |
| 1822 | true: false: |
| 1823 | class Foo : Bar {} vs. class Foo: Bar {} |
| 1824 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1825 | **SpaceBeforeParens** (``SpaceBeforeParensOptions``) |
| 1826 | Defines in which cases to put a space before opening parentheses. |
| 1827 | |
| 1828 | Possible values: |
| 1829 | |
| 1830 | * ``SBPO_Never`` (in configuration: ``Never``) |
| 1831 | Never put a space before opening parentheses. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1832 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1833 | .. code-block:: c++ |
| 1834 | |
| 1835 | void f() { |
| 1836 | if(true) { |
| 1837 | f(); |
| 1838 | } |
| 1839 | } |
| 1840 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1841 | * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) |
| 1842 | Put a space before opening parentheses only after control statement |
| 1843 | keywords (``for/if/while...``). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1844 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1845 | .. code-block:: c++ |
| 1846 | |
| 1847 | void f() { |
| 1848 | if (true) { |
| 1849 | f(); |
| 1850 | } |
| 1851 | } |
| 1852 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1853 | * ``SBPO_Always`` (in configuration: ``Always``) |
| 1854 | Always put a space before opening parentheses, except when it's |
| 1855 | prohibited by the syntax rules (in function-like macro definitions) or |
| 1856 | when determined by other style rules (after unary operators, opening |
| 1857 | parentheses, etc.) |
| 1858 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1859 | .. code-block:: c++ |
| 1860 | |
| 1861 | void f () { |
| 1862 | if (true) { |
| 1863 | f (); |
| 1864 | } |
| 1865 | } |
| 1866 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1867 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1868 | |
Francois Ferrand | 2a9ea78 | 2018-03-01 10:09:13 +0000 | [diff] [blame] | 1869 | **SpaceBeforeRangeBasedForLoopColon** (``bool``) |
| 1870 | If ``false``, spaces will be removed before range-based for loop |
| 1871 | colon. |
| 1872 | |
| 1873 | .. code-block:: c++ |
| 1874 | |
| 1875 | true: false: |
| 1876 | for (auto v : values) {} vs. for(auto v: values) {} |
| 1877 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1878 | **SpaceInEmptyParentheses** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1879 | If ``true``, spaces may be inserted into ``()``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1880 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1881 | .. code-block:: c++ |
| 1882 | |
| 1883 | true: false: |
| 1884 | void f( ) { vs. void f() { |
| 1885 | int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; |
| 1886 | if (true) { if (true) { |
| 1887 | f( ); f(); |
| 1888 | } } |
| 1889 | } } |
| 1890 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1891 | **SpacesBeforeTrailingComments** (``unsigned``) |
Daniel Jasper | c0be760 | 2014-05-15 13:55:19 +0000 | [diff] [blame] | 1892 | The number of spaces before trailing line comments |
| 1893 | (``//`` - comments). |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 1894 | |
Alexander Kornienko | 70f97c9 | 2016-02-27 14:02:08 +0000 | [diff] [blame] | 1895 | This does not affect trailing block comments (``/*`` - comments) as |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1896 | those commonly have different usage patterns and a number of special |
| 1897 | cases. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1898 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1899 | .. code-block:: c++ |
| 1900 | |
| 1901 | SpacesBeforeTrailingComments: 3 |
| 1902 | void f() { |
| 1903 | if (true) { // foo1 |
| 1904 | f(); // bar |
| 1905 | } // foo |
| 1906 | } |
| 1907 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1908 | **SpacesInAngles** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1909 | If ``true``, spaces will be inserted after ``<`` and before ``>`` |
| 1910 | in template argument lists. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 1911 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1912 | .. code-block:: c++ |
| 1913 | |
| 1914 | true: false: |
| 1915 | static_cast< int >(arg); vs. static_cast<int>(arg); |
| 1916 | std::function< void(int) > fct; std::function<void(int)> fct; |
| 1917 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1918 | **SpacesInCStyleCastParentheses** (``bool``) |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1919 | If ``true``, spaces may be inserted into C style casts. |
| 1920 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1921 | .. code-block:: c++ |
| 1922 | |
| 1923 | true: false: |
| 1924 | x = ( int32 )y vs. x = (int32)y |
| 1925 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 1926 | **SpacesInContainerLiterals** (``bool``) |
| 1927 | If ``true``, spaces are inserted inside container literals (e.g. |
| 1928 | ObjC and Javascript array and dict literals). |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1929 | |
Sylvestre Ledru | 35b392d | 2017-03-20 12:56:40 +0000 | [diff] [blame] | 1930 | .. code-block:: js |
| 1931 | |
| 1932 | true: false: |
| 1933 | var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; |
| 1934 | f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); |
| 1935 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1936 | **SpacesInParentheses** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1937 | If ``true``, spaces will be inserted after ``(`` and before ``)``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1938 | |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1939 | .. code-block:: c++ |
| 1940 | |
| 1941 | true: false: |
| 1942 | t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; |
| 1943 | |
Daniel Jasper | ad981f8 | 2014-08-26 11:41:14 +0000 | [diff] [blame] | 1944 | **SpacesInSquareBrackets** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1945 | If ``true``, spaces will be inserted after ``[`` and before ``]``. |
Sylvestre Ledru | d1eff2f | 2017-03-06 16:35:28 +0000 | [diff] [blame] | 1946 | Lambdas or unspecified size array declarations will not be affected. |
| 1947 | |
| 1948 | .. code-block:: c++ |
| 1949 | |
| 1950 | true: false: |
| 1951 | int a[ 5 ]; vs. int a[5]; |
| 1952 | std::unique_ptr<int[]> foo() {} // Won't be affected |
Daniel Jasper | ad981f8 | 2014-08-26 11:41:14 +0000 | [diff] [blame] | 1953 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1954 | **Standard** (``LanguageStandard``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1955 | Format compatible with this standard, e.g. use ``A<A<int> >`` |
| 1956 | instead of ``A<A<int>>`` for ``LS_Cpp03``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1957 | |
| 1958 | Possible values: |
| 1959 | |
| 1960 | * ``LS_Cpp03`` (in configuration: ``Cpp03``) |
| 1961 | Use C++03-compatible syntax. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1962 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1963 | * ``LS_Cpp11`` (in configuration: ``Cpp11``) |
Daniel Jasper | 7fdbb3f | 2017-05-08 15:08:00 +0000 | [diff] [blame] | 1964 | 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] | 1965 | ``A<A<int> >``). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1966 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1967 | * ``LS_Auto`` (in configuration: ``Auto``) |
| 1968 | Automatic detection based on the input. |
| 1969 | |
| 1970 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1971 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 1972 | **TabWidth** (``unsigned``) |
| 1973 | The number of columns used for tab stops. |
| 1974 | |
| 1975 | **UseTab** (``UseTabStyle``) |
| 1976 | The way to use tab characters in the resulting file. |
| 1977 | |
| 1978 | Possible values: |
| 1979 | |
| 1980 | * ``UT_Never`` (in configuration: ``Never``) |
| 1981 | Never use tab. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1982 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 1983 | * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) |
| 1984 | Use tabs only for indentation. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1985 | |
Krasimir Georgiev | 32eaa86 | 2017-03-01 15:35:39 +0000 | [diff] [blame] | 1986 | * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) |
| 1987 | Use tabs only for line continuation and indentation. |
| 1988 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 1989 | * ``UT_Always`` (in configuration: ``Always``) |
| 1990 | Use tabs whenever we need to fill whitespace that spans at least from |
| 1991 | one tab stop to the next one. |
| 1992 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1993 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 1994 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1995 | .. END_FORMAT_STYLE_OPTIONS |
| 1996 | |
Daniel Jasper | 49d3d58 | 2015-10-05 07:24:55 +0000 | [diff] [blame] | 1997 | Adding additional style options |
| 1998 | =============================== |
| 1999 | |
| 2000 | 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] | 2001 | 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] | 2002 | sure that any given combination of options work and that new features don't |
| 2003 | break any of the existing options in any way. There are also costs for end users |
| 2004 | as options become less discoverable and people have to think about and make a |
| 2005 | decision on options they don't really care about. |
| 2006 | |
| 2007 | The goal of the clang-format project is more on the side of supporting a |
| 2008 | limited set of styles really well as opposed to supporting every single style |
| 2009 | used by a codebase somewhere in the wild. Of course, we do want to support all |
| 2010 | major projects and thus have established the following bar for adding style |
| 2011 | options. Each new style option must .. |
| 2012 | |
Daniel Jasper | fcbea71 | 2015-10-05 13:30:42 +0000 | [diff] [blame] | 2013 | * be used in a project of significant size (have dozens of contributors) |
| 2014 | * have a publicly accessible style guide |
| 2015 | * have a person willing to contribute and maintain patches |
Daniel Jasper | 49d3d58 | 2015-10-05 07:24:55 +0000 | [diff] [blame] | 2016 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 2017 | Examples |
| 2018 | ======== |
| 2019 | |
| 2020 | A style similar to the `Linux Kernel style |
| 2021 | <https://www.kernel.org/doc/Documentation/CodingStyle>`_: |
| 2022 | |
| 2023 | .. code-block:: yaml |
| 2024 | |
| 2025 | BasedOnStyle: LLVM |
| 2026 | IndentWidth: 8 |
Alexander Kornienko | 8ba68f6 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 2027 | UseTab: Always |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 2028 | BreakBeforeBraces: Linux |
| 2029 | AllowShortIfStatementsOnASingleLine: false |
| 2030 | IndentCaseLabels: false |
| 2031 | |
| 2032 | The result is (imagine that tabs are used for indentation here): |
| 2033 | |
| 2034 | .. code-block:: c++ |
| 2035 | |
| 2036 | void test() |
| 2037 | { |
| 2038 | switch (x) { |
| 2039 | case 0: |
| 2040 | case 1: |
| 2041 | do_something(); |
| 2042 | break; |
| 2043 | case 2: |
| 2044 | do_something_else(); |
| 2045 | break; |
| 2046 | default: |
| 2047 | break; |
| 2048 | } |
| 2049 | if (condition) |
| 2050 | do_something_completely_different(); |
| 2051 | |
| 2052 | if (x == y) { |
| 2053 | q(); |
| 2054 | } else if (x > y) { |
| 2055 | w(); |
| 2056 | } else { |
| 2057 | r(); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | A style similar to the default Visual Studio formatting style: |
| 2062 | |
| 2063 | .. code-block:: yaml |
| 2064 | |
Alexander Kornienko | 8ba68f6 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 2065 | UseTab: Never |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 2066 | IndentWidth: 4 |
| 2067 | BreakBeforeBraces: Allman |
| 2068 | AllowShortIfStatementsOnASingleLine: false |
| 2069 | IndentCaseLabels: false |
| 2070 | ColumnLimit: 0 |
| 2071 | |
| 2072 | The result is: |
| 2073 | |
| 2074 | .. code-block:: c++ |
| 2075 | |
| 2076 | void test() |
| 2077 | { |
| 2078 | switch (suffix) |
| 2079 | { |
| 2080 | case 0: |
| 2081 | case 1: |
| 2082 | do_something(); |
| 2083 | break; |
| 2084 | case 2: |
| 2085 | do_something_else(); |
| 2086 | break; |
| 2087 | default: |
| 2088 | break; |
| 2089 | } |
| 2090 | if (condition) |
| 2091 | do_somthing_completely_different(); |
| 2092 | |
| 2093 | if (x == y) |
| 2094 | { |
| 2095 | q(); |
| 2096 | } |
| 2097 | else if (x > y) |
| 2098 | { |
| 2099 | w(); |
| 2100 | } |
| 2101 | else |
| 2102 | { |
| 2103 | r(); |
| 2104 | } |
| 2105 | } |