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 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 212 | **AlignEscapedNewlinesLeft** (``bool``) |
| 213 | If ``true``, aligns escaped newlines as far left as possible. |
| 214 | Otherwise puts them into the right-most column. |
| 215 | |
Daniel Jasper | 3219e43 | 2014-12-02 13:24:51 +0000 | [diff] [blame] | 216 | **AlignOperands** (``bool``) |
| 217 | If ``true``, horizontally align operands of binary and ternary |
| 218 | expressions. |
| 219 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 220 | Specifically, this aligns operands of a single expression that needs to be |
| 221 | split over multiple lines, e.g.: |
| 222 | |
| 223 | .. code-block:: c++ |
| 224 | |
| 225 | int aaa = bbbbbbbbbbbbbbb + |
| 226 | ccccccccccccccc; |
| 227 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 228 | **AlignTrailingComments** (``bool``) |
| 229 | If ``true``, aligns trailing comments. |
| 230 | |
| 231 | **AllowAllParametersOfDeclarationOnNextLine** (``bool``) |
| 232 | Allow putting all parameters of a function declaration onto |
| 233 | the next line even if ``BinPackParameters`` is ``false``. |
| 234 | |
Daniel Jasper | 17605d3 | 2014-05-14 09:33:35 +0000 | [diff] [blame] | 235 | **AllowShortBlocksOnASingleLine** (``bool``) |
| 236 | Allows contracting simple braced statements to a single line. |
| 237 | |
| 238 | E.g., this allows ``if (a) { return; }`` to be put on a single line. |
| 239 | |
Daniel Jasper | b87899b | 2014-09-10 13:11:45 +0000 | [diff] [blame] | 240 | **AllowShortCaseLabelsOnASingleLine** (``bool``) |
| 241 | If ``true``, short case labels will be contracted to a single line. |
| 242 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 243 | **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 244 | Dependent on the value, ``int f() { return 0; }`` can be put on a |
| 245 | single line. |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 246 | |
| 247 | Possible values: |
| 248 | |
| 249 | * ``SFS_None`` (in configuration: ``None``) |
| 250 | Never merge functions into a single line. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 251 | |
Daniel Jasper | 3219e43 | 2014-12-02 13:24:51 +0000 | [diff] [blame] | 252 | * ``SFS_Empty`` (in configuration: ``Empty``) |
| 253 | Only merge empty functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 254 | |
Daniel Jasper | 20580fd | 2015-06-11 13:31:45 +0000 | [diff] [blame] | 255 | * ``SFS_Inline`` (in configuration: ``Inline``) |
| 256 | Only merge functions defined inside a class. Implies "empty". |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 257 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 258 | * ``SFS_All`` (in configuration: ``All``) |
| 259 | Merge all functions fitting on a single line. |
| 260 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 261 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 262 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 263 | **AllowShortIfStatementsOnASingleLine** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 264 | If ``true``, ``if (a) return;`` can be put on a single line. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 265 | |
| 266 | **AllowShortLoopsOnASingleLine** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 267 | If ``true``, ``while (true) continue;`` can be put on a single |
| 268 | line. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 269 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 270 | **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 271 | The function definition return type breaking style to use. This |
| 272 | option is deprecated and is retained for backwards compatibility. |
Daniel Jasper | ca4ea1c | 2014-08-05 12:16:31 +0000 | [diff] [blame] | 273 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 274 | Possible values: |
| 275 | |
| 276 | * ``DRTBS_None`` (in configuration: ``None``) |
| 277 | Break after return type automatically. |
| 278 | ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 279 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 280 | * ``DRTBS_All`` (in configuration: ``All``) |
| 281 | Always break after the return type. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 282 | |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 283 | * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 284 | Always break after the return types of top-level functions. |
| 285 | |
| 286 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 287 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 288 | **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) |
| 289 | The function declaration return type breaking style to use. |
| 290 | |
| 291 | Possible values: |
| 292 | |
| 293 | * ``RTBS_None`` (in configuration: ``None``) |
| 294 | Break after return type automatically. |
| 295 | ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 296 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 297 | * ``RTBS_All`` (in configuration: ``All``) |
| 298 | Always break after the return type. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 299 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 300 | * ``RTBS_TopLevel`` (in configuration: ``TopLevel``) |
| 301 | Always break after the return types of top-level functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 302 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 303 | * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) |
| 304 | Always break after the return type of function definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 305 | |
Zachary Turner | 448592e | 2015-12-18 22:20:15 +0000 | [diff] [blame] | 306 | * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) |
| 307 | Always break after the return type of top-level definitions. |
Birunthan Mohanathas | a0388a8 | 2015-06-29 15:30:42 +0000 | [diff] [blame] | 308 | |
Daniel Jasper | ca4ea1c | 2014-08-05 12:16:31 +0000 | [diff] [blame] | 309 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 310 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 311 | **AlwaysBreakBeforeMultilineStrings** (``bool``) |
| 312 | If ``true``, always break before multiline string literals. |
| 313 | |
Daniel Jasper | 2aaedd3 | 2015-06-18 09:12:47 +0000 | [diff] [blame] | 314 | This flag is mean to make cases where there are multiple multiline strings |
| 315 | in a file look more consistent. Thus, it will only take effect if wrapping |
| 316 | the string at that point leads to it being indented |
| 317 | ``ContinuationIndentWidth`` spaces from the start of the line. |
| 318 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 319 | **AlwaysBreakTemplateDeclarations** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 320 | If ``true``, always break after the ``template<...>`` of a template |
| 321 | declaration. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 322 | |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 323 | **BinPackArguments** (``bool``) |
| 324 | If ``false``, a function call's arguments will either be all on the |
| 325 | same line or will have one line each. |
| 326 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 327 | **BinPackParameters** (``bool``) |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 328 | If ``false``, a function declaration's or function definition's |
| 329 | 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] | 330 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 331 | **BraceWrapping** (``BraceWrappingFlags``) |
| 332 | Control of individual brace wrapping cases. |
| 333 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 334 | If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how |
| 335 | each individual brace case should be handled. Otherwise, this is ignored. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 336 | |
| 337 | Nested configuration flags: |
| 338 | |
| 339 | * ``bool AfterClass`` Wrap class definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 340 | * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..). |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 341 | * ``bool AfterEnum`` Wrap enum definitions. |
| 342 | * ``bool AfterFunction`` Wrap function definitions. |
| 343 | * ``bool AfterNamespace`` Wrap namespace definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 344 | * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..). |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 345 | * ``bool AfterStruct`` Wrap struct definitions. |
| 346 | * ``bool AfterUnion`` Wrap union definitions. |
| 347 | * ``bool BeforeCatch`` Wrap before ``catch``. |
| 348 | * ``bool BeforeElse`` Wrap before ``else``. |
| 349 | * ``bool IndentBraces`` Indent the wrapped braces themselves. |
| 350 | |
| 351 | |
Daniel Jasper | 6501f7e | 2015-10-27 12:38:37 +0000 | [diff] [blame] | 352 | **BreakAfterJavaFieldAnnotations** (``bool``) |
| 353 | Break after each annotation on a field in Java files. |
| 354 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 355 | **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) |
| 356 | The way to wrap binary operators. |
| 357 | |
| 358 | Possible values: |
| 359 | |
| 360 | * ``BOS_None`` (in configuration: ``None``) |
| 361 | Break after operators. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 362 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 363 | * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) |
| 364 | Break before operators that aren't assignments. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 365 | |
Daniel Jasper | ac043c9 | 2014-09-15 11:11:00 +0000 | [diff] [blame] | 366 | * ``BOS_All`` (in configuration: ``All``) |
| 367 | Break before operators. |
| 368 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 369 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 370 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 371 | **BreakBeforeBraces** (``BraceBreakingStyle``) |
| 372 | The brace breaking style to use. |
| 373 | |
| 374 | Possible values: |
| 375 | |
| 376 | * ``BS_Attach`` (in configuration: ``Attach``) |
| 377 | Always attach braces to surrounding context. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 378 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 379 | * ``BS_Linux`` (in configuration: ``Linux``) |
| 380 | Like ``Attach``, but break before braces on function, namespace and |
| 381 | class definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 382 | |
Birunthan Mohanathas | 305fa9c | 2015-07-12 03:13:54 +0000 | [diff] [blame] | 383 | * ``BS_Mozilla`` (in configuration: ``Mozilla``) |
| 384 | Like ``Attach``, but break before braces on enum, function, and record |
| 385 | definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 386 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 387 | * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 388 | Like ``Attach``, but break before function definitions, ``catch``, and |
| 389 | ``else``. |
| 390 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 391 | * ``BS_Allman`` (in configuration: ``Allman``) |
| 392 | Always break before braces. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 393 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 394 | * ``BS_GNU`` (in configuration: ``GNU``) |
| 395 | Always break before braces and add an extra level of indentation to |
| 396 | braces of control statements, not to those of class, function |
| 397 | or other definitions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 398 | |
Roman Kashitsyn | 291f64f | 2015-08-10 13:43:19 +0000 | [diff] [blame] | 399 | * ``BS_WebKit`` (in configuration: ``WebKit``) |
| 400 | Like ``Attach``, but break before functions. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 401 | |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 402 | * ``BS_Custom`` (in configuration: ``Custom``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 403 | Configure each individual brace in `BraceWrapping`. |
| 404 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 405 | |
| 406 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 407 | **BreakBeforeTernaryOperators** (``bool``) |
| 408 | If ``true``, ternary operators will be placed after line breaks. |
| 409 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 410 | **BreakConstructorInitializersBeforeComma** (``bool``) |
| 411 | Always break constructor initializers before commas and align |
| 412 | the commas with the colon. |
| 413 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 414 | **BreakStringLiterals** (``bool``) |
| 415 | Allow breaking string literals when formatting. |
| 416 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 417 | **ColumnLimit** (``unsigned``) |
| 418 | The column limit. |
| 419 | |
| 420 | A column limit of ``0`` means that there is no column limit. In this case, |
| 421 | clang-format will respect the input's line breaking decisions within |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 422 | statements unless they contradict other rules. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 423 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 424 | **CommentPragmas** (``std::string``) |
| 425 | A regular expression that describes comments with special meaning, |
| 426 | which should not be split into lines or otherwise changed. |
| 427 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 428 | **ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) |
| 429 | If the constructor initializers don't fit on a line, put each |
| 430 | initializer on its own line. |
| 431 | |
| 432 | **ConstructorInitializerIndentWidth** (``unsigned``) |
| 433 | The number of characters to use for indentation of constructor |
| 434 | initializer lists. |
| 435 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 436 | **ContinuationIndentWidth** (``unsigned``) |
| 437 | Indent width for line continuations. |
| 438 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 439 | **Cpp11BracedListStyle** (``bool``) |
| 440 | If ``true``, format braced lists as best suited for C++11 braced |
| 441 | lists. |
| 442 | |
| 443 | Important differences: |
| 444 | - No spaces inside the braced list. |
| 445 | - No line break before the closing brace. |
| 446 | - Indentation with the continuation indent, not with the block indent. |
| 447 | |
| 448 | Fundamentally, C++11 braced lists are formatted exactly like function |
| 449 | calls would be formatted in their place. If the braced list follows a name |
| 450 | (e.g. a type or variable name), clang-format formats as if the ``{}`` were |
| 451 | the parentheses of a function call with that name. If there is no name, |
| 452 | a zero-length name is assumed. |
| 453 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 454 | **DerivePointerAlignment** (``bool``) |
| 455 | If ``true``, analyze the formatted file for the most common |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 456 | alignment of ``&`` and ``\*``. ``PointerAlignment`` is then used only as |
| 457 | fallback. |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 458 | |
| 459 | **DisableFormat** (``bool``) |
Birunthan Mohanathas | b744e72 | 2015-06-27 09:25:28 +0000 | [diff] [blame] | 460 | Disables formatting completely. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 461 | |
| 462 | **ExperimentalAutoDetectBinPacking** (``bool``) |
| 463 | If ``true``, clang-format detects whether function calls and |
| 464 | definitions are formatted with one parameter per line. |
| 465 | |
| 466 | Each call can be bin-packed, one-per-line or inconclusive. If it is |
| 467 | inconclusive, e.g. completely on one line, but a decision needs to be |
| 468 | made, clang-format analyzes whether there are other bin-packed cases in |
| 469 | the input file and act accordingly. |
| 470 | |
| 471 | NOTE: This is an experimental flag, that might go away or be renamed. Do |
| 472 | not use this in config files, etc. Use at your own risk. |
| 473 | |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 474 | **ForEachMacros** (``std::vector<std::string>``) |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 475 | A vector of macros that should be interpreted as foreach loops |
| 476 | instead of as function calls. |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 477 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 478 | These are expected to be macros of the form: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 479 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 480 | .. code-block:: c++ |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 481 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 482 | FOREACH(<variable-declaration>, ...) |
| 483 | <loop-body> |
| 484 | |
| 485 | In the .clang-format configuration file, this can be configured like: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 486 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 487 | .. code-block:: yaml |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 488 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 489 | ForEachMacros: ['RANGES_FOR', 'FOREACH'] |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 490 | |
| 491 | For example: BOOST_FOREACH. |
Daniel Jasper | e1e4319 | 2014-04-01 12:55:11 +0000 | [diff] [blame] | 492 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 493 | **IncludeCategories** (``std::vector<IncludeCategory>``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 494 | Regular expressions denoting the different ``#include`` categories |
| 495 | used for ordering ``#includes``. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 496 | |
| 497 | These regular expressions are matched against the filename of an include |
| 498 | (including the <> or "") in order. The value belonging to the first |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 499 | matching regular expression is assigned and ``#includes`` are sorted first |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 500 | according to increasing category number and then alphabetically within |
| 501 | each category. |
| 502 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 503 | If none of the regular expressions match, INT_MAX is assigned as |
| 504 | category. The main header for a source file automatically gets category 0. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 505 | so that it is generally kept at the beginning of the ``#includes`` |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 506 | (http://llvm.org/docs/CodingStandards.html#include-style). However, you |
| 507 | can also assign negative priorities if you have certain headers that |
| 508 | always need to be first. |
Daniel Jasper | c1bc38e | 2015-09-29 14:57:55 +0000 | [diff] [blame] | 509 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 510 | To configure this in the .clang-format file, use: |
Daniel Jasper | b5bda7c | 2015-10-06 12:11:51 +0000 | [diff] [blame] | 511 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 512 | .. code-block:: yaml |
Daniel Jasper | 8e1ecca | 2015-10-07 13:02:45 +0000 | [diff] [blame] | 513 | |
Daniel Jasper | 8ce1b8d | 2015-10-06 11:54:18 +0000 | [diff] [blame] | 514 | IncludeCategories: |
| 515 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' |
| 516 | Priority: 2 |
| 517 | - Regex: '^(<|"(gtest|isl|json)/)' |
| 518 | Priority: 3 |
| 519 | - Regex: '.\*' |
| 520 | Priority: 1 |
| 521 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 522 | **IndentCaseLabels** (``bool``) |
| 523 | Indent case labels one level from the switch statement. |
| 524 | |
| 525 | When ``false``, use the same indentation level as for the switch statement. |
| 526 | Switch statement body is always indented one level more than case labels. |
| 527 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 528 | **IndentWidth** (``unsigned``) |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 529 | The number of columns to use for indentation. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 530 | |
Daniel Jasper | c75e1ef | 2014-07-09 08:42:42 +0000 | [diff] [blame] | 531 | **IndentWrappedFunctionNames** (``bool``) |
| 532 | Indent if a function definition or declaration is wrapped after the |
| 533 | type. |
| 534 | |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 535 | **KeepEmptyLinesAtTheStartOfBlocks** (``bool``) |
| 536 | If true, empty lines at the start of blocks are kept. |
| 537 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 538 | **Language** (``LanguageKind``) |
| 539 | Language, this format style is targeted at. |
| 540 | |
| 541 | Possible values: |
| 542 | |
| 543 | * ``LK_None`` (in configuration: ``None``) |
| 544 | Do not use. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 545 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 546 | * ``LK_Cpp`` (in configuration: ``Cpp``) |
| 547 | Should be used for C, C++, ObjectiveC, ObjectiveC++. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 548 | |
Daniel Jasper | 18210d7 | 2014-10-09 09:52:05 +0000 | [diff] [blame] | 549 | * ``LK_Java`` (in configuration: ``Java``) |
| 550 | Should be used for Java. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 551 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 552 | * ``LK_JavaScript`` (in configuration: ``JavaScript``) |
| 553 | Should be used for JavaScript. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 554 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 555 | * ``LK_Proto`` (in configuration: ``Proto``) |
| 556 | Should be used for Protocol Buffers |
| 557 | (https://developers.google.com/protocol-buffers/). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 558 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 559 | * ``LK_TableGen`` (in configuration: ``TableGen``) |
| 560 | Should be used for TableGen code. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 561 | |
| 562 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 563 | |
Birunthan Mohanathas | b001a0b | 2015-07-03 17:25:16 +0000 | [diff] [blame] | 564 | **MacroBlockBegin** (``std::string``) |
| 565 | A regular expression matching macros that start a block. |
| 566 | |
| 567 | **MacroBlockEnd** (``std::string``) |
| 568 | A regular expression matching macros that end a block. |
| 569 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 570 | **MaxEmptyLinesToKeep** (``unsigned``) |
| 571 | The maximum number of consecutive empty lines to keep. |
| 572 | |
| 573 | **NamespaceIndentation** (``NamespaceIndentationKind``) |
| 574 | The indentation used for namespaces. |
| 575 | |
| 576 | Possible values: |
| 577 | |
| 578 | * ``NI_None`` (in configuration: ``None``) |
| 579 | Don't indent in namespaces. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 580 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 581 | * ``NI_Inner`` (in configuration: ``Inner``) |
| 582 | Indent only in inner namespaces (nested in other namespaces). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 583 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 584 | * ``NI_All`` (in configuration: ``All``) |
| 585 | Indent in all namespaces. |
| 586 | |
| 587 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 588 | |
Daniel Jasper | eb2226e | 2014-10-28 16:56:37 +0000 | [diff] [blame] | 589 | **ObjCBlockIndentWidth** (``unsigned``) |
| 590 | The number of characters to use for indentation of ObjC blocks. |
| 591 | |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 592 | **ObjCSpaceAfterProperty** (``bool``) |
| 593 | Add a space after ``@property`` in Objective-C, i.e. use |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 594 | ``@property (readonly)`` instead of ``@property(readonly)``. |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 595 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 596 | **ObjCSpaceBeforeProtocolList** (``bool``) |
| 597 | Add a space in front of an Objective-C protocol list, i.e. use |
| 598 | ``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
| 599 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 600 | **PenaltyBreakBeforeFirstCallParameter** (``unsigned``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 601 | The penalty for breaking a function call after ``call(``. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 602 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 603 | **PenaltyBreakComment** (``unsigned``) |
| 604 | The penalty for each line break introduced inside a comment. |
| 605 | |
| 606 | **PenaltyBreakFirstLessLess** (``unsigned``) |
| 607 | The penalty for breaking before the first ``<<``. |
| 608 | |
| 609 | **PenaltyBreakString** (``unsigned``) |
| 610 | The penalty for each line break introduced inside a string literal. |
| 611 | |
| 612 | **PenaltyExcessCharacter** (``unsigned``) |
| 613 | The penalty for each character outside of the column limit. |
| 614 | |
| 615 | **PenaltyReturnTypeOnItsOwnLine** (``unsigned``) |
| 616 | Penalty for putting the return type of a function onto its own |
| 617 | line. |
| 618 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 619 | **PointerAlignment** (``PointerAlignmentStyle``) |
| 620 | Pointer and reference alignment style. |
| 621 | |
| 622 | Possible values: |
| 623 | |
| 624 | * ``PAS_Left`` (in configuration: ``Left``) |
| 625 | Align pointer to the left. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 626 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 627 | * ``PAS_Right`` (in configuration: ``Right``) |
| 628 | Align pointer to the right. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 629 | |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 630 | * ``PAS_Middle`` (in configuration: ``Middle``) |
| 631 | Align pointer in the middle. |
| 632 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 633 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 634 | |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 635 | **ReflowComments** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 636 | If ``true``, clang-format will attempt to re-flow comments. |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 637 | |
| 638 | **SortIncludes** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 639 | If ``true``, clang-format will sort ``#includes``. |
Alexander Kornienko | 1e04823 | 2016-02-23 16:11:51 +0000 | [diff] [blame] | 640 | |
Daniel Jasper | b87899b | 2014-09-10 13:11:45 +0000 | [diff] [blame] | 641 | **SpaceAfterCStyleCast** (``bool``) |
| 642 | If ``true``, a space may be inserted after C style casts. |
| 643 | |
Daniel Jasper | d94bff3 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 644 | **SpaceBeforeAssignmentOperators** (``bool``) |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 645 | If ``false``, spaces will be removed before assignment operators. |
Daniel Jasper | d94bff3 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 646 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 647 | **SpaceBeforeParens** (``SpaceBeforeParensOptions``) |
| 648 | Defines in which cases to put a space before opening parentheses. |
| 649 | |
| 650 | Possible values: |
| 651 | |
| 652 | * ``SBPO_Never`` (in configuration: ``Never``) |
| 653 | Never put a space before opening parentheses. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 654 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 655 | * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) |
| 656 | Put a space before opening parentheses only after control statement |
| 657 | keywords (``for/if/while...``). |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 658 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 659 | * ``SBPO_Always`` (in configuration: ``Always``) |
| 660 | Always put a space before opening parentheses, except when it's |
| 661 | prohibited by the syntax rules (in function-like macro definitions) or |
| 662 | when determined by other style rules (after unary operators, opening |
| 663 | parentheses, etc.) |
| 664 | |
| 665 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 666 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 667 | **SpaceInEmptyParentheses** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 668 | If ``true``, spaces may be inserted into ``()``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 669 | |
| 670 | **SpacesBeforeTrailingComments** (``unsigned``) |
Daniel Jasper | c0be760 | 2014-05-15 13:55:19 +0000 | [diff] [blame] | 671 | The number of spaces before trailing line comments |
| 672 | (``//`` - comments). |
Daniel Jasper | b552482 | 2014-04-09 14:05:49 +0000 | [diff] [blame] | 673 | |
Alexander Kornienko | 70f97c9 | 2016-02-27 14:02:08 +0000 | [diff] [blame^] | 674 | This does not affect trailing block comments (``/*`` - comments) as |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 675 | those commonly have different usage patterns and a number of special |
| 676 | cases. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 677 | |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 678 | **SpacesInAngles** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 679 | If ``true``, spaces will be inserted after ``<`` and before ``>`` |
| 680 | in template argument lists. |
Alexander Kornienko | fdca83d | 2013-12-10 10:18:34 +0000 | [diff] [blame] | 681 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 682 | **SpacesInCStyleCastParentheses** (``bool``) |
Daniel Jasper | ee107ad | 2014-02-13 12:51:50 +0000 | [diff] [blame] | 683 | If ``true``, spaces may be inserted into C style casts. |
| 684 | |
| 685 | **SpacesInContainerLiterals** (``bool``) |
| 686 | If ``true``, spaces are inserted inside container literals (e.g. |
| 687 | ObjC and Javascript array and dict literals). |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 688 | |
| 689 | **SpacesInParentheses** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 690 | If ``true``, spaces will be inserted after ``(`` and before ``)``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 691 | |
Daniel Jasper | ad981f8 | 2014-08-26 11:41:14 +0000 | [diff] [blame] | 692 | **SpacesInSquareBrackets** (``bool``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 693 | If ``true``, spaces will be inserted after ``[`` and before ``]``. |
Daniel Jasper | ad981f8 | 2014-08-26 11:41:14 +0000 | [diff] [blame] | 694 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 695 | **Standard** (``LanguageStandard``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 696 | Format compatible with this standard, e.g. use ``A<A<int> >`` |
| 697 | instead of ``A<A<int>>`` for ``LS_Cpp03``. |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 698 | |
| 699 | Possible values: |
| 700 | |
| 701 | * ``LS_Cpp03`` (in configuration: ``Cpp03``) |
| 702 | Use C++03-compatible syntax. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 703 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 704 | * ``LS_Cpp11`` (in configuration: ``Cpp11``) |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 705 | Use features of C++11 (e.g. ``A<A<int>>`` instead of ``A<A<int> >``). |
| 706 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 707 | * ``LS_Auto`` (in configuration: ``Auto``) |
| 708 | Automatic detection based on the input. |
| 709 | |
| 710 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 711 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 712 | **TabWidth** (``unsigned``) |
| 713 | The number of columns used for tab stops. |
| 714 | |
| 715 | **UseTab** (``UseTabStyle``) |
| 716 | The way to use tab characters in the resulting file. |
| 717 | |
| 718 | Possible values: |
| 719 | |
| 720 | * ``UT_Never`` (in configuration: ``Never``) |
| 721 | Never use tab. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 722 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 723 | * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) |
| 724 | Use tabs only for indentation. |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 725 | |
Alexander Kornienko | 45ca09b | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 726 | * ``UT_Always`` (in configuration: ``Always``) |
| 727 | Use tabs whenever we need to fill whitespace that spans at least from |
| 728 | one tab stop to the next one. |
| 729 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 730 | |
Alexander Kornienko | b00a7d2 | 2016-02-23 16:12:00 +0000 | [diff] [blame] | 731 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 732 | .. END_FORMAT_STYLE_OPTIONS |
| 733 | |
Daniel Jasper | 49d3d58 | 2015-10-05 07:24:55 +0000 | [diff] [blame] | 734 | Adding additional style options |
| 735 | =============================== |
| 736 | |
| 737 | 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] | 738 | 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] | 739 | sure that any given combination of options work and that new features don't |
| 740 | break any of the existing options in any way. There are also costs for end users |
| 741 | as options become less discoverable and people have to think about and make a |
| 742 | decision on options they don't really care about. |
| 743 | |
| 744 | The goal of the clang-format project is more on the side of supporting a |
| 745 | limited set of styles really well as opposed to supporting every single style |
| 746 | used by a codebase somewhere in the wild. Of course, we do want to support all |
| 747 | major projects and thus have established the following bar for adding style |
| 748 | options. Each new style option must .. |
| 749 | |
Daniel Jasper | fcbea71 | 2015-10-05 13:30:42 +0000 | [diff] [blame] | 750 | * be used in a project of significant size (have dozens of contributors) |
| 751 | * have a publicly accessible style guide |
| 752 | * have a person willing to contribute and maintain patches |
Daniel Jasper | 49d3d58 | 2015-10-05 07:24:55 +0000 | [diff] [blame] | 753 | |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 754 | Examples |
| 755 | ======== |
| 756 | |
| 757 | A style similar to the `Linux Kernel style |
| 758 | <https://www.kernel.org/doc/Documentation/CodingStyle>`_: |
| 759 | |
| 760 | .. code-block:: yaml |
| 761 | |
| 762 | BasedOnStyle: LLVM |
| 763 | IndentWidth: 8 |
Alexander Kornienko | 8ba68f6 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 764 | UseTab: Always |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 765 | BreakBeforeBraces: Linux |
| 766 | AllowShortIfStatementsOnASingleLine: false |
| 767 | IndentCaseLabels: false |
| 768 | |
| 769 | The result is (imagine that tabs are used for indentation here): |
| 770 | |
| 771 | .. code-block:: c++ |
| 772 | |
| 773 | void test() |
| 774 | { |
| 775 | switch (x) { |
| 776 | case 0: |
| 777 | case 1: |
| 778 | do_something(); |
| 779 | break; |
| 780 | case 2: |
| 781 | do_something_else(); |
| 782 | break; |
| 783 | default: |
| 784 | break; |
| 785 | } |
| 786 | if (condition) |
| 787 | do_something_completely_different(); |
| 788 | |
| 789 | if (x == y) { |
| 790 | q(); |
| 791 | } else if (x > y) { |
| 792 | w(); |
| 793 | } else { |
| 794 | r(); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | A style similar to the default Visual Studio formatting style: |
| 799 | |
| 800 | .. code-block:: yaml |
| 801 | |
Alexander Kornienko | 8ba68f6 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 802 | UseTab: Never |
Alexander Kornienko | d278e0e | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 803 | IndentWidth: 4 |
| 804 | BreakBeforeBraces: Allman |
| 805 | AllowShortIfStatementsOnASingleLine: false |
| 806 | IndentCaseLabels: false |
| 807 | ColumnLimit: 0 |
| 808 | |
| 809 | The result is: |
| 810 | |
| 811 | .. code-block:: c++ |
| 812 | |
| 813 | void test() |
| 814 | { |
| 815 | switch (suffix) |
| 816 | { |
| 817 | case 0: |
| 818 | case 1: |
| 819 | do_something(); |
| 820 | break; |
| 821 | case 2: |
| 822 | do_something_else(); |
| 823 | break; |
| 824 | default: |
| 825 | break; |
| 826 | } |
| 827 | if (condition) |
| 828 | do_somthing_completely_different(); |
| 829 | |
| 830 | if (x == y) |
| 831 | { |
| 832 | q(); |
| 833 | } |
| 834 | else if (x > y) |
| 835 | { |
| 836 | w(); |
| 837 | } |
| 838 | else |
| 839 | { |
| 840 | r(); |
| 841 | } |
| 842 | } |
| 843 | |