blob: fd14d90ff537fe39bc7514922a1c90dcd44d34b8 [file] [log] [blame]
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
10the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
11custom style by configuring specific style options.
12
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
Hans Wennborg9f6581b2013-09-10 15:41:12 +000019use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000021
22When using ``-style=file``, :program:`clang-format` for each input file will
23try to find the ``.clang-format`` file located in the closest parent directory
24of the input file. When the standard input is used, the search is started from
25the current directory.
26
27The ``.clang-format`` file uses YAML format:
28
29.. code-block:: yaml
30
31 key1: value1
32 key2: value2
33 # A comment.
34 ...
35
Alexander Kornienko092cb212014-08-12 13:34:22 +000036The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An 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 Kornienkod278e0e2013-09-04 15:09:13 +000073An easy way to get a valid ``.clang-format`` file containing all configuration
74options of a certain predefined style is:
75
76.. code-block:: console
77
78 clang-format -style=llvm -dump-config > .clang-format
79
80When specifying configuration in the ``-style=`` option, the same configuration
81is 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 Jasperd8b4ec02014-10-07 12:15:15 +000088Disabling Formatting on a Piece of Code
89=======================================
90
91Clang-format understands also special comments that switch formatting in a
92delimited 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
95will 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 Kornienkod278e0e2013-09-04 15:09:13 +0000106Configuring Style in Code
107=========================
108
109When using ``clang::format::reformat(...)`` functions, the format is specified
110by supplying the `clang::format::FormatStyle
111<http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
112structure.
113
114
115Configurable Format Style Options
116=================================
117
118This section lists the supported style options. Value type is specified for
119each option. For enumeration types possible values are specified both as a C++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000120enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
121the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000122
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``)
151 The extra indent or outdent of access modifiers, e.g. ``public:``.
152
Daniel Jasper3219e432014-12-02 13:24:51 +0000153**AlignAfterOpenBracket** (``bool``)
154 If ``true``, horizontally aligns arguments after an open bracket.
155
156 This applies to round brackets (parentheses), angle brackets and square
157 brackets. This will result in formattings like
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000158 .. code-block:: c++
159 someLongFunction(argument1,
160 argument2);
Daniel Jasper3219e432014-12-02 13:24:51 +0000161
Daniel Jaspera44991332015-04-29 13:06:49 +0000162**AlignConsecutiveAssignments** (``bool``)
163 If ``true``, aligns consecutive assignments.
164
165 This will align the assignment operators of consecutive lines. This
166 will result in formattings like
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000167 .. code-block:: c++
168 int aaaa = 12;
169 int b = 23;
170 int ccc = 23;
171
172**AlignConsecutiveDeclarations** (``bool``)
173 If ``true``, aligns consecutive declarations.
174
175 This will align the declaration names of consecutive lines. This
176 will result in formattings like
177 .. code-block:: c++
178 int aaaa = 12;
179 float b = 23;
180 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000181
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000182**AlignEscapedNewlinesLeft** (``bool``)
183 If ``true``, aligns escaped newlines as far left as possible.
184 Otherwise puts them into the right-most column.
185
Daniel Jasper3219e432014-12-02 13:24:51 +0000186**AlignOperands** (``bool``)
187 If ``true``, horizontally align operands of binary and ternary
188 expressions.
189
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000190**AlignTrailingComments** (``bool``)
191 If ``true``, aligns trailing comments.
192
193**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
194 Allow putting all parameters of a function declaration onto
195 the next line even if ``BinPackParameters`` is ``false``.
196
Daniel Jasper17605d32014-05-14 09:33:35 +0000197**AllowShortBlocksOnASingleLine** (``bool``)
198 Allows contracting simple braced statements to a single line.
199
200 E.g., this allows ``if (a) { return; }`` to be put on a single line.
201
Daniel Jasperb87899b2014-09-10 13:11:45 +0000202**AllowShortCaseLabelsOnASingleLine** (``bool``)
203 If ``true``, short case labels will be contracted to a single line.
204
Daniel Jasperb5524822014-04-09 14:05:49 +0000205**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
206 Dependent on the value, ``int f() { return 0; }`` can be put
207 on a single line.
208
209 Possible values:
210
211 * ``SFS_None`` (in configuration: ``None``)
212 Never merge functions into a single line.
Daniel Jasper3219e432014-12-02 13:24:51 +0000213 * ``SFS_Empty`` (in configuration: ``Empty``)
214 Only merge empty functions.
Daniel Jasper20580fd2015-06-11 13:31:45 +0000215 * ``SFS_Inline`` (in configuration: ``Inline``)
216 Only merge functions defined inside a class. Implies "empty".
Daniel Jasperb5524822014-04-09 14:05:49 +0000217 * ``SFS_All`` (in configuration: ``All``)
218 Merge all functions fitting on a single line.
219
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000220
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000221**AllowShortIfStatementsOnASingleLine** (``bool``)
222 If ``true``, ``if (a) return;`` can be put on a single
223 line.
224
225**AllowShortLoopsOnASingleLine** (``bool``)
226 If ``true``, ``while (true) continue;`` can be put on a
227 single line.
228
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000229**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
230 The function definition return type breaking style to use.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000231
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000232 Possible values:
233
234 * ``DRTBS_None`` (in configuration: ``None``)
235 Break after return type automatically.
236 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
237 * ``DRTBS_All`` (in configuration: ``All``)
238 Always break after the return type.
239 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
240 Always break after the return types of top level functions.
241
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000242
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000243**AlwaysBreakBeforeMultilineStrings** (``bool``)
244 If ``true``, always break before multiline string literals.
245
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000246 This flag is mean to make cases where there are multiple multiline strings
247 in a file look more consistent. Thus, it will only take effect if wrapping
248 the string at that point leads to it being indented
249 ``ContinuationIndentWidth`` spaces from the start of the line.
250
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000251**AlwaysBreakTemplateDeclarations** (``bool``)
252 If ``true``, always break after the ``template<...>`` of a
253 template declaration.
254
Daniel Jasper18210d72014-10-09 09:52:05 +0000255**BinPackArguments** (``bool``)
256 If ``false``, a function call's arguments will either be all on the
257 same line or will have one line each.
258
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000259**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000260 If ``false``, a function declaration's or function definition's
261 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000262
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000263**BraceWrapping** (``BraceWrappingFlags``)
264 Control of individual brace wrapping cases.
265
266 If ``BreakBeforeBraces`` is set to ``custom``, use this to specify how each
267 individual brace case should be handled. Otherwise, this is ignored.
268
269 Nested configuration flags:
270
271 * ``bool AfterClass`` Wrap class definitions.
272 * ``bool AfterControlStatement`` Wrap control statements (if/for/while/switch/..).
273 * ``bool AfterEnum`` Wrap enum definitions.
274 * ``bool AfterFunction`` Wrap function definitions.
275 * ``bool AfterNamespace`` Wrap namespace definitions.
276 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (@autoreleasepool, interfaces, ..).
277 * ``bool AfterStruct`` Wrap struct definitions.
278 * ``bool AfterUnion`` Wrap union definitions.
279 * ``bool BeforeCatch`` Wrap before ``catch``.
280 * ``bool BeforeElse`` Wrap before ``else``.
281 * ``bool IndentBraces`` Indent the wrapped braces themselves.
282
283
Daniel Jasperac043c92014-09-15 11:11:00 +0000284**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
285 The way to wrap binary operators.
286
287 Possible values:
288
289 * ``BOS_None`` (in configuration: ``None``)
290 Break after operators.
291 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
292 Break before operators that aren't assignments.
293 * ``BOS_All`` (in configuration: ``All``)
294 Break before operators.
295
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000296
297**BreakBeforeBraces** (``BraceBreakingStyle``)
298 The brace breaking style to use.
299
300 Possible values:
301
302 * ``BS_Attach`` (in configuration: ``Attach``)
303 Always attach braces to surrounding context.
304 * ``BS_Linux`` (in configuration: ``Linux``)
305 Like ``Attach``, but break before braces on function, namespace and
306 class definitions.
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000307 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
308 Like ``Attach``, but break before braces on enum, function, and record
309 definitions.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000310 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Roman Kashitsyn291f64f2015-08-10 13:43:19 +0000311 Like ``Attach``, but break before function definitions, 'catch', and 'else'.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000312 * ``BS_Allman`` (in configuration: ``Allman``)
313 Always break before braces.
Daniel Jasperee107ad2014-02-13 12:51:50 +0000314 * ``BS_GNU`` (in configuration: ``GNU``)
315 Always break before braces and add an extra level of indentation to
316 braces of control statements, not to those of class, function
317 or other definitions.
Roman Kashitsyn291f64f2015-08-10 13:43:19 +0000318 * ``BS_WebKit`` (in configuration: ``WebKit``)
319 Like ``Attach``, but break before functions.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000320 * ``BS_Custom`` (in configuration: ``Custom``)
321 Configure each individual brace in ``BraceWrapping``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000322
323
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000324**BreakBeforeTernaryOperators** (``bool``)
325 If ``true``, ternary operators will be placed after line breaks.
326
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000327**BreakConstructorInitializersBeforeComma** (``bool``)
328 Always break constructor initializers before commas and align
329 the commas with the colon.
330
331**ColumnLimit** (``unsigned``)
332 The column limit.
333
334 A column limit of ``0`` means that there is no column limit. In this case,
335 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000336 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000337
Daniel Jasperee107ad2014-02-13 12:51:50 +0000338**CommentPragmas** (``std::string``)
339 A regular expression that describes comments with special meaning,
340 which should not be split into lines or otherwise changed.
341
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000342**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
343 If the constructor initializers don't fit on a line, put each
344 initializer on its own line.
345
346**ConstructorInitializerIndentWidth** (``unsigned``)
347 The number of characters to use for indentation of constructor
348 initializer lists.
349
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000350**ContinuationIndentWidth** (``unsigned``)
351 Indent width for line continuations.
352
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000353**Cpp11BracedListStyle** (``bool``)
354 If ``true``, format braced lists as best suited for C++11 braced
355 lists.
356
357 Important differences:
358 - No spaces inside the braced list.
359 - No line break before the closing brace.
360 - Indentation with the continuation indent, not with the block indent.
361
362 Fundamentally, C++11 braced lists are formatted exactly like function
363 calls would be formatted in their place. If the braced list follows a name
364 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
365 the parentheses of a function call with that name. If there is no name,
366 a zero-length name is assumed.
367
Daniel Jasper553d4872014-06-17 12:40:34 +0000368**DerivePointerAlignment** (``bool``)
369 If ``true``, analyze the formatted file for the most common
Daniel Jasper7f432662014-12-02 14:21:16 +0000370 alignment of & and \*. ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +0000371
372**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +0000373 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000374
375**ExperimentalAutoDetectBinPacking** (``bool``)
376 If ``true``, clang-format detects whether function calls and
377 definitions are formatted with one parameter per line.
378
379 Each call can be bin-packed, one-per-line or inconclusive. If it is
380 inconclusive, e.g. completely on one line, but a decision needs to be
381 made, clang-format analyzes whether there are other bin-packed cases in
382 the input file and act accordingly.
383
384 NOTE: This is an experimental flag, that might go away or be renamed. Do
385 not use this in config files, etc. Use at your own risk.
386
Daniel Jaspere1e43192014-04-01 12:55:11 +0000387**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +0000388 A vector of macros that should be interpreted as foreach loops
389 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +0000390
Daniel Jasperb5524822014-04-09 14:05:49 +0000391 These are expected to be macros of the form:
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000392 .. code-block:: c++
393 FOREACH(<variable-declaration>, ...)
394 <loop-body>
395
396 In the .clang-format configuration file, this can be configured like:
397 .. code-block:: c++
398 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +0000399
400 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +0000401
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000402**IncludeCategories** (``std::vector<IncludeCategory>``)
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000403 Regular expressions denoting the different #include categories used
404 for ordering #includes.
405
406 These regular expressions are matched against the filename of an include
407 (including the <> or "") in order. The value belonging to the first
408 matching regular expression is assigned and #includes are sorted first
409 according to increasing category number and then alphabetically within
410 each category.
411
412 If none of the regular expressions match, UINT_MAX is assigned as
413 category. The main header for a source file automatically gets category 0,
414 so that it is kept at the beginning of the #includes
415 (http://llvm.org/docs/CodingStandards.html#include-style).
416
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000417 To configure this in the .clang-format file, use:
418 .. code-block:: c++
419 IncludeCategories:
420 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
421 Priority: 2
422 - Regex: '^(<|"(gtest|isl|json)/)'
423 Priority: 3
424 - Regex: '.\*'
425 Priority: 1
426
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000427**IndentCaseLabels** (``bool``)
428 Indent case labels one level from the switch statement.
429
430 When ``false``, use the same indentation level as for the switch statement.
431 Switch statement body is always indented one level more than case labels.
432
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000433**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +0000434 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000435
Daniel Jasperc75e1ef2014-07-09 08:42:42 +0000436**IndentWrappedFunctionNames** (``bool``)
437 Indent if a function definition or declaration is wrapped after the
438 type.
439
Daniel Jasperb5524822014-04-09 14:05:49 +0000440**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
441 If true, empty lines at the start of blocks are kept.
442
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000443**Language** (``LanguageKind``)
444 Language, this format style is targeted at.
445
446 Possible values:
447
448 * ``LK_None`` (in configuration: ``None``)
449 Do not use.
450 * ``LK_Cpp`` (in configuration: ``Cpp``)
451 Should be used for C, C++, ObjectiveC, ObjectiveC++.
Daniel Jasper18210d72014-10-09 09:52:05 +0000452 * ``LK_Java`` (in configuration: ``Java``)
453 Should be used for Java.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000454 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
455 Should be used for JavaScript.
Daniel Jasperee107ad2014-02-13 12:51:50 +0000456 * ``LK_Proto`` (in configuration: ``Proto``)
457 Should be used for Protocol Buffers
458 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000459
460
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +0000461**MacroBlockBegin** (``std::string``)
462 A regular expression matching macros that start a block.
463
464**MacroBlockEnd** (``std::string``)
465 A regular expression matching macros that end a block.
466
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000467**MaxEmptyLinesToKeep** (``unsigned``)
468 The maximum number of consecutive empty lines to keep.
469
470**NamespaceIndentation** (``NamespaceIndentationKind``)
471 The indentation used for namespaces.
472
473 Possible values:
474
475 * ``NI_None`` (in configuration: ``None``)
476 Don't indent in namespaces.
477 * ``NI_Inner`` (in configuration: ``Inner``)
478 Indent only in inner namespaces (nested in other namespaces).
479 * ``NI_All`` (in configuration: ``All``)
480 Indent in all namespaces.
481
482
Daniel Jaspereb2226e2014-10-28 16:56:37 +0000483**ObjCBlockIndentWidth** (``unsigned``)
484 The number of characters to use for indentation of ObjC blocks.
485
Daniel Jasperee107ad2014-02-13 12:51:50 +0000486**ObjCSpaceAfterProperty** (``bool``)
487 Add a space after ``@property`` in Objective-C, i.e. use
Daniel Jasper17605d32014-05-14 09:33:35 +0000488 ``\@property (readonly)`` instead of ``\@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +0000489
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000490**ObjCSpaceBeforeProtocolList** (``bool``)
491 Add a space in front of an Objective-C protocol list, i.e. use
492 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
493
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000494**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
495 The penalty for breaking a function call after "call(".
496
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000497**PenaltyBreakComment** (``unsigned``)
498 The penalty for each line break introduced inside a comment.
499
500**PenaltyBreakFirstLessLess** (``unsigned``)
501 The penalty for breaking before the first ``<<``.
502
503**PenaltyBreakString** (``unsigned``)
504 The penalty for each line break introduced inside a string literal.
505
506**PenaltyExcessCharacter** (``unsigned``)
507 The penalty for each character outside of the column limit.
508
509**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
510 Penalty for putting the return type of a function onto its own
511 line.
512
Daniel Jasper553d4872014-06-17 12:40:34 +0000513**PointerAlignment** (``PointerAlignmentStyle``)
514 Pointer and reference alignment style.
515
516 Possible values:
517
518 * ``PAS_Left`` (in configuration: ``Left``)
519 Align pointer to the left.
520 * ``PAS_Right`` (in configuration: ``Right``)
521 Align pointer to the right.
522 * ``PAS_Middle`` (in configuration: ``Middle``)
523 Align pointer in the middle.
524
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000525
Daniel Jasperb87899b2014-09-10 13:11:45 +0000526**SpaceAfterCStyleCast** (``bool``)
527 If ``true``, a space may be inserted after C style casts.
528
Daniel Jasperd94bff32013-09-25 15:15:02 +0000529**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +0000530 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +0000531
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000532**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
533 Defines in which cases to put a space before opening parentheses.
534
535 Possible values:
536
537 * ``SBPO_Never`` (in configuration: ``Never``)
538 Never put a space before opening parentheses.
539 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
540 Put a space before opening parentheses only after control statement
541 keywords (``for/if/while...``).
542 * ``SBPO_Always`` (in configuration: ``Always``)
543 Always put a space before opening parentheses, except when it's
544 prohibited by the syntax rules (in function-like macro definitions) or
545 when determined by other style rules (after unary operators, opening
546 parentheses, etc.)
547
548
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000549**SpaceInEmptyParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +0000550 If ``true``, spaces may be inserted into '()'.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000551
552**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +0000553 The number of spaces before trailing line comments
554 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +0000555
Daniel Jasperc0be7602014-05-15 13:55:19 +0000556 This does not affect trailing block comments (``/**/`` - comments) as those
Daniel Jasperb5524822014-04-09 14:05:49 +0000557 commonly have different usage patterns and a number of special cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000558
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000559**SpacesInAngles** (``bool``)
560 If ``true``, spaces will be inserted after '<' and before '>' in
561 template argument lists
562
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000563**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +0000564 If ``true``, spaces may be inserted into C style casts.
565
566**SpacesInContainerLiterals** (``bool``)
567 If ``true``, spaces are inserted inside container literals (e.g.
568 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000569
570**SpacesInParentheses** (``bool``)
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000571 If ``true``, spaces will be inserted after '(' and before ')'.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000572
Daniel Jasperad981f82014-08-26 11:41:14 +0000573**SpacesInSquareBrackets** (``bool``)
Daniel Jasperb87899b2014-09-10 13:11:45 +0000574 If ``true``, spaces will be inserted after '[' and before ']'.
Daniel Jasperad981f82014-08-26 11:41:14 +0000575
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000576**Standard** (``LanguageStandard``)
577 Format compatible with this standard, e.g. use
578 ``A<A<int> >`` instead of ``A<A<int>>`` for LS_Cpp03.
579
580 Possible values:
581
582 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
583 Use C++03-compatible syntax.
584 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
585 Use features of C++11 (e.g. ``A<A<int>>`` instead of
586 ``A<A<int> >``).
587 * ``LS_Auto`` (in configuration: ``Auto``)
588 Automatic detection based on the input.
589
590
Alexander Kornienko45ca09b2013-09-27 16:16:55 +0000591**TabWidth** (``unsigned``)
592 The number of columns used for tab stops.
593
594**UseTab** (``UseTabStyle``)
595 The way to use tab characters in the resulting file.
596
597 Possible values:
598
599 * ``UT_Never`` (in configuration: ``Never``)
600 Never use tab.
601 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
602 Use tabs only for indentation.
603 * ``UT_Always`` (in configuration: ``Always``)
604 Use tabs whenever we need to fill whitespace that spans at least from
605 one tab stop to the next one.
606
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000607
608.. END_FORMAT_STYLE_OPTIONS
609
Daniel Jasper49d3d582015-10-05 07:24:55 +0000610Adding additional style options
611===============================
612
613Each additional style option adds costs to the clang-format project. Some of
614these costs affect the clang-format developement itself, as we need to make
615sure that any given combination of options work and that new features don't
616break any of the existing options in any way. There are also costs for end users
617as options become less discoverable and people have to think about and make a
618decision on options they don't really care about.
619
620The goal of the clang-format project is more on the side of supporting a
621limited set of styles really well as opposed to supporting every single style
622used by a codebase somewhere in the wild. Of course, we do want to support all
623major projects and thus have established the following bar for adding style
624options. Each new style option must ..
625
Daniel Jasperfcbea712015-10-05 13:30:42 +0000626 * be used in a project of significant size (have dozens of contributors)
627 * have a publicly accessible style guide
628 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +0000629
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000630Examples
631========
632
633A style similar to the `Linux Kernel style
634<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
635
636.. code-block:: yaml
637
638 BasedOnStyle: LLVM
639 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +0000640 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000641 BreakBeforeBraces: Linux
642 AllowShortIfStatementsOnASingleLine: false
643 IndentCaseLabels: false
644
645The result is (imagine that tabs are used for indentation here):
646
647.. code-block:: c++
648
649 void test()
650 {
651 switch (x) {
652 case 0:
653 case 1:
654 do_something();
655 break;
656 case 2:
657 do_something_else();
658 break;
659 default:
660 break;
661 }
662 if (condition)
663 do_something_completely_different();
664
665 if (x == y) {
666 q();
667 } else if (x > y) {
668 w();
669 } else {
670 r();
671 }
672 }
673
674A style similar to the default Visual Studio formatting style:
675
676.. code-block:: yaml
677
Alexander Kornienko8ba68f62013-09-27 16:19:25 +0000678 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000679 IndentWidth: 4
680 BreakBeforeBraces: Allman
681 AllowShortIfStatementsOnASingleLine: false
682 IndentCaseLabels: false
683 ColumnLimit: 0
684
685The result is:
686
687.. code-block:: c++
688
689 void test()
690 {
691 switch (suffix)
692 {
693 case 0:
694 case 1:
695 do_something();
696 break;
697 case 2:
698 do_something_else();
699 break;
700 default:
701 break;
702 }
703 if (condition)
704 do_somthing_completely_different();
705
706 if (x == y)
707 {
708 q();
709 }
710 else if (x > y)
711 {
712 w();
713 }
714 else
715 {
716 r();
717 }
718 }
719