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