-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
ClangFormatStyleOptions.rst
Ignoring revisions in .git-blame-ignore-revs.
6942 lines (4867 loc) · 182 KB
1
2
3
4
5
6
..
!!!!NOTE!!!!
This file is automatically generated, in part. Do not edit the style options
in this file directly. Instead, modify them in include/clang/Format/Format.h
and run the docs/tools/dump_format_style.py script to update this file.
7
8
9
.. raw:: html
<style type="text/css">
10
.versionbadge { background-color: #1c913d; height: 20px; display: inline-block; min-width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family: "Verdana,Geneva,DejaVu Sans,sans-serif"; }
11
12
13
14
</style>
.. role:: versionbadge
15
16
17
18
19
20
21
22
23
==========================
Clang-Format Style Options
==========================
:doc:`ClangFormatStyleOptions` describes configurable formatting style options
supported by :doc:`LibFormat` and :doc:`ClangFormat`.
When using :program:`clang-format` command line utility or
``clang::format::reformat(...)`` functions from code, one can either use one of
24
25
the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
create a custom style by configuring specific style options.
26
27
28
29
30
31
32
Configuring Style with clang-format
===================================
:program:`clang-format` supports two ways to provide custom style options:
directly specify style configuration in the ``-style=`` command line option or
33
34
use ``-style=file`` and put style configuration in the ``.clang-format`` or
``_clang-format`` file in the project directory.
35
36
37
38
39
40
When using ``-style=file``, :program:`clang-format` for each input file will
try to find the ``.clang-format`` file located in the closest parent directory
of the input file. When the standard input is used, the search is started from
the current directory.
41
42
43
44
When using ``-style=file:<format_file_path>``, :program:`clang-format` for
each input file will use the format file located at `<format_file_path>`.
The path may be absolute or relative to the working directory.
45
46
47
48
49
50
51
52
53
The ``.clang-format`` file uses YAML format:
.. code-block:: yaml
key1: value1
key2: value2
# A comment.
...
54
55
56
57
The configuration file can consist of several sections each having different
``Language:`` parameter denoting the programming language this section of the
configuration is targeted at. See the description of the **Language** option
below for the list of supported languages. The first section may have no
58
language set, it will set the default style options for all languages.
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Configuration sections for specific language will override options set in the
default section.
When :program:`clang-format` formats a file, it auto-detects the language using
the file name. When formatting standard input or a file that doesn't have the
extension corresponding to its language, ``-assume-filename=`` option can be
used to override the file name :program:`clang-format` uses to detect the
language.
An example of a configuration file for multiple languages:
.. code-block:: yaml
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
89
90
91
92
---
Language: CSharp
# Use 100 columns for C#.
ColumnLimit: 100
93
94
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
An easy way to get a valid ``.clang-format`` file containing all configuration
options of a certain predefined style is:
.. code-block:: console
clang-format -style=llvm -dump-config > .clang-format
When specifying configuration in the ``-style=`` option, the same configuration
is applied for all input files. The format of the configuration is:
.. code-block:: console
-style='{key1: value1, key2: value2, ...}'
110
111
112
113
114
115
Disabling Formatting on a Piece of Code
=======================================
Clang-format understands also special comments that switch formatting in a
delimited range. The code between a comment ``// clang-format off`` or
``/* clang-format off */`` up to a comment ``// clang-format on`` or
116
117
``/* clang-format on */`` will not be formatted. The comments themselves will be
formatted (aligned) normally. Also, a colon (``:``) and additional text may
118
follow ``// clang-format off`` or ``// clang-format on`` to explain why
119
clang-format is turned off or back on.
120
121
122
123
124
125
126
127
128
129
.. code-block:: c++
int formatted_code;
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
130
131
132
133
134
Configuring Style in Code
=========================
When using ``clang::format::reformat(...)`` functions, the format is specified
by supplying the `clang::format::FormatStyle
135
<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
136
137
138
139
140
141
142
143
structure.
Configurable Format Style Options
=================================
This section lists the supported style options. Value type is specified for
each option. For enumeration types possible values are specified both as a C++
144
145
enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
the configuration (without a prefix: ``Auto``).
146
147
.. _BasedOnStyle:
148
149
**BasedOnStyle** (``String``) :ref:`¶ <BasedOnStyle>`
150
151
152
153
154
155
156
157
158
The style used for all options not specifically set in the configuration.
This option is supported only in the :program:`clang-format` configuration
(both within ``-style='{...}'`` and the ``.clang-format`` file).
Possible values:
* ``LLVM``
A style complying with the `LLVM coding standards
159
<https://llvm.org/docs/CodingStandards.html>`_
160
161
* ``Google``
A style complying with `Google's C++ style guide
162
<https://google.github.io/styleguide/cppguide.html>`_
163
164
* ``Chromium``
A style complying with `Chromium's style guide
165
<https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_
166
167
* ``Mozilla``
A style complying with `Mozilla's style guide
168
<https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_
169
170
* ``WebKit``
A style complying with `WebKit's style guide
171
<https://www.webkit.org/coding/coding-style.html>`_
172
173
* ``Microsoft``
A style complying with `Microsoft's style guide
174
<https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_
175
176
177
* ``GNU``
A style complying with the `GNU coding standards
<https://www.gnu.org/prep/standards/standards.html>`_
178
179
180
181
182
183
184
185
186
* ``InheritParentConfig``
Not a real style, but allows to use the ``.clang-format`` file from the
parent directory (or its parent if there is none). If there is no parent
file found it falls back to the ``fallback`` style, and applies the changes
to that.
With this option you can overwrite some parts of your main style for your
subdirectories. This is also possible through the command line, e.g.:
``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``
187
188
189
.. START_FORMAT_STYLE_OPTIONS
190
191
192
.. _AccessModifierOffset:
**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`¶ <AccessModifierOffset>`
193
The extra indent or outdent of access modifiers, e.g. ``public:``.
194
195
196
197
.. _AlignAfterOpenBracket:
**AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignAfterOpenBracket>`
198
199
200
If ``true``, horizontally aligns arguments after an open bracket.
This applies to round brackets (parentheses), angle brackets and square
201
brackets.
202
203
204
205
206
207
208
209
210
211
Possible values:
* ``BAS_Align`` (in configuration: ``Align``)
Align parameters on the open bracket, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
212
213
214
215
216
217
218
219
* ``BAS_DontAlign`` (in configuration: ``DontAlign``)
Don't align, instead use ``ContinuationIndentWidth``, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
220
221
222
223
224
225
226
227
228
* ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
Always break after an open bracket, if the parameters don't fit
on a single line, e.g.:
.. code-block:: c++
someLongFunction(
argument1, argument2);
229
230
231
232
233
234
235
236
237
238
239
240
241
* ``BAS_BlockIndent`` (in configuration: ``BlockIndent``)
Always break after an open bracket, if the parameters don't fit
on a single line. Closing brackets will be placed on a new line.
E.g.:
.. code-block:: c++
someLongFunction(
argument1, argument2
)
242
.. note::
243
244
245
This currently only applies to braced initializer lists (when
``Cpp11BracedListStyle`` is ``true``) and parentheses.
246
247
248
249
250
251
.. _AlignArrayOfStructures:
**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>`
252
If not ``None``, when using initialization for an array of structs
253
254
aligns the fields into columns.
255
256
257
258
259
.. note::
As of clang-format 15 this option only applied to arrays with equal
number of columns per row.
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
Possible values:
* ``AIAS_Left`` (in configuration: ``Left``)
Align array column and left justify the columns e.g.:
.. code-block:: c++
struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{7, 5, "!!" }
};
* ``AIAS_Right`` (in configuration: ``Right``)
Align array column and right justify the columns e.g.:
.. code-block:: c++
struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{ 7, 5, "!!"}
};
* ``AIAS_None`` (in configuration: ``None``)
Don't align array initializer columns.
292
293
294
.. _AlignConsecutiveAssignments:
**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveAssignments>`
295
Style of aligning consecutive assignments.
296
297
``Consecutive`` will result in formattings like:
298
299
.. code-block:: c++
300
301
302
303
int a = 1;
int somelongname = 2;
double c = 3;
304
305
306
307
308
309
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
310
311
312
313
314
315
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
316
317
318
319
320
321
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
322
AlignConsecutiveAssignments: AcrossEmptyLines
323
324
AlignConsecutiveAssignments:
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
342
343
344
345
int aaaa : 1;
int b : 12;
int ccc : 8;
346
347
348
349
int aaaa = 12;
float b = 23;
std::string ccc;
350
351
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
352
353
.. code-block:: c++
354
355
356
357
358
true:
int a = 1;
int somelongname = 2;
double c = 3;
359
360
int d = 3;
361
362
363
364
365
false:
int a = 1;
int somelongname = 2;
double c = 3;
366
367
int d = 3;
368
369
* ``bool AcrossComments`` Whether to align across comments.
370
371
.. code-block:: c++
372
373
374
375
376
true:
int d = 3;
/* A comment. */
double e = 4;
377
378
379
380
381
false:
int d = 3;
/* A comment. */
double e = 4;
382
383
384
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
385
386
387
388
389
390
391
392
393
394
395
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
428
429
430
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
431
432
433
434
435
436
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
437
438
439
a = 2;
bbb >>= 2;
440
441
442
443
false:
a >>= 2;
bbb = 2;
444
445
446
a = 2;
bbb >>= 2;
447
448
449
450
451
.. _AlignConsecutiveBitFields:
**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`¶ <AlignConsecutiveBitFields>`
452
Style of aligning consecutive bit fields.
453
454
455
``Consecutive`` will align the bitfield separators of consecutive lines.
This will result in formattings like:
456
457
458
459
460
461
462
.. code-block:: c++
int aaaa : 1;
int b : 12;
int ccc : 8;
463
464
465
466
467
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
468
469
470
471
472
473
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
474
475
476
477
478
479
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
480
AlignConsecutiveBitFields: AcrossEmptyLines
481
482
AlignConsecutiveBitFields:
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
500
501
502
503
int aaaa : 1;
int b : 12;
int ccc : 8;
504
505
506
507
int aaaa = 12;
float b = 23;
std::string ccc;
508
509
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
510
511
.. code-block:: c++
512
513
514
515
516
true:
int a = 1;
int somelongname = 2;
double c = 3;
517
518
int d = 3;
519
520
521
522
523
false:
int a = 1;
int somelongname = 2;
double c = 3;
524
525
int d = 3;
526
527
* ``bool AcrossComments`` Whether to align across comments.
528
529
.. code-block:: c++
530
531
532
533
534
true:
int d = 3;
/* A comment. */
double e = 4;
535
536
537
538
539
false:
int d = 3;
/* A comment. */
double e = 4;
540
541
542
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
543
544
545
546
547
548
549
550
551
552
553
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
586
587
588
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
589
590
591
592
593
594
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
595
596
597
a = 2;
bbb >>= 2;
598
599
600
601
false:
a >>= 2;
bbb = 2;
602
603
604
a = 2;
bbb >>= 2;
605
606
607
608
609
.. _AlignConsecutiveDeclarations:
**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveDeclarations>`
610
Style of aligning consecutive declarations.
611
612
613
``Consecutive`` will align the declaration names of consecutive lines.
This will result in formattings like:
614
615
.. code-block:: c++
616
617
618
int aaaa = 12;
float b = 23;
619
std::string ccc;
620
621
622
623
624
625
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
626
627
628
629
630
631
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
632
633
634
635
636
637
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
638
AlignConsecutiveDeclarations: AcrossEmptyLines
639
640
AlignConsecutiveDeclarations:
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
658
659
660
661
int aaaa : 1;
int b : 12;
int ccc : 8;
662
663
664
665
int aaaa = 12;
float b = 23;
std::string ccc;
666
667
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
668
669
.. code-block:: c++
670
671
672
673
674
true:
int a = 1;
int somelongname = 2;
double c = 3;
675
676
int d = 3;
677
678
679
680
681
false:
int a = 1;
int somelongname = 2;
double c = 3;
682
683
int d = 3;
684
685
* ``bool AcrossComments`` Whether to align across comments.
686
687
.. code-block:: c++
688
689
690
691
692
true:
int d = 3;
/* A comment. */
double e = 4;
693
694
695
696
697
false:
int d = 3;
/* A comment. */
double e = 4;
698
699
700
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
701
702
703
704
705
706
707
708
709
710
711
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
744
745
746
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
747
748
749
750
751
752
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
753
754
755
a = 2;
bbb >>= 2;
756
757
758
759
false:
a >>= 2;
bbb = 2;
760
761
762
a = 2;
bbb >>= 2;
763
764
765
766
767
.. _AlignConsecutiveMacros:
**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AlignConsecutiveMacros>`
768
Style of aligning consecutive macro definitions.
769
770
``Consecutive`` will result in formattings like:
771
772
773
774
775
776
777
778
779
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
780
781
782
783
784
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
785
786
787
788
789
790
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
AlignConsecutiveMacros: AcrossEmptyLines
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
817
818
819
820
int aaaa : 1;
int b : 12;
int ccc : 8;
821
822
823
824
int aaaa = 12;
float b = 23;
std::string ccc;
825
826
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
827
828
.. code-block:: c++
829
830
831
832
833
true:
int a = 1;
int somelongname = 2;
double c = 3;
834
835
int d = 3;
836
837
838
839
840
false:
int a = 1;
int somelongname = 2;
double c = 3;
841
842
int d = 3;
843
844
* ``bool AcrossComments`` Whether to align across comments.
845
846
.. code-block:: c++
847
848
849
850
851
true:
int d = 3;
/* A comment. */
double e = 4;
852
853
854
855
856
false:
int d = 3;
/* A comment. */
double e = 4;
857
858
859
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
860
861
862
863
864
865
866
867
868
869
870
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
903
904
905
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
906
907
908
909
910
911
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
912
913
914
a = 2;
bbb >>= 2;
915
916
917
918
false:
a >>= 2;
bbb = 2;
919
920
921
a = 2;
bbb >>= 2;
922
923
924
925
926
927
.. _AlignConsecutiveShortCaseStatements:
**AlignConsecutiveShortCaseStatements** (``ShortCaseStatementsAlignmentStyle``) :versionbadge:`clang-format 17` :ref:`¶ <AlignConsecutiveShortCaseStatements>`
Style of aligning consecutive short case labels.
928
929
Only applies if ``AllowShortCaseExpressionOnASingleLine`` or
``AllowShortCaseLabelsOnASingleLine`` is ``true``.
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. code-block:: yaml
# Example of usage:
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
Nested configuration flags:
Alignment options.
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
* ``bool AcrossComments`` Whether to align across comments.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
/* A comment. */
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
/* A comment. */
default: return "";