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