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