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